@semiont/api-client 0.4.13 → 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/README.md CHANGED
@@ -6,168 +6,96 @@
6
6
  [![npm downloads](https://img.shields.io/npm/dm/@semiont/api-client.svg)](https://www.npmjs.com/package/@semiont/api-client)
7
7
  [![License](https://img.shields.io/npm/l/@semiont/api-client.svg)](https://github.com/The-AI-Alliance/semiont/blob/main/LICENSE)
8
8
 
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.
9
+ TypeScript SDK for [Semiont](https://github.com/The-AI-Alliance/semiont) a knowledge management system for semantic annotations, AI-powered analysis, and collaborative document understanding.
10
10
 
11
- This package provides two clients, SSE streams, and utilities for working with Semiont:
11
+ The api-client is a transparent proxy to `@semiont/make-meaning`. The frontend writes code as though it has direct access to the knowledge system. HTTP, auth, SSE, and caching are internal concerns.
12
12
 
13
- - **`SemiontApiClient`** HTTP client for the Semiont REST API
14
- - **`EventBusClient`** — Direct EventBus client (no HTTP needed)
13
+ ## The 7 Verbs
15
14
 
16
- OpenAPI types are re-exported from [`@semiont/core`](../core/README.md) (the source of truth).
17
-
18
- ## What is Semiont?
19
-
20
- Semiont lets you:
21
-
22
- - **Store and manage documents** (text, markdown, images, PDFs)
23
- - **Create semantic annotations** using W3C Web Annotation standard
24
- - **Link and reference** between documents
25
- - **Track provenance** with event sourcing
26
- - **Collaborate in real-time** via SSE streams
27
- - **Detect annotations** using AI for text formats (highlights, assessments, comments, tags, entity references)
28
- - **Retrieve context** for LLMs via graph traversal
29
- - **Generate new documents** from annotations with AI
30
-
31
- ## Installation
32
-
33
- Install the latest stable release from npm:
34
-
35
- ```bash
36
- npm install @semiont/api-client
37
- ```
38
-
39
- Or install the latest development build:
40
-
41
- ```bash
42
- npm install @semiont/api-client@dev
43
- ```
44
-
45
- **Prerequisites**: Semiont backend running. See [Running the Backend](../../apps/backend/README.md#quick-start) for setup.
46
-
47
- ## Quick Start
15
+ The API is organized by the domain's verbs — the same verbs that organize the EventBus protocol, the documentation, and the backend actors:
48
16
 
49
17
  ```typescript
50
- import { SemiontApiClient, baseUrl, email, resourceUri } from '@semiont/api-client';
51
-
52
- const client = new SemiontApiClient({
53
- baseUrl: baseUrl('http://localhost:4000'),
54
- });
18
+ import { SemiontApiClient } from '@semiont/api-client';
55
19
 
56
- // Authenticate (local development mode)
57
- await client.authenticateLocal(email('user@example.com'));
20
+ const semiont = new SemiontApiClient({ baseUrl, eventBus, getToken });
58
21
 
59
- // Create a text document
60
- const { resource } = await client.createResource({
61
- name: 'My Document',
62
- file: Buffer.from('The quick brown fox jumps over the lazy dog.'),
63
- format: 'text/plain',
64
- entityTypes: ['example']
65
- });
22
+ // Browse reads from materialized views
23
+ const resource = semiont.browse.resource(resourceId); // Observable
24
+ const annotations = semiont.browse.annotations(resourceId); // Observable
25
+ const content = await semiont.browse.resourceContent(rid); // Promise
66
26
 
67
- console.log('Created resource:', resource['@id']);
27
+ // Mark — annotation CRUD + AI assist
28
+ await semiont.mark.annotation(resourceId, input);
29
+ await semiont.mark.delete(resourceId, annotationId);
30
+ semiont.mark.assist(resourceId, 'linking', options); // Observable (progress)
68
31
 
69
- // Detect annotations with AI (text/markdown formats only)
70
- const stream = client.sse.detectAnnotations(resourceUri(resource['@id']), {
71
- entityTypes: ['Animal', 'Color']
72
- });
32
+ // Bind reference linking
33
+ await semiont.bind.body(resourceId, annotationId, operations);
73
34
 
74
- stream.onProgress((p) => console.log(`Scanning: ${p.currentEntityType}`));
75
- stream.onComplete((result) => console.log(`Found ${result.foundCount} annotations`));
35
+ // Gather LLM context assembly
36
+ semiont.gather.annotation(annotationId, resourceId); // Observable (progress context)
76
37
 
77
- // Get annotations
78
- const annotations = await client.getResourceAnnotations(resourceUri(resource['@id']));
79
- console.log('Annotations:', annotations.annotations.length);
80
- ```
38
+ // Match — semantic search
39
+ semiont.match.search(resourceId, referenceId, context); // Observable (results)
81
40
 
82
- ## EventBus Client (No HTTP)
41
+ // Yield resource creation + AI generation
42
+ await semiont.yield.resource(data);
43
+ semiont.yield.fromAnnotation(resourceId, annotationId, opts); // Observable (progress)
83
44
 
84
- The `EventBusClient` communicates directly via the RxJS EventBus no HTTP server needed. It covers all knowledge-domain operations (resource reads, annotations, entity types, search, LLM context, clone tokens, job status).
45
+ // Beckonattention coordination
46
+ semiont.beckon.attention(annotationId, resourceId); // void (ephemeral)
85
47
 
86
- ```typescript
87
- import { EventBusClient } from '@semiont/api-client';
88
- import { EventBus, resourceId } from '@semiont/core';
89
- import { startMakeMeaning } from '@semiont/make-meaning';
90
-
91
- // Start the knowledge system
92
- const eventBus = new EventBus();
93
- const makeMeaning = await startMakeMeaning(config, eventBus, logger);
94
-
95
- // Use EventBusClient instead of SemiontApiClient
96
- const client = new EventBusClient(eventBus);
97
-
98
- // Same operations, no HTTP
99
- const resources = await client.listResources({ limit: 10 });
100
- const resource = await client.getResource(resourceId('doc-123'));
101
- const annotations = await client.getAnnotations(resourceId('doc-123'));
102
- const entityTypes = await client.listEntityTypes();
103
- const results = await client.searchResources('quantum computing');
48
+ // + Job, Auth, Admin namespaces
104
49
  ```
105
50
 
106
- **What's covered**: All browse, bind, mark, gather, yield (clone), and job operations.
51
+ ## Return Type Conventions
107
52
 
108
- **What's NOT covered** (HTTP-only): Auth, admin, health/status, binary content upload/download, SSE streaming.
53
+ - **Browse live queries** → `Observable` (events-stream driven, cached in BehaviorSubject)
54
+ - **Browse one-shot reads** → `Promise` (fetch once, no cache)
55
+ - **Commands** (mark, bind, yield.resource) → `Promise` (fire-and-forget)
56
+ - **Long-running ops** (gather, match, yield.fromAnnotation, mark.assist) → `Observable` (progress + result)
57
+ - **Ephemeral signals** (beckon) → `void`
109
58
 
110
- ## Logging
59
+ ## Auth is Internal
111
60
 
112
- Enable logging to debug requests and monitor API usage:
61
+ The client takes a `getToken` function at construction. No per-call auth:
113
62
 
114
63
  ```typescript
115
- import { SemiontApiClient, Logger, baseUrl } from '@semiont/api-client';
116
- import winston from 'winston';
117
-
118
- const logger = winston.createLogger({
119
- level: 'debug',
120
- format: winston.format.json(),
121
- transports: [new winston.transports.Console()]
122
- });
123
-
124
- const client = new SemiontApiClient({
64
+ const semiont = new SemiontApiClient({
125
65
  baseUrl: baseUrl('http://localhost:4000'),
126
- logger
66
+ eventBus: new EventBus(),
67
+ getToken: () => accessToken(token),
127
68
  });
128
69
 
129
- // Now all HTTP requests and SSE streams will be logged
70
+ // No auth on individual calls
71
+ const annotations = semiont.browse.annotations(resourceId);
72
+ await semiont.mark.annotation(resourceId, input);
73
+ await semiont.bind.body(resourceId, annotationId, operations);
130
74
  ```
131
75
 
132
- **What gets logged**: HTTP requests/responses, SSE stream lifecycle, individual events, and errors
133
-
134
- **Security**: Authorization headers are never logged to prevent token leaks
76
+ Update the token getter at any time via `semiont.setTokenGetter(getter)`.
135
77
 
136
- 📘 **[Complete Logging Guide](./docs/LOGGING.md)** - Logger setup, integration examples, structured metadata, troubleshooting
137
-
138
- ## Documentation
78
+ ## Installation
139
79
 
140
- 📚 **[Usage Guide](./docs/Usage.md)** - Authentication, resources, annotations, SSE streaming
80
+ ```bash
81
+ npm install @semiont/api-client
82
+ ```
141
83
 
142
- 📖 **[API Reference](./docs/API-Reference.md)** - Complete method documentation
84
+ **Prerequisites**: Semiont backend running. See [Running the Backend](../../apps/backend/README.md#quick-start).
143
85
 
144
- 🛠️ **[Utilities Guide](./docs/Utilities.md)** - Text encoding, fuzzy anchoring, SVG utilities
86
+ ## Documentation
145
87
 
146
- 🗄️ **[Observable Stores](./docs/STORES.md)** - Reactive resource and annotation caches, EventBus-driven invalidation, React integration
88
+ - [Usage Guide](./docs/Usage.md) authentication, resources, annotations, streaming
89
+ - [API Reference](./docs/API-Reference.md) — complete method documentation
90
+ - [Utilities Guide](./docs/Utilities.md) — text encoding, fuzzy anchoring, SVG utilities
91
+ - [Logging Guide](./docs/LOGGING.md) — logger setup and troubleshooting
147
92
 
148
93
  ## Key Features
149
94
 
150
- - **Two clients** - HTTP (`SemiontApiClient`) and EventBus (`EventBusClient`) for the same operations
151
- - **Type-safe** - Re-exports OpenAPI types from `@semiont/core` with branded types
152
- - **W3C compliant** - Web Annotation standard with fuzzy text matching
153
- - **Real-time** - SSE streaming for long operations
154
- - **Framework-agnostic** - Pure TypeScript utilities work everywhere
155
- - **Character encoding** - Proper UTF-8, ISO-8859-1, Windows-1252 support
156
-
157
- **Note**: OpenAPI types are generated in `@semiont/core` (source of truth) and re-exported here for convenience.
158
-
159
- ## Use Cases
160
-
161
- **SemiontApiClient (HTTP)**:
162
- - MCP servers and AI integrations
163
- - Frontend applications (wrap with React hooks)
164
- - CLI tools and automation scripts
165
- - Third-party integrations
166
-
167
- **EventBusClient (direct)**:
168
- - Scripts that run alongside make-meaning (no HTTP server)
169
- - Testing without HTTP overhead
170
- - Embedded scenarios where EventBus is available directly
95
+ - **Verb-oriented** 7 domain namespaces mirror `@semiont/make-meaning`'s actor model
96
+ - **Type-safe** OpenAPI types from `@semiont/core`, branded identifiers
97
+ - **Observable reads** — live-updating views via EventBus + events-stream SSE
98
+ - **Framework-agnostic** pure TypeScript + RxJS, no React dependency
171
99
 
172
100
  ## License
173
101