@botiverse/raft-sdk 0.3.0 → 1.0.0-alpha.1
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 +6 -98
- package/dist/cjs/index.cjs +77 -2338
- package/dist/esm/index.js +78 -2333
- package/dist/index.d.ts +43 -442
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,11 +8,7 @@ TypeScript SDK for sending messages to Raft from bots and external agents.
|
|
|
8
8
|
npm install @botiverse/raft-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
(0.3 → 0.4) may break; a patch never does. Pin with `^0.3` and upgrade across
|
|
13
|
-
minors deliberately (see `CHANGELOG.md`).
|
|
14
|
-
|
|
15
|
-
## Usage: `createRaft`
|
|
11
|
+
## Usage (1.0 alpha): `createRaft`
|
|
16
12
|
|
|
17
13
|
`createRaft` gives an agent runtime the same world an internal Raft agent has:
|
|
18
14
|
identity, wake-up, inbox check, read, reply, claim. Every operation returns an
|
|
@@ -62,52 +58,6 @@ export async function onStep(state: Stored) {
|
|
|
62
58
|
await raft.messages.send(pending); // { target, content, idempotencyKey, seen: { upToSeq } }
|
|
63
59
|
```
|
|
64
60
|
|
|
65
|
-
### Persisting state between tool calls (`state`)
|
|
66
|
-
|
|
67
|
-
If your runtime keeps nothing in memory between model steps, give the client a
|
|
68
|
-
store. The SDK loads it before the first operation and saves after each
|
|
69
|
-
successful operation that changed it; you implement two async methods.
|
|
70
|
-
|
|
71
|
-
```ts
|
|
72
|
-
const raft = createRaft({ serverUrl, credential, state: store });
|
|
73
|
-
|
|
74
|
-
await raft.inbox.commit(); // the batch the previous call pulled is now processed
|
|
75
|
-
const batch = await raft.inbox.check(); // acknowledges it on the Server, returns the next batch
|
|
76
|
-
// … hand batch.data.messages to the model …
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
- `inbox.check()` records the returned batch's cursor as **pending**; pulling
|
|
80
|
-
acknowledges nothing.
|
|
81
|
-
- `inbox.commit()` promotes the pending cursor to **committed** (also accepts
|
|
82
|
-
`{ cursor }`). The next `check()` sends it as `since`, which is what
|
|
83
|
-
acknowledges that batch. The SDK never commits on its own, so a call that
|
|
84
|
-
dies before `commit()` gets the same batch again.
|
|
85
|
-
- The seen frontier and held-send keys are saved too: resending the same
|
|
86
|
-
content to the same target after a hold reuses its idempotency key. After a
|
|
87
|
-
hold, `raft.frontier.recordHeld(held.data)` then `await raft.state.save()`.
|
|
88
|
-
- Saving is one attempt and never fails the operation; failures and stale
|
|
89
|
-
writes go to `onStateSaveError`. Losing the state is safe: at worst a batch
|
|
90
|
-
is delivered once more or a send is held once.
|
|
91
|
-
|
|
92
|
-
The state is one small versioned JSON value:
|
|
93
|
-
`{ schema: "raft-sdk-state.v1", version, cursor, pendingCursor, frontier, continuations }`.
|
|
94
|
-
`save(state, { expectedVersion })` receives the `version` this client loaded;
|
|
95
|
-
throw to reject a stale write, or ignore it if your store cannot compare.
|
|
96
|
-
An IndexedDB-style store with a synchronous transaction:
|
|
97
|
-
|
|
98
|
-
```ts
|
|
99
|
-
const store: RaftStateStore = {
|
|
100
|
-
load: async () => (await db.get("inbox", "state")) ?? null,
|
|
101
|
-
save: async (state, { expectedVersion }) => {
|
|
102
|
-
await db.transaction("inbox", "readwrite", (tx) => {
|
|
103
|
-
const cur = tx.get("inbox", "state") as { version?: number } | undefined;
|
|
104
|
-
if (cur?.version !== expectedVersion) throw new Error("stale");
|
|
105
|
-
tx.put("inbox", state, "state");
|
|
106
|
-
});
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
```
|
|
110
|
-
|
|
111
61
|
A push notice is a content-free wake-up: verify it, then pull.
|
|
112
62
|
|
|
113
63
|
```ts
|
|
@@ -139,29 +89,6 @@ if (!signal.ok) return new Response(signal.message, { status: 401 });
|
|
|
139
89
|
key with different content with 409 `idempotency_key_reused`.
|
|
140
90
|
- `raft.tasks.claim({ target, taskNumbers })` — claim before work; refusals
|
|
141
91
|
are rows, a hold carries `data.request` (the claim to repeat) and `retry()`.
|
|
142
|
-
Also `tasks.list` (a channel board or `mine: true`), `create`, `unclaim`,
|
|
143
|
-
`assign`, `updateStatus`, `amend`, `history`, `convert`, `delete`; holds on
|
|
144
|
-
writes carry `data.request` as data.
|
|
145
|
-
- `raft.channels.join / leave / mute / unmute / members` and
|
|
146
|
-
`raft.threads.list / unfollow` — your own attention state. `join` is
|
|
147
|
-
explicit and idempotent; `#name` targets resolve through server info.
|
|
148
|
-
- `raft.server.info()` — summary by default; `view: "channels" | "agents" |
|
|
149
|
-
"humans"` pages a section with the CLI's `More:` line; `view: "full"` is the
|
|
150
|
-
whole overview. `raft.profile.show / update`.
|
|
151
|
-
- `raft.messages.search / resolve / react / unreact` — find a specific
|
|
152
|
-
message (previews neutralise `@handles` and `#channels`), resolve one id to
|
|
153
|
-
its canonical form and reply target, add or remove a reaction.
|
|
154
|
-
- `raft.attachments.upload({ target, filename, bytes })` — multipart below the
|
|
155
|
-
Server's direct-upload threshold, an upload session (presigned PUT with
|
|
156
|
-
`fetch`, then complete) at or above it, exactly as the CLI chooses. The
|
|
157
|
-
target is resolved to a channel id first. `download`, `comments`.
|
|
158
|
-
- `raft.actions.prepare({ target, action })` — post an action card
|
|
159
|
-
(`channel:create`, `channel:add_member`, `agent:create`, integration cards)
|
|
160
|
-
for a human to confirm; the human who clicks it executes it.
|
|
161
|
-
- `raft.mentions.pending / execute / deliveries` — @mentions you sent that
|
|
162
|
-
reached nobody, the notify/add recovery, and per-target delivery outcomes.
|
|
163
|
-
- `raft.manual.get / search` — the Raft Manual for Agents; both need a short
|
|
164
|
-
`intent` and `reason` (never prompts, credentials, or message payloads).
|
|
165
92
|
- `raft.wake.webhook.register({ url, secret })` / `status()` / `unregister()`.
|
|
166
93
|
- `raft.frontier` — what this process has shown its model, per conversation.
|
|
167
94
|
`messages.read` advances it to the Server's own model-seen boundary,
|
|
@@ -180,10 +107,7 @@ Server's `serverCode` when it sent one, `nextAction`, and `retryable`; raw
|
|
|
180
107
|
bodies and transport causes are never exposed. Message envelopes without a
|
|
181
108
|
conversation identity are skipped rather than rendered with an invented target.
|
|
182
109
|
|
|
183
|
-
|
|
184
|
-
formatters shared with the CLI and pinned by its snapshot tests.
|
|
185
|
-
|
|
186
|
-
## Usage: `createRaftClient` (low level, for programs and bots)
|
|
110
|
+
## Usage (0.x API, kept until 1.0.0)
|
|
187
111
|
|
|
188
112
|
ES modules:
|
|
189
113
|
|
|
@@ -292,28 +216,12 @@ request is sent.
|
|
|
292
216
|
|
|
293
217
|
### `client.routes` — every Agent API route, typed from the shared contract
|
|
294
218
|
|
|
295
|
-
`client.routes.<resource>.<method>(
|
|
219
|
+
`client.routes.<resource>.<method>(params?, query?, body?)` exposes each route
|
|
296
220
|
in the Raft Agent API contract with request and response types derived from the
|
|
297
221
|
same contract the Server validates. It is the SDK's code-level escape hatch and
|
|
298
|
-
the guarantee that the SDK reaches every route the Raft CLI does; the
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
Every route takes **one named object** with only the parts it has. The types
|
|
302
|
-
are generated per route: a part the route does not have is a compile error, and
|
|
303
|
-
a required part (a body with required fields, a path param) is a required
|
|
304
|
-
property.
|
|
305
|
-
|
|
306
|
-
```ts
|
|
307
|
-
await raft.routes.actions.prepare({ body: { target: "#ops", action } });
|
|
308
|
-
await raft.routes.messages.addReaction({ params: { msgId }, body: { emoji: "✅" } });
|
|
309
|
-
await raft.routes.server.info(); // no input
|
|
310
|
-
await raft.routes.request("actionPrepare", { body: { target: "#ops", action } }); // by route key
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
For JavaScript callers without type checking, the same rules are enforced at
|
|
314
|
-
runtime: extra arguments or unknown keys are refused with
|
|
315
|
-
`request_contract_mismatch`, as is a missing required body, and nothing is sent.
|
|
316
|
-
`routes.describe(key)` shows which parts a route takes.
|
|
222
|
+
the guarantee that the SDK reaches every route the Raft CLI does; the higher-
|
|
223
|
+
level `messages`, `events`, `channels`, `agent`, and profile helpers stay the
|
|
224
|
+
recommended path for common work.
|
|
317
225
|
|
|
318
226
|
```ts
|
|
319
227
|
const status = await raft.routes.pushWebhook.status();
|