@novu/framework 2.11.1 → 2.11.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +114 -9
  2. package/ai-sdk/package.json +4 -0
  3. package/cards/package.json +4 -0
  4. package/dist/{esm/index-D6L0Yufw.d.ts → cjs/agent.types-DdgaVUb7.d.cts} +356 -193
  5. package/dist/cjs/ai-sdk/index.cjs +1 -0
  6. package/dist/cjs/ai-sdk/index.d.cts +39 -0
  7. package/dist/cjs/cards.cjs +57 -0
  8. package/dist/cjs/cards.d.cts +2 -0
  9. package/dist/cjs/{health-check.types-D4NEyjyC.d.cts → health-check.types-CkUmYLNG.d.cts} +6 -140
  10. package/dist/cjs/index-BCp3U0UG.d.cts +189 -0
  11. package/dist/cjs/index.cjs +138 -138
  12. package/dist/cjs/index.d.cts +5 -3
  13. package/dist/cjs/internal/index.cjs +1 -1
  14. package/dist/cjs/internal/index.d.cts +96 -4
  15. package/dist/cjs/jsx-dev-runtime.cjs +1 -1
  16. package/dist/cjs/jsx-runtime.cjs +1 -1
  17. package/dist/cjs/langchain/index.cjs +1 -0
  18. package/dist/cjs/langchain/index.d.cts +105 -0
  19. package/dist/cjs/servers/express.cjs +137 -137
  20. package/dist/cjs/servers/express.d.cts +6 -4
  21. package/dist/cjs/servers/h3.cjs +136 -136
  22. package/dist/cjs/servers/h3.d.cts +6 -4
  23. package/dist/cjs/servers/lambda.cjs +137 -137
  24. package/dist/cjs/servers/lambda.d.cts +6 -5
  25. package/dist/cjs/servers/nest.cjs +136 -136
  26. package/dist/cjs/servers/nest.d.cts +21 -7
  27. package/dist/cjs/servers/next.cjs +138 -138
  28. package/dist/cjs/servers/next.d.cts +6 -4
  29. package/dist/cjs/servers/nuxt.cjs +136 -136
  30. package/dist/cjs/servers/nuxt.d.cts +6 -4
  31. package/dist/cjs/servers/remix.cjs +138 -138
  32. package/dist/cjs/servers/remix.d.cts +6 -4
  33. package/dist/cjs/servers/sveltekit.cjs +136 -136
  34. package/dist/cjs/servers/sveltekit.d.cts +6 -4
  35. package/dist/cjs/step-resolver.d.cts +3 -2
  36. package/dist/cjs/{subscriber.types-PRaHFLJu.d.cts → subscriber.types-DxMMRBIi.d.cts} +2 -78
  37. package/dist/cjs/util.types-DaFfsxgy.d.cts +78 -0
  38. package/dist/{cjs/index-BNiIiOE-.d.cts → esm/agent.types-Bu3DhlVb.d.ts} +356 -193
  39. package/dist/esm/ai-sdk/index.d.ts +39 -0
  40. package/dist/esm/ai-sdk/index.js +1 -0
  41. package/dist/esm/cards.d.ts +2 -0
  42. package/dist/esm/cards.js +1 -0
  43. package/dist/esm/{chunk-KLCBNFAF.js → chunk-3XT6S7TZ.js} +14 -14
  44. package/dist/esm/chunk-3ZWME5KT.js +0 -0
  45. package/dist/esm/chunk-C3P3ZH2I.js +36 -0
  46. package/dist/esm/chunk-FHYMHX3T.js +1 -0
  47. package/dist/esm/chunk-KLIOXJR3.js +1 -0
  48. package/dist/esm/chunk-W6DIBD4Z.js +1 -0
  49. package/dist/esm/chunk-YF62BBGH.js +98 -0
  50. package/dist/esm/{health-check.types-C-81VaBO.d.ts → health-check.types-nDCnGlmX.d.ts} +6 -140
  51. package/dist/esm/index-DEehllqa.d.ts +189 -0
  52. package/dist/esm/index.d.ts +5 -3
  53. package/dist/esm/index.js +1 -1
  54. package/dist/esm/internal/index.d.ts +96 -4
  55. package/dist/esm/internal/index.js +1 -1
  56. package/dist/esm/jsx-dev-runtime.js +1 -1
  57. package/dist/esm/jsx-runtime-7EPQR56T.js +1 -0
  58. package/dist/esm/jsx-runtime.js +1 -1
  59. package/dist/esm/langchain/index.d.ts +105 -0
  60. package/dist/esm/langchain/index.js +1 -0
  61. package/dist/esm/servers/express.d.ts +6 -4
  62. package/dist/esm/servers/express.js +1 -1
  63. package/dist/esm/servers/h3.d.ts +6 -4
  64. package/dist/esm/servers/h3.js +1 -1
  65. package/dist/esm/servers/lambda.d.ts +6 -5
  66. package/dist/esm/servers/lambda.js +1 -1
  67. package/dist/esm/servers/nest.d.ts +21 -7
  68. package/dist/esm/servers/nest.js +1 -1
  69. package/dist/esm/servers/next.d.ts +6 -4
  70. package/dist/esm/servers/next.js +1 -1
  71. package/dist/esm/servers/nuxt.d.ts +6 -4
  72. package/dist/esm/servers/nuxt.js +1 -1
  73. package/dist/esm/servers/remix.d.ts +6 -4
  74. package/dist/esm/servers/remix.js +1 -1
  75. package/dist/esm/servers/sveltekit.d.ts +6 -4
  76. package/dist/esm/servers/sveltekit.js +1 -1
  77. package/dist/esm/step-resolver.d.ts +3 -2
  78. package/dist/esm/step-resolver.js +1 -1
  79. package/dist/esm/{subscriber.types-CC7F0JO_.d.ts → subscriber.types-BbyO_Cz6.d.ts} +2 -78
  80. package/dist/esm/util.types-DaFfsxgy.d.ts +78 -0
  81. package/dist/esm/validators.js +1 -1
  82. package/package.json +55 -7
  83. package/dist/esm/chunk-52LSX2V5.js +0 -1
  84. package/dist/esm/chunk-N4PZBM53.js +0 -1
  85. package/dist/esm/chunk-ND6IQFTA.js +0 -133
