@novu/framework 2.10.1-alpha.4 → 2.10.1-alpha.6
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/dist/cjs/{index-ZVAtl8F3.d.cts → index-BAY1Gj4h.d.cts} +151 -13
- package/dist/cjs/index.cjs +70 -70
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/servers/express.cjs +59 -59
- package/dist/cjs/servers/express.d.cts +2 -2
- package/dist/cjs/servers/h3.cjs +59 -59
- package/dist/cjs/servers/h3.d.cts +2 -2
- package/dist/cjs/servers/lambda.cjs +59 -59
- package/dist/cjs/servers/lambda.d.cts +2 -2
- package/dist/cjs/servers/nest.cjs +60 -60
- package/dist/cjs/servers/nest.d.cts +2 -2
- package/dist/cjs/servers/next.cjs +59 -59
- package/dist/cjs/servers/next.d.cts +2 -2
- package/dist/cjs/servers/nuxt.cjs +59 -59
- package/dist/cjs/servers/nuxt.d.cts +2 -2
- package/dist/cjs/servers/remix.cjs +59 -59
- package/dist/cjs/servers/remix.d.cts +2 -2
- package/dist/cjs/servers/sveltekit.cjs +57 -57
- package/dist/cjs/servers/sveltekit.d.cts +2 -2
- package/dist/esm/chunk-H2XIPY7V.js +130 -0
- package/dist/esm/{index-D0d-O6LJ.d.ts → index-DiFdSsia.d.ts} +151 -13
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/servers/express.d.ts +2 -2
- package/dist/esm/servers/express.js +1 -1
- package/dist/esm/servers/h3.d.ts +2 -2
- package/dist/esm/servers/h3.js +1 -1
- package/dist/esm/servers/lambda.d.ts +2 -2
- package/dist/esm/servers/lambda.js +1 -1
- package/dist/esm/servers/nest.d.ts +2 -2
- package/dist/esm/servers/nest.js +1 -1
- package/dist/esm/servers/next.d.ts +2 -2
- package/dist/esm/servers/next.js +1 -1
- package/dist/esm/servers/nuxt.d.ts +2 -2
- package/dist/esm/servers/nuxt.js +1 -1
- package/dist/esm/servers/remix.d.ts +2 -2
- package/dist/esm/servers/remix.js +1 -1
- package/dist/esm/servers/sveltekit.d.ts +2 -2
- package/dist/esm/servers/sveltekit.js +1 -1
- package/package.json +1 -1
- package/dist/esm/chunk-FI2YN7IA.js +0 -130
|
@@ -10,12 +10,14 @@ declare enum AgentEventEnum {
|
|
|
10
10
|
ON_RESOLVE = "onResolve",
|
|
11
11
|
ON_REACTION = "onReaction"
|
|
12
12
|
}
|
|
13
|
+
/** Identity of the user or bot that authored a message. */
|
|
13
14
|
interface AgentMessageAuthor {
|
|
14
15
|
userId: string;
|
|
15
16
|
fullName: string;
|
|
16
17
|
userName: string;
|
|
17
18
|
isBot: boolean | 'unknown';
|
|
18
19
|
}
|
|
20
|
+
/** A file or media attachment included with a message. */
|
|
19
21
|
interface AgentAttachment {
|
|
20
22
|
type: string;
|
|
21
23
|
url?: string;
|
|
@@ -23,22 +25,35 @@ interface AgentAttachment {
|
|
|
23
25
|
mimeType?: string;
|
|
24
26
|
size?: number;
|
|
25
27
|
}
|
|
28
|
+
/** An incoming message from the user in the current conversation. */
|
|
26
29
|
interface AgentMessage {
|
|
30
|
+
/** Plain-text content of the message. */
|
|
27
31
|
text: string;
|
|
32
|
+
/** Platform-native message ID (e.g. Slack `ts`, Teams `activityId`). */
|
|
28
33
|
platformMessageId: string;
|
|
29
34
|
author: AgentMessageAuthor;
|
|
30
35
|
timestamp: string;
|
|
31
36
|
attachments?: AgentAttachment[];
|
|
32
37
|
}
|
|
38
|
+
/** Live state of the current conversation thread. */
|
|
33
39
|
interface AgentConversation {
|
|
40
|
+
/** Stable identifier for this conversation. */
|
|
34
41
|
identifier: string;
|
|
42
|
+
/** Lifecycle status (e.g. `'open'`, `'resolved'`). */
|
|
35
43
|
status: string;
|
|
44
|
+
/**
|
|
45
|
+
* Key/value store for this conversation.
|
|
46
|
+
* Values are written via `ctx.metadata.set()` and readable on subsequent messages.
|
|
47
|
+
*/
|
|
36
48
|
metadata: Record<string, unknown>;
|
|
49
|
+
/** Number of messages exchanged so far; starts at 1 for the first message. */
|
|
37
50
|
messageCount: number;
|
|
38
51
|
createdAt: string;
|
|
39
52
|
lastActivityAt: string;
|
|
40
53
|
}
|
|
54
|
+
/** The Novu subscriber who initiated or is participating in the conversation. */
|
|
41
55
|
interface AgentSubscriber {
|
|
56
|
+
/** Stable Novu subscriber ID. */
|
|
42
57
|
subscriberId: string;
|
|
43
58
|
firstName?: string;
|
|
44
59
|
lastName?: string;
|
|
@@ -46,31 +61,54 @@ interface AgentSubscriber {
|
|
|
46
61
|
phone?: string;
|
|
47
62
|
avatar?: string;
|
|
48
63
|
locale?: string;
|
|
64
|
+
/** Arbitrary custom data attached to the subscriber in Novu. */
|
|
49
65
|
data?: Record<string, unknown>;
|
|
50
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* A single entry in the conversation history.
|
|
69
|
+
* `ctx.history` is an ordered array of these entries — map them to your LLM's
|
|
70
|
+
* message format before making a model call.
|
|
71
|
+
*/
|
|
51
72
|
interface AgentHistoryEntry {
|
|
73
|
+
/** Message role: `'user'`, `'assistant'`, or `'system'`. */
|
|
52
74
|
role: string;
|
|
75
|
+
/** Content type: `'text'`, `'card'`, etc. */
|
|
53
76
|
type: string;
|
|
77
|
+
/** Plain-text representation of the message content. */
|
|
54
78
|
content: string;
|
|
55
79
|
richContent?: Record<string, unknown>;
|
|
56
80
|
senderName?: string;
|
|
81
|
+
/** Present on system entries that carry a Novu signal (e.g. metadata updates). */
|
|
57
82
|
signalData?: {
|
|
58
83
|
type: string;
|
|
59
84
|
payload?: Record<string, unknown>;
|
|
60
85
|
};
|
|
61
86
|
createdAt: string;
|
|
62
87
|
}
|
|
88
|
+
/** Platform-specific identifiers for the thread and channel. */
|
|
63
89
|
interface AgentPlatformContext {
|
|
90
|
+
/** Platform-native thread ID (e.g. Slack thread `ts`, Teams conversation ID). */
|
|
64
91
|
threadId: string;
|
|
92
|
+
/** Platform-native channel or chat ID. */
|
|
65
93
|
channelId: string;
|
|
94
|
+
/** Whether the message arrived in a direct message rather than a shared channel. */
|
|
66
95
|
isDM: boolean;
|
|
67
96
|
}
|
|
68
97
|
interface FileRef {
|
|
69
98
|
filename: string;
|
|
70
99
|
mimeType?: string;
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Inline file data. Binary values are encoded to base64 before being sent to Novu.
|
|
102
|
+
* Node Buffers are supported because Buffer extends Uint8Array.
|
|
103
|
+
*
|
|
104
|
+
* Limit: <= 5 MB decoded. Use `url` for larger files.
|
|
105
|
+
*/
|
|
106
|
+
data?: string | Uint8Array | ArrayBuffer | Blob;
|
|
107
|
+
/**
|
|
108
|
+
* Publicly-accessible HTTP(S) URL. Recommended for larger files.
|
|
109
|
+
*
|
|
110
|
+
* Server-side limits: 25 MB per file, 15 files per message, 50 MB aggregate.
|
|
111
|
+
*/
|
|
74
112
|
url?: string;
|
|
75
113
|
}
|
|
76
114
|
/**
|
|
@@ -88,16 +126,25 @@ interface ReplyContent {
|
|
|
88
126
|
card?: CardElement;
|
|
89
127
|
files?: FileRef[];
|
|
90
128
|
}
|
|
129
|
+
/** Data carried by a button click or other interactive action. */
|
|
91
130
|
interface AgentAction {
|
|
131
|
+
/** The `id` prop of the clicked `<Button>` or action element. */
|
|
92
132
|
actionId: string;
|
|
133
|
+
/** The `value` prop of the clicked element, if set. */
|
|
93
134
|
value?: string;
|
|
135
|
+
/** Platform-native message ID of the message containing the clicked button/action. */
|
|
136
|
+
sourceMessageId?: string;
|
|
94
137
|
}
|
|
138
|
+
/** An emoji reaction added to or removed from a message. */
|
|
95
139
|
interface AgentReaction {
|
|
140
|
+
/** Platform-native ID of the message that was reacted to. */
|
|
96
141
|
messageId: string;
|
|
97
142
|
emoji: {
|
|
98
143
|
name: string;
|
|
99
144
|
};
|
|
145
|
+
/** `true` when the reaction was added, `false` when it was removed. */
|
|
100
146
|
added: boolean;
|
|
147
|
+
/** The message that was reacted to, if available. */
|
|
101
148
|
message: AgentMessage | null;
|
|
102
149
|
}
|
|
103
150
|
/**
|
|
@@ -115,15 +162,23 @@ interface ReplyHandle {
|
|
|
115
162
|
files?: FileRef[];
|
|
116
163
|
}): Promise<ReplyHandle>;
|
|
117
164
|
}
|
|
118
|
-
interface
|
|
119
|
-
|
|
120
|
-
readonly action: AgentAction | null;
|
|
121
|
-
readonly message: AgentMessage | null;
|
|
122
|
-
readonly reaction: AgentReaction | null;
|
|
165
|
+
interface AgentContextBase {
|
|
166
|
+
/** Live state of the current conversation, including persisted metadata. */
|
|
123
167
|
readonly conversation: AgentConversation;
|
|
168
|
+
/**
|
|
169
|
+
* The Novu subscriber who sent the message, or `null` if Novu could not
|
|
170
|
+
* resolve a subscriber for this conversation.
|
|
171
|
+
*/
|
|
124
172
|
readonly subscriber: AgentSubscriber | null;
|
|
173
|
+
/**
|
|
174
|
+
* Full conversation history as an ordered array of entries.
|
|
175
|
+
* Map to your LLM's message format before making a model call:
|
|
176
|
+
* `ctx.history.map(h => ({ role: h.role, content: h.content }))`
|
|
177
|
+
*/
|
|
125
178
|
readonly history: AgentHistoryEntry[];
|
|
179
|
+
/** Platform identifier (e.g. `'slack'`, `'msteams'`, `'in-app'`). */
|
|
126
180
|
readonly platform: string;
|
|
181
|
+
/** Platform-specific thread and channel identifiers. */
|
|
127
182
|
readonly platformContext: AgentPlatformContext;
|
|
128
183
|
/**
|
|
129
184
|
* Post a message to the conversation and return a handle to it.
|
|
@@ -141,9 +196,26 @@ interface AgentContext {
|
|
|
141
196
|
reply(content: MessageContent, options?: {
|
|
142
197
|
files?: FileRef[];
|
|
143
198
|
}): Promise<ReplyHandle>;
|
|
199
|
+
/**
|
|
200
|
+
* Mark the conversation as resolved. Optionally provide a summary for the resolution record.
|
|
201
|
+
* Triggers the `onResolve` handler if one is registered.
|
|
202
|
+
*/
|
|
144
203
|
resolve(summary?: string): void;
|
|
204
|
+
/**
|
|
205
|
+
* Persistent key/value store for this conversation.
|
|
206
|
+
*
|
|
207
|
+
* - `get(key)` — read a value from the current metadata state
|
|
208
|
+
* - `set(key, value)` — write a value (flushed with the next reply or on handler completion)
|
|
209
|
+
* - `delete(key)` — remove a key
|
|
210
|
+
* - `clear()` — reset metadata to `{}`
|
|
211
|
+
* - `current` — readonly snapshot of the current state
|
|
212
|
+
*/
|
|
145
213
|
metadata: {
|
|
214
|
+
get(key: string): unknown;
|
|
146
215
|
set(key: string, value: unknown): void;
|
|
216
|
+
delete(key: string): void;
|
|
217
|
+
clear(): void;
|
|
218
|
+
readonly current: Readonly<Record<string, unknown>>;
|
|
147
219
|
};
|
|
148
220
|
/**
|
|
149
221
|
* Trigger a Novu workflow from within this agent handler.
|
|
@@ -183,11 +255,69 @@ interface AgentContext {
|
|
|
183
255
|
*/
|
|
184
256
|
addReaction(messageId: string, emojiName: Emoji): void;
|
|
185
257
|
}
|
|
258
|
+
/** Context passed to the `onMessage` handler. */
|
|
259
|
+
interface AgentMessageContext extends AgentContextBase {
|
|
260
|
+
readonly event: 'onMessage';
|
|
261
|
+
/** The incoming message that triggered this handler. */
|
|
262
|
+
readonly message: AgentMessage;
|
|
263
|
+
}
|
|
264
|
+
/** Context passed to the `onAction` handler. */
|
|
265
|
+
interface AgentActionContext extends AgentContextBase {
|
|
266
|
+
readonly event: 'onAction';
|
|
267
|
+
/** The button click or interactive action that triggered this handler. */
|
|
268
|
+
readonly action: AgentAction;
|
|
269
|
+
}
|
|
270
|
+
/** Context passed to the `onReaction` handler. */
|
|
271
|
+
interface AgentReactionContext extends AgentContextBase {
|
|
272
|
+
readonly event: 'onReaction';
|
|
273
|
+
/** The emoji reaction that triggered this handler. */
|
|
274
|
+
readonly reaction: AgentReaction;
|
|
275
|
+
}
|
|
276
|
+
/** Context passed to the `onResolve` handler. */
|
|
277
|
+
interface AgentResolveContext extends AgentContextBase {
|
|
278
|
+
readonly event: 'onResolve';
|
|
279
|
+
}
|
|
280
|
+
type AgentContext = AgentMessageContext | AgentActionContext | AgentReactionContext | AgentResolveContext;
|
|
281
|
+
/** Event handlers for a conversational agent. */
|
|
186
282
|
interface AgentHandlers {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Fires on every text message the user sends.
|
|
285
|
+
* `message` is the incoming message. `ctx` provides conversation history, subscriber,
|
|
286
|
+
* metadata, and reply/trigger methods.
|
|
287
|
+
* Return a string or JSX card to reply, or call `ctx.reply()` directly
|
|
288
|
+
* for more control (e.g. editing a message in place).
|
|
289
|
+
*/
|
|
290
|
+
onMessage: (payload: {
|
|
291
|
+
message: AgentMessage;
|
|
292
|
+
ctx: AgentMessageContext;
|
|
293
|
+
}) => Awaitable<MessageContent | void>;
|
|
294
|
+
/**
|
|
295
|
+
* Fires when the user adds or removes an emoji reaction to a message.
|
|
296
|
+
* `reaction` carries the emoji and whether it was added or removed.
|
|
297
|
+
* Return a string or card to post a reply, or return nothing to silently acknowledge.
|
|
298
|
+
*/
|
|
299
|
+
onReaction?: (payload: {
|
|
300
|
+
reaction: AgentReaction;
|
|
301
|
+
ctx: AgentReactionContext;
|
|
302
|
+
}) => Awaitable<MessageContent | void>;
|
|
303
|
+
/**
|
|
304
|
+
* Fires when the user clicks a `<Button>` or other interactive element.
|
|
305
|
+
* `actionId` is the `id` prop of the clicked element; `value` is its `value` prop.
|
|
306
|
+
* Return a string or card to reply, or return nothing to silently acknowledge the click.
|
|
307
|
+
*/
|
|
308
|
+
onAction?: (payload: {
|
|
309
|
+
actionId: string;
|
|
310
|
+
value?: string;
|
|
311
|
+
ctx: AgentActionContext;
|
|
312
|
+
}) => Awaitable<MessageContent | void>;
|
|
313
|
+
/**
|
|
314
|
+
* Fires after `ctx.resolve()` is called and the conversation is marked resolved.
|
|
315
|
+
* Use for post-resolution side-effects (e.g. triggering a follow-up workflow).
|
|
316
|
+
* Access subscriber and conversation via `ctx.subscriber` and `ctx.conversation`.
|
|
317
|
+
*/
|
|
318
|
+
onResolve?: (payload: {
|
|
319
|
+
ctx: AgentResolveContext;
|
|
320
|
+
}) => Awaitable<MessageContent | void>;
|
|
191
321
|
}
|
|
192
322
|
interface Agent {
|
|
193
323
|
id: string;
|
|
@@ -213,8 +343,16 @@ interface AgentBridgeRequest {
|
|
|
213
343
|
}
|
|
214
344
|
type MetadataSignal = {
|
|
215
345
|
type: 'metadata';
|
|
346
|
+
action: 'set';
|
|
216
347
|
key: string;
|
|
217
348
|
value: unknown;
|
|
349
|
+
} | {
|
|
350
|
+
type: 'metadata';
|
|
351
|
+
action: 'delete';
|
|
352
|
+
key: string;
|
|
353
|
+
} | {
|
|
354
|
+
type: 'metadata';
|
|
355
|
+
action: 'clear';
|
|
218
356
|
};
|
|
219
357
|
/**
|
|
220
358
|
* Queued by `ctx.trigger()` — instructs Novu to fire a workflow from inside an agent handler.
|
|
@@ -439,4 +577,4 @@ declare class NovuRequestHandler<Input extends any[] = any[], Output = any> {
|
|
|
439
577
|
*/
|
|
440
578
|
declare function workflow<T_PayloadSchema extends Schema, T_ControlSchema extends Schema, T_EnvSchema extends Schema, T_PayloadValidated extends Record<string, unknown> = FromSchema<T_PayloadSchema>, T_PayloadUnvalidated extends Record<string, unknown> = FromSchemaUnvalidated<T_PayloadSchema>, T_Controls extends Record<string, unknown> = FromSchema<T_ControlSchema>, T_Env extends Record<string, unknown> = FromSchema<T_EnvSchema>>(workflowId: string, execute: Execute<T_PayloadValidated, T_Controls, T_Env>, workflowOptions?: WorkflowOptions<T_PayloadSchema, T_ControlSchema, T_EnvSchema>): Workflow<T_PayloadUnvalidated>;
|
|
441
579
|
|
|
442
|
-
export { type Agent as A, Client as C, type EditPayload as E, type FileRef as F, type INovuRequestHandlerOptions as I, type MessageContent as M, NovuRequestHandler as N, type ReplyContent as R, type ServeHandlerOptions as S, type TriggerSignal as T, type AgentAction as a, type
|
|
580
|
+
export { type Agent as A, Client as C, type EditPayload as E, type FileRef as F, type INovuRequestHandlerOptions as I, type MessageContent as M, NovuRequestHandler as N, type ReplyContent as R, type ServeHandlerOptions as S, type TriggerSignal as T, type AgentAction as a, type AgentActionContext as b, type AgentAttachment as c, type AgentBridgeRequest as d, type AgentContext as e, type AgentConversation as f, AgentDeliveryError as g, AgentEventEnum as h, type AgentHandlers as i, type AgentHistoryEntry as j, type AgentMessage as k, type AgentMessageAuthor as l, type AgentMessageContext as m, type AgentPlatformContext as n, type AgentReaction as o, type AgentReactionContext as p, type AgentReplyPayload as q, type AgentResolveContext as r, type AgentSubscriber as s, type MetadataSignal as t, type ReplyHandle as u, type SentMessageInfo as v, type Signal as w, agent as x, workflow as y };
|