@dnotifier-realtime/dnotifier 1.1.26 → 1.1.29
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 +5 -606
- package/dist/agent-runtime/backendClient.js +1 -1
- package/dist/agent-runtime/descriptors.js +1 -1
- package/dist/agent-runtime/errors.js +1 -1
- package/dist/agent-runtime/ids.js +1 -1
- package/dist/agent-runtime/index.js +1 -1
- package/dist/agent-runtime/localCompletions.js +1 -1
- package/dist/agent-runtime/mcp/client.js +1 -1
- package/dist/agent-runtime/mcp/registry.js +1 -1
- package/dist/agent-runtime/observability.js +1 -1
- package/dist/agent-runtime/permissions.js +1 -1
- package/dist/agent-runtime/runtime.js +1 -1
- package/dist/agent-runtime/schema.js +1 -1
- package/dist/agent-runtime/toolRegistry.js +1 -1
- package/dist/cjs/dnotifier.js +1 -1
- package/dist/cjs/providers/openai.js +1 -1
- package/dist/cjs/transport/httpTransport.js +1 -1
- package/dist/cjs/transport/websocketTransport.js +1 -1
- package/dist/cjs/utils/buffer.js +1 -1
- package/dist/cjs/utils/frame.js +1 -1
- package/dist/cjs/utils/id.js +1 -1
- package/dist/cjs/utils/payload.js +1 -1
- package/dist/config/endpoints.js +1 -1
- package/dist/dnotifier.cjs +7 -11173
- package/dist/dnotifier.d.ts +24 -7
- package/dist/dnotifier.js +1 -1
- package/dist/providers/openai.js +1 -1
- package/dist/transport/httpTransport.js +1 -1
- package/dist/transport/websocketTransport.js +1 -1
- package/dist/utils/buffer.js +1 -1
- package/dist/utils/frame.js +1 -1
- package/dist/utils/id.js +1 -1
- package/dist/utils/logs.js +1 -1
- package/dist/utils/payload.js +1 -1
- package/dist/workflow/agent.js +1 -1
- package/dist/workflow/context.d.ts +5 -0
- package/dist/workflow/context.js +1 -1
- package/dist/workflow/errors.js +1 -1
- package/dist/workflow/graphParents.js +1 -1
- package/dist/workflow/ids.js +1 -1
- package/dist/workflow/jsonPayload.js +1 -1
- package/dist/workflow/mockObservabilityClient.js +1 -1
- package/dist/workflow/observability.js +1 -1
- package/dist/workflow/remoteAgentClient.js +1 -1
- package/dist/workflow/remoteAgentProtocol.js +1 -1
- package/dist/workflow/runner.js +1 -1
- package/dist/workflow/stepTypes.js +1 -1
- package/dist/workflow/workflow.js +1 -1
- package/dist/workflow/workflowObservabilityClient.js +1 -1
- package/package.json +1 -1
- package/dist/agent-runtime/backendClient.d.ts.map +0 -1
- package/dist/agent-runtime/descriptors.d.ts.map +0 -1
- package/dist/agent-runtime/errors.d.ts.map +0 -1
- package/dist/agent-runtime/ids.d.ts.map +0 -1
- package/dist/agent-runtime/index.d.ts.map +0 -1
- package/dist/agent-runtime/localCompletions.d.ts.map +0 -1
- package/dist/agent-runtime/mcp/client.d.ts.map +0 -1
- package/dist/agent-runtime/mcp/registry.d.ts.map +0 -1
- package/dist/agent-runtime/observability.d.ts.map +0 -1
- package/dist/agent-runtime/permissions.d.ts.map +0 -1
- package/dist/agent-runtime/runtime.d.ts.map +0 -1
- package/dist/agent-runtime/schema.d.ts.map +0 -1
- package/dist/agent-runtime/toolRegistry.d.ts.map +0 -1
- package/dist/config/endpoints.d.ts.map +0 -1
- package/dist/dnotifier.d.ts.map +0 -1
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/transport/httpTransport.d.ts.map +0 -1
- package/dist/transport/websocketTransport.d.ts.map +0 -1
- package/dist/utils/buffer.d.ts.map +0 -1
- package/dist/utils/frame.d.ts.map +0 -1
- package/dist/utils/id.d.ts.map +0 -1
- package/dist/utils/logs.d.ts.map +0 -1
- package/dist/utils/payload.d.ts.map +0 -1
- package/dist/workflow/agent.d.ts.map +0 -1
- package/dist/workflow/context.d.ts.map +0 -1
- package/dist/workflow/errors.d.ts.map +0 -1
- package/dist/workflow/graphParents.d.ts.map +0 -1
- package/dist/workflow/ids.d.ts.map +0 -1
- package/dist/workflow/index.d.ts.map +0 -1
- package/dist/workflow/jsonPayload.d.ts.map +0 -1
- package/dist/workflow/mockObservabilityClient.d.ts.map +0 -1
- package/dist/workflow/observability.d.ts.map +0 -1
- package/dist/workflow/remoteAgentClient.d.ts.map +0 -1
- package/dist/workflow/remoteAgentProtocol.d.ts.map +0 -1
- package/dist/workflow/runner.d.ts.map +0 -1
- package/dist/workflow/stepTypes.d.ts.map +0 -1
- package/dist/workflow/workflow.d.ts.map +0 -1
- package/dist/workflow/workflowObservabilityClient.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,44 +1,18 @@
|
|
|
1
1
|
# DNotifier JavaScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Use it to send prompts, run RAG over a knowledge base, define agents and workflows, and trace runs in the dashboard. AI, RAG, and workflow calls use **HTTP** and return from the method. Directed 1:1 messaging is available on the same client when you need it.
|
|
3
|
+
Official JavaScript / TypeScript SDK for **AI agents**, **workflows**, **RAG**, and **observability**. Works in Node.js and the browser.
|
|
6
4
|
|
|
7
5
|
**Documentation:** [dnotifier.gitbook.io/product-docs](https://dnotifier.gitbook.io/product-docs)
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|-------|----------------|
|
|
11
|
-
| [AI overview](https://dnotifier.gitbook.io/product-docs/ai/overview) | Prompts, providers, sessions, RAG, semantic search |
|
|
12
|
-
| [Workflows & agents](https://dnotifier.gitbook.io/product-docs/workflows/overview) | Multi-step pipelines, tools, and MCP |
|
|
13
|
-
| [Observability](https://dnotifier.gitbook.io/product-docs/observability) | `logs`, `saveHistory`, and workflow telemetry |
|
|
14
|
-
| [Install — JavaScript / TypeScript](https://dnotifier.gitbook.io/product-docs/getting-started/installation/javascript-typescript) | npm install, ESM, CommonJS, and Node WebSocket |
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Features
|
|
19
|
-
|
|
20
|
-
- AI prompts and chat-style messages (`sendAI`), including provider and model selection
|
|
21
|
-
- Sessions, AI history, and dashboard session logging (`logs: true`)
|
|
22
|
-
- Knowledge base (RAG): add, update, get, list, delete, and semantic `search`
|
|
23
|
-
- Workflows: named agents, multi-step pipelines, local tools, and MCP
|
|
24
|
-
- Dashboard observability for AI sessions and workflow runs
|
|
25
|
-
- HTTP transport for AI, RAG, and workflows
|
|
26
|
-
- Plan limits from auth (`getPlanLimits`, `aiEnabled`)
|
|
27
|
-
- Directed 1:1 messaging over WebSocket when you need live delivery
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## Installation
|
|
7
|
+
## Install
|
|
32
8
|
|
|
33
9
|
```bash
|
|
34
10
|
npm install @dnotifier-realtime/dnotifier
|
|
35
11
|
```
|
|
36
12
|
|
|
37
|
-
---
|
|
38
|
-
|
|
39
13
|
## Quick start
|
|
40
14
|
|
|
41
|
-
AI calls use
|
|
15
|
+
AI calls use `transport: "http"`. The response comes back from `sendAI`.
|
|
42
16
|
|
|
43
17
|
```js
|
|
44
18
|
import { DNotifier } from "@dnotifier-realtime/dnotifier";
|
|
@@ -48,7 +22,6 @@ const notifier = new DNotifier({
|
|
|
48
22
|
secret: "your-app-secret",
|
|
49
23
|
transport: "http",
|
|
50
24
|
userId: "user-123",
|
|
51
|
-
logs: true,
|
|
52
25
|
onConnected: () => {},
|
|
53
26
|
onMessage: () => {},
|
|
54
27
|
onDisconnected: () => {},
|
|
@@ -56,588 +29,14 @@ const notifier = new DNotifier({
|
|
|
56
29
|
|
|
57
30
|
await notifier.connect();
|
|
58
31
|
|
|
59
|
-
if (!notifier.aiEnabled) {
|
|
60
|
-
throw new Error("AI is not enabled for this plan");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const response = await notifier.sendAI({
|
|
64
|
-
senderId: "user-123",
|
|
65
|
-
message: { text: "Summarize our refund policy in two sentences." },
|
|
66
|
-
});
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
Continue in the docs: [Send a prompt](https://dnotifier.gitbook.io/product-docs/ai/send-prompt) · [Build an AI assistant](https://dnotifier.gitbook.io/product-docs/ai/example-ai-assistant) · [RAG Q&A bot](https://dnotifier.gitbook.io/product-docs/ai/example-rag-bot)
|
|
70
|
-
|
|
71
|
-
---
|
|
72
|
-
|
|
73
|
-
## Connection and configuration
|
|
74
|
-
|
|
75
|
-
| Option | Type | Description |
|
|
76
|
-
|--------|------|-------------|
|
|
77
|
-
| `appId` | `string` | Your DNotifier application id |
|
|
78
|
-
| `secret` | `string` | Application secret |
|
|
79
|
-
| `transport` | `"ws"` \| `"http"` | `"http"` for AI, RAG, and workflows; `"ws"` for directed 1:1 messaging |
|
|
80
|
-
| `userId` | `string` | End-user or agent id for auth and routing |
|
|
81
|
-
| `logs` | `boolean` | When `true`, tracks AI sessions in the DNotifier logs dashboard |
|
|
82
|
-
| `url` | `string` | Optional custom WebSocket URL |
|
|
83
|
-
| `WebSocketImpl` | `class` | Required in Node when using `transport: "ws"` |
|
|
84
|
-
| `onConnected` | `function` | Called when the client is ready |
|
|
85
|
-
| `onMessage` | `function` | Called with `{ metadata, payload }` for incoming messages |
|
|
86
|
-
| `onDisconnected` | `function` | Called when the connection closes |
|
|
87
|
-
|
|
88
|
-
```js
|
|
89
|
-
await notifier.connect();
|
|
90
|
-
|
|
91
|
-
const limits = notifier.getPlanLimits();
|
|
92
|
-
console.log(limits?.aiEnabled, limits?.maxAIRequestsPerMonth);
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
After `connect()`, these properties are available:
|
|
96
|
-
|
|
97
|
-
| Property | Description |
|
|
98
|
-
|----------|-------------|
|
|
99
|
-
| `isConnected` | Whether the client is connected |
|
|
100
|
-
| `aiEnabled` | Whether AI is enabled for the current plan |
|
|
101
|
-
| `authToken` | Auth token from the last successful connect |
|
|
102
|
-
| `messageSizeLimit` | Max message size in bytes (from plan) |
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
## Real-time messaging
|
|
107
|
-
|
|
108
|
-
Directed 1:1 delivery over WebSocket. Messages go from a `senderId` to a `receiverId` (or a list of `receiverIds`). There are no broadcast topics.
|
|
109
|
-
|
|
110
|
-
Full guide: [Realtime communication](https://dnotifier.gitbook.io/product-docs/realtime-communication/overview).
|
|
111
|
-
|
|
112
|
-
In **Node.js**, pass a `WebSocket` implementation when `transport` is `"ws"`:
|
|
113
|
-
|
|
114
|
-
```js
|
|
115
|
-
import WebSocket from "ws";
|
|
116
|
-
|
|
117
|
-
const notifier = new DNotifier({
|
|
118
|
-
appId: "your-app-id",
|
|
119
|
-
secret: "your-app-secret",
|
|
120
|
-
transport: "ws",
|
|
121
|
-
userId: "user-123",
|
|
122
|
-
WebSocketImpl: WebSocket,
|
|
123
|
-
onConnected: () => {},
|
|
124
|
-
onMessage: () => {},
|
|
125
|
-
onDisconnected: () => {},
|
|
126
|
-
});
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### Text and structured messages
|
|
130
|
-
|
|
131
|
-
Use any `type` in `data` that fits your app (`text`, `image`, `audio`, `doc`, etc.):
|
|
132
|
-
|
|
133
|
-
```js
|
|
134
|
-
await notifier.send({
|
|
135
|
-
senderId: "user-123",
|
|
136
|
-
receiverId: "user-456",
|
|
137
|
-
data: {
|
|
138
|
-
type: "text",
|
|
139
|
-
text: "hello from dnotifier sdk!",
|
|
140
|
-
},
|
|
141
|
-
saveHistory: true, // default true
|
|
142
|
-
});
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
Send to multiple receivers:
|
|
146
|
-
|
|
147
|
-
```js
|
|
148
|
-
await notifier.send({
|
|
149
|
-
senderId: "user-123",
|
|
150
|
-
receiverIds: ["user-456", "user-789"],
|
|
151
|
-
data: { type: "text", text: "Hello everyone" },
|
|
152
|
-
});
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Images, audio, and binary
|
|
156
|
-
|
|
157
|
-
Prefer `send()` with a typed payload. The SDK chunks large payloads automatically.
|
|
158
|
-
|
|
159
|
-
```js
|
|
160
|
-
import { readFileSync } from "fs";
|
|
161
|
-
|
|
162
|
-
const imageBytes = readFileSync("./photo.png");
|
|
163
|
-
|
|
164
|
-
await notifier.send({
|
|
165
|
-
senderId: "user-123",
|
|
166
|
-
receiverId: "user-456",
|
|
167
|
-
data: {
|
|
168
|
-
type: "image",
|
|
169
|
-
content: imageBytes,
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
Handle incoming messages in `onMessage`:
|
|
175
|
-
|
|
176
|
-
```js
|
|
177
|
-
onMessage: (msg) => {
|
|
178
|
-
const body = msg.payload.toJSON();
|
|
179
|
-
if (body?.type === "image") {
|
|
180
|
-
// body.content — image bytes or base64 depending on your app convention
|
|
181
|
-
} else if (body?.type === "text") {
|
|
182
|
-
console.log(body.text);
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### Raw binary (`sendBinary`)
|
|
188
|
-
|
|
189
|
-
```js
|
|
190
|
-
notifier.sendBinary({
|
|
191
|
-
senderId: "user-123",
|
|
192
|
-
receiverIds: ["user-456"],
|
|
193
|
-
buffer: new Uint8Array([0x00, 0x01, 0x02]),
|
|
194
|
-
type: "binary",
|
|
195
|
-
});
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
---
|
|
199
|
-
|
|
200
|
-
## AI
|
|
201
|
-
|
|
202
|
-
Requires `aiEnabled` on your plan. Use `transport: "http"` so `sendAI` returns the response directly.
|
|
203
|
-
|
|
204
|
-
Full guide: [AI overview](https://dnotifier.gitbook.io/product-docs/ai/overview).
|
|
205
|
-
|
|
206
|
-
### Simple prompt
|
|
207
|
-
|
|
208
|
-
```js
|
|
209
32
|
const response = await notifier.sendAI({
|
|
210
33
|
senderId: "user-123",
|
|
211
34
|
message: { text: "Summarize our refund policy in two sentences." },
|
|
212
35
|
});
|
|
213
36
|
```
|
|
214
37
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
```js
|
|
218
|
-
const response = await notifier.sendAI({
|
|
219
|
-
senderId: "user-123",
|
|
220
|
-
message: {
|
|
221
|
-
useKnowledgeBase: true,
|
|
222
|
-
messages: [
|
|
223
|
-
{ role: "system", content: "You are a helpful support agent." },
|
|
224
|
-
{ role: "user", content: "How do I reset my password?" },
|
|
225
|
-
],
|
|
226
|
-
},
|
|
227
|
-
saveHistory: true,
|
|
228
|
-
});
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
### Continue an existing session
|
|
232
|
-
|
|
233
|
-
```js
|
|
234
|
-
const first = await notifier.sendAI({
|
|
235
|
-
senderId: "user-123",
|
|
236
|
-
message: { text: "Start a new support session." },
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
const sessionId = first?.metadata?.packet?.id;
|
|
240
|
-
|
|
241
|
-
await notifier.sendAI({
|
|
242
|
-
senderId: "user-123",
|
|
243
|
-
sessionId,
|
|
244
|
-
message: { text: "Follow-up question in the same session." },
|
|
245
|
-
});
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
### AI history
|
|
249
|
-
|
|
250
|
-
```js
|
|
251
|
-
const history = await notifier.fetchAIHistory({ senderId: "user-123" });
|
|
252
|
-
|
|
253
|
-
await notifier.deleteAIHistoryMessage({
|
|
254
|
-
senderId: "user-123",
|
|
255
|
-
messageId: "message-id-to-delete",
|
|
256
|
-
});
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
---
|
|
260
|
-
|
|
261
|
-
## Knowledge base (RAG)
|
|
262
|
-
|
|
263
|
-
Index content, then answer from it with `search` or `sendAI({ message: { useKnowledgeBase: true } })`.
|
|
264
|
-
|
|
265
|
-
Full guide: [Knowledge base (RAG)](https://dnotifier.gitbook.io/product-docs/ai/knowledge-base-overview).
|
|
266
|
-
|
|
267
|
-
```js
|
|
268
|
-
// Add
|
|
269
|
-
await notifier.addDocument({
|
|
270
|
-
senderId: "user-123",
|
|
271
|
-
recordId: "doc-001",
|
|
272
|
-
content: "Refund requests are processed within 5 business days.",
|
|
273
|
-
type: "text",
|
|
274
|
-
metadata: { source: "help-center" },
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// Update
|
|
278
|
-
await notifier.updateDocument({
|
|
279
|
-
senderId: "user-123",
|
|
280
|
-
recordId: "doc-001",
|
|
281
|
-
content: "Updated refund policy text...",
|
|
282
|
-
type: "text",
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
// Get one document
|
|
286
|
-
const doc = await notifier.getDocument({
|
|
287
|
-
senderId: "user-123",
|
|
288
|
-
recordId: "doc-001",
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
// List
|
|
292
|
-
const list = await notifier.listDocuments({
|
|
293
|
-
senderId: "user-123",
|
|
294
|
-
limit: 20,
|
|
295
|
-
offset: 0,
|
|
296
|
-
type: "text",
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
// Semantic search
|
|
300
|
-
const hits = await notifier.search({
|
|
301
|
-
senderId: "user-123",
|
|
302
|
-
query: "how long do refunds take",
|
|
303
|
-
limit: 5,
|
|
304
|
-
minSimilarity: 0.7,
|
|
305
|
-
filterbySource: "help-center",
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
// Delete
|
|
309
|
-
await notifier.deleteDocument({
|
|
310
|
-
senderId: "user-123",
|
|
311
|
-
recordId: "doc-001",
|
|
312
|
-
});
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
---
|
|
316
|
-
|
|
317
|
-
## Chat history
|
|
318
|
-
|
|
319
|
-
```js
|
|
320
|
-
await notifier.fetchChatHistory({
|
|
321
|
-
senderId: "user-123",
|
|
322
|
-
receiverIds: ["user-456"],
|
|
323
|
-
});
|
|
324
|
-
// Server responds via onMessage with the history payload.
|
|
325
|
-
|
|
326
|
-
await notifier.deleteChatHistoryMessage({
|
|
327
|
-
senderId: "user-123",
|
|
328
|
-
messageId: "message-id-to-delete",
|
|
329
|
-
});
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
---
|
|
333
|
-
|
|
334
|
-
## Session logging
|
|
335
|
-
|
|
336
|
-
Enable automatic AI session tracking in the DNotifier dashboard:
|
|
337
|
-
|
|
338
|
-
```js
|
|
339
|
-
const notifier = new DNotifier({
|
|
340
|
-
appId: "your-app-id",
|
|
341
|
-
secret: "your-app-secret",
|
|
342
|
-
transport: "http",
|
|
343
|
-
userId: "user-123",
|
|
344
|
-
logs: true,
|
|
345
|
-
onConnected: () => {},
|
|
346
|
-
onMessage: () => {},
|
|
347
|
-
onDisconnected: () => {},
|
|
348
|
-
});
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
When `logs: true`, `sendAI` reports session start, completion, and token usage to DNotifier.
|
|
352
|
-
|
|
353
|
-
---
|
|
354
|
-
|
|
355
|
-
## Workflows and agents
|
|
356
|
-
|
|
357
|
-
Build deterministic, multi-step AI pipelines with **named agents**, shared **workflow state**, and optional **observability** (execution and step telemetry in the DNotifier workflow dashboard).
|
|
358
|
-
|
|
359
|
-
Full guide: [Workflows overview](https://dnotifier.gitbook.io/product-docs/workflows/overview) · [Tools & MCP](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/tools-and-mcp).
|
|
360
|
-
|
|
361
|
-
### 1. Define agents
|
|
362
|
-
|
|
363
|
-
```js
|
|
364
|
-
import { DNotifier } from "@dnotifier-realtime/dnotifier";
|
|
365
|
-
|
|
366
|
-
const intentAgent = DNotifier.defineAgent({
|
|
367
|
-
name: "intent-agent",
|
|
368
|
-
async run(ctx) {
|
|
369
|
-
await ctx.sendAI({
|
|
370
|
-
message: { text: "Classify: search or general?" },
|
|
371
|
-
saveHistory: false,
|
|
372
|
-
label: "Intent classification",
|
|
373
|
-
});
|
|
374
|
-
return { intent: "search" };
|
|
375
|
-
},
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
const generalAgent = DNotifier.defineAgent({
|
|
379
|
-
name: "general-agent",
|
|
380
|
-
async run(ctx) {
|
|
381
|
-
const question = ctx.input?.question ?? ctx.input;
|
|
382
|
-
return { answer: `You asked: ${question}` };
|
|
383
|
-
},
|
|
384
|
-
});
|
|
385
|
-
```
|
|
386
|
-
|
|
387
|
-
### 2. Define a workflow
|
|
388
|
-
|
|
389
|
-
```js
|
|
390
|
-
const workflow = new DNotifier.Workflow({
|
|
391
|
-
name: "intent-router",
|
|
392
|
-
description: "Route user input to search or general Q&A",
|
|
393
|
-
observability: true,
|
|
394
|
-
async entry(ctx) {
|
|
395
|
-
const { intent } = await ctx.runAgent("intent-agent");
|
|
396
|
-
|
|
397
|
-
if (intent === "search") {
|
|
398
|
-
await ctx.search({
|
|
399
|
-
query: String(ctx.input),
|
|
400
|
-
limit: 5,
|
|
401
|
-
label: "Knowledge search",
|
|
402
|
-
});
|
|
403
|
-
return { branch: "search" };
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
const answer = await ctx.runAgent("general-agent", {
|
|
407
|
-
input: { question: ctx.input },
|
|
408
|
-
});
|
|
409
|
-
return { branch: "general", answer };
|
|
410
|
-
},
|
|
411
|
-
}).registerAgents({
|
|
412
|
-
"intent-agent": intentAgent,
|
|
413
|
-
"general-agent": generalAgent,
|
|
414
|
-
});
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
### 3. Run the workflow
|
|
418
|
-
|
|
419
|
-
```js
|
|
420
|
-
const notifier = new DNotifier({
|
|
421
|
-
appId: "your-app-id",
|
|
422
|
-
secret: "your-app-secret",
|
|
423
|
-
transport: "http",
|
|
424
|
-
userId: "user-123",
|
|
425
|
-
onConnected: () => {},
|
|
426
|
-
onMessage: () => {},
|
|
427
|
-
onDisconnected: () => {},
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
await notifier.connect();
|
|
431
|
-
|
|
432
|
-
const run = await notifier.runWorkflow({
|
|
433
|
-
workflow,
|
|
434
|
-
input: "How does messaging work?",
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
console.log(run.executionId); // present when observability: true
|
|
438
|
-
console.log(run.result); // { branch: "search" } or similar
|
|
439
|
-
console.log(run.state); // shared state from the run
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
### Multi-stage pipeline example
|
|
443
|
-
|
|
444
|
-
```js
|
|
445
|
-
const createAgent = DNotifier.defineAgent({
|
|
446
|
-
name: "content-creator",
|
|
447
|
-
async run(ctx) {
|
|
448
|
-
const brief = ctx.input;
|
|
449
|
-
const aiResponse = await ctx.sendAI({
|
|
450
|
-
message: {
|
|
451
|
-
useKnowledgeBase: false,
|
|
452
|
-
messages: [
|
|
453
|
-
{ role: "system", content: "Write a blog draft in markdown." },
|
|
454
|
-
{ role: "user", content: `Topic: ${brief.topic}` },
|
|
455
|
-
],
|
|
456
|
-
},
|
|
457
|
-
saveHistory: false,
|
|
458
|
-
label: "Draft creation",
|
|
459
|
-
});
|
|
460
|
-
const content = aiResponse?.data?.content ?? "";
|
|
461
|
-
ctx.state.draft = content;
|
|
462
|
-
return { content };
|
|
463
|
-
},
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
const workflow = new DNotifier.Workflow({
|
|
467
|
-
name: "blog-article-writer",
|
|
468
|
-
description: "Create, refine, and optimize a blog post",
|
|
469
|
-
observability: true,
|
|
470
|
-
async entry(ctx) {
|
|
471
|
-
const draft = await ctx.runAgent("content-creator");
|
|
472
|
-
const refined = await ctx.runAgent("clarity-editor", {
|
|
473
|
-
input: { content: draft.content },
|
|
474
|
-
});
|
|
475
|
-
return { article: refined.content };
|
|
476
|
-
},
|
|
477
|
-
}).registerAgents({
|
|
478
|
-
"content-creator": createAgent,
|
|
479
|
-
"clarity-editor": clarityEditorAgent,
|
|
480
|
-
});
|
|
481
|
-
```
|
|
482
|
-
|
|
483
|
-
### Agent tools and MCP
|
|
484
|
-
|
|
485
|
-
Register local tools and MCP servers on the connected client. Attach them to `DNotifier.defineAgent` — there is no separate `agents.create`.
|
|
486
|
-
|
|
487
|
-
```js
|
|
488
|
-
const getOrderStatus = notifier.tools.register({
|
|
489
|
-
name: "get_order_status",
|
|
490
|
-
description: "Get the current status of an order",
|
|
491
|
-
inputSchema: {
|
|
492
|
-
type: "object",
|
|
493
|
-
properties: { orderId: { type: "string" } },
|
|
494
|
-
required: ["orderId"],
|
|
495
|
-
},
|
|
496
|
-
execute: async ({ orderId }, context) => {
|
|
497
|
-
return { status: "shipped", orderId };
|
|
498
|
-
},
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
const github = await notifier.mcp.connect({
|
|
502
|
-
id: "github",
|
|
503
|
-
name: "GitHub",
|
|
504
|
-
transport: "http",
|
|
505
|
-
endpoint: process.env.GITHUB_MCP_URL,
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
const supportAgent = DNotifier.defineAgent({
|
|
509
|
-
name: "customer-support",
|
|
510
|
-
description: "Handles customer support requests",
|
|
511
|
-
tools: [getOrderStatus, ...github.tools()],
|
|
512
|
-
permissions: {
|
|
513
|
-
get_order_status: ["execute"],
|
|
514
|
-
},
|
|
515
|
-
});
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
Use the same agent in a workflow or on its own. The SDK owns the tool-call loop.
|
|
519
|
-
|
|
520
|
-
```js
|
|
521
|
-
// Workflow
|
|
522
|
-
const workflow = new DNotifier.Workflow({
|
|
523
|
-
name: "support-pipeline",
|
|
524
|
-
entry: async (ctx) =>
|
|
525
|
-
ctx.runAgent("customer-support", {
|
|
526
|
-
input: "What is the status of order ORD-123?",
|
|
527
|
-
}),
|
|
528
|
-
}).registerAgents({ "customer-support": supportAgent });
|
|
529
|
-
|
|
530
|
-
await notifier.runWorkflow({ workflow, input: {} });
|
|
531
|
-
|
|
532
|
-
// Standalone
|
|
533
|
-
const { output, executionId } = await notifier.runAgent(supportAgent, {
|
|
534
|
-
input: "What is the status of order ORD-123?",
|
|
535
|
-
userId: "user_123",
|
|
536
|
-
});
|
|
537
|
-
```
|
|
538
|
-
|
|
539
|
-
Agents without `tools` keep today's one-shot `ctx.sendAI`. Agents with `tools` and a custom `run(ctx)` still use that function as the workflow body; each `ctx.sendAI` inside it runs the tool loop.
|
|
540
|
-
|
|
541
|
-
### `WorkflowContext` (inside `entry` and agent `run`)
|
|
542
|
-
|
|
543
|
-
| Member / method | Description |
|
|
544
|
-
|-----------------|-------------|
|
|
545
|
-
| `ctx.input` | Workflow input passed to `runWorkflow` (or overridden per `runAgent`) |
|
|
546
|
-
| `ctx.state` | Shared mutable object for the current execution |
|
|
547
|
-
| `ctx.agentName` | Name of the agent currently running (inside agent handlers) |
|
|
548
|
-
| `ctx.runAgent(name, { input? })` | Invoke a registered agent |
|
|
549
|
-
| `ctx.sendAI({ message, saveHistory?, label? })` | AI call; steps recorded when observability is on |
|
|
550
|
-
| `ctx.fetchAIHistory({ label? })` | Fetch AI history |
|
|
551
|
-
| `ctx.search({ query, limit?, minSimilarity?, filterbySource?, label? })` | Semantic search |
|
|
552
|
-
| `ctx.addDocument(opts)` | Add knowledge-base document |
|
|
553
|
-
| `ctx.updateDocument(opts)` | Update document |
|
|
554
|
-
| `ctx.deleteDocument(opts)` | Delete document |
|
|
555
|
-
| `ctx.listDocuments(opts?)` | List documents |
|
|
556
|
-
| `ctx.getDocument(opts)` | Get document by id |
|
|
557
|
-
| `ctx.recordStep({ label, input?, output?, status?, type? })` | Record a custom step when observability is enabled |
|
|
558
|
-
|
|
559
|
-
When `observability: true` on the workflow, SDK calls and `recordStep` are sent to the DNotifier workflow dashboard. No extra setup is required beyond `connect()`.
|
|
560
|
-
|
|
561
|
-
---
|
|
562
|
-
|
|
563
|
-
## API reference
|
|
564
|
-
|
|
565
|
-
### `DNotifier`
|
|
566
|
-
|
|
567
|
-
| Method | Description |
|
|
568
|
-
|--------|-------------|
|
|
569
|
-
| `connect()` | Authenticate and connect |
|
|
570
|
-
| `disconnect()` | Close the WebSocket connection |
|
|
571
|
-
| `getPlanLimits()` | Plan limits from last auth |
|
|
572
|
-
| `send({ senderId, receiverId?, receiverIds?, data, saveHistory? })` | Send a message |
|
|
573
|
-
| `sendBinary({ senderId, receiverIds, buffer, type? })` | Send raw bytes |
|
|
574
|
-
| `sendAI({ senderId, message, saveHistory?, sessionId? })` | Send to AI pipeline |
|
|
575
|
-
| `fetchAIHistory({ senderId })` | Fetch AI conversation history |
|
|
576
|
-
| `deleteAIHistoryMessage({ senderId, messageId })` | Delete one AI history message |
|
|
577
|
-
| `fetchChatHistory({ senderId, receiverIds })` | Request chat history (response via `onMessage`) |
|
|
578
|
-
| `deleteChatHistoryMessage({ senderId, messageId })` | Delete one chat history message |
|
|
579
|
-
| `search({ senderId, query, limit?, minSimilarity?, filterbySource? })` | Semantic search over knowledge base |
|
|
580
|
-
| `addDocument({ senderId, recordId, content, type?, metadata? })` | Add a document |
|
|
581
|
-
| `updateDocument({ senderId, recordId, content, type?, metadata? })` | Update a document |
|
|
582
|
-
| `getDocument({ senderId, recordId })` | Get a document |
|
|
583
|
-
| `listDocuments({ senderId, limit?, offset?, type? })` | List documents |
|
|
584
|
-
| `deleteDocument({ senderId, recordId })` | Delete a document |
|
|
585
|
-
| `runWorkflow({ workflow, input, senderId? })` | Run a workflow after `connect()` |
|
|
586
|
-
| `runAgent(agent, { input?, userId?, sessionId? })` | Run a `defineAgent` result outside a workflow |
|
|
587
|
-
| `tools.register(...)` / `tools.get` / `tools.list` | Local tool registry |
|
|
588
|
-
| `mcp.connect(...)` / `mcp.get` / `mcp.list` | MCP HTTP connections and discovery |
|
|
589
|
-
| `sendWithOpenAI(...)` | **Deprecated** — use `sendAI` |
|
|
590
|
-
|
|
591
|
-
### Workflow exports
|
|
592
|
-
|
|
593
|
-
| Export | Description |
|
|
594
|
-
|--------|-------------|
|
|
595
|
-
| `DNotifier.defineAgent({ name, run?, tools?, permissions? })` | Create a named agent (optional tools) |
|
|
596
|
-
| `DNotifier.Workflow` | Workflow definition class |
|
|
597
|
-
| `DNotifier.WorkflowContext` | Context type passed to `entry` and agent `run` |
|
|
598
|
-
| `DNotifier.WorkflowError` | Workflow validation and runtime errors |
|
|
599
|
-
| `Agent` | Agent class (also available via `defineAgent`) |
|
|
600
|
-
|
|
601
|
-
`runWorkflow` is the recommended way to execute a workflow. `WorkflowRunner` is exported for advanced custom hosting but is not required for typical use.
|
|
602
|
-
|
|
603
|
-
### Message and payload types
|
|
604
|
-
|
|
605
|
-
**`DNotifierMessage`**
|
|
606
|
-
|
|
607
|
-
- `metadata` — `{ id, sender, timestamp, type }`
|
|
608
|
-
- `payload` — `Payload` instance
|
|
609
|
-
|
|
610
|
-
**`Payload`**
|
|
611
|
-
|
|
612
|
-
- `toJSON()` — parse JSON body
|
|
613
|
-
- `toString()` — string body
|
|
614
|
-
- `toBase64()` — base64 string
|
|
615
|
-
- `raw()` — raw bytes
|
|
616
|
-
|
|
617
|
-
**`getPlanLimits()` return value**
|
|
618
|
-
|
|
619
|
-
- `messagesHardLimit`, `maxAIRequestsPerMonth`, `maxAIWordsPerMonth`
|
|
620
|
-
- `knowledgeBaseMaxWords`, `aiEnabled`, `maxUsers`, `maxRowsPerUser`
|
|
621
|
-
|
|
622
|
-
**`runWorkflow` return value**
|
|
623
|
-
|
|
624
|
-
- `result` — return value of the workflow `entry` function
|
|
625
|
-
- `state` — final shared workflow state
|
|
626
|
-
- `executionId` — present when `observability: true`
|
|
627
|
-
|
|
628
|
-
---
|
|
38
|
+
[AI overview](https://dnotifier.gitbook.io/product-docs/ai/overview) · [Workflows](https://dnotifier.gitbook.io/product-docs/workflows/overview) · [Install](https://dnotifier.gitbook.io/product-docs/getting-started/installation/javascript-typescript)
|
|
629
39
|
|
|
630
40
|
## License
|
|
631
41
|
|
|
632
|
-
Proprietary — see [LICENSE](LICENSE).
|
|
633
|
-
|
|
634
|
-
---
|
|
635
|
-
|
|
636
|
-
## Links
|
|
637
|
-
|
|
638
|
-
- **Documentation (GitBook):** [dnotifier.gitbook.io/product-docs](https://dnotifier.gitbook.io/product-docs)
|
|
639
|
-
- **AI:** [AI overview](https://dnotifier.gitbook.io/product-docs/ai/overview)
|
|
640
|
-
- **Workflows:** [Workflows overview](https://dnotifier.gitbook.io/product-docs/workflows/overview)
|
|
641
|
-
- **JavaScript install:** [Install — JavaScript / TypeScript](https://dnotifier.gitbook.io/product-docs/getting-started/installation/javascript-typescript)
|
|
642
|
-
- **Product:** [dnotifier.com](https://www.dnotifier.com)
|
|
643
|
-
- **Dashboard:** [app.dnotifier.com](https://app.dnotifier.com)
|
|
42
|
+
Proprietary — see [LICENSE](LICENSE).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HttpTransport}from'../transport/httpTransport.js';import{DNotifierEndpoints}from'../config/endpoints.js';import{toPublicTool}from'./descriptors.js';import{agentBackendId}from'./ids.js';import{BackendError}from'./errors.js';const SDK_VERSION='1.1.23';function unwrap(
|
|
1
|
+
import{HttpTransport}from'../transport/httpTransport.js';import{DNotifierEndpoints}from'../config/endpoints.js';import{toPublicTool}from'./descriptors.js';import{agentBackendId}from'./ids.js';import{BackendError}from'./errors.js';const SDK_VERSION='1.1.23';function unwrap(_0x14b621){var _0x1bcf60,_0xcf76f1;if(_0x14b621&&'object'==typeof _0x14b621&&null!=_0x14b621['_responseCode']){if(0xc8!==Number(_0x14b621['_responseCode'])){const _0x1771fa='string'==typeof _0x14b621['_responseData']?_0x14b621['_responseData']:JSON['stringify'](null!==(_0x1bcf60=_0x14b621['_responseData'])&&void 0x0!==_0x1bcf60?_0x1bcf60:'');throw new Error(_0x1771fa||'Backend\x20response\x20'+_0x14b621['_responseCode']);}return null!==(_0xcf76f1=_0x14b621['_responseData'])&&void 0x0!==_0xcf76f1?_0xcf76f1:_0x14b621;}return _0x14b621;}export class AgentBackendClient{constructor({token:_0xa4040b=null,requestTimeoutMs:_0x1d0c12=0x7530}={}){this['token']=_0xa4040b,this['requestTimeoutMs']=_0x1d0c12;}['configure']({token:_0x39f738}={}){void 0x0!==_0x39f738&&(this['token']=_0x39f738);}async['post'](_0x33df68,_0x33fe84){var _0x2bc62e;if(!this['token'])throw new BackendError('Agent\x20backend\x20call\x20requires\x20a\x20connected\x20client');const _0x36c110=new HttpTransport({'url':_0x33df68,'headers':{'authorization':''+this['token']},'timeoutMs':this['requestTimeoutMs']});try{return unwrap(await _0x36c110['send'](_0x33fe84));}catch(_0x1e43c7){if(_0x1e43c7 instanceof BackendError)throw _0x1e43c7;throw new BackendError(null!==(_0x2bc62e=null==_0x1e43c7?void 0x0:_0x1e43c7['message'])&&void 0x0!==_0x2bc62e?_0x2bc62e:'Backend\x20request\x20failed',{'cause':_0x1e43c7 instanceof Error?_0x1e43c7:void 0x0});}}async['postQuiet'](_0x118c96,_0x1062cb){if(this['token'])try{await this['post'](_0x118c96,_0x1062cb);}catch{}}async['registerTool'](_0x33e479){await this['post'](DNotifierEndpoints['agentToolRegisterUrl'],{...toPublicTool(_0x33e479),'sdkVersion':'1.1.23'});}async['registerMcpServer'](_0x57e6b3){await this['post'](DNotifierEndpoints['agentMcpServerRegisterUrl'],{'id':_0x57e6b3['id'],'name':_0x57e6b3['name'],'transport':_0x57e6b3['transport'],'sdkVersion':'1.1.23'});}async['registerMcpServerTools'](_0x356b24,_0x41a5d5){await this['post'](DNotifierEndpoints['agentMcpServerToolsUrl'](_0x356b24),{'tools':_0x41a5d5['map'](toPublicTool),'sdkVersion':'1.1.23'});}async['registerAgent'](_0x1aab91){var _0x539965,_0x2851e4,_0x3f03dc,_0x1fc8a1;const _0x22c0d0=agentBackendId(_0x1aab91['name']),_0x5d9049=null!==(_0x539965=_0x1aab91['tools'])&&void 0x0!==_0x539965?_0x539965:[],_0x1162dc=[...new Set(_0x5d9049['map'](_0x4e2d27=>_0x4e2d27['mcpServerId'])['filter'](Boolean))];await this['post'](DNotifierEndpoints['agentRegisterUrl'],{'id':_0x22c0d0,'name':_0x1aab91['name'],'description':null!==(_0x2851e4=_0x1aab91['description'])&&void 0x0!==_0x2851e4?_0x2851e4:'','toolIds':_0x5d9049['map'](_0x1f2974=>_0x1f2974['id']),'mcpServerIds':_0x1162dc,'permissions':null!==(_0x3f03dc=_0x1aab91['permissions'])&&void 0x0!==_0x3f03dc?_0x3f03dc:{},'sdkVersion':'1.1.23'}),await this['post'](DNotifierEndpoints['agentToolsUrl'](_0x22c0d0),{'toolIds':_0x5d9049['map'](_0x31f7d7=>_0x31f7d7['id'])}),await this['post'](DNotifierEndpoints['agentPermissionsUrl'](_0x22c0d0),{'permissions':null!==(_0x1fc8a1=_0x1aab91['permissions'])&&void 0x0!==_0x1fc8a1?_0x1fc8a1:{}});}async['checkPermission'](_0xffbb34){return this['post'](DNotifierEndpoints['agentPermissionCheckUrl'],_0xffbb34);}}export class AgentSync{constructor({backend:_0x34cd8f}){this['backend']=_0x34cd8f,this['_tools']=new Map(),this['_servers']=new Map(),this['_agents']=new Map(),this['_chain']=Promise['resolve']();}['enqueueTool'](_0x5a213c){this['_tools']['set'](_0x5a213c['id'],_0x5a213c),this['backend']['token']&&this['flush']()['catch'](()=>{});}['enqueueServer'](_0x2ba8f0,_0x339b16){this['_servers']['set'](_0x2ba8f0['id'],{'server':_0x2ba8f0,'tools':_0x339b16}),this['backend']['token']&&this['flush']()['catch'](()=>{});}['enqueueAgent'](_0x556cf0){this['_agents']['set'](agentBackendId(_0x556cf0['name']),_0x556cf0);}async['flush'](){const _0xb286ca=this['_chain']['then'](()=>this['_flushOnce'](),()=>this['_flushOnce']());return this['_chain']=_0xb286ca['then'](()=>{},()=>{}),_0xb286ca;}async['_flushOnce'](){if(!this['backend']['token'])return;let _0x476073=0x0;for(const [_0xecd4df,_0x2f20ce]of[...this['_tools']]){try{await this['backend']['registerTool'](_0x2f20ce);}catch{_0x476073+=0x1;}this['_tools']['delete'](_0xecd4df);}for(const [_0x578d44,_0x4fb3e1]of[...this['_servers']]){try{await this['backend']['registerMcpServer'](_0x4fb3e1['server']),await this['backend']['registerMcpServerTools'](_0x578d44,_0x4fb3e1['tools']);}catch{_0x476073+=0x1;}this['_servers']['delete'](_0x578d44);}for(const [_0x4f933a,_0x58043a]of[...this['_agents']]){try{await this['backend']['registerAgent'](_0x58043a);}catch{_0x476073+=0x1;}this['_agents']['delete'](_0x4f933a);}_0x476073>0x0&&console['warn']('[dnotifier]\x20skipped\x20'+_0x476073+'\x20agent-backend\x20register\x20call(s)\x20(routes\x20not\x20available\x20yet)');}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function toPublicTool(
|
|
1
|
+
export function toPublicTool(_0x56cdcd){var _0x588077,_0x364203;const _0x34536e={'id':_0x56cdcd['id'],'name':_0x56cdcd['name'],'description':null!==(_0x588077=_0x56cdcd['description'])&&void 0x0!==_0x588077?_0x588077:'','inputSchema':null!==(_0x364203=_0x56cdcd['inputSchema'])&&void 0x0!==_0x364203?_0x364203:{'type':'object'},'provider':_0x56cdcd['provider']};return _0x56cdcd['mcpServerId']&&(_0x34536e['mcpServerId']=_0x56cdcd['mcpServerId']),_0x34536e;}
|