@semiont/api-client 0.4.14 → 0.4.15

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,20 +1,21 @@
1
1
  import * as _semiont_core from '@semiont/core';
2
- import { EntityType, BaseUrl, Logger, ResourceId, AccessToken, AnnotationId, components, EventBus, paths, Email, RefreshToken, GoogleCredential, ContentFormat, SearchQuery, CloneToken, Motivation, UserDID, JobId, UserId } from '@semiont/core';
2
+ import { BaseUrl, Logger, ResourceId, AccessToken, components, UserDID, paths, AnnotationId, GraphConnection, UpdateResourceInput, Motivation, MarkProgress, BodyOperation, GatheredContext, YieldProgress as YieldProgress$1, JobId, EventBus, Email, RefreshToken, GoogleCredential, ContentFormat, SearchQuery, CloneToken, EntityType } from '@semiont/core';
3
3
  export { Logger, Selector, getFragmentSelector, getSvgSelector, getTextPositionSelector, validateSvgMarkup } from '@semiont/core';
4
- import { Subscription, Observable } from 'rxjs';
4
+ import { Observable } from 'rxjs';
5
5
  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';
6
6
 
7
7
  /**
8
- * TypeScript types for Server-Sent Events (SSE) streaming
8
+ * TypeScript types for SSE event payloads.
9
9
  *
10
- * These types match the event payloads sent by backend SSE endpoints.
11
- * They are not validated (per SSE-VALIDATION-CONSIDERATIONS.md) but provide
12
- * type safety for client code consuming the streams.
10
+ * Progress and result types for events delivered via the long-lived
11
+ * events-stream. These match the payloads emitted by job workers on
12
+ * the resource-scoped EventBus. Used by the MCP server for type-safe
13
+ * event handling.
13
14
  */
14
15
  /**
15
16
  * Progress event for reference/linking detection stream
16
17
  *
17
- * Sent by POST /resources/:id/annotate-references-stream
18
+ * Sent by POST /resources/:id/annotate-references
18
19
  *
19
20
  * @example
20
21
  * ```typescript
@@ -45,7 +46,7 @@ interface ReferenceDetectionProgress {
45
46
  /**
46
47
  * Progress event for resource generation stream
47
48
  *
48
- * Sent by POST /resources/:resourceId/annotations/:annotationId/yield-resource-stream
49
+ * Sent by POST /resources/:resourceId/annotations/:annotationId/yield-resource
49
50
  *
50
51
  * @example
51
52
  * ```typescript
@@ -110,7 +111,7 @@ interface YieldProgress {
110
111
  * eventBus.get('detection:failed').subscribe(({ error }) => console.error(error));
111
112
  *
112
113
  * // Start stream - eventBus is required (TypeScript enforced)
113
- * const stream = client.sse.detectReferences(resourceId, request, { auth, eventBus });
114
+ * const stream = client.sse.markReferences(resourceId, request, { auth, eventBus });
114
115
  *
115
116
  * // Cleanup when done
116
117
  * stream.close();
@@ -127,7 +128,7 @@ interface SSEStream {
127
128
  * ```typescript
128
129
  * // React cleanup
129
130
  * useEffect(() => {
130
- * const stream = client.sse.detectReferences(..., { auth, eventBus });
131
+ * const stream = client.sse.markReferences(..., { auth, eventBus });
131
132
  * return () => stream.close();
132
133
  * }, []);
133
134
  * ```
@@ -141,72 +142,6 @@ interface SSEStream {
141
142
  */
142
143
  declare const SSE_STREAM_CONNECTED: "stream-connected";
143
144
  type SSEStreamConnected = typeof SSE_STREAM_CONNECTED;
144
- /**
145
- * Request body for reference annotation stream
146
- */
147
- interface AnnotateReferencesStreamRequest {
148
- entityTypes: EntityType[];
149
- includeDescriptiveReferences?: boolean;
150
- }
151
- /**
152
- * Request body for generation stream
153
- * Uses generated type from OpenAPI schema
154
- */
155
- type YieldResourceStreamRequest = components['schemas']['YieldResourceStreamRequest'];
156
- /**
157
- * Request body for highlight annotation stream
158
- */
159
- interface AnnotateHighlightsStreamRequest {
160
- instructions?: string;
161
- /** Desired number of highlights per 2000 words (1-15) */
162
- density?: number;
163
- }
164
- /**
165
- * Request body for assessment annotation stream
166
- */
167
- interface AnnotateAssessmentsStreamRequest {
168
- instructions?: string;
169
- tone?: 'analytical' | 'critical' | 'balanced' | 'constructive';
170
- /** Desired number of assessments per 2000 words (1-10) */
171
- density?: number;
172
- /** BCP 47 language tag for generated text (e.g. 'en', 'fr') */
173
- language?: string;
174
- }
175
- /**
176
- * Request body for comment annotation stream
177
- */
178
- interface AnnotateCommentsStreamRequest {
179
- instructions?: string;
180
- tone?: 'scholarly' | 'explanatory' | 'conversational' | 'technical';
181
- /** Desired number of comments per 2000 words (2-12) */
182
- density?: number;
183
- /** BCP 47 language tag for generated text (e.g. 'en', 'fr') */
184
- language?: string;
185
- }
186
- /**
187
- * Request body for tag annotation stream
188
- */
189
- interface AnnotateTagsStreamRequest {
190
- schemaId: string;
191
- categories: string[];
192
- }
193
- /**
194
- * Request body for resource gather stream
195
- */
196
- type GatherResourceStreamRequest = components['schemas']['GatherResourceStreamRequest'];
197
- /**
198
- * Request body for annotation gather stream
199
- */
200
- type GatherAnnotationStreamRequest = components['schemas']['GatherAnnotationStreamRequest'];
201
- /**
202
- * Request body for bind annotation stream
203
- * Uses generated type from OpenAPI schema
204
- */
205
- type BindAnnotationStreamRequest = components['schemas']['BindAnnotationStreamRequest'];
206
- /**
207
- * Request body for match search stream
208
- */
209
- type MatchSearchStreamRequest = components['schemas']['MatchSearchStreamRequest'];
210
145
  /**
211
146
  * SSE Client configuration
212
147
  */
@@ -223,28 +158,27 @@ interface SSERequestOptions {
223
158
  eventBus: _semiont_core.EventBus;
224
159
  }
225
160
  /**
226
- * SSE Client for real-time streaming operations
161
+ * SSE Client for long-lived streaming connections.
227
162
  *
228
- * Separate from the main HTTP client to clearly mark streaming endpoints.
229
- * Uses native fetch() instead of ky for SSE support.
163
+ * This client has three methods one per long-lived broadcast stream.
164
+ * Per-operation SSE routes have been replaced by plain HTTP POSTs with
165
+ * results delivered via the events-stream.
230
166
  *
231
- * This client is stateless - auth tokens are passed per-request via options.
167
+ * Uses native fetch() instead of ky for SSE support.
168
+ * Auth tokens are passed per-request via options.
232
169
  *
233
170
  * @example
234
171
  * ```typescript
235
- * const sseClient = new SSEClient({
236
- * baseUrl: 'http://localhost:4000'
237
- * });
172
+ * const sseClient = new SSEClient({ baseUrl: 'http://localhost:4000' });
238
173
  *
239
- * const stream = sseClient.markReferences(
240
- * 'http://localhost:4000/resources/doc-123',
241
- * { entityTypes: ['Person', 'Organization'] },
242
- * { auth: 'your-token' }
243
- * );
174
+ * // Open a long-lived resource events stream (auto-reconnects on disconnect)
175
+ * const stream = sseClient.resourceEvents(resourceId, { auth, eventBus });
244
176
  *
245
- * stream.onProgress((p) => console.log(p.message));
246
- * stream.onComplete((r) => console.log(`Found ${r.foundCount} entities`));
247
- * stream.onError((e) => console.error('Detection failed:', e));
177
+ * // Events auto-route to EventBus typed channels
178
+ * eventBus.get('mark:body-updated').subscribe((event) => { ... });
179
+ *
180
+ * // Close when done
181
+ * stream.close();
248
182
  * ```
249
183
  */
