@novu/framework 2.10.1-alpha.5 → 2.10.1-alpha.7

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.
Files changed (40) hide show
  1. package/dist/cjs/{index-B4t9LyOV.d.cts → index-DtCBrkhW.d.cts} +142 -11
  2. package/dist/cjs/index.cjs +47 -47
  3. package/dist/cjs/index.d.cts +1 -1
  4. package/dist/cjs/servers/express.cjs +24 -24
  5. package/dist/cjs/servers/express.d.cts +2 -2
  6. package/dist/cjs/servers/h3.cjs +2 -2
  7. package/dist/cjs/servers/h3.d.cts +2 -2
  8. package/dist/cjs/servers/lambda.cjs +24 -24
  9. package/dist/cjs/servers/lambda.d.cts +2 -2
  10. package/dist/cjs/servers/nest.cjs +47 -47
  11. package/dist/cjs/servers/nest.d.cts +2 -2
  12. package/dist/cjs/servers/next.cjs +24 -24
  13. package/dist/cjs/servers/next.d.cts +2 -2
  14. package/dist/cjs/servers/nuxt.cjs +2 -2
  15. package/dist/cjs/servers/nuxt.d.cts +2 -2
  16. package/dist/cjs/servers/remix.cjs +24 -24
  17. package/dist/cjs/servers/remix.d.cts +2 -2
  18. package/dist/cjs/servers/sveltekit.cjs +40 -40
  19. package/dist/cjs/servers/sveltekit.d.cts +2 -2
  20. package/dist/esm/{chunk-TJFK73XZ.js → chunk-E6L6ATIB.js} +21 -21
  21. package/dist/esm/{index-BCzJp-zE.d.ts → index-CAMe0gXf.d.ts} +142 -11
  22. package/dist/esm/index.d.ts +1 -1
  23. package/dist/esm/index.js +1 -1
  24. package/dist/esm/servers/express.d.ts +2 -2
  25. package/dist/esm/servers/express.js +1 -1
  26. package/dist/esm/servers/h3.d.ts +2 -2
  27. package/dist/esm/servers/h3.js +1 -1
  28. package/dist/esm/servers/lambda.d.ts +2 -2
  29. package/dist/esm/servers/lambda.js +1 -1
  30. package/dist/esm/servers/nest.d.ts +2 -2
  31. package/dist/esm/servers/nest.js +1 -1
  32. package/dist/esm/servers/next.d.ts +2 -2
  33. package/dist/esm/servers/next.js +1 -1
  34. package/dist/esm/servers/nuxt.d.ts +2 -2
  35. package/dist/esm/servers/nuxt.js +1 -1
  36. package/dist/esm/servers/remix.d.ts +2 -2
  37. package/dist/esm/servers/remix.js +1 -1
  38. package/dist/esm/servers/sveltekit.d.ts +2 -2
  39. package/dist/esm/servers/sveltekit.js +1 -1
  40. package/package.json +1 -1
