@semiont/api-client 0.4.21 → 0.4.22

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,109 +6,67 @@
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 analysis, and collaborative document understanding.
9
+ HTTP-specific transport adapters for the Semiont SDK. This is the wire-side
10
+ implementation of the `ITransport` and `IContentTransport` contracts defined
11
+ in [`@semiont/core`](../core/), consumed by [`@semiont/sdk`](../sdk/).
10
12
 
11
- The api-client is a transparent proxy to `@semiont/make-meaning`. The browser writes code as though it has direct access to the knowledge system. HTTP, auth, SSE, and caching are internal concerns.
13
+ Most application code does **not** import this package directly. The sdk
14
+ re-exports the HTTP adapters for convenience, so a typical consumer writes:
12
15
 
13
- ## The 7 Verbs
16
+ ```ts
17
+ import { SemiontClient, HttpTransport, HttpContentTransport } from '@semiont/sdk';
18
+ import { baseUrl } from '@semiont/core';
14
19
 
15
- The API is organized by the domain's verbs — the same verbs that organize the EventBus protocol, the documentation, and the backend actors:
16
-
17
- ```typescript
18
- import { SemiontApiClient } from '@semiont/api-client';
19
-
20
- const semiont = new SemiontApiClient({ baseUrl, eventBus, token$ });
21
-
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
26
-
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)
31
-
32
- // Bind — reference linking
33
- await semiont.bind.body(resourceId, annotationId, operations);
34
-
35
- // Gather — LLM context assembly
36
- semiont.gather.annotation(annotationId, resourceId); // Observable (progress → context)
37
-
38
- // Match — semantic search
39
- semiont.match.search(resourceId, referenceId, context); // Observable (results)
40
-
41
- // Yield — resource creation + AI generation
42
- await semiont.yield.resource(data);
43
- semiont.yield.fromAnnotation(resourceId, annotationId, opts); // Observable (progress)
44
-
45
- // Beckon — attention coordination
46
- semiont.beckon.attention(annotationId, resourceId); // void (ephemeral)
47
-
48
- // + Job, Auth, Admin namespaces
20
+ const transport = new HttpTransport({ baseUrl: baseUrl('https://kb.example/') });
21
+ const client = new SemiontClient(transport, new HttpContentTransport(transport));
49
22
  ```
50
23
 
51
- ## Return Type Conventions
52
-
53
- - **Browse live queries** `Observable` (bus-gateway 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`
58
-
59
- ## Auth is Internal
60
-
61
- The client takes an observable `token$` at construction. All namespace
62
- calls and the bus SSE connection read the current value. Update by
63
- calling `.next(newToken)` on the BehaviorSubject — the client auto-starts
64
- the bus actor the first time the token transitions from null to a real
65
- value, and the actor reconnects with the new token after refresh.
66
-
67
- ```typescript
68
- import { BehaviorSubject } from 'rxjs';
69
-
70
- const token$ = new BehaviorSubject<AccessToken | null>(accessToken(token));
71
-
72
- const semiont = new SemiontApiClient({
73
- baseUrl: baseUrl('http://localhost:4000'),
74
- eventBus: new EventBus(),
75
- token$,
76
- });
77
-
78
- // No auth on individual calls
79
- const annotations = semiont.browse.annotations(resourceId);
80
- await semiont.mark.annotation(resourceId, input);
81
- await semiont.bind.body(resourceId, annotationId, operations);
82
-
83
- // Token rotation — e.g. after refresh
84
- token$.next(accessToken(newToken));
24
+ Direct imports from `@semiont/api-client` are appropriate when constructing
25
+ the transport stack by hand — e.g. CLI factories, MCP entrypoints, or worker
26
+ pools that wire bespoke `tokenRefresher` / `BehaviorSubject` token sources.
27
+
28
+ ## Public surface
29
+
30
+ ```ts
31
+ import {
32
+ HttpTransport,
33
+ HttpContentTransport,
34
+ type HttpTransportConfig,
35
+ type TokenRefresher,
36
+ APIError,
37
+ // SSE-actor machinery used by SDK adapters; not application code:
38
+ createActorVM,
39
+ type ActorVM,
40
+ type BusEvent,
41
+ type ActorVMOptions,
42
+ DEGRADED_THRESHOLD_MS,
43
+ } from '@semiont/api-client';
85
44
  ```
86
45
 
87
- Omit `token$` entirely for unauthenticated usage (public endpoints only).
88
- The bus actor will not connect until a non-null token is available.
89
-
90
- ## Installation
91
-
92
- ```bash
93
- npm install @semiont/api-client
94
- ```
46
+ That's the entire surface. Everything else moved out:
95
47
 
96
- **Prerequisites**: Semiont backend running. See [Running the Backend](../../apps/backend/README.md#quick-start).
48
+ - **`ITransport`, `IContentTransport`, `BRIDGED_CHANNELS`, `ConnectionState`,
49
+ response/progress types** live in [`@semiont/core`](../core/).
50
+ - **`SemiontClient`, namespaces, `SemiontSession`, `SemiontBrowser`,
51
+ view-models, `bus-request`, `cache`** live in [`@semiont/sdk`](../sdk/).
97
52
 
98
- ## Documentation
53
+ ## Behavioral contract
99
54
 
100
- - [Usage Guide](./docs/Usage.md) authentication, resources, annotations, streaming
101
- - [API Reference](./docs/API-Reference.md) complete method documentation
102
- - [Utilities Guide](./docs/Utilities.md) — text encoding, fuzzy anchoring, SVG utilities
103
- - [Logging Guide](./docs/LOGGING.md) logger setup and troubleshooting
55
+ The guarantees every `ITransport` implementation must honor — including
56
+ `HttpTransport`are documented in
57
+ [`packages/core/docs/TRANSPORT-CONTRACT.md`](../core/docs/TRANSPORT-CONTRACT.md).
58
+ HTTP-specific guarantees (the `/bus/emit` gateway, SSE reconnect, `Last-Event-ID`
59
+ replay, etc.) live alongside the backend at
60
+ [`apps/backend/docs/TRANSPORT.md`](../../apps/backend/docs/TRANSPORT.md).
104
61
 
105
- ## Key Features
62
+ ## Writing a new transport
106
63
 
107
- - **Verb-oriented** 7 domain namespaces mirror `@semiont/make-meaning`'s actor model
108
- - **Type-safe** OpenAPI types from `@semiont/core`, branded identifiers
109
- - **Observable reads** live-updating views via the bus gateway (single SSE connection)
110
- - **Framework-agnostic** — pure TypeScript + RxJS, no React dependency
64
+ If you need to add a non-HTTP transport (gRPC, WebSocket, IPC, …), implement
65
+ `ITransport` + `IContentTransport` from `@semiont/core` and consume the
66
+ contract from there. There's no inheritance from `HttpTransport`. For an
67
+ in-process example, see `LocalTransport` in
68
+ [`@semiont/make-meaning`](../make-meaning/).
111
69
 
112
70
  ## License
113
71
 
114
- Apache-2.0
72
+ Apache-2.0 — see [LICENSE](./LICENSE).