@@ -0,0 +1,39 @@
1
+ import { g as AgentHandlers, i as AgentMessage, k as AgentMessageContext, M as MessageContent, s as ToolApprovalDecision, b as AgentActionContext, R as ReplyHandle, A as Agent, h as AgentHistoryEntry } from '../agent.types-Bu3DhlVb.js';
2
+ import { streamText, generateText, ModelMessage } from 'ai';
3
+ import { A as Awaitable } from '../util.types-DaFfsxgy.js';
4
+ import 'chat';
5
+
6
+ type AiSdkStreamResult = Awaited<ReturnType<typeof streamText>>;
7
+ type AiSdkGenerateResult = Awaited<ReturnType<typeof generateText>>;
8
+ type AiSdkResult = AiSdkStreamResult | AiSdkGenerateResult;
9
+ /**
10
+ * Handlers for `@novu/framework/ai-sdk` agents.
11
+ *
12
+ * Extends {@link AgentHandlers}: same events and config (`toolApproval`, etc.),
13
+ * but `onMessage` and `onToolApproval` may return an AI SDK result for automatic delivery.
14
+ */
15
+ type AiSdkAgentHandlers = Omit<AgentHandlers, 'onMessage' | 'onToolApproval'> & {
16
+ onMessage: (message: AgentMessage, ctx: AgentMessageContext) => Awaitable<MessageContent | AiSdkResult | void>;
17
+ /**
18
+ * Optional. Auto-resumes `onMessage` after approve/deny unless you return an
19
+ * `AiSdkResult` to drive the resume yourself.
20
+ */
21
+ onToolApproval?: (decision: ToolApprovalDecision, ctx: AgentActionContext) => Awaitable<MessageContent | AiSdkResult | ReplyHandle | void>;
22
+ };
23
+
24
+ type AiSdkMessageHandler = AiSdkAgentHandlers['onMessage'];
25
+ declare function agent(id: string, handlers: AiSdkMessageHandler | AiSdkAgentHandlers): Agent;
26
+
27
+ /**
28
+ * Convert `ctx.history` into AI SDK `ModelMessage[]` for `streamText` / `generateText`.
29
+ *
30
+ * History already includes the current incoming message — do not append the handler's
31
+ * `message` argument on top of it.
32
+ *
33
+ * Pass the system prompt via the top-level `instructions` option of `streamText` /
34
+ * `generateText`. AI SDK 7 rejects `system` messages inside the `messages` array by default,
35
+ * so this helper never injects one.
36
+ */
37
+ declare function toModelMessages(history: AgentHistoryEntry[]): ModelMessage[];
38
+
39
+ export { type AiSdkAgentHandlers, agent, toModelMessages };
@@ -0,0 +1 @@
1
+ import{b as d,c as m,f as y}from"../chunk-W6DIBD4Z.js";import"../chunk-FHYMHX3T.js";function x(e){return e.role==="tool"&&Array.isArray(e.content)}function H(e){return typeof e=="object"&&e!==null&&e.type==="tool-result"}function _(e){return typeof e=="object"&&e!==null&&"type"in e&&e.type==="execution-denied"}function q(e){if(e&&typeof e=="object"&&"type"in e&&"value"in e){let t=e;if(t.type==="json"||t.type==="text")return t.value}return e}async function N(e){var o;return((o=await Promise.resolve(e.responseMessages))!=null?o:[]).filter(x).flatMap(n=>n.content).filter(H).filter(n=>!_(n.output)).map(n=>({toolCallId:n.toolCallId,toolName:n.toolName,output:q(n.output)}))}function O(e){var o;let t=new Set;for(let n of e.history)n.type==="tool_approval_request"&&((o=n.toolData)!=null&&o.toolCallId)&&t.add(n.toolData.toolCallId);return t}async function R(e,t){var s;let o=await N(e);if(o.length===0)return;let n=O(t);for(let r of o)n.has(r.toolCallId)&&t.emitToolResult({toolCallId:r.toolCallId,toolName:r.toolName,output:r.output,preview:`Tool "${(s=r.toolName)!=null?s:r.toolCallId}" result`})}function g(e){return typeof e=="object"&&e!==null&&typeof e.consumeStream=="function"}function h(e){return typeof e=="object"&&e!==null&&"text"in e&&"steps"in e&&"usage"in e&&!g(e)}function c(e){return typeof e!="object"||e===null||m(e)?!1:g(e)||h(e)}function b(e){var o;if(typeof e!="object"||e===null||e.type!=="tool-approval-request")return!1;let t=e;return!t.isAutomatic&&typeof((o=t.toolCall)==null?void 0:o.toolCallId)=="string"}async function D(e){let t=await Promise.resolve(e.content);return Array.isArray(t)?t.filter(b):[]}async function f(e,t,o){g(e)&&await e.consumeStream(),await R(e,t);let n=await D(e);if(n.length>0){let s=n[0],r={id:s.toolCall.toolCallId,name:s.toolCall.toolName,input:s.toolCall.input};await y(t,r,o,s.approvalId);return}await L(e,t)}async function L(e,t){let o=(await Promise.resolve(e.text)).trim();if(!o){await t.typing.stop();return}await t.reply(o)}var j={text:"",platformMessageId:"",author:{userId:"",fullName:"",userName:"",isBot:!1},timestamp:""};function Y(e){return typeof e=="object"&&e!==null&&"messageId"in e&&"platformThreadId"in e}function G(e,t){let o=typeof t=="function"?{onMessage:t}:t;if(typeof o.onMessage!="function")throw new Error(`agent('${e}') requires an onMessage handler`);return o}function U(e,t){if(!e)throw new Error("agent() requires a non-empty agentId");let o=G(e,t),n=o.toolApproval,s=typeof o.onToolApproval=="function",r=async l=>{let i=d(l),p=await o.onMessage(j,i.asMessageContext());c(p)&&await f(p,i,n)},a={onMessage:async(l,i)=>{let p=await o.onMessage(l,i);if(c(p)){await f(p,d(i),n);return}return p},onToolApproval:async(l,i)=>{let p=d(i);if(o.onToolApproval){let u=await o.onToolApproval(l,i);if(c(u)){await f(u,p,n);return}u!=null&&!Y(u)&&await p.reply(u)}await r(i)},...n&&{toolApproval:n},...o.onAction&&{onAction:o.onAction},...o.onReaction&&{onReaction:o.onReaction},...o.onResolve&&{onResolve:o.onResolve}};return{id:e,handlers:a,userOnToolApproval:s}}var V="tool_approval_request",$="tool_approval_decision",z="tool_result";function I(e){var o;let t=e.toolData;if(!(!t||typeof t.approvalId!="string"||typeof t.toolCallId!="string"))return{approvalId:t.approvalId,toolCallId:t.toolCallId,name:(o=t.toolName)!=null?o:"tool",input:t.input}}function T(e){let t=e.toolData;if(!(!t||typeof t.approvalId!="string"||typeof t.approved!="boolean"))return{approvalId:t.approvalId,approved:t.approved}}function M(e){let t=e.toolData;if(!(!t||typeof t.toolCallId!="string"))return{toolCallId:t.toolCallId,toolName:t.toolName,output:t.output}}function C(e){let t=new Set,o=new Map,n=new Map,s=new Set;for(let a of e)if(a.type===V){let l=I(a);l&&(n.set(l.approvalId,l.toolCallId),s.add(l.toolCallId))}else if(a.type===$){let l=T(a);l&&!l.approved&&t.add(l.approvalId)}else if(a.type===z){let l=M(a);l&&o.set(l.toolCallId,l)}let r=new Set;for(let a of o.keys())s.has(a)&&r.add(a);return{deniedApprovalIds:t,toolResults:o,approvalIdToToolCallId:n,pairedAtRequest:r}}function Q(e,t){return t.deniedApprovalIds.has(e.approvalId)?"denied":t.toolResults.has(e.toolCallId)?"resolved":"in-flight"}function A(e,t){var n;let o=[{type:"tool-call",toolCallId:e.toolCallId,toolName:e.name,input:(n=e.input)!=null?n:{}}];return t&&o.push({type:"tool-approval-request",approvalId:e.approvalId,toolCallId:e.toolCallId}),{role:"assistant",content:o}}function B(e){return{role:"tool",content:[{type:"tool-result",toolCallId:e,toolName:"tool",output:{type:"execution-denied"}}]}}function S(e){var t;return{role:"tool",content:[{type:"tool-result",toolCallId:e.toolCallId,toolName:(t=e.toolName)!=null?t:"tool",output:{type:"json",value:e.output}}]}}function v(e,t){return[A(e,!1),t]}function w(e,t){let o=I(e);if(!o)return[];let n=Q(o,t);switch(n){case"denied":return v(o,B(o.toolCallId));case"resolved":{let s=t.toolResults.get(o.toolCallId);return s?v(o,S(s)):[A(o,!1)]}case"in-flight":return[A(o,!0)];default:return n}}function k(e,t){let o=T(e);if(!o||!o.approved)return;let n=t.approvalIdToToolCallId.get(o.approvalId);if(!(n&&t.toolResults.has(n)))return{role:"tool",content:[{type:"tool-approval-response",approvalId:o.approvalId,approved:!0}]}}function P(e,t){let o=M(e);if(o&&!t.pairedAtRequest.has(o.toolCallId))return S(o)}var F="message",J="tool_approval_request",K="tool_approval_decision",W="tool_result";function E(e){return e==="agent"||e==="assistant"}function X(e){let t=new Set;for(let o of e)!E(o.role)&&o.role!=="system"&&o.senderName&&t.add(o.senderName);return t.size}function Z(e,t){if(!e.content.trim())return;let o=E(e.role),n=!o&&t&&e.senderName?`${e.senderName}: ${e.content}`:e.content;return{role:o?"assistant":"user",content:n}}function ee(e,t,o){switch(e.type){case F:{let n=Z(e,t);return n?[n]:[]}case J:return w(e,o);case K:{let n=k(e,o);return n?[n]:[]}case W:{let n=P(e,o);return n?[n]:[]}default:return[]}}function te(e){let t=X(e)>1,o=C(e);return e.flatMap(n=>ee(n,t,o))}export{U as agent,te as toModelMessages};
@@ -0,0 +1,2 @@
1
+ export { Actions, ActionsElement, Button, ButtonElement, Card, CardChild, CardElement, CardLink, CardText, Divider, DividerElement, LinkElement, Select, SelectElement, SelectOption, SelectOptionElement, TextElement, TextInput, TextInputElement } from 'chat';
2
+ import 'chat/jsx-runtime';
@@ -0,0 +1 @@
1
+ import{a as e,b as t,c as n,d as l,e as i,f as m,g as r,h as o,i as E}from"./chunk-C3P3ZH2I.js";import"./chunk-3XT6S7TZ.js";import"./chunk-FHYMHX3T.js";export{e as Actions,t as Button,n as Card,l as CardLink,i as CardText,m as Divider,r as Select,o as SelectOption,E as TextInput};