@@ -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,23 +61,37 @@ 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 {
@@ -97,16 +126,30 @@ interface ReplyContent {
97
126
  card?: CardElement;
98
127
  files?: FileRef[];
99
128
  }
129
+ /**
130
+ * Data carried by a button click or other interactive action.
131
+ *
132
+ * Used both on the bridge wire (`AgentBridgeRequest.action`) and as the
133
+ * handler-facing argument passed to `onAction(action, ctx)`.
134
+ */
100
135
  interface AgentAction {
101
- actionId: string;
136
+ /** The `id` prop of the clicked `<Button>` or action element. */
137
+ id: string;
138
+ /** The `value` prop of the clicked element, if set. */
102
139
  value?: string;
140
+ /** Platform-native message ID of the message containing the clicked button/action. */
141
+ sourceMessageId?: string;
103
142
  }
143
+ /** An emoji reaction added to or removed from a message. */
104
144
  interface AgentReaction {
145
+ /** Platform-native ID of the message that was reacted to. */
105
146
  messageId: string;
106
147
  emoji: {
107
148
  name: string;
108
149
  };
150
+ /** `true` when the reaction was added, `false` when it was removed. */
109
151
  added: boolean;
152
+ /** The message that was reacted to, if available. */
110
153
  message: AgentMessage | null;
111
154
  }
112
155
  /**
@@ -124,15 +167,23 @@ interface ReplyHandle {
124
167
  files?: FileRef[];
125
168
  }): Promise<ReplyHandle>;
126
169
  }
127
- interface AgentContext {
128
- readonly event: string;
129
- readonly action: AgentAction | null;
130
- readonly message: AgentMessage | null;
131
- readonly reaction: AgentReaction | null;
170
+ interface AgentContextBase {
171
+ /** Live state of the current conversation, including persisted metadata. */
132
172
  readonly conversation: AgentConversation;
173
+ /**
174
+ * The Novu subscriber who sent the message, or `null` if Novu could not
175
+ * resolve a subscriber for this conversation.
176
+ */
133
177
  readonly subscriber: AgentSubscriber | null;
178
+ /**
179
+ * Full conversation history as an ordered array of entries.
180
+ * Map to your LLM's message format before making a model call:
181
+ * `ctx.history.map(h => ({ role: h.role, content: h.content }))`
182
+ */
134
183
  readonly history: AgentHistoryEntry[];
184
+ /** Platform identifier (e.g. `'slack'`, `'msteams'`, `'in-app'`). */
135
185
  readonly platform: string;
186
+ /** Platform-specific thread and channel identifiers. */
136
187
  readonly platformContext: AgentPlatformContext;
137
188
  /**
138
189
  * Post a message to the conversation and return a handle to it.
@@ -150,9 +201,26 @@ interface AgentContext {
150
201
  reply(content: MessageContent, options?: {
151
202
  files?: FileRef[];
152
203
  }): Promise<ReplyHandle>;
204
+ /**
205
+ * Mark the conversation as resolved. Optionally provide a summary for the resolution record.
206
+ * Triggers the `onResolve` handler if one is registered.
207
+ */
153
208
  resolve(summary?: string): void;
209
+ /**
210
+ * Persistent key/value store for this conversation.
211
+ *
212
+ * - `get(key)` — read a value from the current metadata state
213
+ * - `set(key, value)` — write a value (flushed with the next reply or on handler completion)
214
+ * - `delete(key)` — remove a key
215
+ * - `clear()` — reset metadata to `{}`
216
+ * - `current` — readonly snapshot of the current state
217
+ */
154
218
  metadata: {
219
+ get(key: string): unknown;
155
220
  set(key: string, value: unknown): void;
221
+ delete(key: string): void;
222
+ clear(): void;
223
+ readonly current: Readonly<Record<string, unknown>>;
156
224
  };
157
225
  /**
158
226
  * Trigger a Novu workflow from within this agent handler.
@@ -192,11 +260,66 @@ interface AgentContext {
192
260
  */
193
261
  addReaction(messageId: string, emojiName: Emoji): void;
194
262
  }