250
184
  declare class SSEClient {
@@ -255,280 +189,6 @@ declare class SSEClient {
255
189
  * Get common headers for SSE requests
256
190
  */
257
191
  private getHeaders;
258
- /**
259
- * Detect annotations in a resource (streaming)
260
- *
261
- * Streams entity detection progress via Server-Sent Events.
262
- *
263
- * @param resourceId - Resource URI or ID
264
- * @param request - Detection configuration (entity types to detect)
265
- * @param options - Request options (auth token)
266
- * @returns SSE stream controller with progress/complete/error callbacks
267
- *
268
- * @example
269
- * ```typescript
270
- * const stream = sseClient.markReferences(
271
- * 'http://localhost:4000/resources/doc-123',
272
- * { entityTypes: ['Person', 'Organization'] },
273
- * { auth: 'your-token' }
274
- * );
275
- *
276
- * stream.onProgress((progress) => {
277
- * console.log(`Scanning: ${progress.currentEntityType}`);
278
- * console.log(`Progress: ${progress.processedEntityTypes}/${progress.totalEntityTypes}`);
279
- * });
280
- *
281
- * stream.onComplete((result) => {
282
- * console.log(`Detection complete! Found ${result.foundCount} entities`);
283
- * });
284
- *
285
- * stream.onError((error) => {
286
- * console.error('Detection failed:', error.message);
287
- * });
288
- *
289
- * // Cleanup when done
290
- * stream.close();
291
- * ```
292
- */
293
- markReferences(resourceId: ResourceId, request: AnnotateReferencesStreamRequest, options: SSERequestOptions): SSEStream;
294
- /**
295
- * Generate resource from annotation (streaming)
296
- *
297
- * Streams resource generation progress via Server-Sent Events.
298
- *
299
- * @param resourceId - Source resource URI or ID
300
- * @param annotationId - Annotation URI or ID to use as generation source
301
- * @param request - Generation options (title, prompt, language)
302
- * @param options - Request options (auth token)
303
- * @returns SSE stream controller with progress/complete/error callbacks
304
- *
305
- * @example
306
- * ```typescript
307
- * const stream = sseClient.yieldResource(
308
- * 'http://localhost:4000/resources/doc-123',
309
- * 'http://localhost:4000/annotations/ann-456',
310
- * { language: 'es', title: 'Spanish Summary' },
311
- * { auth: 'your-token' }
312
- * );
313
- *
314
- * stream.onProgress((progress) => {
315
- * console.log(`${progress.status}: ${progress.percentage}%`);
316
- * console.log(progress.message);
317
- * });
318
- *
319
- * stream.onComplete((result) => {
320
- * console.log(`Yielded resource: ${result.resourceId}`);
321
- * });
322
- *
323
- * stream.onError((error) => {
324
- * console.error('Yield failed:', error.message);
325
- * });
326
- *
327
- * // Cleanup when done
328
- * stream.close();
329
- * ```
330
- */
331
- yieldResource(resourceId: ResourceId, annotationId: AnnotationId, request: YieldResourceStreamRequest, options: SSERequestOptions): SSEStream;
332
- /**
333
- * Detect highlights in a resource (streaming)
334
- *
335
- * Streams highlight annotation progress via Server-Sent Events.
336
- *
337
- * @param resourceId - Resource URI or ID
338
- * @param request - Detection configuration (optional instructions)
339
- * @param options - Request options (auth token)
340
- * @returns SSE stream controller with progress/complete/error callbacks
341
- *
342
- * @example
343
- * ```typescript
344
- * const stream = sseClient.markHighlights(
345
- * 'http://localhost:4000/resources/doc-123',
346
- * { instructions: 'Focus on key technical points' },
347
- * { auth: 'your-token' }
348
- * );
349
- *
350
- * stream.onProgress((progress) => {
351
- * console.log(`${progress.status}: ${progress.percentage}%`);
352
- * console.log(progress.message);
353
- * });
354
- *
355
- * stream.onComplete((result) => {
356
- * console.log(`Detection complete! Created ${result.createdCount} highlights`);
357
- * });
358
- *
359
- * stream.onError((error) => {
360
- * console.error('Detection failed:', error.message);
361
- * });
362
- *
363
- * // Cleanup when done
364
- * stream.close();
365
- * ```
366
- */
367
- markHighlights(resourceId: ResourceId, request: AnnotateHighlightsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
368
- /**
369
- * Detect assessments in a resource (streaming)
370
- *
371
- * Streams assessment annotation progress via Server-Sent Events.
372
- *
373
- * @param resourceId - Resource URI or ID
374
- * @param request - Detection configuration (optional instructions)
375
- * @param options - Request options (auth token)
376
- * @returns SSE stream controller with progress/complete/error callbacks
377
- *
378
- * @example
379
- * ```typescript
380
- * const stream = sseClient.markAssessments(
381
- * 'http://localhost:4000/resources/doc-123',
382
- * { instructions: 'Evaluate claims for accuracy' },
383
- * { auth: 'your-token' }
384
- * );
385
- *
386
- * stream.onProgress((progress) => {
387
- * console.log(`${progress.status}: ${progress.percentage}%`);
388
- * console.log(progress.message);
389
- * });
390
- *
391
- * stream.onComplete((result) => {
392
- * console.log(`Detection complete! Created ${result.createdCount} assessments`);
393
- * });
394
- *
395
- * stream.onError((error) => {
396
- * console.error('Detection failed:', error.message);
397
- * });
398
- *
399
- * // Cleanup when done
400
- * stream.close();
401
- * ```
402
- */
403
- markAssessments(resourceId: ResourceId, request: AnnotateAssessmentsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
404
- /**
405
- * Detect comments in a resource (streaming)
406
- *
407
- * Streams comment annotation progress via Server-Sent Events.
408
- * Uses AI to identify passages that would benefit from explanatory comments
409
- * and creates comment annotations with contextual information.
410
- *
411
- * @param resourceId - Resource URI or ID
412
- * @param request - Detection configuration (optional instructions and tone)
413
- * @param options - Request options (auth token)
414
- * @returns SSE stream controller with progress/complete/error callbacks
415
- *
416
- * @example
417
- * ```typescript
418
- * const stream = sseClient.markComments(
419
- * 'http://localhost:4000/resources/doc-123',
420
- * {
421
- * instructions: 'Focus on technical terminology',
422
- * tone: 'scholarly'
423
- * },
424
- * { auth: 'your-token' }
425
- * );
426
- *
427
- * stream.onProgress((progress) => {
428
- * console.log(`${progress.status}: ${progress.percentage}%`);
429
- * });
430
- *
431
- * stream.onComplete((result) => {
432
- * console.log(`Detection complete! Created ${result.createdCount} comments`);
433
- * });
434
- *
435
- * stream.onError((error) => {
436
- * console.error('Detection failed:', error.message);
437
- * });
438
- *
439
- * // Cleanup when done
440
- * stream.close();
441
- * ```
442
- */
443
- markComments(resourceId: ResourceId, request: AnnotateCommentsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
444
- /**
445
- * Detect tags in a resource (streaming)
446
- *
447
- * Streams tag annotation progress via Server-Sent Events.
448
- * Uses AI to identify passages serving specific structural roles
449
- * (e.g., IRAC, IMRAD, Toulmin) and creates tag annotations with dual-body structure.
450
- *
451
- * @param resourceId - Resource URI or ID
452
- * @param request - Detection configuration (schema and categories to detect)
453
- * @param options - Request options (auth token)
454
- * @returns SSE stream controller with progress/complete/error callbacks
455
- *
456
- * @example
457
- * ```typescript
458
- * const stream = sseClient.markTags(
459
- * 'http://localhost:4000/resources/doc-123',
460
- * {
461
- * schemaId: 'legal-irac',
462
- * categories: ['Issue', 'Rule', 'Application', 'Conclusion']
463
- * },
464
- * { auth: 'your-token' }
465
- * );
466
- *
467
- * stream.onProgress((progress) => {
468
- * console.log(`${progress.status}: ${progress.percentage}%`);
469
- * console.log(`Processing ${progress.currentCategory}...`);
470
- * });
471
- *
472
- * stream.onComplete((result) => {
473
- * console.log(`Detection complete! Created ${result.tagsCreated} tags`);
474
- * });
475
- *
476
- * stream.onError((error) => {
477
- * console.error('Detection failed:', error.message);
478
- * });
479
- *
480
- * // Cleanup when done
481
- * stream.close();
482
- * ```
483
- */
484
- markTags(resourceId: ResourceId, request: AnnotateTagsStreamRequest, options: SSERequestOptions): SSEStream;
485
- /**
486
- * Gather LLM context for a resource (streaming)
487
- *
488
- * Streams resource LLM context gathering progress via Server-Sent Events.
489
- *
490
- * @param resourceId - Resource URI or ID
491
- * @param request - Gather configuration (depth, maxResources, includeContent, includeSummary)
492
- * @param options - Request options (auth token, eventBus)
493
- * @returns SSE stream controller with progress/complete/error callbacks
494
- */
495
- gatherResource(resourceId: ResourceId, request: GatherResourceStreamRequest, options: SSERequestOptions): SSEStream;
496
- /**
497
- * Gather LLM context for an annotation (streaming)
498
- *
499
- * Streams annotation LLM context gathering progress via Server-Sent Events.
500
- *
501
- * @param resourceId - Resource URI or ID
502
- * @param annotationId - Annotation URI or ID
503
- * @param request - Gather configuration (contextWindow)
504
- * @param options - Request options (auth token, eventBus)
505
- * @returns SSE stream controller with progress/complete/error callbacks
506
- */
507
- gatherAnnotation(resourceId: ResourceId, annotationId: AnnotationId, request: GatherAnnotationStreamRequest, options: SSERequestOptions): SSEStream;
508
- /**
509
- * Bind annotation body (streaming)
510
- *
511
- * Applies annotation body operations and streams completion via Server-Sent Events.
512
- *
513
- * @param resourceId - Resource URI or ID
514
- * @param annotationId - Annotation URI or ID
515
- * @param request - Bind operations (resourceId + operations array)
516
- * @param options - Request options (auth token, eventBus)
517
- * @returns SSE stream controller with complete/error callbacks
518
- */
519
- bindAnnotation(resourceId: ResourceId, annotationId: AnnotationId, request: BindAnnotationStreamRequest, options: SSERequestOptions): SSEStream;
520
- /**
521
- * Search for binding candidates (streaming)
522
- *
523
- * Bridges match:search-requested to the backend Matcher actor via SSE.
524
- * Results emit as match:search-results on the browser EventBus.
525
- *
526
- * @param resourceId - Resource the annotation belongs to
527
- * @param request - Search configuration (referenceId, context, limit)
528
- * @param options - Request options (auth token, eventBus)
529
- * @returns SSE stream controller
530
- */
531
- matchSearch(resourceId: ResourceId, request: MatchSearchStreamRequest, options: SSERequestOptions): SSEStream;
532
192
  /**
533
193
  * Subscribe to resource events (long-lived stream)
534
194
  *
@@ -579,11 +239,9 @@ declare class SSEClient {
579
239
  * ```typescript
580
240
  * const stream = sseClient.globalEvents({ auth: 'your-token', eventBus });
581
241
  *
582
- * // Events auto-emit to EventBus — subscribe there
583
- * eventBus.get('make-meaning:event').subscribe((event) => {
584
- * if (event.type === 'entitytype.added') {
585
- * // Invalidate entity types query
586
- * }
242
+ * // Events auto-emit to EventBus typed channels — subscribe there
243
+ * eventBus.get('mark:entity-type-added').subscribe((stored) => {
244
+ * // Invalidate entity types query
587
245
  * });
588
246
  *
589
247
  * // Close when no longer needed
@@ -611,205 +269,629 @@ declare class SSEClient {
611
269
  }
612
270
 
613
271
  /**
614
- * FlowEngine framework-agnostic flow orchestration
272
+ * Verb Namespace Interfaces
273
+ *
274
+ * These interfaces define the public API of the Semiont api-client,
275
+ * organized by the 7 domain flows (Browse, Mark, Bind, Gather, Match,
276
+ * Yield, Beckon) plus infrastructure namespaces (Job, Auth, Admin).
277
+ *
278
+ * Each namespace maps 1:1 to a flow. Each flow maps to a clear actor
279
+ * on the backend. The frontend calls `client.mark.annotation()` and the
280
+ * proxy handles HTTP, auth, SSE, and caching internally.
281
+ *
282
+ * Return type conventions:
283
+ * - Browse live queries → Observable (events-stream driven, cached)
284
+ * - Browse one-shot reads → Promise (fetch once, no cache)
285
+ * - Commands (mark, bind, yield.resource) → Promise (fire-and-forget)
286
+ * - Long-running ops (gather, match, yield.fromAnnotation, mark.assist) → Observable (progress + result)
287
+ * - Ephemeral signals (beckon) → void
288
+ */
289
+
290
+ type Annotation$1 = components['schemas']['Annotation'];
291
+ type ResourceDescriptor$2 = components['schemas']['ResourceDescriptor'];
292
+ type StoredEventResponse$1 = components['schemas']['StoredEventResponse'];
293
+ type GatherProgress = components['schemas']['GatherProgress'];
294
+ type MatchSearchResult = components['schemas']['MatchSearchResult'];
295
+ type MarkAssistFinished = components['schemas']['MarkAssistFinished'];
296
+ type GatherAnnotationComplete = components['schemas']['GatherAnnotationComplete'];
297
+ type JobStatusResponse$1 = components['schemas']['JobStatusResponse'];
298
+ type AuthResponse$1 = components['schemas']['AuthResponse'];
299
+ type OAuthConfigResponse$1 = components['schemas']['OAuthConfigResponse'];
300
+ type AdminUserStatsResponse$1 = components['schemas']['AdminUserStatsResponse'];
301
+ type ResponseContent$1<T> = T extends {
302
+ responses: {
303
+ 200: {
304
+ content: {
305
+ 'application/json': infer R;
306
+ };
307
+ };
308
+ };
309
+ } ? R : T extends {
310
+ responses: {
311
+ 201: {
312
+ content: {
313
+ 'application/json': infer R;
314
+ };
315
+ };
316
+ };
317
+ } ? R : never;
318
+ type RequestContent$1<T> = T extends {
319
+ requestBody?: {
320
+ content: {
321
+ 'application/json': infer R;
322
+ };
323
+ };
324
+ } ? R : never;
325
+ /** Input for creating an annotation via mark.annotation() */
326
+ type CreateAnnotationInput = RequestContent$1<paths['/resources/{id}/annotations']['post']>;
327
+ /** Input for creating a resource via yield.resource() */
328
+ interface CreateResourceInput {
329
+ name: string;
330
+ file: File | Buffer;
331
+ format: string;
332
+ entityTypes?: string[];
333
+ language?: string;
334
+ creationMethod?: string;
335
+ sourceAnnotationId?: string;
336
+ sourceResourceId?: string;
337
+ storageUri: string;
338
+ }
339
+ /** Options for yield.fromAnnotation() */
340
+ interface GenerationOptions {
341
+ title: string;
342
+ storageUri: string;
343
+ context: GatheredContext;
344
+ prompt?: string;
345
+ language?: string;
346
+ temperature?: number;
347
+ maxTokens?: number;
348
+ }
349
+ /** Options for mark.assist() */
350
+ interface MarkAssistOptions {
351
+ entityTypes?: string[];
352
+ includeDescriptiveReferences?: boolean;
353
+ instructions?: string;
354
+ density?: number;
355
+ tone?: string;
356
+ language?: string;
357
+ schemaId?: string;
358
+ categories?: string[];
359
+ }
360
+ /** Options for yield.createFromToken() */
361
+ type CreateFromTokenOptions = RequestContent$1<paths['/api/clone-tokens/create-resource']['post']>;
362
+ /** Referenced-by entry from browse.referencedBy() */
363
+ type ReferencedByEntry = ResponseContent$1<paths['/resources/{id}/referenced-by']['get']>['referencedBy'][number];
364
+ /** Annotation history from browse.annotationHistory() */
365
+ type AnnotationHistoryResponse = ResponseContent$1<paths['/resources/{resourceId}/annotations/{annotationId}/history']['get']>;
366
+ /** User object from auth/admin responses */
367
+ type User = AuthResponse$1['user'];
368
+ /**
369
+ * Progress emitted by gather.annotation() Observable.
370
+ * Emits GatherProgress during assembly, then GatherAnnotationComplete on finish.
371
+ */
372
+ type GatherAnnotationProgress = GatherProgress | GatherAnnotationComplete;
373
+ /**
374
+ * Progress emitted by match.search() Observable.
375
+ * Emits the final MatchSearchResult (no intermediate progress events currently).
376
+ */
377
+ type MatchSearchProgress = MatchSearchResult;
378
+ /**
379
+ * Progress emitted by mark.assist() Observable.
380
+ * Emits MarkProgress during scanning, then MarkAssistFinished on completion.
381
+ * On failure, the Observable errors with MarkAssistFailed.
382
+ */
383
+ type MarkAssistProgress = MarkProgress | MarkAssistFinished;
384
+ /**
385
+ * Browse — reads from materialized views
386
+ *
387
+ * Live queries return Observables that emit initial state and re-emit
388
+ * on events-stream updates. One-shot reads return Promises.
389
+ *
390
+ * Backend actor: Browser (context classes)
391
+ * Event prefix: browse:*
392
+ */
393
+ interface BrowseNamespace$1 {
394
+ resource(resourceId: ResourceId): Observable<ResourceDescriptor$2 | undefined>;
395
+ resources(filters?: {
396
+ limit?: number;
397
+ archived?: boolean;
398
+ }): Observable<ResourceDescriptor$2[] | undefined>;
399
+ annotations(resourceId: ResourceId): Observable<Annotation$1[] | undefined>;
400
+ annotation(resourceId: ResourceId, annotationId: AnnotationId): Observable<Annotation$1 | undefined>;
401
+ entityTypes(): Observable<string[] | undefined>;
402
+ referencedBy(resourceId: ResourceId): Observable<ReferencedByEntry[] | undefined>;
403
+ resourceContent(resourceId: ResourceId): Promise<string>;
404
+ resourceRepresentation(resourceId: ResourceId, options?: {
405
+ accept?: string;
406
+ }): Promise<{
407
+ data: ArrayBuffer;
408
+ contentType: string;
409
+ }>;
410
+ resourceRepresentationStream(resourceId: ResourceId, options?: {
411
+ accept?: string;
412
+ }): Promise<{
413
+ stream: ReadableStream<Uint8Array>;
414
+ contentType: string;
415
+ }>;
416
+ resourceEvents(resourceId: ResourceId): Promise<StoredEventResponse$1[]>;
417
+ annotationHistory(resourceId: ResourceId, annotationId: AnnotationId): Promise<AnnotationHistoryResponse>;
418
+ connections(resourceId: ResourceId): Promise<GraphConnection[]>;
419
+ backlinks(resourceId: ResourceId): Promise<Annotation$1[]>;
420
+ resourcesByName(query: string, limit?: number): Promise<ResourceDescriptor$2[]>;
421
+ files(dirPath?: string, sort?: 'name' | 'mtime' | 'annotationCount'): Promise<ResponseContent$1<paths['/api/browse/files']['get']>>;
422
+ }
423
+ /**
424
+ * Mark — annotation CRUD, entity types, AI assist
425
+ *
426
+ * Commands return Promises that resolve on HTTP acceptance (202).
427
+ * Results appear on browse Observables via events-stream.
428
+ * assist() returns an Observable for long-running progress.
429
+ *
430
+ * Backend actor: Stower
431
+ * Event prefix: mark:*
432
+ */
433
+ interface MarkNamespace$1 {
434
+ annotation(resourceId: ResourceId, input: CreateAnnotationInput): Promise<{
435
+ annotationId: string;
436
+ }>;
437
+ delete(resourceId: ResourceId, annotationId: AnnotationId): Promise<void>;
438
+ entityType(type: string): Promise<void>;
439
+ entityTypes(types: string[]): Promise<void>;
440
+ updateResource(resourceId: ResourceId, data: UpdateResourceInput): Promise<void>;
441
+ archive(resourceId: ResourceId): Promise<void>;
442
+ unarchive(resourceId: ResourceId): Promise<void>;
443
+ assist(resourceId: ResourceId, motivation: Motivation, options: MarkAssistOptions): Observable<MarkAssistProgress>;
444
+ }
445
+ /**
446
+ * Bind — reference linking
447
+ *
448
+ * The simplest namespace. One method. The result (updated annotation
449
+ * with resolved reference) arrives on browse.annotations() via the
450
+ * enriched mark:body-updated event.
451
+ *
452
+ * Backend actor: Stower (via mark:update-body)
453
+ * Event prefix: mark:body-updated (shares mark event pipeline)
454
+ */
455
+ interface BindNamespace$1 {
456
+ body(resourceId: ResourceId, annotationId: AnnotationId, operations: BodyOperation[]): Promise<void>;
457
+ }
458
+ /**
459
+ * Gather — context assembly
460
+ *
461
+ * Long-running (LLM calls + graph traversal). Returns Observables
462
+ * that emit progress then the gathered context.
463
+ *
464
+ * Backend actor: Gatherer
465
+ * Event prefix: gather:*
466
+ */
467
+ interface GatherNamespace$1 {
468
+ annotation(annotationId: AnnotationId, resourceId: ResourceId, options?: {
469
+ contextWindow?: number;
470
+ }): Observable<GatherAnnotationProgress>;
471
+ resource(resourceId: ResourceId, options?: {
472
+ contextWindow?: number;
473
+ }): Observable<GatherAnnotationProgress>;
474
+ }
475
+ /**
476
+ * Match — search and ranking
477
+ *
478
+ * Long-running (semantic search, optional LLM scoring). Returns
479
+ * Observable with progress then results.
480
+ *
481
+ * Backend actor: Matcher
482
+ * Event prefix: match:*
483
+ */
484
+ interface MatchNamespace$1 {
485
+ search(resourceId: ResourceId, referenceId: string, context: GatheredContext, options?: {
486
+ limit?: number;
487
+ useSemanticScoring?: boolean;
488
+ }): Observable<MatchSearchProgress>;
489
+ }
490
+ /**
491
+ * Yield — resource creation
492
+ *
493
+ * resource() is synchronous file upload (Promise).
494
+ * fromAnnotation() is long-running LLM generation (Observable).
495
+ *
496
+ * Backend actor: Stower + generation worker
497
+ * Event prefix: yield:*
498
+ */
499
+ interface YieldNamespace$1 {
500
+ resource(data: CreateResourceInput): Promise<{
501
+ resourceId: string;
502
+ }>;
503
+ fromAnnotation(resourceId: ResourceId, annotationId: AnnotationId, options: GenerationOptions): Observable<YieldProgress$1>;
504
+ cloneToken(resourceId: ResourceId): Promise<{
505
+ token: string;
506
+ expiresAt: string;
507
+ }>;
508
+ fromToken(token: string): Promise<ResourceDescriptor$2>;
509
+ createFromToken(options: CreateFromTokenOptions): Promise<{
510
+ resourceId: string;
511
+ }>;
512
+ }
513
+ /**
514
+ * Beckon — attention coordination
515
+ *
516
+ * Fire-and-forget. Ephemeral presence signal delivered via the
517
+ * attention-stream to other participants.
518
+ *
519
+ * Backend actor: (frontend relay via attention-stream)
520
+ * Event prefix: beckon:*
521
+ */
522
+ interface BeckonNamespace$1 {
523
+ attention(annotationId: AnnotationId, resourceId: ResourceId): void;
524
+ }
525
+ /**
526
+ * Job — worker lifecycle
527
+ */
528
+ interface JobNamespace$1 {
529
+ status(jobId: JobId): Promise<JobStatusResponse$1>;
530
+ pollUntilComplete(jobId: JobId, options?: {
531
+ interval?: number;
532
+ timeout?: number;
533
+ onProgress?: (status: JobStatusResponse$1) => void;
534
+ }): Promise<JobStatusResponse$1>;
535
+ cancel(jobId: JobId, type: string): Promise<void>;
536
+ }
537
+ /**
538
+ * Auth — authentication
539
+ */
540
+ interface AuthNamespace$1 {
541
+ password(email: string, password: string): Promise<AuthResponse$1>;
542
+ google(credential: string): Promise<AuthResponse$1>;
543
+ refresh(token: string): Promise<AuthResponse$1>;
544
+ logout(): Promise<void>;
545
+ me(): Promise<User>;
546
+ acceptTerms(): Promise<void>;
547
+ mcpToken(): Promise<{
548
+ token: string;
549
+ }>;
550
+ mediaToken(resourceId: ResourceId): Promise<{
551
+ token: string;
552
+ }>;
553
+ }
554
+ /**
555
+ * Admin — administration
556
+ */
557
+ interface AdminNamespace$1 {
558
+ users(): Promise<User[]>;
559
+ userStats(): Promise<AdminUserStatsResponse$1>;
560
+ updateUser(userId: UserDID, data: RequestContent$1<paths['/api/admin/users/{id}']['patch']>): Promise<User>;
561
+ oauthConfig(): Promise<OAuthConfigResponse$1>;
562
+ healthCheck(): Promise<ResponseContent$1<paths['/api/health']['get']>>;
563
+ status(): Promise<ResponseContent$1<paths['/api/status']['get']>>;
564
+ backup(): Promise<Response>;
565
+ restore(file: File, onProgress?: (event: {
566
+ phase: string;
567
+ message?: string;
568
+ result?: Record<string, unknown>;
569
+ }) => void): Promise<{
570
+ phase: string;
571
+ message?: string;
572
+ result?: Record<string, unknown>;
573
+ }>;
574
+ exportKnowledgeBase(params?: {
575
+ includeArchived?: boolean;
576
+ }): Promise<Response>;
577
+ importKnowledgeBase(file: File, onProgress?: (event: {
578
+ phase: string;
579
+ message?: string;
580
+ result?: Record<string, unknown>;
581
+ }) => void): Promise<{
582
+ phase: string;
583
+ message?: string;
584
+ result?: Record<string, unknown>;
585
+ }>;
586
+ }
587
+
588
+ /**
589
+ * BrowseNamespace — reads from materialized views
615
590
  *
616
- * Owns the subscription/SSE-bridge logic that was previously scattered across
617
- * React hooks (useBindFlow, useYieldFlow, useMarkFlow, useContextGatherFlow,
618
- * useResourceEvents, useAttentionStream).
591
+ * Absorbs AnnotationStore and ResourceStore logic. Live queries return
592
+ * Observables backed by BehaviorSubjects that update reactively when
593
+ * EventBus events arrive. One-shot reads are Promise wrappers over HTTP.
619
594
  *
620
- * Each method accepts a `getToken` function called at event-handling time so
621
- * the token is always fresh (the client is stateless; tokens rotate).
595
+ * Backend actor: Browser (context classes)
596
+ * Event prefix: browse:*
597
+ */
598
+
599
+ type Annotation = components['schemas']['Annotation'];
600
+ type ResourceDescriptor$1 = components['schemas']['ResourceDescriptor'];
601
+ type StoredEventResponse = components['schemas']['StoredEventResponse'];
602
+ type TokenGetter$9 = () => AccessToken | undefined;
603
+ declare class BrowseNamespace implements BrowseNamespace$1 {
604
+ private readonly http;
605
+ private readonly eventBus;
606
+ private readonly annotationList$;
607
+ private readonly fetchingAnnotationList;
608
+ private readonly annotationListObs$;
609
+ private readonly annotationDetail$;
610
+ private readonly fetchingAnnotationDetail;
611
+ private readonly annotationDetailObs$;
612
+ private readonly resourceDetail$;
613
+ private readonly fetchingResourceDetail;
614
+ private readonly resourceDetailObs$;
615
+ private readonly resourceList$;
616
+ private readonly fetchingResourceList;
617
+ private readonly resourceListObs$;
618
+ private readonly entityTypes$;
619
+ private fetchingEntityTypes;
620
+ private readonly referencedBy$;
621
+ private readonly fetchingReferencedBy;
622
+ private readonly referencedByObs$;
623
+ private readonly getToken;
624
+ constructor(http: SemiontApiClient, eventBus: EventBus, getToken: TokenGetter$9);
625
+ resource(resourceId: ResourceId): Observable<ResourceDescriptor$1 | undefined>;
626
+ resources(filters?: {
627
+ limit?: number;
628
+ archived?: boolean;
629
+ }): Observable<ResourceDescriptor$1[] | undefined>;
630
+ annotations(resourceId: ResourceId): Observable<Annotation[] | undefined>;
631
+ annotation(resourceId: ResourceId, annotationId: AnnotationId): Observable<Annotation | undefined>;
632
+ entityTypes(): Observable<string[] | undefined>;
633
+ referencedBy(resourceId: ResourceId): Observable<ReferencedByEntry[] | undefined>;
634
+ resourceContent(resourceId: ResourceId): Promise<string>;
635
+ resourceRepresentation(resourceId: ResourceId, options?: {
636
+ accept?: string;
637
+ }): Promise<{
638
+ data: ArrayBuffer;
639
+ contentType: string;
640
+ }>;
641
+ resourceRepresentationStream(resourceId: ResourceId, options?: {
642
+ accept?: string;
643
+ }): Promise<{
644
+ stream: ReadableStream<Uint8Array>;
645
+ contentType: string;
646
+ }>;
647
+ resourceEvents(resourceId: ResourceId): Promise<StoredEventResponse[]>;
648
+ annotationHistory(resourceId: ResourceId, annotationId: AnnotationId): Promise<AnnotationHistoryResponse>;
649
+ connections(_resourceId: ResourceId): Promise<GraphConnection[]>;
650
+ backlinks(_resourceId: ResourceId): Promise<Annotation[]>;
651
+ resourcesByName(_query: string, _limit?: number): Promise<ResourceDescriptor$1[]>;
652
+ files(dirPath?: string, sort?: 'name' | 'mtime' | 'annotationCount'): Promise<ResponseContent$1<paths['/api/browse/files']['get']>>;
653
+ invalidateAnnotationList(resourceId: ResourceId): void;
654
+ invalidateAnnotationDetail(annotationId: AnnotationId): void;
655
+ invalidateResourceDetail(id: ResourceId): void;
656
+ invalidateResourceLists(): void;
657
+ invalidateEntityTypes(): void;
658
+ invalidateReferencedBy(resourceId: ResourceId): void;
659
+ updateAnnotationInPlace(resourceId: ResourceId, annotation: Annotation): void;
660
+ private subscribeToEvents;
661
+ private fetchAnnotationList;
662
+ private fetchAnnotationDetail;
663
+ private fetchResourceDetail;
664
+ private fetchResourceList;
665
+ private fetchEntityTypes;
666
+ private fetchReferencedBy;
667
+ }
668
+
669
+ /**
670
+ * MarkNamespace — annotation CRUD, entity types, AI assist
622
671
  *
623
- * Each method returns an RxJS Subscription. The caller is responsible for
624
- * calling .unsubscribe() when the flow is no longer needed (e.g. in a
625
- * React useEffect cleanup or on workspace teardown).
672
+ * Commands return Promises that resolve on HTTP acceptance.
673
+ * Results appear on browse Observables via events-stream.
674
+ * assist() returns an Observable for long-running progress.
626
675
  *
627
- * No React imports. No DOM imports. Pure RxJS + EventBus.
676
+ * Backend actor: Stower
677
+ * Event prefix: mark:*
628
678
  */
629
679
 
630
- type TokenGetter$2 = () => AccessToken | undefined;
631
- declare class FlowEngine {
680
+ type TokenGetter$8 = () => AccessToken | undefined;
681
+ declare class MarkNamespace implements MarkNamespace$1 {
682
+ private readonly http;
632
683
  private readonly eventBus;
633
- private readonly sse;
684
+ private readonly getToken;
685
+ constructor(http: SemiontApiClient, eventBus: EventBus, getToken: TokenGetter$8);
686
+ annotation(resourceId: ResourceId, input: CreateAnnotationInput): Promise<{
687
+ annotationId: string;
688
+ }>;
689
+ delete(resourceId: ResourceId, annotationId: AnnotationId): Promise<void>;
690
+ entityType(type: string): Promise<void>;
691
+ entityTypes(types: string[]): Promise<void>;
692
+ updateResource(resourceId: ResourceId, data: UpdateResourceInput): Promise<void>;
693
+ archive(resourceId: ResourceId): Promise<void>;
694
+ unarchive(resourceId: ResourceId): Promise<void>;
695
+ assist(resourceId: ResourceId, motivation: Motivation, options: MarkAssistOptions): Observable<MarkAssistProgress>;
696
+ private dispatchAssist;
697
+ }
698
+
699
+ /**
700
+ * BindNamespace — reference linking
701
+ *
702
+ * The simplest namespace. One method. The result (updated annotation
703
+ * with resolved reference) arrives on browse.annotations() via the
704
+ * enriched mark:body-updated event.
705
+ *
706
+ * Backend actor: Stower (via mark:update-body)
707
+ * Event prefix: mark:body-updated (shares mark event pipeline)
708
+ */
709
+
710
+ type TokenGetter$7 = () => AccessToken | undefined;
711
+ declare class BindNamespace implements BindNamespace$1 {
634
712
  private readonly http;
635
- constructor(eventBus: EventBus, sse: SSEClient, http: SemiontApiClient);
636
- /**
637
- * Activate the bind flow for a resource.
638
- *
639
- * @subscribes bind:update-body — calls SSE bindAnnotation
640
- * @subscribes match:search-requested — calls SSE bindSearch
641
- * @emits bind:body-updated, bind:body-update-failed
642
- */
643
- bind(rUri: ResourceId, getToken: TokenGetter$2): Subscription;
644
- /**
645
- * Activate the yield (generation) flow for a resource.
646
- *
647
- * @subscribes yield:request — calls SSE yieldResource
648
- * @subscribes yield:finished — links generated resource back to the reference annotation via bind:update-body
649
- * @subscribes job:cancel-requested (generation) — aborts in-flight stream
650
- */
651
- yield(_rUri: ResourceId, getToken: TokenGetter$2): Subscription;
652
- /**
653
- * Activate the mark (annotation CRUD + assist) flow for a resource.
654
- *
655
- * @subscribes mark:submit — HTTP markAnnotation
656
- * @subscribes mark:delete — HTTP deleteAnnotation
657
- * @subscribes mark:assist-request — SSE mark* (by motivation)
658
- * @subscribes job:cancel-requested (annotation) — aborts in-flight assist
659
- * @emits mark:created, mark:create-failed, mark:deleted, mark:delete-failed
660
- */
661
- mark(rUri: ResourceId, getToken: TokenGetter$2): Subscription;
662
- /**
663
- * Activate the gather-context flow for a resource.
664
- *
665
- * @subscribes gather:requested — calls SSE gatherAnnotation, threads correlationId
666
- * @emits gather:complete (re-emitted from SSE gather:annotation-finished)
667
- */
668
- gatherContext(rUri: ResourceId, getToken: TokenGetter$2): Subscription;
669
- /**
670
- * Open the long-lived resource-events SSE stream.
671
- * Returns a Subscription whose teardown closes the stream.
672
- */
673
- resourceEvents(rUri: ResourceId, getToken: TokenGetter$2): Subscription;
674
- /**
675
- * Open the long-lived participant attention SSE stream.
676
- * Returns a Subscription whose teardown closes the stream.
677
- */
678
- attentionStream(getToken: TokenGetter$2): Subscription;
713
+ private readonly getToken;
714
+ constructor(http: SemiontApiClient, getToken: TokenGetter$7);
715
+ body(resourceId: ResourceId, annotationId: AnnotationId, operations: BodyOperation[]): Promise<void>;
679
716
  }
680
717
 
681
718
  /**
682
- * ResourceStoreper-workspace observable resource cache
719
+ * GatherNamespacecontext assembly
720
+ *
721
+ * Long-running (LLM calls + graph traversal). Returns Observables
722
+ * that emit progress then the gathered context.
683
723
  *
684
- * BehaviorSubject-backed store that:
685
- * - Populates lazily on first subscribe (no up-front fetch)
686
- * - Updates reactively when EventBus events arrive (no manual invalidation)
687
- * - Is readable from outside React
724
+ * Backend actor: Gatherer
725
+ * Event prefix: gather:*
726
+ */
727
+
728
+ type TokenGetter$6 = () => AccessToken | undefined;
729
+ declare class GatherNamespace implements GatherNamespace$1 {
730
+ private readonly http;
731
+ private readonly eventBus;
732
+ private readonly getToken;
733
+ constructor(http: SemiontApiClient, eventBus: EventBus, getToken: TokenGetter$6);
734
+ annotation(annotationId: AnnotationId, resourceId: ResourceId, options?: {
735
+ contextWindow?: number;
736
+ }): Observable<GatherAnnotationProgress>;
737
+ resource(_resourceId: ResourceId, _options?: {
738
+ contextWindow?: number;
739
+ }): Observable<GatherAnnotationProgress>;
740
+ }
741
+
742
+ /**
743
+ * MatchNamespace — search and ranking
688
744
  *
689
- * EventBus events handled:
690
- * - yield:created → fetch new resource into map, invalidate lists
691
- * - mark:archived → invalidate resource detail + lists
692
- * - mark:unarchived → invalidate resource detail + lists
693
- * - mark:entity-tag-added / mark:entity-tag-removed → invalidate resource detail
745
+ * Long-running (semantic search, optional LLM scoring). Returns
746
+ * Observable with results.
694
747
  *
695
- * Token: mutable — call setTokenGetter() from the React layer when auth changes.
748
+ * Backend actor: Matcher
749
+ * Event prefix: match:*
696
750
  */
697
751
 
698
- type ResponseContent$2<T> = T extends {
699
- responses: {
700
- 200: {
701
- content: {
702
- 'application/json': infer R;
703
- };
704
- };
705
- };
706
- } ? R : never;
707
- type ResourceDetail = ResponseContent$2<paths['/resources/{id}']['get']>;
708
- type ResourceListResponse = ResponseContent$2<paths['/resources']['get']>;
709
- type TokenGetter$1 = () => AccessToken | undefined;
710
- declare class ResourceStore {
752
+ type TokenGetter$5 = () => AccessToken | undefined;
753
+ declare class MatchNamespace implements MatchNamespace$1 {
711
754
  private readonly http;
712
- /** Cache of individual resource details, keyed by ResourceId */
713
- private readonly detail$;
714
- /** Cache of list responses, keyed by a serialized options string */
715
- private readonly list$;
716
- /** Track in-flight fetches to avoid duplicate requests */
717
- private readonly fetchingDetail;
718
- private readonly fetchingList;
719
- /** Memoized Observables — same instance returned for the same key */
720
- private readonly detailObs$;
721
- private readonly listObs$;
722
- /** Mutable token getter — updated from the React layer when auth changes */
723
- private getToken;
724
- /** Update the token getter (called from React when auth token changes) */
725
- setTokenGetter(getter: TokenGetter$1): void;
726
- constructor(http: SemiontApiClient, eventBus: EventBus);
727
- /**
728
- * Get a single resource by ID as an Observable.
729
- * Triggers a fetch if not cached.
730
- */
731
- get(id: ResourceId): Observable<ResourceDetail | undefined>;
732
- /**
733
- * List resources as an Observable.
734
- * Triggers a fetch if not cached.
735
- */
736
- list(options?: {
755
+ private readonly eventBus;
756
+ private readonly getToken;
757
+ constructor(http: SemiontApiClient, eventBus: EventBus, getToken: TokenGetter$5);
758
+ search(resourceId: ResourceId, referenceId: string, context: GatheredContext, options?: {
737
759
  limit?: number;
738
- archived?: boolean;
739
- }): Observable<ResourceListResponse | undefined>;
740
- /** Invalidate and re-fetch a specific resource detail */
741
- invalidateDetail(id: ResourceId): void;
742
- /** Remove all list caches (triggers re-fetch on next subscribe) */
743
- invalidateLists(): void;
744
- private fetchDetail;
745
- private fetchList;
760
+ useSemanticScoring?: boolean;
761
+ }): Observable<MatchSearchProgress>;
746
762
  }
747
763
 
748
764
  /**
749
- * AnnotationStoreper-workspace observable annotation cache
765
+ * YieldNamespaceresource creation
750
766
  *
751
- * BehaviorSubject-backed store that:
752
- * - Populates lazily on first subscribe (no up-front fetch)
753
- * - Updates reactively when EventBus events arrive (no manual invalidation)
754
- * - Is readable from outside React
767
+ * resource() is synchronous file upload (Promise).
768
+ * fromAnnotation() is long-running LLM generation (Observable).
769
+ *
770
+ * Backend actor: Stower + generation worker
771
+ * Event prefix: yield:*
772
+ */
773
+
774
+ type ResourceDescriptor = components['schemas']['ResourceDescriptor'];
775
+ type TokenGetter$4 = () => AccessToken | undefined;
776
+ declare class YieldNamespace implements YieldNamespace$1 {
777
+ private readonly http;
778
+ private readonly eventBus;
779
+ private readonly getToken;
780
+ constructor(http: SemiontApiClient, eventBus: EventBus, getToken: TokenGetter$4);
781
+ resource(data: CreateResourceInput): Promise<{
782
+ resourceId: string;
783
+ }>;
784
+ fromAnnotation(resourceId: ResourceId, annotationId: AnnotationId, options: GenerationOptions): Observable<YieldProgress$1>;
785
+ cloneToken(resourceId: ResourceId): Promise<{
786
+ token: string;
787
+ expiresAt: string;
788
+ }>;
789
+ fromToken(token: string): Promise<ResourceDescriptor>;
790
+ createFromToken(options: CreateFromTokenOptions): Promise<{
791
+ resourceId: string;
792
+ }>;
793
+ }
794
+
795
+ /**
796
+ * BeckonNamespace — attention coordination
755
797
  *
756
- * EventBus events handled:
757
- * - mark:deleted → remove from detail cache
758
- * - mark:added → invalidate annotation list (SSE domain event; resourceId on BaseEvent)
759
- * - mark:removed → invalidate annotation list + detail (SSE domain event)
760
- * - mark:body-updated → invalidate annotation list + detail (SSE domain event)
761
- * - mark:entity-tag-added / mark:entity-tag-removed → invalidate list for resource
798
+ * Fire-and-forget. Ephemeral presence signal delivered via the
799
+ * attention-stream to other participants.
762
800
  *
763
- * Token: mutable call setTokenGetter() from the React layer when auth changes.
801
+ * Backend actor: (frontend relay via attention-stream)
802
+ * Event prefix: beckon:*
764
803
  */
765
804
 
766
- type ResponseContent$1<T> = T extends {
767
- responses: {
768
- 200: {
769
- content: {
770
- 'application/json': infer R;
771
- };
772
- };
773
- };
774
- } ? R : never;
775
- type AnnotationsListResponse = ResponseContent$1<paths['/resources/{id}/annotations']['get']>;
776
- type AnnotationDetail = ResponseContent$1<paths['/resources/{resourceId}/annotations/{annotationId}']['get']>;
805
+ type TokenGetter$3 = () => AccessToken | undefined;
806
+ declare class BeckonNamespace implements BeckonNamespace$1 {
807
+ private readonly http;
808
+ private readonly getToken;
809
+ constructor(http: SemiontApiClient, getToken: TokenGetter$3);
810
+ attention(annotationId: AnnotationId, resourceId: ResourceId): void;
811
+ }
812
+
813
+ /**
814
+ * JobNamespace — worker lifecycle
815
+ */
816
+
817
+ type JobStatusResponse = components['schemas']['JobStatusResponse'];
818
+ type TokenGetter$2 = () => AccessToken | undefined;
819
+ declare class JobNamespace implements JobNamespace$1 {
820
+ private readonly http;
821
+ private readonly getToken;
822
+ constructor(http: SemiontApiClient, getToken: TokenGetter$2);
823
+ status(jobId: JobId): Promise<JobStatusResponse>;
824
+ pollUntilComplete(jobId: JobId, options?: {
825
+ interval?: number;
826
+ timeout?: number;
827
+ onProgress?: (status: JobStatusResponse) => void;
828
+ }): Promise<JobStatusResponse>;
829
+ cancel(jobId: JobId, type: string): Promise<void>;
830
+ }
831
+
832
+ /**
833
+ * AuthNamespace — authentication
834
+ */
835
+
836
+ type AuthResponse = components['schemas']['AuthResponse'];
837
+ type TokenGetter$1 = () => AccessToken | undefined;
838
+ declare class AuthNamespace implements AuthNamespace$1 {
839
+ private readonly http;
840
+ private readonly getToken;
841
+ constructor(http: SemiontApiClient, getToken: TokenGetter$1);
842
+ password(emailStr: string, passwordStr: string): Promise<AuthResponse>;
843
+ google(credential: string): Promise<AuthResponse>;
844
+ refresh(token: string): Promise<AuthResponse>;
845
+ logout(): Promise<void>;
846
+ me(): Promise<User>;
847
+ acceptTerms(): Promise<void>;
848
+ mcpToken(): Promise<{
849
+ token: string;
850
+ }>;
851
+ mediaToken(resourceId: ResourceId): Promise<{
852
+ token: string;
853
+ }>;
854
+ }
855
+
856
+ /**
857
+ * AdminNamespace — administration
858
+ */
859
+
860
+ type AdminUserStatsResponse = components['schemas']['AdminUserStatsResponse'];
861
+ type OAuthConfigResponse = components['schemas']['OAuthConfigResponse'];
777
862
  type TokenGetter = () => AccessToken | undefined;
778
- declare class AnnotationStore {
863
+ declare class AdminNamespace implements AdminNamespace$1 {
779
864
  private readonly http;
780
- /** Annotation list responses keyed by ResourceId */
781
- private readonly list$;
782
- /** Individual annotation details keyed by AnnotationId */
783
- private readonly detail$;
784
- /** Track in-flight fetches */
785
- private readonly fetchingList;
786
- private readonly fetchingDetail;
787
- /** Memoized Observables — same instance returned for the same key */
788
- private readonly listObs$;
789
- private readonly detailObs$;
790
- /** Mutable token getter — updated from the React layer when auth changes */
791
- private getToken;
792
- /** Update the token getter (called from React when auth token changes) */
793
- setTokenGetter(getter: TokenGetter): void;
794
- constructor(http: SemiontApiClient, eventBus: EventBus);
795
- /**
796
- * Get annotations for a resource as an Observable.
797
- * Triggers a fetch if not cached.
798
- */
799
- listForResource(resourceId: ResourceId): Observable<AnnotationsListResponse | undefined>;
800
- /**
801
- * Get a single annotation detail as an Observable.
802
- * Triggers a fetch if not cached.
803
- */
804
- get(resourceId: ResourceId, annotationId: AnnotationId): Observable<AnnotationDetail | undefined>;
805
- /** Invalidate and re-fetch a resource's annotation list */
806
- invalidateList(resourceId: ResourceId): void;
807
- /** Invalidate a single annotation detail (re-fetched on next subscribe) */
808
- invalidateDetail(annotationId: AnnotationId): void;
809
- /** Remove an annotation from the detail cache without re-fetching */
810
- private removeFromDetailCache;
811
- private fetchList;
812
- private fetchDetail;
865
+ private readonly getToken;
866
+ constructor(http: SemiontApiClient, getToken: TokenGetter);
867
+ users(): Promise<User[]>;
868
+ userStats(): Promise<AdminUserStatsResponse>;
869
+ updateUser(userId: UserDID, data: RequestContent$1<paths['/api/admin/users/{id}']['patch']>): Promise<User>;
870
+ oauthConfig(): Promise<OAuthConfigResponse>;
871
+ healthCheck(): Promise<ResponseContent$1<paths['/api/health']['get']>>;
872
+ status(): Promise<ResponseContent$1<paths['/api/status']['get']>>;
873
+ backup(): Promise<Response>;
874
+ restore(file: File, onProgress?: (event: {
875
+ phase: string;
876
+ message?: string;
877
+ result?: Record<string, unknown>;
878
+ }) => void): Promise<{
879
+ phase: string;
880
+ message?: string;
881
+ result?: Record<string, unknown>;
882
+ }>;
883
+ exportKnowledgeBase(params?: {
884
+ includeArchived?: boolean;
885
+ }): Promise<Response>;
886
+ importKnowledgeBase(file: File, onProgress?: (event: {
887
+ phase: string;
888
+ message?: string;
889
+ result?: Record<string, unknown>;
890
+ }) => void): Promise<{
891
+ phase: string;
892
+ message?: string;
893
+ result?: Record<string, unknown>;
894
+ }>;
813
895
  }
814
896
 
815
897
  /**
@@ -853,6 +935,18 @@ declare class APIError extends Error {
853
935
  details?: unknown | undefined;
854
936
  constructor(message: string, status: number, statusText: string, details?: unknown | undefined);
855
937
  }
938
+ /**
939
+ * Optional callback invoked when a request fails with HTTP 401. If it
940
+ * resolves to a non-null token, the failed request is retried once with
941
+ * the new Bearer token. If it resolves to null (or throws), the original
942
+ * 401 propagates as an APIError.
943
+ *
944
+ * Implementations must dedupe concurrent calls so that simultaneous 401s
945
+ * don't fire multiple parallel refresh requests. The frontend's
946
+ * KnowledgeBaseSessionProvider provides this via an in-flight Promise map
947
+ * keyed by KB id.
948
+ */
949
+ type TokenRefresher = () => Promise<string | null>;
856
950
  interface SemiontApiClientConfig {
857
951
  baseUrl: BaseUrl;
858
952
  /** Per-workspace EventBus. Required — one bus per workspace, constructed externally. */
@@ -860,6 +954,15 @@ interface SemiontApiClientConfig {
860
954
  timeout?: number;
861
955
  retry?: number;
862
956
  logger?: Logger;
957
+ /** Optional 401-recovery hook. See {@link TokenRefresher}. */
958
+ tokenRefresher?: TokenRefresher;
959
+ /**
960
+ * Token getter for the verb-namespace API (client.browse, client.mark, etc.).
961
+ * When provided, auth is managed internally — no per-call auth needed.
962
+ * The getter is called on each request to get the current token.
963
+ * If not provided, namespace methods use undefined auth (public endpoints only).
964
+ */
965
+ getToken?: () => AccessToken | undefined;
863
966
  }
864
967
  /**
865
968
  * Options for individual API requests
@@ -880,6 +983,11 @@ declare class SemiontApiClient {
880
983
  /** The workspace-scoped EventBus this client was constructed with. */
881
984
  readonly eventBus: EventBus;
882
985
  private logger?;
986
+ /**
987
+ * Shared mutable token getter. All verb namespaces read from this.
988
+ * Updated via setTokenGetter() from the React auth layer.
989
+ */
990
+ private _getToken;
883
991
  /**
884
992
  * SSE streaming client for real-time operations
885
993
  *
@@ -887,21 +995,23 @@ declare class SemiontApiClient {
887
995
  * Uses native fetch() instead of ky for SSE support.
888
996
  */
889
997
  readonly sse: SSEClient;
998
+ readonly browse: BrowseNamespace;
999
+ readonly mark: MarkNamespace;
1000
+ readonly bind: BindNamespace;
1001
+ readonly gather: GatherNamespace;
1002
+ readonly match: MatchNamespace;
1003
+ readonly yield: YieldNamespace;
1004
+ readonly beckon: BeckonNamespace;
1005
+ readonly job: JobNamespace;
1006
+ readonly auth: AuthNamespace;
1007
+ readonly admin: AdminNamespace;
1008
+ constructor(config: SemiontApiClientConfig);
890
1009
  /**
891
- * Framework-agnostic flow orchestration.
892
- * Each method returns a Subscription; call .unsubscribe() to tear down.
893
- */
894
- readonly flows: FlowEngine;
895
- /**
896
- * Per-workspace observable stores for entity data.
897
- * Call stores.resources.setTokenGetter() / stores.annotations.setTokenGetter()
898
- * from the React layer when the auth token changes.
1010
+ * Update the token getter for all verb namespaces.
1011
+ * Called from the React auth layer when the token changes.
1012
+ * All namespaces share this getter via closure — no per-namespace sync needed.
899
1013
  */
900
- readonly stores: {
901
- resources: ResourceStore;
902
- annotations: AnnotationStore;
903
- };
904
- constructor(config: SemiontApiClientConfig);
1014
+ setTokenGetter(getter: () => AccessToken | undefined): void;
905
1015
  private authHeaders;
906
1016
  authenticatePassword(email: Email, password: string, options?: RequestOptions): Promise<ResponseContent<paths['/api/tokens/password']['post']>>;
907
1017
  refreshToken(token: RefreshToken, options?: RequestOptions): Promise<ResponseContent<paths['/api/tokens/refresh']['post']>>;
@@ -1029,8 +1139,78 @@ declare class SemiontApiClient {
1029
1139
  browseAnnotation(resourceId: ResourceId, annotationId: AnnotationId, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{resourceId}/annotations/{annotationId}']['get']>>;
1030
1140
  browseAnnotations(id: ResourceId, motivation?: Motivation, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}/annotations']['get']>>;
1031
1141
  deleteAnnotation(resourceId: ResourceId, annotationId: AnnotationId, options?: RequestOptions): Promise<void>;
1032
- bindAnnotation(resourceId: ResourceId, annotationId: AnnotationId, data: RequestContent<paths['/resources/{resourceId}/annotations/{annotationId}/body']['put']>, options?: RequestOptions): Promise<void>;
1142
+ bindAnnotation(resourceId: ResourceId, annotationId: AnnotationId, data: {
1143
+ operations: BodyOperation[];
1144
+ }, options?: RequestOptions): Promise<{
1145
+ correlationId: string;
1146
+ }>;
1033
1147
  getAnnotationHistory(resourceId: ResourceId, annotationId: AnnotationId, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{resourceId}/annotations/{annotationId}/history']['get']>>;
1148
+ annotateReferences(resourceId: ResourceId, data: {
1149
+ entityTypes: string[];
1150
+ includeDescriptiveReferences?: boolean;
1151
+ }, options?: RequestOptions): Promise<{
1152
+ correlationId: string;
1153
+ jobId: string;
1154
+ }>;
1155
+ annotateHighlights(resourceId: ResourceId, data: {
1156
+ instructions?: string;
1157
+ density?: number;
1158
+ }, options?: RequestOptions): Promise<{
1159
+ correlationId: string;
1160
+ jobId: string;
1161
+ }>;
1162
+ annotateAssessments(resourceId: ResourceId, data: {
1163
+ instructions?: string;
1164
+ tone?: string;
1165
+ density?: number;
1166
+ language?: string;
1167
+ }, options?: RequestOptions): Promise<{
1168
+ correlationId: string;
1169
+ jobId: string;
1170
+ }>;
1171
+ annotateComments(resourceId: ResourceId, data: {
1172
+ instructions?: string;
1173
+ tone?: string;
1174
+ density?: number;
1175
+ language?: string;
1176
+ }, options?: RequestOptions): Promise<{
1177
+ correlationId: string;
1178
+ jobId: string;
1179
+ }>;
1180
+ annotateTags(resourceId: ResourceId, data: {
1181
+ schemaId: string;
1182
+ categories: string[];
1183
+ }, options?: RequestOptions): Promise<{
1184
+ correlationId: string;
1185
+ jobId: string;
1186
+ }>;
1187
+ yieldResourceFromAnnotation(resourceId: ResourceId, annotationId: AnnotationId, data: {
1188
+ title: string;
1189
+ storageUri: string;
1190
+ context: unknown;
1191
+ prompt?: string;
1192
+ language?: string;
1193
+ temperature?: number;
1194
+ maxTokens?: number;
1195
+ }, options?: RequestOptions): Promise<{
1196
+ correlationId: string;
1197
+ jobId: string;
1198
+ }>;
1199
+ gatherAnnotationContext(resourceId: ResourceId, annotationId: AnnotationId, data: {
1200
+ correlationId: string;
1201
+ contextWindow?: number;
1202
+ }, options?: RequestOptions): Promise<{
1203
+ correlationId: string;
1204
+ }>;
1205
+ matchSearch(resourceId: ResourceId, data: {
1206
+ correlationId: string;
1207
+ referenceId: string;
1208
+ context: unknown;
1209
+ limit?: number;
1210
+ useSemanticScoring?: boolean;
1211
+ }, options?: RequestOptions): Promise<{
1212
+ correlationId: string;
1213
+ }>;
1034
1214
  addEntityType(type: EntityType, options?: RequestOptions): Promise<void>;
1035
1215
  addEntityTypesBulk(types: EntityType[], options?: RequestOptions): Promise<void>;
1036
1216
  listEntityTypes(options?: RequestOptions): Promise<ResponseContent<paths['/api/entity-types']['get']>>;
@@ -1104,77 +1284,6 @@ declare class SemiontApiClient {
1104
1284
  browseFiles(dirPath?: string, sort?: 'name' | 'mtime' | 'annotationCount', options?: RequestOptions): Promise<ResponseContent<paths['/api/browse/files']['get']>>;
1105
1285
  }
1106
1286
 
1107
- /**
1108
- * EventBus-Only Client
1109
- *
1110
- * Implements the same knowledge-domain operations as SemiontApiClient
1111
- * but communicates directly via EventBus instead of HTTP.
1112
- *
1113
- * This proves the EventBus is a complete interface for all knowledge-domain
1114
- * operations. Binary content transfer and auth/admin stay HTTP-only.
1115
- *
1116
- * Usage:
1117
- * ```typescript
1118
- * import { EventBus } from '@semiont/core';
1119
- * import { EventBusClient } from '@semiont/api-client';
1120
- *
1121
- * const eventBus = new EventBus();
1122
- * const client = new EventBusClient(eventBus);
1123
- *
1124
- * const resources = await client.browseResources({ limit: 10 });
1125
- * const resource = await client.browseResource(resourceId('doc-123'));
1126
- * ```
1127
- */
1128
-
1129
- declare class EventBusClient {
1130
- private eventBus;
1131
- private timeoutMs;
1132
- constructor(eventBus: EventBus, timeoutMs?: number);
1133
- browseResource(resourceId: ResourceId): Promise<components['schemas']['GetResourceResponse']>;
1134
- browseResources(options?: {
1135
- search?: string;
1136
- archived?: boolean;
1137
- entityType?: string;
1138
- offset?: number;
1139
- limit?: number;
1140
- }): Promise<components['schemas']['ListResourcesResponse']>;
1141
- getAnnotations(resourceId: ResourceId): Promise<components['schemas']['GetAnnotationsResponse']>;
1142
- getAnnotation(resourceId: ResourceId, annotationId: AnnotationId): Promise<components['schemas']['GetAnnotationResponse']>;
1143
- getEvents(resourceId: ResourceId, options?: {
1144
- type?: string;
1145
- userId?: string;
1146
- limit?: number;
1147
- }): Promise<components['schemas']['GetEventsResponse']>;
1148
- getAnnotationHistory(resourceId: ResourceId, annotationId: AnnotationId): Promise<components['schemas']['GetAnnotationHistoryResponse']>;
1149
- getReferencedBy(resourceId: ResourceId, motivation?: string): Promise<components['schemas']['GetReferencedByResponse']>;
1150
- listEntityTypes(): Promise<components['schemas']['GetEntityTypesResponse']>;
1151
- addEntityType(tag: string, userId: UserId): void;
1152
- generateCloneToken(resourceId: ResourceId): Promise<components['schemas']['CloneResourceWithTokenResponse']>;
1153
- getResourceByToken(token: string): Promise<components['schemas']['GetResourceByTokenResponse']>;
1154
- createResourceFromToken(options: {
1155
- token: string;
1156
- name: string;
1157
- content: string;
1158
- userId: UserId;
1159
- archiveOriginal?: boolean;
1160
- }): Promise<{
1161
- resourceId: ResourceId;
1162
- }>;
1163
- getJobStatus(jobId: JobId): Promise<components['schemas']['JobStatusResponse']>;
1164
- gatherAnnotation(annotationId: AnnotationId, resourceId: ResourceId, options?: {
1165
- includeSourceContext?: boolean;
1166
- includeTargetContext?: boolean;
1167
- contextWindow?: number;
1168
- }): Promise<components['schemas']['AnnotationLLMContextResponse']>;
1169
- gatherResource(resourceId: ResourceId, options: {
1170
- depth: number;
1171
- maxResources: number;
1172
- includeContent: boolean;
1173
- includeSummary: boolean;
1174
- }): Promise<components['schemas']['ResourceLLMContextResponse']>;
1175
- searchResources(searchTerm: string): Promise<components['schemas']['ResourceDescriptor'][]>;
1176
- }
1177
-
1178
1287
  /**
1179
1288
  * MIME type utilities for Semiont
1180
1289
  *
@@ -1213,4 +1322,4 @@ declare function isPdfMimeType(mimeType: string): boolean;
1213
1322
  type MimeCategory = 'text' | 'image' | 'unsupported';
1214
1323
  declare function getMimeCategory(mimeType: string): MimeCategory;
1215
1324
 
1216
- export { APIError, type AnnotateReferencesStreamRequest, type AnnotationDetail, AnnotationStore, type AnnotationsListResponse, EventBusClient, FlowEngine, type MatchSearchStreamRequest, type MimeCategory, type ReferenceDetectionProgress, type RequestOptions, type ResourceDetail, type ResourceListResponse, ResourceStore, SSEClient, type SSEClientConfig, type SSEStream, type SSEStreamConnected, SSE_STREAM_CONNECTED, SemiontApiClient, type SemiontApiClientConfig, type YieldProgress, type YieldResourceStreamRequest, getExtensionForMimeType, getMimeCategory, isImageMimeType, isPdfMimeType, isTextMimeType };
1325
+ export { APIError, AdminNamespace, type AnnotationHistoryResponse, AuthNamespace, BeckonNamespace, BindNamespace, BrowseNamespace, type CreateAnnotationInput, type CreateFromTokenOptions, type CreateResourceInput, type GatherAnnotationProgress, GatherNamespace, type GenerationOptions, JobNamespace, type MarkAssistOptions, type MarkAssistProgress, MarkNamespace, MatchNamespace, type MatchSearchProgress, type MimeCategory, type ReferenceDetectionProgress, type ReferencedByEntry, type RequestContent$1 as RequestContent, type RequestOptions, type ResponseContent$1 as ResponseContent, SSEClient, type SSEClientConfig, type SSEStream, type SSEStreamConnected, SSE_STREAM_CONNECTED, SemiontApiClient, type SemiontApiClientConfig, type TokenRefresher, type User, YieldNamespace, type YieldProgress, getExtensionForMimeType, getMimeCategory, isImageMimeType, isPdfMimeType, isTextMimeType };