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