@semiont/api-client 0.2.45 → 0.2.46
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/README.md +44 -6
- package/dist/index.d.ts +115 -11
- package/dist/index.js +318 -54
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +3 -33
- package/dist/utils/index.js +2 -38
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -8,7 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
TypeScript SDK for [Semiont](https://github.com/The-AI-Alliance/semiont) - a knowledge management system for semantic annotations, AI-powered annotation detection, and collaborative document analysis.
|
|
10
10
|
|
|
11
|
-
This package provides
|
|
11
|
+
This package provides two clients, SSE streams, and utilities for working with Semiont:
|
|
12
|
+
|
|
13
|
+
- **`SemiontApiClient`** — HTTP client for the Semiont REST API
|
|
14
|
+
- **`EventBusClient`** — Direct EventBus client (no HTTP needed)
|
|
15
|
+
|
|
16
|
+
OpenAPI types are re-exported from [`@semiont/core`](../core/README.md) (the source of truth).
|
|
12
17
|
|
|
13
18
|
## What is Semiont?
|
|
14
19
|
|
|
@@ -74,6 +79,34 @@ const annotations = await client.getResourceAnnotations(resourceUri(resource['@i
|
|
|
74
79
|
console.log('Annotations:', annotations.annotations.length);
|
|
75
80
|
```
|
|
76
81
|
|
|
82
|
+
## EventBus Client (No HTTP)
|
|
83
|
+
|
|
84
|
+
The `EventBusClient` communicates directly via the RxJS EventBus — no HTTP server needed. It covers all knowledge-domain operations (resource reads, annotations, entity types, search, LLM context, clone tokens, job status).
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { EventBusClient } from '@semiont/api-client';
|
|
88
|
+
import { EventBus, resourceId } from '@semiont/core';
|
|
89
|
+
import { startMakeMeaning } from '@semiont/make-meaning';
|
|
90
|
+
|
|
91
|
+
// Start the knowledge system
|
|
92
|
+
const eventBus = new EventBus();
|
|
93
|
+
const makeMeaning = await startMakeMeaning(config, eventBus, logger);
|
|
94
|
+
|
|
95
|
+
// Use EventBusClient instead of SemiontApiClient
|
|
96
|
+
const client = new EventBusClient(eventBus);
|
|
97
|
+
|
|
98
|
+
// Same operations, no HTTP
|
|
99
|
+
const resources = await client.listResources({ limit: 10 });
|
|
100
|
+
const resource = await client.getResource(resourceId('doc-123'));
|
|
101
|
+
const annotations = await client.getAnnotations(resourceId('doc-123'));
|
|
102
|
+
const entityTypes = await client.listEntityTypes();
|
|
103
|
+
const results = await client.searchResources('quantum computing');
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**What's covered**: All browse, bind, mark, gather, yield (clone), and job operations.
|
|
107
|
+
|
|
108
|
+
**What's NOT covered** (HTTP-only): Auth, admin, health/status, binary content upload/download, SSE streaming.
|
|
109
|
+
|
|
77
110
|
## Logging
|
|
78
111
|
|
|
79
112
|
Enable logging to debug requests and monitor API usage:
|
|
@@ -112,6 +145,7 @@ const client = new SemiontApiClient({
|
|
|
112
145
|
|
|
113
146
|
## Key Features
|
|
114
147
|
|
|
148
|
+
- **Two clients** - HTTP (`SemiontApiClient`) and EventBus (`EventBusClient`) for the same operations
|
|
115
149
|
- **Type-safe** - Re-exports OpenAPI types from `@semiont/core` with branded types
|
|
116
150
|
- **W3C compliant** - Web Annotation standard with fuzzy text matching
|
|
117
151
|
- **Real-time** - SSE streaming for long operations
|
|
@@ -122,12 +156,16 @@ const client = new SemiontApiClient({
|
|
|
122
156
|
|
|
123
157
|
## Use Cases
|
|
124
158
|
|
|
125
|
-
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
-
|
|
159
|
+
**SemiontApiClient (HTTP)**:
|
|
160
|
+
- MCP servers and AI integrations
|
|
161
|
+
- Frontend applications (wrap with React hooks)
|
|
162
|
+
- CLI tools and automation scripts
|
|
163
|
+
- Third-party integrations
|
|
129
164
|
|
|
130
|
-
|
|
165
|
+
**EventBusClient (direct)**:
|
|
166
|
+
- Scripts that run alongside make-meaning (no HTTP server)
|
|
167
|
+
- Testing without HTTP overhead
|
|
168
|
+
- Embedded scenarios where EventBus is available directly
|
|
131
169
|
|
|
132
170
|
## License
|
|
133
171
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 } from '@semiont/core';
|
|
3
|
-
export { Logger } from '@semiont/core';
|
|
4
|
-
export { BoundingBox, ContentCache, FragmentSelector, JWTTokenSchema, LOCALES, LocaleInfo, MatchQuality, Point,
|
|
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';
|
|
3
|
+
export { Logger, Selector, getFragmentSelector, getSvgSelector, getTextPositionSelector, validateSvgMarkup } from '@semiont/core';
|
|
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
|
|
|
6
6
|
/**
|
|
7
7
|
* TypeScript types for Server-Sent Events (SSE) streaming
|
|
@@ -505,6 +505,33 @@ declare class SSEClient {
|
|
|
505
505
|
resourceEvents(resourceId: ResourceUri, options: SSERequestOptions & {
|
|
506
506
|
onConnected?: () => void;
|
|
507
507
|
}): SSEStream;
|
|
508
|
+
/**
|
|
509
|
+
* Subscribe to global system events (long-lived stream)
|
|
510
|
+
*
|
|
511
|
+
* Opens a long-lived SSE connection to receive system-level domain events
|
|
512
|
+
* (entity type additions, etc.) that are not scoped to a specific resource.
|
|
513
|
+
*
|
|
514
|
+
* @param options - Request options (auth token, eventBus)
|
|
515
|
+
* @returns SSE stream controller
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```typescript
|
|
519
|
+
* const stream = sseClient.globalEvents({ auth: 'your-token', eventBus });
|
|
520
|
+
*
|
|
521
|
+
* // Events auto-emit to EventBus — subscribe there
|
|
522
|
+
* eventBus.get('make-meaning:event').subscribe((event) => {
|
|
523
|
+
* if (event.type === 'entitytype.added') {
|
|
524
|
+
* // Invalidate entity types query
|
|
525
|
+
* }
|
|
526
|
+
* });
|
|
527
|
+
*
|
|
528
|
+
* // Close when no longer needed
|
|
529
|
+
* stream.close();
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
globalEvents(options: SSERequestOptions & {
|
|
533
|
+
onConnected?: () => void;
|
|
534
|
+
}): SSEStream;
|
|
508
535
|
}
|
|
509
536
|
|
|
510
537
|
/**
|
|
@@ -622,7 +649,9 @@ declare class SemiontApiClient {
|
|
|
622
649
|
creationMethod?: string;
|
|
623
650
|
sourceAnnotationId?: string;
|
|
624
651
|
sourceResourceId?: string;
|
|
625
|
-
}, options?: RequestOptions): Promise<
|
|
652
|
+
}, options?: RequestOptions): Promise<{
|
|
653
|
+
resourceId: string;
|
|
654
|
+
}>;
|
|
626
655
|
getResource(resourceUri: ResourceUri, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}']['get']>>;
|
|
627
656
|
/**
|
|
628
657
|
* Get resource representation using W3C content negotiation
|
|
@@ -697,7 +726,7 @@ declare class SemiontApiClient {
|
|
|
697
726
|
contentType: string;
|
|
698
727
|
}>;
|
|
699
728
|
listResources(limit?: number, archived?: boolean, query?: SearchQuery, options?: RequestOptions): Promise<ResponseContent<paths['/resources']['get']>>;
|
|
700
|
-
updateResource(resourceUri: ResourceUri, data: RequestContent<paths['/resources/{id}']['patch']>, options?: RequestOptions): Promise<
|
|
729
|
+
updateResource(resourceUri: ResourceUri, data: RequestContent<paths['/resources/{id}']['patch']>, options?: RequestOptions): Promise<void>;
|
|
701
730
|
getResourceEvents(resourceUri: ResourceUri, options?: RequestOptions): Promise<{
|
|
702
731
|
events: any[];
|
|
703
732
|
}>;
|
|
@@ -711,16 +740,20 @@ declare class SemiontApiClient {
|
|
|
711
740
|
}>;
|
|
712
741
|
generateCloneToken(resourceUri: ResourceUri, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}/clone-with-token']['post']>>;
|
|
713
742
|
getResourceByToken(token: CloneToken, options?: RequestOptions): Promise<ResponseContent<paths['/api/clone-tokens/{token}']['get']>>;
|
|
714
|
-
createResourceFromToken(data: RequestContent<paths['/api/clone-tokens/create-resource']['post']>, options?: RequestOptions): Promise<
|
|
715
|
-
|
|
743
|
+
createResourceFromToken(data: RequestContent<paths['/api/clone-tokens/create-resource']['post']>, options?: RequestOptions): Promise<{
|
|
744
|
+
resourceId: string;
|
|
745
|
+
}>;
|
|
746
|
+
createAnnotation(resourceUri: ResourceUri, data: RequestContent<paths['/resources/{id}/annotations']['post']>, options?: RequestOptions): Promise<{
|
|
747
|
+
annotationId: string;
|
|
748
|
+
}>;
|
|
716
749
|
getAnnotation(annotationUri: AnnotationUri, options?: RequestOptions): Promise<ResponseContent<paths['/annotations/{id}']['get']>>;
|
|
717
750
|
getResourceAnnotation(annotationUri: ResourceAnnotationUri, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{resourceId}/annotations/{annotationId}']['get']>>;
|
|
718
751
|
listAnnotations(resourceUri: ResourceUri, motivation?: Motivation, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}/annotations']['get']>>;
|
|
719
752
|
deleteAnnotation(annotationUri: ResourceAnnotationUri, options?: RequestOptions): Promise<void>;
|
|
720
|
-
updateAnnotationBody(annotationUri: ResourceAnnotationUri, data: RequestContent<paths['/resources/{resourceId}/annotations/{annotationId}/body']['put']>, options?: RequestOptions): Promise<
|
|
753
|
+
updateAnnotationBody(annotationUri: ResourceAnnotationUri, data: RequestContent<paths['/resources/{resourceId}/annotations/{annotationId}/body']['put']>, options?: RequestOptions): Promise<void>;
|
|
721
754
|
getAnnotationHistory(annotationUri: ResourceAnnotationUri, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{resourceId}/annotations/{annotationId}/history']['get']>>;
|
|
722
|
-
addEntityType(type: EntityType, options?: RequestOptions): Promise<
|
|
723
|
-
addEntityTypesBulk(types: EntityType[], options?: RequestOptions): Promise<
|
|
755
|
+
addEntityType(type: EntityType, options?: RequestOptions): Promise<void>;
|
|
756
|
+
addEntityTypesBulk(types: EntityType[], options?: RequestOptions): Promise<void>;
|
|
724
757
|
listEntityTypes(options?: RequestOptions): Promise<ResponseContent<paths['/api/entity-types']['get']>>;
|
|
725
758
|
listUsers(options?: RequestOptions): Promise<ResponseContent<paths['/api/admin/users']['get']>>;
|
|
726
759
|
getUserStats(options?: RequestOptions): Promise<ResponseContent<paths['/api/admin/users/stats']['get']>>;
|
|
@@ -754,6 +787,77 @@ declare class SemiontApiClient {
|
|
|
754
787
|
getStatus(options?: RequestOptions): Promise<ResponseContent<paths['/api/status']['get']>>;
|
|
755
788
|
}
|
|
756
789
|
|
|
790
|
+
/**
|
|
791
|
+
* EventBus-Only Client
|
|
792
|
+
*
|
|
793
|
+
* Implements the same knowledge-domain operations as SemiontApiClient
|
|
794
|
+
* but communicates directly via EventBus instead of HTTP.
|
|
795
|
+
*
|
|
796
|
+
* This proves the EventBus is a complete interface for all knowledge-domain
|
|
797
|
+
* operations. Binary content transfer and auth/admin stay HTTP-only.
|
|
798
|
+
*
|
|
799
|
+
* Usage:
|
|
800
|
+
* ```typescript
|
|
801
|
+
* import { EventBus } from '@semiont/core';
|
|
802
|
+
* import { EventBusClient } from '@semiont/api-client';
|
|
803
|
+
*
|
|
804
|
+
* const eventBus = new EventBus();
|
|
805
|
+
* const client = new EventBusClient(eventBus);
|
|
806
|
+
*
|
|
807
|
+
* const resources = await client.listResources({ limit: 10 });
|
|
808
|
+
* const resource = await client.getResource(resourceId('doc-123'));
|
|
809
|
+
* ```
|
|
810
|
+
*/
|
|
811
|
+
|
|
812
|
+
declare class EventBusClient {
|
|
813
|
+
private eventBus;
|
|
814
|
+
private timeoutMs;
|
|
815
|
+
constructor(eventBus: EventBus, timeoutMs?: number);
|
|
816
|
+
getResource(resourceId: ResourceId): Promise<components['schemas']['GetResourceResponse']>;
|
|
817
|
+
listResources(options?: {
|
|
818
|
+
search?: string;
|
|
819
|
+
archived?: boolean;
|
|
820
|
+
entityType?: string;
|
|
821
|
+
offset?: number;
|
|
822
|
+
limit?: number;
|
|
823
|
+
}): Promise<components['schemas']['ListResourcesResponse']>;
|
|
824
|
+
getAnnotations(resourceId: ResourceId): Promise<components['schemas']['GetAnnotationsResponse']>;
|
|
825
|
+
getAnnotation(resourceId: ResourceId, annotationId: AnnotationId): Promise<components['schemas']['GetAnnotationResponse']>;
|
|
826
|
+
getEvents(resourceId: ResourceId, options?: {
|
|
827
|
+
type?: string;
|
|
828
|
+
userId?: string;
|
|
829
|
+
limit?: number;
|
|
830
|
+
}): Promise<components['schemas']['GetEventsResponse']>;
|
|
831
|
+
getAnnotationHistory(resourceId: ResourceId, annotationId: AnnotationId): Promise<components['schemas']['GetAnnotationHistoryResponse']>;
|
|
832
|
+
getReferencedBy(resourceId: ResourceId, motivation?: string): Promise<components['schemas']['GetReferencedByResponse']>;
|
|
833
|
+
listEntityTypes(): Promise<components['schemas']['GetEntityTypesResponse']>;
|
|
834
|
+
addEntityType(tag: string, userId: UserId): void;
|
|
835
|
+
generateCloneToken(resourceId: ResourceId): Promise<components['schemas']['CloneResourceWithTokenResponse']>;
|
|
836
|
+
getResourceByToken(token: string): Promise<components['schemas']['GetResourceByTokenResponse']>;
|
|
837
|
+
createResourceFromToken(options: {
|
|
838
|
+
token: string;
|
|
839
|
+
name: string;
|
|
840
|
+
content: string;
|
|
841
|
+
userId: UserId;
|
|
842
|
+
archiveOriginal?: boolean;
|
|
843
|
+
}): Promise<{
|
|
844
|
+
resourceId: ResourceId;
|
|
845
|
+
}>;
|
|
846
|
+
getJobStatus(jobId: JobId): Promise<components['schemas']['JobStatusResponse']>;
|
|
847
|
+
getAnnotationLLMContext(annotationUri: string, resourceUri: string, options?: {
|
|
848
|
+
includeSourceContext?: boolean;
|
|
849
|
+
includeTargetContext?: boolean;
|
|
850
|
+
contextWindow?: number;
|
|
851
|
+
}): Promise<components['schemas']['AnnotationLLMContextResponse']>;
|
|
852
|
+
getResourceLLMContext(resourceUri: string, options: {
|
|
853
|
+
depth: number;
|
|
854
|
+
maxResources: number;
|
|
855
|
+
includeContent: boolean;
|
|
856
|
+
includeSummary: boolean;
|
|
857
|
+
}): Promise<components['schemas']['ResourceLLMContextResponse']>;
|
|
858
|
+
searchResources(searchTerm: string): Promise<components['schemas']['ResourceDescriptor'][]>;
|
|
859
|
+
}
|
|
860
|
+
|
|
757
861
|
/**
|
|
758
862
|
* MIME type utilities for Semiont
|
|
759
863
|
*
|
|
@@ -792,4 +896,4 @@ declare function isPdfMimeType(mimeType: string): boolean;
|
|
|
792
896
|
type MimeCategory = 'text' | 'image' | 'unsupported';
|
|
793
897
|
declare function getMimeCategory(mimeType: string): MimeCategory;
|
|
794
898
|
|
|
795
|
-
export { APIError, type AnnotateReferencesStreamRequest, 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 };
|
|
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 };
|