@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/README.md +56 -128
- package/dist/index.d.ts +736 -627
- package/dist/index.js +804 -1218
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,168 +6,96 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/@semiont/api-client)
|
|
7
7
|
[](https://github.com/The-AI-Alliance/semiont/blob/main/LICENSE)
|
|
8
8
|
|
|
9
|
-
TypeScript SDK for [Semiont](https://github.com/The-AI-Alliance/semiont)
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
- **`EventBusClient`** — Direct EventBus client (no HTTP needed)
|
|
13
|
+
## The 7 Verbs
|
|
15
14
|
|
|
16
|
-
|
|
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
|
|
51
|
-
|
|
52
|
-
const client = new SemiontApiClient({
|
|
53
|
-
baseUrl: baseUrl('http://localhost:4000'),
|
|
54
|
-
});
|
|
18
|
+
import { SemiontApiClient } from '@semiont/api-client';
|
|
55
19
|
|
|
56
|
-
|
|
57
|
-
await client.authenticateLocal(email('user@example.com'));
|
|
20
|
+
const semiont = new SemiontApiClient({ baseUrl, eventBus, getToken });
|
|
58
21
|
|
|
59
|
-
//
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
70
|
-
|
|
71
|
-
entityTypes: ['Animal', 'Color']
|
|
72
|
-
});
|
|
32
|
+
// Bind — reference linking
|
|
33
|
+
await semiont.bind.body(resourceId, annotationId, operations);
|
|
73
34
|
|
|
74
|
-
|
|
75
|
-
|
|
35
|
+
// Gather — LLM context assembly
|
|
36
|
+
semiont.gather.annotation(annotationId, resourceId); // Observable (progress → context)
|
|
76
37
|
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
console.log('Annotations:', annotations.annotations.length);
|
|
80
|
-
```
|
|
38
|
+
// Match — semantic search
|
|
39
|
+
semiont.match.search(resourceId, referenceId, context); // Observable (results)
|
|
81
40
|
|
|
82
|
-
|
|
41
|
+
// Yield — resource creation + AI generation
|
|
42
|
+
await semiont.yield.resource(data);
|
|
43
|
+
semiont.yield.fromAnnotation(resourceId, annotationId, opts); // Observable (progress)
|
|
83
44
|
|
|
84
|
-
|
|
45
|
+
// Beckon — attention coordination
|
|
46
|
+
semiont.beckon.attention(annotationId, resourceId); // void (ephemeral)
|
|
85
47
|
|
|
86
|
-
|
|
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
|
-
|
|
51
|
+
## Return Type Conventions
|
|
107
52
|
|
|
108
|
-
**
|
|
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
|
-
##
|
|
59
|
+
## Auth is Internal
|
|
111
60
|
|
|
112
|
-
|
|
61
|
+
The client takes a `getToken` function at construction. No per-call auth:
|
|
113
62
|
|
|
114
63
|
```typescript
|
|
115
|
-
|
|
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
|
-
|
|
66
|
+
eventBus: new EventBus(),
|
|
67
|
+
getToken: () => accessToken(token),
|
|
127
68
|
});
|
|
128
69
|
|
|
129
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
## Documentation
|
|
78
|
+
## Installation
|
|
139
79
|
|
|
140
|
-
|
|
80
|
+
```bash
|
|
81
|
+
npm install @semiont/api-client
|
|
82
|
+
```
|
|
141
83
|
|
|
142
|
-
|
|
84
|
+
**Prerequisites**: Semiont backend running. See [Running the Backend](../../apps/backend/README.md#quick-start).
|
|
143
85
|
|
|
144
|
-
|
|
86
|
+
## Documentation
|
|
145
87
|
|
|
146
|
-
|
|
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
|
-
- **
|
|
151
|
-
- **Type-safe**
|
|
152
|
-
- **
|
|
153
|
-
- **
|
|
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
|
|