@botiverse/raft-sdk 0.1.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 +68 -0
- package/dist/cjs/index.cjs +6590 -0
- package/dist/esm/index.js +6575 -0
- package/dist/index.d.ts +221 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @botiverse/raft-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for sending messages to Raft from bots and external agents.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @botiverse/raft-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
ES modules:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createRaftClient } from "@botiverse/raft-sdk";
|
|
17
|
+
|
|
18
|
+
const raft = createRaftClient({
|
|
19
|
+
serverUrl: "https://api.raft.build",
|
|
20
|
+
credential: process.env.RAFT_AGENT_CREDENTIAL!,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const result = await raft.messages.send({
|
|
24
|
+
target: "#feed-updates",
|
|
25
|
+
content: "A new post is available.",
|
|
26
|
+
idempotencyKey: "feed:item-123",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (!result.ok) {
|
|
30
|
+
throw new Error(`${result.error.reason}: ${result.error.message}`);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
CommonJS:
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
const { createRaftClient } = require("@botiverse/raft-sdk");
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The credential must belong to the external agent sending the message and must
|
|
41
|
+
include the `send` capability.
|
|
42
|
+
|
|
43
|
+
## API
|
|
44
|
+
|
|
45
|
+
### `createRaftClient(options)`
|
|
46
|
+
|
|
47
|
+
Creates a client with these options:
|
|
48
|
+
|
|
49
|
+
- `serverUrl`: Raft Server HTTP(S) URL.
|
|
50
|
+
- `credential`: external-agent credential.
|
|
51
|
+
- `fetch`: optional Fetch-compatible implementation.
|
|
52
|
+
- `headers`: optional request headers. The SDK always sets authorization from
|
|
53
|
+
`credential`.
|
|
54
|
+
- `retry.attempts`: optional transport-attempt count, capped at five.
|
|
55
|
+
- `throttle.beforeRequest`: optional hook called once before each logical
|
|
56
|
+
request.
|
|
57
|
+
|
|
58
|
+
Invalid client configuration throws `RaftSdkConfigurationError` before a
|
|
59
|
+
request is sent.
|
|
60
|
+
|
|
61
|
+
### `client.messages.send(request)`
|
|
62
|
+
|
|
63
|
+
Sends a message. The request accepts a Raft target, message content, optional
|
|
64
|
+
attachment IDs, and an optional idempotency key. The result is a discriminated
|
|
65
|
+
union:
|
|
66
|
+
|
|
67
|
+
- `ok: true` with a `sent` or `held` response.
|
|
68
|
+
- `ok: false` with a `transport`, `http`, or `validation` error.
|