@semiont/api-client 0.2.34-build.88 → 0.2.34-build.90
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 +5 -1
- package/dist/index.d.ts +26 -207
- package/dist/index.js +52 -113
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +603 -1
- package/dist/utils/index.js +1 -7
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -7
- package/dist/index-CJqmerJr.d.ts +0 -3859
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
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 the HTTP client, SSE streams, and utilities for working with the Semiont API. OpenAPI types are re-exported from [`@semiont/core`](../core/README.md) (the source of truth).
|
|
12
|
+
|
|
11
13
|
## What is Semiont?
|
|
12
14
|
|
|
13
15
|
Semiont lets you:
|
|
@@ -110,12 +112,14 @@ const client = new SemiontApiClient({
|
|
|
110
112
|
|
|
111
113
|
## Key Features
|
|
112
114
|
|
|
113
|
-
- **Type-safe** -
|
|
115
|
+
- **Type-safe** - Re-exports OpenAPI types from `@semiont/core` with branded types
|
|
114
116
|
- **W3C compliant** - Web Annotation standard with fuzzy text matching
|
|
115
117
|
- **Real-time** - SSE streaming for long operations
|
|
116
118
|
- **Framework-agnostic** - Pure TypeScript utilities work everywhere
|
|
117
119
|
- **Character encoding** - Proper UTF-8, ISO-8859-1, Windows-1252 support
|
|
118
120
|
|
|
121
|
+
**Note**: OpenAPI types are generated in `@semiont/core` (source of truth) and re-exported here for convenience.
|
|
122
|
+
|
|
119
123
|
## Use Cases
|
|
120
124
|
|
|
121
125
|
- ✅ MCP servers and AI integrations
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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';
|
|
3
|
+
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';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* TypeScript types for Server-Sent Events (SSE) streaming
|
|
@@ -68,134 +69,6 @@ interface GenerationProgress {
|
|
|
68
69
|
/** Human-readable status message */
|
|
69
70
|
message?: string;
|
|
70
71
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Progress event for highlight detection stream
|
|
73
|
-
*
|
|
74
|
-
* Sent by POST /resources/:id/detect-highlights-stream
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```typescript
|
|
78
|
-
* stream.onProgress((progress: HighlightDetectionProgress) => {
|
|
79
|
-
* if (progress.status === 'analyzing') {
|
|
80
|
-
* console.log(`Analyzing: ${progress.percentage}%`);
|
|
81
|
-
* }
|
|
82
|
-
* });
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
interface HighlightDetectionProgress {
|
|
86
|
-
/** Current status of highlight detection operation */
|
|
87
|
-
status: 'started' | 'analyzing' | 'creating' | 'complete' | 'error';
|
|
88
|
-
/** Resource ID being analyzed */
|
|
89
|
-
resourceId: string;
|
|
90
|
-
/** Current stage of processing */
|
|
91
|
-
stage?: 'analyzing' | 'creating';
|
|
92
|
-
/** Percentage complete (0-100) */
|
|
93
|
-
percentage?: number;
|
|
94
|
-
/** Human-readable status message */
|
|
95
|
-
message?: string;
|
|
96
|
-
/** Total highlights found */
|
|
97
|
-
foundCount?: number;
|
|
98
|
-
/** Total highlights created */
|
|
99
|
-
createdCount?: number;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Progress event for assessment detection stream
|
|
103
|
-
*
|
|
104
|
-
* Sent by POST /resources/:id/detect-assessments-stream
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* stream.onProgress((progress: AssessmentDetectionProgress) => {
|
|
109
|
-
* if (progress.status === 'analyzing') {
|
|
110
|
-
* console.log(`Analyzing: ${progress.percentage}%`);
|
|
111
|
-
* }
|
|
112
|
-
* });
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
interface AssessmentDetectionProgress {
|
|
116
|
-
/** Current status of assessment detection operation */
|
|
117
|
-
status: 'started' | 'analyzing' | 'creating' | 'complete' | 'error';
|
|
118
|
-
/** Resource ID being analyzed */
|
|
119
|
-
resourceId: string;
|
|
120
|
-
/** Current stage of processing */
|
|
121
|
-
stage?: 'analyzing' | 'creating';
|
|
122
|
-
/** Percentage complete (0-100) */
|
|
123
|
-
percentage?: number;
|
|
124
|
-
/** Human-readable status message */
|
|
125
|
-
message?: string;
|
|
126
|
-
/** Total assessments found */
|
|
127
|
-
foundCount?: number;
|
|
128
|
-
/** Total assessments created */
|
|
129
|
-
createdCount?: number;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Progress event for comment detection stream
|
|
133
|
-
*
|
|
134
|
-
* Sent by POST /resources/:id/detect-comments-stream
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```typescript
|
|
138
|
-
* stream.onProgress((progress: CommentDetectionProgress) => {
|
|
139
|
-
* if (progress.status === 'analyzing') {
|
|
140
|
-
* console.log(`Analyzing: ${progress.percentage}%`);
|
|
141
|
-
* }
|
|
142
|
-
* });
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
interface CommentDetectionProgress {
|
|
146
|
-
/** Current status of comment detection operation */
|
|
147
|
-
status: 'started' | 'analyzing' | 'creating' | 'complete' | 'error';
|
|
148
|
-
/** Resource ID being analyzed */
|
|
149
|
-
resourceId: string;
|
|
150
|
-
/** Current stage of processing */
|
|
151
|
-
stage?: 'analyzing' | 'creating';
|
|
152
|
-
/** Percentage complete (0-100) */
|
|
153
|
-
percentage?: number;
|
|
154
|
-
/** Human-readable status message */
|
|
155
|
-
message?: string;
|
|
156
|
-
/** Total comments found */
|
|
157
|
-
foundCount?: number;
|
|
158
|
-
/** Total comments created */
|
|
159
|
-
createdCount?: number;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Progress event for tag detection stream
|
|
163
|
-
*
|
|
164
|
-
* Sent by POST /resources/:id/detect-tags-stream
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```typescript
|
|
168
|
-
* stream.onProgress((progress: TagDetectionProgress) => {
|
|
169
|
-
* if (progress.status === 'analyzing') {
|
|
170
|
-
* console.log(`Analyzing ${progress.currentCategory}: ${progress.percentage}%`);
|
|
171
|
-
* }
|
|
172
|
-
* });
|
|
173
|
-
* ```
|
|
174
|
-
*/
|
|
175
|
-
interface TagDetectionProgress {
|
|
176
|
-
/** Current status of tag detection operation */
|
|
177
|
-
status: 'started' | 'analyzing' | 'creating' | 'complete' | 'error';
|
|
178
|
-
/** Resource ID being analyzed */
|
|
179
|
-
resourceId: string;
|
|
180
|
-
/** Current stage of processing */
|
|
181
|
-
stage?: 'analyzing' | 'creating';
|
|
182
|
-
/** Percentage complete (0-100) */
|
|
183
|
-
percentage?: number;
|
|
184
|
-
/** Currently processing this category */
|
|
185
|
-
currentCategory?: string;
|
|
186
|
-
/** Number of categories processed */
|
|
187
|
-
processedCategories?: number;
|
|
188
|
-
/** Total number of categories */
|
|
189
|
-
totalCategories?: number;
|
|
190
|
-
/** Human-readable status message */
|
|
191
|
-
message?: string;
|
|
192
|
-
/** Total tags found */
|
|
193
|
-
tagsFound?: number;
|
|
194
|
-
/** Total tags created */
|
|
195
|
-
tagsCreated?: number;
|
|
196
|
-
/** Tags found by category */
|
|
197
|
-
byCategory?: Record<string, number>;
|
|
198
|
-
}
|
|
199
72
|
/**
|
|
200
73
|
* Resource event from real-time event stream
|
|
201
74
|
*
|
|
@@ -220,43 +93,28 @@ interface TagDetectionProgress {
|
|
|
220
93
|
/**
|
|
221
94
|
* SSE stream controller interface
|
|
222
95
|
*
|
|
223
|
-
* Returned by all SSE methods.
|
|
96
|
+
* Returned by all SSE methods. Events auto-emit to EventBus (required).
|
|
224
97
|
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
98
|
+
* **Architecture Note**: All SSE methods require `eventBus` in options to enforce
|
|
99
|
+
* event-driven architecture. This is enforced at compile time via TypeScript.
|
|
227
100
|
*
|
|
228
101
|
* @example
|
|
229
102
|
* ```typescript
|
|
230
|
-
* const
|
|
231
|
-
* client.sse.detectAnnotations(resourceId, { entityTypes: ['Person'] });
|
|
103
|
+
* const eventBus = new EventBus();
|
|
232
104
|
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
105
|
+
* // Subscribe to events
|
|
106
|
+
* eventBus.get('detection:progress').subscribe((p) => console.log(p.message));
|
|
107
|
+
* eventBus.get('detection:complete').subscribe(() => console.log('Done!'));
|
|
108
|
+
* eventBus.get('detection:failed').subscribe(({ error }) => console.error(error));
|
|
109
|
+
*
|
|
110
|
+
* // Start stream - eventBus is required (TypeScript enforced)
|
|
111
|
+
* const stream = client.sse.detectReferences(resourceId, request, { auth, eventBus });
|
|
236
112
|
*
|
|
237
113
|
* // Cleanup when done
|
|
238
114
|
* stream.close();
|
|
239
115
|
* ```
|
|
240
116
|
*/
|
|
241
|
-
interface SSEStream
|
|
242
|
-
/**
|
|
243
|
-
* Register callback for progress events
|
|
244
|
-
*
|
|
245
|
-
* Called for each progress update (e.g., detection-started, detection-progress)
|
|
246
|
-
*/
|
|
247
|
-
onProgress(callback: (progress: TProgress) => void): void;
|
|
248
|
-
/**
|
|
249
|
-
* Register callback for completion event
|
|
250
|
-
*
|
|
251
|
-
* Called once when operation completes successfully (e.g., detection-complete)
|
|
252
|
-
*/
|
|
253
|
-
onComplete(callback: (result: TComplete) => void): void;
|
|
254
|
-
/**
|
|
255
|
-
* Register callback for error events
|
|
256
|
-
*
|
|
257
|
-
* Called if operation fails or stream encounters an error
|
|
258
|
-
*/
|
|
259
|
-
onError(callback: (error: Error) => void): void;
|
|
117
|
+
interface SSEStream {
|
|
260
118
|
/**
|
|
261
119
|
* Close the SSE stream and abort the connection
|
|
262
120
|
*
|
|
@@ -267,7 +125,7 @@ interface SSEStream<TProgress, TComplete> {
|
|
|
267
125
|
* ```typescript
|
|
268
126
|
* // React cleanup
|
|
269
127
|
* useEffect(() => {
|
|
270
|
-
* const stream = client.sse.
|
|
128
|
+
* const stream = client.sse.detectReferences(..., { auth, eventBus });
|
|
271
129
|
* return () => stream.close();
|
|
272
130
|
* }, []);
|
|
273
131
|
* ```
|
|
@@ -303,13 +161,6 @@ interface Logger {
|
|
|
303
161
|
error(message: string, meta?: any): void;
|
|
304
162
|
}
|
|
305
163
|
|
|
306
|
-
/**
|
|
307
|
-
* SSE Client for Semiont Streaming Endpoints
|
|
308
|
-
*
|
|
309
|
-
* Provides type-safe methods for Server-Sent Events streaming.
|
|
310
|
-
* Does NOT use ky - uses native fetch() for SSE support.
|
|
311
|
-
*/
|
|
312
|
-
|
|
313
164
|
/**
|
|
314
165
|
* Request body for reference detection stream
|
|
315
166
|
*/
|
|
@@ -367,6 +218,8 @@ interface SSEClientConfig {
|
|
|
367
218
|
*/
|
|
368
219
|
interface SSERequestOptions {
|
|
369
220
|
auth?: AccessToken;
|
|
221
|
+
/** EventBus for event-driven architecture (required) */
|
|
222
|
+
eventBus: _semiont_core.EventBus;
|
|
370
223
|
}
|
|
371
224
|
/**
|
|
372
225
|
* SSE Client for real-time streaming operations
|
|
@@ -444,7 +297,7 @@ declare class SSEClient {
|
|
|
444
297
|
* stream.close();
|
|
445
298
|
* ```
|
|
446
299
|
*/
|
|
447
|
-
detectReferences(resourceId: ResourceUri, request: DetectReferencesStreamRequest, options?: SSERequestOptions): SSEStream
|
|
300
|
+
detectReferences(resourceId: ResourceUri, request: DetectReferencesStreamRequest, options?: SSERequestOptions): SSEStream;
|
|
448
301
|
/**
|
|
449
302
|
* Generate resource from annotation (streaming)
|
|
450
303
|
*
|
|
@@ -482,7 +335,7 @@ declare class SSEClient {
|
|
|
482
335
|
* stream.close();
|
|
483
336
|
* ```
|
|
484
337
|
*/
|
|
485
|
-
generateResourceFromAnnotation(resourceId: ResourceUri, annotationId: AnnotationUri, request: GenerateResourceStreamRequest, options?: SSERequestOptions): SSEStream
|
|
338
|
+
generateResourceFromAnnotation(resourceId: ResourceUri, annotationId: AnnotationUri, request: GenerateResourceStreamRequest, options?: SSERequestOptions): SSEStream;
|
|
486
339
|
/**
|
|
487
340
|
* Detect highlights in a resource (streaming)
|
|
488
341
|
*
|
|
@@ -518,7 +371,7 @@ declare class SSEClient {
|
|
|
518
371
|
* stream.close();
|
|
519
372
|
* ```
|
|
520
373
|
*/
|
|
521
|
-
detectHighlights(resourceId: ResourceUri, request?: DetectHighlightsStreamRequest, options?: SSERequestOptions): SSEStream
|
|
374
|
+
detectHighlights(resourceId: ResourceUri, request?: DetectHighlightsStreamRequest, options?: SSERequestOptions): SSEStream;
|
|
522
375
|
/**
|
|
523
376
|
* Detect assessments in a resource (streaming)
|
|
524
377
|
*
|
|
@@ -554,7 +407,7 @@ declare class SSEClient {
|
|
|
554
407
|
* stream.close();
|
|
555
408
|
* ```
|
|
556
409
|
*/
|
|
557
|
-
detectAssessments(resourceId: ResourceUri, request?: DetectAssessmentsStreamRequest, options?: SSERequestOptions): SSEStream
|
|
410
|
+
detectAssessments(resourceId: ResourceUri, request?: DetectAssessmentsStreamRequest, options?: SSERequestOptions): SSEStream;
|
|
558
411
|
/**
|
|
559
412
|
* Detect comments in a resource (streaming)
|
|
560
413
|
*
|
|
@@ -594,7 +447,7 @@ declare class SSEClient {
|
|
|
594
447
|
* stream.close();
|
|
595
448
|
* ```
|
|
596
449
|
*/
|
|
597
|
-
detectComments(resourceId: ResourceUri, request?: DetectCommentsStreamRequest, options?: SSERequestOptions): SSEStream
|
|
450
|
+
detectComments(resourceId: ResourceUri, request?: DetectCommentsStreamRequest, options?: SSERequestOptions): SSEStream;
|
|
598
451
|
/**
|
|
599
452
|
* Detect tags in a resource (streaming)
|
|
600
453
|
*
|
|
@@ -635,7 +488,7 @@ declare class SSEClient {
|
|
|
635
488
|
* stream.close();
|
|
636
489
|
* ```
|
|
637
490
|
*/
|
|
638
|
-
detectTags(resourceId: ResourceUri, request: DetectTagsStreamRequest, options?: SSERequestOptions): SSEStream
|
|
491
|
+
detectTags(resourceId: ResourceUri, request: DetectTagsStreamRequest, options?: SSERequestOptions): SSEStream;
|
|
639
492
|
/**
|
|
640
493
|
* Subscribe to resource events (long-lived stream)
|
|
641
494
|
*
|
|
@@ -672,7 +525,7 @@ declare class SSEClient {
|
|
|
672
525
|
*/
|
|
673
526
|
resourceEvents(resourceId: ResourceUri, options?: SSERequestOptions & {
|
|
674
527
|
onConnected?: () => void;
|
|
675
|
-
}): SSEStream
|
|
528
|
+
}): SSEStream;
|
|
676
529
|
}
|
|
677
530
|
|
|
678
531
|
/**
|
|
@@ -960,38 +813,4 @@ declare function isPdfMimeType(mimeType: string): boolean;
|
|
|
960
813
|
type MimeCategory = 'text' | 'image' | 'unsupported';
|
|
961
814
|
declare function getMimeCategory(mimeType: string): MimeCategory;
|
|
962
815
|
|
|
963
|
-
|
|
964
|
-
* @semiont/api-client
|
|
965
|
-
*
|
|
966
|
-
* Complete SDK for Semiont - types, client, and utilities
|
|
967
|
-
*
|
|
968
|
-
* This package provides:
|
|
969
|
-
* - TypeScript types generated from the OpenAPI specification
|
|
970
|
-
* - A SemiontApiClient class for making API requests
|
|
971
|
-
* - Utilities for working with annotations, events, and text
|
|
972
|
-
*
|
|
973
|
-
* Example:
|
|
974
|
-
* ```typescript
|
|
975
|
-
* import { SemiontApiClient, isReference, getExactText } from '@semiont/api-client';
|
|
976
|
-
*
|
|
977
|
-
* const client = new SemiontApiClient({ baseUrl: 'http://localhost:4000' });
|
|
978
|
-
* await client.authenticateLocal('user@example.com', '123456');
|
|
979
|
-
*
|
|
980
|
-
* const doc = await client.createResource({
|
|
981
|
-
* name: 'My Resource',
|
|
982
|
-
* content: 'Hello World',
|
|
983
|
-
* format: 'text/plain',
|
|
984
|
-
* entityTypes: ['example']
|
|
985
|
-
* });
|
|
986
|
-
*
|
|
987
|
-
* // Use utilities
|
|
988
|
-
* if (isReference(annotation)) {
|
|
989
|
-
* const text = getExactText(annotation.target.selector);
|
|
990
|
-
* }
|
|
991
|
-
* ```
|
|
992
|
-
*/
|
|
993
|
-
|
|
994
|
-
type GenerationContext = components['schemas']['GenerationContext'];
|
|
995
|
-
type AnnotationLLMContextResponse = components['schemas']['AnnotationLLMContextResponse'];
|
|
996
|
-
|
|
997
|
-
export { APIError, AccessToken, type AnnotationLLMContextResponse, AnnotationUri, BaseUrl, CloneToken, ContentFormat, type DetectReferencesStreamRequest, Email, EntityType, type GenerateResourceStreamRequest, type GenerationContext, type GenerationProgress, GoogleCredential, JobId, type Logger, type MimeCategory, Motivation, type ReferenceDetectionProgress, RefreshToken, type RequestOptions, ResourceAnnotationUri, ResourceUri, SSEClient, type SSEClientConfig, type SSEStream, SearchQuery, SemiontApiClient, type SemiontApiClientConfig, UserDID, components, getExtensionForMimeType, getMimeCategory, isImageMimeType, isPdfMimeType, isTextMimeType, paths };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import ky from 'ky';
|
|
2
|
+
import { resourceUri } from '@semiont/core';
|
|
2
3
|
|
|
3
4
|
// src/client.ts
|
|
4
5
|
|
|
5
6
|
// src/sse/stream.ts
|
|
6
7
|
function createSSEStream(url, fetchOptions, config, logger) {
|
|
7
8
|
const abortController = new AbortController();
|
|
8
|
-
let progressCallback = null;
|
|
9
|
-
let completeCallback = null;
|
|
10
|
-
let errorCallback = null;
|
|
11
9
|
const customHandlers = /* @__PURE__ */ new Map();
|
|
12
10
|
let closed = false;
|
|
13
11
|
const connect = async () => {
|
|
@@ -98,7 +96,6 @@ function createSSEStream(url, fetchOptions, config, logger) {
|
|
|
98
96
|
error: error.message,
|
|
99
97
|
phase: "stream"
|
|
100
98
|
});
|
|
101
|
-
errorCallback?.(error);
|
|
102
99
|
} else if (error instanceof Error && error.name === "AbortError") {
|
|
103
100
|
logger?.info("SSE Stream Closed", {
|
|
104
101
|
type: "sse_closed",
|
|
@@ -126,21 +123,21 @@ function createSSEStream(url, fetchOptions, config, logger) {
|
|
|
126
123
|
handler(parsed);
|
|
127
124
|
return;
|
|
128
125
|
}
|
|
129
|
-
progressCallback?.(parsed);
|
|
130
|
-
return;
|
|
131
126
|
}
|
|
132
|
-
if (config.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
+
}
|
|
144
141
|
}
|
|
145
142
|
} catch (error) {
|
|
146
143
|
console.error("[SSE] Failed to parse event data:", error);
|
|
@@ -150,15 +147,6 @@ function createSSEStream(url, fetchOptions, config, logger) {
|
|
|
150
147
|
};
|
|
151
148
|
connect();
|
|
152
149
|
return {
|
|
153
|
-
onProgress(callback) {
|
|
154
|
-
progressCallback = callback;
|
|
155
|
-
},
|
|
156
|
-
onComplete(callback) {
|
|
157
|
-
completeCallback = callback;
|
|
158
|
-
},
|
|
159
|
-
onError(callback) {
|
|
160
|
-
errorCallback = callback;
|
|
161
|
-
},
|
|
162
150
|
close() {
|
|
163
151
|
abortController.abort();
|
|
164
152
|
},
|
|
@@ -248,7 +236,9 @@ var SSEClient = class {
|
|
|
248
236
|
{
|
|
249
237
|
progressEvents: ["reference-detection-started", "reference-detection-progress"],
|
|
250
238
|
completeEvent: "reference-detection-complete",
|
|
251
|
-
errorEvent: "reference-detection-error"
|
|
239
|
+
errorEvent: "reference-detection-error",
|
|
240
|
+
eventBus: options?.eventBus,
|
|
241
|
+
eventPrefix: "detection"
|
|
252
242
|
},
|
|
253
243
|
this.logger
|
|
254
244
|
);
|
|
@@ -304,7 +294,9 @@ var SSEClient = class {
|
|
|
304
294
|
{
|
|
305
295
|
progressEvents: ["generation-started", "generation-progress"],
|
|
306
296
|
completeEvent: "generation-complete",
|
|
307
|
-
errorEvent: "generation-error"
|
|
297
|
+
errorEvent: "generation-error",
|
|
298
|
+
eventBus: options?.eventBus,
|
|
299
|
+
eventPrefix: "generation"
|
|
308
300
|
},
|
|
309
301
|
this.logger
|
|
310
302
|
);
|
|
@@ -357,7 +349,9 @@ var SSEClient = class {
|
|
|
357
349
|
{
|
|
358
350
|
progressEvents: ["highlight-detection-started", "highlight-detection-progress"],
|
|
359
351
|
completeEvent: "highlight-detection-complete",
|
|
360
|
-
errorEvent: "highlight-detection-error"
|
|
352
|
+
errorEvent: "highlight-detection-error",
|
|
353
|
+
eventBus: options?.eventBus,
|
|
354
|
+
eventPrefix: "detection"
|
|
361
355
|
},
|
|
362
356
|
this.logger
|
|
363
357
|
);
|
|
@@ -410,7 +404,9 @@ var SSEClient = class {
|
|
|
410
404
|
{
|
|
411
405
|
progressEvents: ["assessment-detection-started", "assessment-detection-progress"],
|
|
412
406
|
completeEvent: "assessment-detection-complete",
|
|
413
|
-
errorEvent: "assessment-detection-error"
|
|
407
|
+
errorEvent: "assessment-detection-error",
|
|
408
|
+
eventBus: options?.eventBus,
|
|
409
|
+
eventPrefix: "detection"
|
|
414
410
|
},
|
|
415
411
|
this.logger
|
|
416
412
|
);
|
|
@@ -467,7 +463,9 @@ var SSEClient = class {
|
|
|
467
463
|
{
|
|
468
464
|
progressEvents: ["comment-detection-started", "comment-detection-progress"],
|
|
469
465
|
completeEvent: "comment-detection-complete",
|
|
470
|
-
errorEvent: "comment-detection-error"
|
|
466
|
+
errorEvent: "comment-detection-error",
|
|
467
|
+
eventBus: options?.eventBus,
|
|
468
|
+
eventPrefix: "detection"
|
|
471
469
|
},
|
|
472
470
|
this.logger
|
|
473
471
|
);
|
|
@@ -525,7 +523,9 @@ var SSEClient = class {
|
|
|
525
523
|
{
|
|
526
524
|
progressEvents: ["tag-detection-started", "tag-detection-progress"],
|
|
527
525
|
completeEvent: "tag-detection-complete",
|
|
528
|
-
errorEvent: "tag-detection-error"
|
|
526
|
+
errorEvent: "tag-detection-error",
|
|
527
|
+
eventBus: options?.eventBus,
|
|
528
|
+
eventPrefix: "detection"
|
|
529
529
|
},
|
|
530
530
|
this.logger
|
|
531
531
|
);
|
|
@@ -630,9 +630,9 @@ var SemiontApiClient = class {
|
|
|
630
630
|
*/
|
|
631
631
|
sse;
|
|
632
632
|
constructor(config) {
|
|
633
|
-
const { baseUrl
|
|
633
|
+
const { baseUrl, timeout = 3e4, retry = 2, logger } = config;
|
|
634
634
|
this.logger = logger;
|
|
635
|
-
this.baseUrl =
|
|
635
|
+
this.baseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
636
636
|
this.http = ky.create({
|
|
637
637
|
timeout,
|
|
638
638
|
retry,
|
|
@@ -703,9 +703,9 @@ var SemiontApiClient = class {
|
|
|
703
703
|
// ============================================================================
|
|
704
704
|
// AUTHENTICATION
|
|
705
705
|
// ============================================================================
|
|
706
|
-
async authenticatePassword(
|
|
706
|
+
async authenticatePassword(email, password, options) {
|
|
707
707
|
return this.http.post(`${this.baseUrl}/api/tokens/password`, {
|
|
708
|
-
json: { email
|
|
708
|
+
json: { email, password },
|
|
709
709
|
...options,
|
|
710
710
|
auth: options?.auth
|
|
711
711
|
}).json();
|
|
@@ -968,14 +968,14 @@ var SemiontApiClient = class {
|
|
|
968
968
|
auth: options?.auth
|
|
969
969
|
}).json();
|
|
970
970
|
}
|
|
971
|
-
async getAnnotation(
|
|
972
|
-
return this.http.get(
|
|
971
|
+
async getAnnotation(annotationUri, options) {
|
|
972
|
+
return this.http.get(annotationUri, {
|
|
973
973
|
...options,
|
|
974
974
|
auth: options?.auth
|
|
975
975
|
}).json();
|
|
976
976
|
}
|
|
977
|
-
async getResourceAnnotation(
|
|
978
|
-
return this.http.get(
|
|
977
|
+
async getResourceAnnotation(annotationUri, options) {
|
|
978
|
+
return this.http.get(annotationUri, {
|
|
979
979
|
...options,
|
|
980
980
|
auth: options?.auth
|
|
981
981
|
}).json();
|
|
@@ -989,24 +989,24 @@ var SemiontApiClient = class {
|
|
|
989
989
|
auth: options?.auth
|
|
990
990
|
}).json();
|
|
991
991
|
}
|
|
992
|
-
async deleteAnnotation(
|
|
993
|
-
await this.http.delete(
|
|
992
|
+
async deleteAnnotation(annotationUri, options) {
|
|
993
|
+
await this.http.delete(annotationUri, {
|
|
994
994
|
...options,
|
|
995
995
|
auth: options?.auth
|
|
996
996
|
});
|
|
997
997
|
}
|
|
998
|
-
async updateAnnotationBody(
|
|
999
|
-
return this.http.put(`${
|
|
998
|
+
async updateAnnotationBody(annotationUri, data, options) {
|
|
999
|
+
return this.http.put(`${annotationUri}/body`, {
|
|
1000
1000
|
json: data,
|
|
1001
1001
|
...options,
|
|
1002
1002
|
auth: options?.auth
|
|
1003
1003
|
}).json();
|
|
1004
1004
|
}
|
|
1005
|
-
async getAnnotationHistory(
|
|
1005
|
+
async getAnnotationHistory(annotationUri, options) {
|
|
1006
1006
|
if (options) {
|
|
1007
|
-
return this.http.get(`${
|
|
1007
|
+
return this.http.get(`${annotationUri}/history`, options).json();
|
|
1008
1008
|
}
|
|
1009
|
-
return this.http.get(`${
|
|
1009
|
+
return this.http.get(`${annotationUri}/history`).json();
|
|
1010
1010
|
}
|
|
1011
1011
|
// ============================================================================
|
|
1012
1012
|
// ENTITY TYPES
|
|
@@ -1126,67 +1126,6 @@ var SemiontApiClient = class {
|
|
|
1126
1126
|
return this.http.get(`${this.baseUrl}/api/status`).json();
|
|
1127
1127
|
}
|
|
1128
1128
|
};
|
|
1129
|
-
|
|
1130
|
-
// src/branded-types.ts
|
|
1131
|
-
function email(value) {
|
|
1132
|
-
return value;
|
|
1133
|
-
}
|
|
1134
|
-
function authCode(value) {
|
|
1135
|
-
return value;
|
|
1136
|
-
}
|
|
1137
|
-
function googleCredential(value) {
|
|
1138
|
-
return value;
|
|
1139
|
-
}
|
|
1140
|
-
function accessToken(value) {
|
|
1141
|
-
return value;
|
|
1142
|
-
}
|
|
1143
|
-
function refreshToken(value) {
|
|
1144
|
-
return value;
|
|
1145
|
-
}
|
|
1146
|
-
function mcpToken(value) {
|
|
1147
|
-
return value;
|
|
1148
|
-
}
|
|
1149
|
-
function cloneToken(value) {
|
|
1150
|
-
return value;
|
|
1151
|
-
}
|
|
1152
|
-
function jobId(value) {
|
|
1153
|
-
return value;
|
|
1154
|
-
}
|
|
1155
|
-
function userDID(value) {
|
|
1156
|
-
return value;
|
|
1157
|
-
}
|
|
1158
|
-
function entityType(value) {
|
|
1159
|
-
return value;
|
|
1160
|
-
}
|
|
1161
|
-
function searchQuery(value) {
|
|
1162
|
-
return value;
|
|
1163
|
-
}
|
|
1164
|
-
function baseUrl(value) {
|
|
1165
|
-
return value;
|
|
1166
|
-
}
|
|
1167
|
-
function resourceUri(uri) {
|
|
1168
|
-
if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
|
|
1169
|
-
throw new TypeError(`Expected ResourceUri, got: ${uri}`);
|
|
1170
|
-
}
|
|
1171
|
-
return uri;
|
|
1172
|
-
}
|
|
1173
|
-
function annotationUri(uri) {
|
|
1174
|
-
if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
|
|
1175
|
-
throw new TypeError(`Expected AnnotationUri, got: ${uri}`);
|
|
1176
|
-
}
|
|
1177
|
-
return uri;
|
|
1178
|
-
}
|
|
1179
|
-
function resourceAnnotationUri(uri) {
|
|
1180
|
-
if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
|
|
1181
|
-
throw new TypeError(`Expected ResourceAnnotationUri, got: ${uri}`);
|
|
1182
|
-
}
|
|
1183
|
-
if (!uri.includes("/resources/") || !uri.includes("/annotations/")) {
|
|
1184
|
-
throw new TypeError(`Expected nested ResourceAnnotationUri format, got: ${uri}`);
|
|
1185
|
-
}
|
|
1186
|
-
return uri;
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
// src/utils/annotations.ts
|
|
1190
1129
|
function getBodySource(body) {
|
|
1191
1130
|
if (Array.isArray(body)) {
|
|
1192
1131
|
for (const item of body) {
|
|
@@ -1900,12 +1839,12 @@ function validateData(schema, data) {
|
|
|
1900
1839
|
};
|
|
1901
1840
|
}
|
|
1902
1841
|
}
|
|
1903
|
-
function isValidEmail(
|
|
1904
|
-
if (
|
|
1842
|
+
function isValidEmail(email) {
|
|
1843
|
+
if (email.length < 1 || email.length > 255) {
|
|
1905
1844
|
return false;
|
|
1906
1845
|
}
|
|
1907
1846
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
1908
|
-
return emailRegex.test(
|
|
1847
|
+
return emailRegex.test(email);
|
|
1909
1848
|
}
|
|
1910
1849
|
|
|
1911
1850
|
// src/mime-utils.ts
|
|
@@ -1938,6 +1877,6 @@ function getMimeCategory(mimeType) {
|
|
|
1938
1877
|
return "unsupported";
|
|
1939
1878
|
}
|
|
1940
1879
|
|
|
1941
|
-
export { APIError, JWTTokenSchema, LOCALES, SSEClient, SemiontApiClient,
|
|
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 };
|
|
1942
1881
|
//# sourceMappingURL=index.js.map
|
|
1943
1882
|
//# sourceMappingURL=index.js.map
|