@semiont/sdk 0.4.21 → 0.5.0
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 +60 -40
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
# @semiont/sdk
|
|
2
2
|
|
|
3
|
-
The
|
|
4
|
-
|
|
3
|
+
[](https://github.com/The-AI-Alliance/semiont/actions/workflows/package-tests.yml?query=branch%3Amain+is%3Asuccess+job%3A%22Test+sdk%22)
|
|
4
|
+
[](https://codecov.io/gh/The-AI-Alliance/semiont?flag=sdk)
|
|
5
|
+
[](https://www.npmjs.com/package/@semiont/sdk)
|
|
6
|
+
[](https://www.npmjs.com/package/@semiont/sdk)
|
|
7
|
+
[](https://github.com/The-AI-Alliance/semiont/blob/main/LICENSE)
|
|
8
|
+
|
|
9
|
+
The developer-facing SDK for [Semiont](https://github.com/The-AI-Alliance/semiont). This package owns the high-level surface every Semiont consumer reaches for: a verb-oriented `SemiontClient`, per-KB sessions, RxJS view-models, and the helpers that wire them all together.
|
|
10
|
+
|
|
11
|
+
The SDK is **transport-agnostic** — it consumes the `ITransport` and `IContentTransport` contracts from [`@semiont/core`](https://github.com/The-AI-Alliance/semiont/tree/main/packages/core). For HTTP, the canonical wire adapter is re-exported here for convenience. For in-process operation, use `LocalTransport` from [`@semiont/make-meaning`](https://github.com/The-AI-Alliance/semiont/tree/main/packages/make-meaning).
|
|
12
|
+
|
|
13
|
+
## What's in the box
|
|
5
14
|
|
|
6
15
|
- **`SemiontClient`** — the verb-oriented coordinator over a wire transport.
|
|
7
|
-
- **
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
- **
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
(per-key SWR cache).
|
|
18
|
-
|
|
19
|
-
The sdk is **transport-agnostic**: it consumes the `ITransport` /
|
|
20
|
-
`IContentTransport` contract defined in
|
|
21
|
-
[`@semiont/core`](../core/). For HTTP, the canonical wire adapter is
|
|
22
|
-
re-exported from this package for convenience; for in-process operation,
|
|
23
|
-
use `LocalTransport` from
|
|
24
|
-
[`@semiont/make-meaning`](../make-meaning/).
|
|
16
|
+
- **Verb namespaces** — `browse`, `mark`, `bind`, `gather`, `match`, `yield`, `beckon`, `job`, `auth`, `admin`. Typed methods that wrap the bus protocol; consumers never touch raw channel strings.
|
|
17
|
+
- **Session layer** — `SemiontSession` (per-KB authentication, token refresh, lifecycle), `SemiontBrowser` (tab-singleton coordinator), and `SessionStorage` adapters (`InMemorySessionStorage`, plus a web one in `@semiont/react-ui`).
|
|
18
|
+
- **View-models** — RxJS-based MVVM factories the React layer mounts via `useViewModel`.
|
|
19
|
+
- **Helpers** — `bus-request` (correlation-ID request/reply) and `cache` (per-key SWR cache).
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @semiont/sdk
|
|
25
|
+
```
|
|
25
26
|
|
|
26
27
|
## Quick start (HTTP)
|
|
27
28
|
|
|
@@ -46,17 +47,25 @@ const kb: KnowledgeBase = {
|
|
|
46
47
|
};
|
|
47
48
|
|
|
48
49
|
const storage = new InMemorySessionStorage();
|
|
49
|
-
setStoredSession(storage, kb.id, {
|
|
50
|
+
setStoredSession(storage, kb.id, {
|
|
51
|
+
access: accessToken('your-jwt'),
|
|
52
|
+
refresh: '',
|
|
53
|
+
});
|
|
50
54
|
|
|
51
55
|
const session = await SemiontSession.create({ kb, storage });
|
|
56
|
+
|
|
52
57
|
const resources = await firstValueFrom(
|
|
53
|
-
session.client.browse.resources({ limit: 10 }).pipe(
|
|
58
|
+
session.client.browse.resources({ limit: 10 }).pipe(
|
|
59
|
+
filter((r): r is NonNullable<typeof r> => r !== undefined),
|
|
60
|
+
),
|
|
54
61
|
);
|
|
55
62
|
console.log(resources);
|
|
56
63
|
```
|
|
57
64
|
|
|
58
65
|
## Quick start (in-process)
|
|
59
66
|
|
|
67
|
+
When you want the SDK without an HTTP backend — e.g. in a CLI, a unit test, or an Electron-style desktop app — wire `LocalTransport` directly to a knowledge system:
|
|
68
|
+
|
|
60
69
|
```ts
|
|
61
70
|
import { SemiontClient } from '@semiont/sdk';
|
|
62
71
|
import {
|
|
@@ -71,45 +80,56 @@ const transport = new LocalTransport({
|
|
|
71
80
|
eventBus,
|
|
72
81
|
userId,
|
|
73
82
|
});
|
|
74
|
-
const client = new SemiontClient(
|
|
83
|
+
const client = new SemiontClient(
|
|
84
|
+
transport,
|
|
85
|
+
new LocalContentTransport(ks.knowledgeSystem),
|
|
86
|
+
);
|
|
75
87
|
```
|
|
76
88
|
|
|
89
|
+
Same `SemiontClient`, same verb namespaces — no network involved.
|
|
90
|
+
|
|
77
91
|
## Verb namespaces
|
|
78
92
|
|
|
79
|
-
All ten namespaces hang off `SemiontClient`. Each method either returns a
|
|
80
|
-
`Promise` (for one-shot RPC-style operations) or an `Observable` (for
|
|
81
|
-
streaming subscriptions). The bus is invisible to callers — channel
|
|
82
|
-
strings, correlation IDs, and reconnection are internal.
|
|
93
|
+
All ten namespaces hang off `SemiontClient`. Each method either returns a `Promise` (one-shot RPC-style operations) or an `Observable` (streaming subscriptions). The bus is invisible to callers — channel strings, correlation IDs, and reconnection are internal.
|
|
83
94
|
|
|
84
95
|
```ts
|
|
85
|
-
// Browse
|
|
96
|
+
// Browse — read the knowledge graph.
|
|
86
97
|
await client.browse.resources({ limit: 10 });
|
|
87
98
|
client.browse.resource(resourceId).subscribe(/* ... */);
|
|
88
99
|
|
|
89
|
-
// Mark / Bind
|
|
100
|
+
// Mark / Bind — create and modify annotations.
|
|
90
101
|
const { annotationId } = await client.mark.annotation(rid, request);
|
|
91
|
-
await client.bind.body(rid, aid, [{ op: 'add', item: {
|
|
102
|
+
await client.bind.body(rid, aid, [{ op: 'add', item: { /* W3C body */ } }]);
|
|
92
103
|
|
|
93
|
-
// Gather / Match
|
|
104
|
+
// Gather / Match — assemble context and run semantic search.
|
|
94
105
|
const ctx = await lastValueFrom(client.gather.annotation(aid, rid));
|
|
95
106
|
client.match.search(rid, refId, ctx, { limit: 10 }).subscribe(/* ... */);
|
|
96
107
|
|
|
97
|
-
// Yield
|
|
98
|
-
const { resourceId } = await client.yield.resource({
|
|
108
|
+
// Yield — author new resources.
|
|
109
|
+
const { resourceId } = await client.yield.resource({
|
|
110
|
+
name, file, format, storageUri,
|
|
111
|
+
});
|
|
99
112
|
|
|
100
|
-
// Beckon
|
|
113
|
+
// Beckon — UI signals (hover, focus, selection).
|
|
101
114
|
client.beckon.hover(annotationId);
|
|
102
115
|
```
|
|
103
116
|
|
|
104
|
-
|
|
117
|
+
The verb-by-verb walkthroughs live in [docs/flows](https://github.com/The-AI-Alliance/semiont/tree/main/docs/flows).
|
|
105
118
|
|
|
106
119
|
## Behavioral contract
|
|
107
120
|
|
|
108
|
-
The guarantees every `ITransport` implementation must honor are documented in
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
[`apps/backend/docs/TRANSPORT.md`](../../apps/backend/docs/TRANSPORT.md).
|
|
121
|
+
The guarantees every `ITransport` implementation must honor — what `subscribe()` does on disconnect, what `LastEventId` replay must look like, what `puts` must be idempotent — are documented in [packages/core/docs/TRANSPORT-CONTRACT.md](https://github.com/The-AI-Alliance/semiont/blob/main/packages/core/docs/TRANSPORT-CONTRACT.md). HTTP-specific guarantees (the `/bus/emit` gateway, SSE reconnect, `Last-Event-ID` replay window) live alongside the backend at [apps/backend/docs/TRANSPORT.md](https://github.com/The-AI-Alliance/semiont/blob/main/apps/backend/docs/TRANSPORT.md).
|
|
122
|
+
|
|
123
|
+
When implementing a new transport (gRPC, WebSocket, IPC, …), implement those interfaces from `@semiont/core` directly — there is no inheritance from `HttpTransport`.
|
|
112
124
|
|
|
113
125
|
## License
|
|
114
126
|
|
|
115
|
-
Apache-2.0 — see [LICENSE](
|
|
127
|
+
Apache-2.0 — see [LICENSE](https://github.com/The-AI-Alliance/semiont/blob/main/LICENSE).
|
|
128
|
+
|
|
129
|
+
## Related packages
|
|
130
|
+
|
|
131
|
+
- [`@semiont/core`](https://github.com/The-AI-Alliance/semiont/tree/main/packages/core) — domain types, `ITransport` contract, OpenAPI-derived schemas
|
|
132
|
+
- [`@semiont/api-client`](https://github.com/The-AI-Alliance/semiont/tree/main/packages/api-client) — HTTP transport (`HttpTransport`, `HttpContentTransport`)
|
|
133
|
+
- [`@semiont/make-meaning`](https://github.com/The-AI-Alliance/semiont/tree/main/packages/make-meaning) — in-process transport (`LocalTransport`) and the actor model behind it
|
|
134
|
+
- [`@semiont/observability`](https://github.com/The-AI-Alliance/semiont/tree/main/packages/observability) — OpenTelemetry tracing the SDK propagates across the bus
|
|
135
|
+
- [`@semiont/react-ui`](https://github.com/The-AI-Alliance/semiont/tree/main/packages/react-ui) — React bindings (`useViewModel`, web `SessionStorage`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semiont/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Semiont SDK — SemiontClient, namespaces, session/browser, view-models, and the bus-request/cache helpers. Transport-agnostic; pair with @semiont/api-client (HttpTransport) or @semiont/make-meaning (LocalTransport) for the wire.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"test:coverage": "vitest run --coverage"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@semiont/api-client": "
|
|
43
|
-
"@semiont/core": "
|
|
42
|
+
"@semiont/api-client": "*",
|
|
43
|
+
"@semiont/core": "*",
|
|
44
44
|
"rxjs": "^7.8.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|