263
+ /** Context passed to the `onMessage` handler. */
264
+ interface AgentMessageContext extends AgentContextBase {
265
+ readonly event: 'onMessage';
266
+ }
267
+ /** Context passed to the `onAction` handler. */
268
+ interface AgentActionContext extends AgentContextBase {
269
+ readonly event: 'onAction';
270
+ /** The button click or interactive action that triggered this handler. */
271
+ readonly action: AgentAction;
272
+ }
273
+ /** Context passed to the `onReaction` handler. */
274
+ interface AgentReactionContext extends AgentContextBase {
275
+ readonly event: 'onReaction';
276
+ /** The emoji reaction that triggered this handler. */
277
+ readonly reaction: AgentReaction;
278
+ }
279
+ /** Context passed to the `onResolve` handler. */
280
+ interface AgentResolveContext extends AgentContextBase {
281
+ readonly event: 'onResolve';
282
+ }
283
+ type AgentContext = AgentMessageContext | AgentActionContext | AgentReactionContext | AgentResolveContext;
284
+ /** Event handlers for a conversational agent. */
195
285
  interface AgentHandlers {
196
- onMessage: (ctx: AgentContext) => Awaitable<MessageContent | void>;
197
- onReaction?: (ctx: AgentContext) => Awaitable<MessageContent | void>;
198
- onAction?: (ctx: AgentContext) => Awaitable<MessageContent | void>;
199
- onResolve?: (ctx: AgentContext) => Awaitable<MessageContent | void>;
286
+ /**
287
+ * Fires on every text message the user sends.
288
+ *
289
+ * @param message - The incoming message that triggered this handler.
290
+ * @param ctx - Conversation history, subscriber, metadata, and reply/trigger methods.
291
+ *
292
+ * Return a string or JSX card to reply, or call `ctx.reply()` directly
293
+ * for more control (e.g. editing a message in place).
294
+ */
295
+ onMessage: (message: AgentMessage, ctx: AgentMessageContext) => Awaitable<MessageContent | void>;
296
+ /**
297
+ * Fires when the user adds or removes an emoji reaction to a message.
298
+ *
299
+ * @param reaction - The emoji reaction (carries the emoji and whether it was added or removed).
300
+ * @param ctx - Conversation context (history, subscriber, metadata, reply/trigger methods).
301
+ *
302
+ * Return a string or card to post a reply, or return nothing to silently acknowledge.
303
+ */
304
+ onReaction?: (reaction: AgentReaction, ctx: AgentReactionContext) => Awaitable<MessageContent | void>;
305
+ /**
306
+ * Fires when the user clicks a `<Button>` or other interactive element.
307
+ *
308
+ * @param action - The interactive action that triggered this handler.
309
+ * `action.id` is the `id` prop of the clicked element; `action.value` is its `value` prop.
310
+ * @param ctx - Conversation context (history, subscriber, metadata, reply/trigger methods).
311
+ *
312
+ * Return a string or card to reply, or return nothing to silently acknowledge the click.
313
+ */
314
+ onAction?: (action: AgentAction, ctx: AgentActionContext) => Awaitable<MessageContent | void>;
315
+ /**
316
+ * Fires after `ctx.resolve()` is called and the conversation is marked resolved.
317
+ * Use for post-resolution side-effects (e.g. triggering a follow-up workflow).
318
+ *
319
+ * @param ctx - Conversation context. Access subscriber and conversation via
320
+ * `ctx.subscriber` and `ctx.conversation`.
321
+ */
322
+ onResolve?: (ctx: AgentResolveContext) => Awaitable<MessageContent | void>;
200
323
  }
201
324
  interface Agent {
202
325
  id: string;
@@ -222,8 +345,16 @@ interface AgentBridgeRequest {
222
345
  }
223
346
  type MetadataSignal = {
224
347
  type: 'metadata';
348
+ action: 'set';
225
349
  key: string;
226
350
  value: unknown;
351
+ } | {
352
+ type: 'metadata';
353
+ action: 'delete';
354
+ key: string;
355
+ } | {
356
+ type: 'metadata';
357
+ action: 'clear';
227
358
  };
228
359
  /**
229
360
  * Queued by `ctx.trigger()` — instructs Novu to fire a workflow from inside an agent handler.
@@ -448,4 +579,4 @@ declare class NovuRequestHandler<Input extends any[] = any[], Output = any> {
448
579
  */
449
580
  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>;
450
581
 
451
- 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 AgentAttachment as b, type AgentBridgeRequest as c, type AgentContext as d, type AgentConversation as e, AgentDeliveryError as f, AgentEventEnum as g, type AgentHandlers as h, type AgentHistoryEntry as i, type AgentMessage as j, type AgentMessageAuthor as k, type AgentPlatformContext as l, type AgentReaction as m, type AgentReplyPayload as n, type AgentSubscriber as o, type MetadataSignal as p, type ReplyHandle as q, type SentMessageInfo as r, type Signal as s, agent as t, workflow as w };
582
+ 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 };