@sippulse/niva-sdk 0.1.0 → 0.2.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 +25 -0
- package/chat.d.ts +2 -0
- package/chat.js +1083 -0
- package/chunk-50ad2r7x.js +76 -0
- package/chunk-wx0m9ra5.js +4349 -0
- package/dts/src/chat/client.d.ts +10 -0
- package/dts/src/chat/download.d.ts +19 -0
- package/dts/src/chat/emitter.d.ts +8 -0
- package/dts/src/chat/end.d.ts +9 -0
- package/dts/src/chat/error.d.ts +15 -0
- package/dts/src/chat/index.d.ts +5 -0
- package/dts/src/chat/input.d.ts +12 -0
- package/dts/src/chat/policy.d.ts +14 -0
- package/dts/src/chat/queue.d.ts +24 -0
- package/dts/src/chat/socket.d.ts +12 -0
- package/dts/src/chat/storage.d.ts +18 -0
- package/dts/src/chat/timers.d.ts +12 -0
- package/dts/src/chat/transfer.d.ts +21 -0
- package/dts/src/chat/types.d.ts +236 -0
- package/dts/src/chat/upload.d.ts +48 -0
- package/dts/src/chat/wire.d.ts +46 -0
- package/dts/src/client.d.ts +8 -0
- package/dts/src/entry/chat.d.ts +2 -0
- package/dts/src/generated/client.d.ts +587 -46
- package/dts/src/generated/meta.d.ts +1 -1
- package/dts/src/generated/operations.d.ts +13194 -4748
- package/dts/src/generated/webhooks.d.ts +208 -1
- package/index.bun.js +48 -3419
- package/index.default.js +45 -3383
- package/index.deno.js +48 -3419
- package/index.node.js +47 -3418
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -161,6 +161,31 @@ On an unrecognized runtime the `default` entry resolves and `.serve()` throws `N
|
|
|
161
161
|
|
|
162
162
|
See the webhook receiver guide in the NIVA docs (`/sdk/webhooks`) for the event registry and payload shapes.
|
|
163
163
|
|
|
164
|
+
## Chat
|
|
165
|
+
|
|
166
|
+
Build your own chat interface over the Chat API with `connectChat`, from the `@sippulse/niva-sdk/chat` subpath. It speaks the WebSocket protocol for you: starts the plan, pings, reconnects with backoff, resumes without losing or repeating messages, and holds the visitor's sends until the plan waits for them.
|
|
167
|
+
|
|
168
|
+
On your backend, create the session with the API key (`ws_url` comes back absolute, ready to hand to the browser):
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
const { ws_url } = await niva.chat.createSession({ plan_id: "vp_..." });
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
In the browser, `session` asks YOUR backend for it; the API key never reaches the page:
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { connectChat } from "@sippulse/niva-sdk/chat";
|
|
178
|
+
|
|
179
|
+
const chat = connectChat({
|
|
180
|
+
session: async () => (await fetch("/chat/session", { method: "POST" }).then((r) => r.json())).ws_url,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
chat.on("change", (state) => render(state)); // state.messages, connection, status, typing
|
|
184
|
+
chat.send("Hello");
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
`chat.state` is a new frozen object on every change, so it plugs into React, Vue or Svelte as is. Events: `message`, `typing`, `status`, `connection`, `error` and `change`. Errors are `NivaChatError` with `code` and `fatal`. `persist` (`"tab"` by default, `"browser"` or `"none"`) keeps the conversation across a page reload.
|
|
188
|
+
|
|
164
189
|
## Compatibility
|
|
165
190
|
|
|
166
191
|
The SDK is generated from, and handshakes against, the server `/api/v1` contract.
|
package/chat.d.ts
ADDED