@novu/framework 2.13.0 → 2.13.1-rc.72c80d5b17
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/{agent.types-Dqm2VBTO.d.cts → agent.types-B5VnP69G.d.cts} +48 -2
- package/dist/cjs/ai-sdk/index.d.cts +1 -1
- package/dist/cjs/cards.cjs +1 -1
- package/dist/cjs/{health-check.types-B9FbzRbm.d.cts → health-check.types-CtWQ_YSy.d.cts} +4 -3
- package/dist/cjs/{index-CLZZRnNV.d.cts → index-vgb88C84.d.cts} +3 -3
- package/dist/cjs/index.cjs +88 -88
- package/dist/cjs/index.d.cts +5 -5
- package/dist/cjs/internal/index.cjs +43 -43
- package/dist/cjs/internal/index.d.cts +19 -15
- package/dist/cjs/langchain/index.cjs +1 -1
- package/dist/cjs/langchain/index.d.cts +15 -1
- package/dist/cjs/servers/express.cjs +88 -88
- package/dist/cjs/servers/express.d.cts +6 -6
- package/dist/cjs/servers/h3.cjs +86 -86
- package/dist/cjs/servers/h3.d.cts +6 -6
- package/dist/cjs/servers/hono.cjs +86 -86
- package/dist/cjs/servers/hono.d.cts +6 -6
- package/dist/cjs/servers/lambda.cjs +88 -88
- package/dist/cjs/servers/lambda.d.cts +6 -6
- package/dist/cjs/servers/nest.cjs +96 -96
- package/dist/cjs/servers/nest.d.cts +8 -8
- package/dist/cjs/servers/next.cjs +90 -90
- package/dist/cjs/servers/next.d.cts +6 -6
- package/dist/cjs/servers/nuxt.cjs +86 -86
- package/dist/cjs/servers/nuxt.d.cts +6 -6
- package/dist/cjs/servers/remix.cjs +86 -86
- package/dist/cjs/servers/remix.d.cts +6 -6
- package/dist/cjs/servers/sveltekit.cjs +74 -74
- package/dist/cjs/servers/sveltekit.d.cts +6 -6
- package/dist/cjs/step-resolver.cjs +4 -4
- package/dist/cjs/step-resolver.d.cts +17 -4
- package/dist/cjs/{subscriber.types-DubxcL8q.d.cts → subscriber.types-CyNKT0nZ.d.cts} +67 -2
- package/dist/cjs/validators.cjs +1 -1
- package/dist/esm/{agent.types-E3sxq6xr.d.ts → agent.types-HUDhyXrV.d.ts} +48 -2
- package/dist/esm/ai-sdk/index.d.ts +1 -1
- package/dist/esm/cards.js +1 -1
- package/dist/esm/{chunk-WDBIT4NK.js → chunk-CGZ5P44A.js} +66 -66
- package/dist/esm/chunk-FMKD6TON.js +1 -0
- package/dist/esm/{chunk-CANJPWLT.js → chunk-SPS3KBKF.js} +4 -4
- package/dist/esm/{chunk-FRWG7YTE.js → chunk-VY27ZAO7.js} +1 -1
- package/dist/esm/{chunk-46AHJTS7.js → chunk-X5AZIKIR.js} +8 -8
- package/dist/esm/{chunk-22DBAEUX.js → chunk-XIVU4VDS.js} +1 -1
- package/dist/esm/{chunk-2M25EATE.js → chunk-YLCLZVYS.js} +1 -1
- package/dist/esm/{health-check.types-BNocZ4Wk.d.ts → health-check.types-0Rv-l8yD.d.ts} +4 -3
- package/dist/esm/{index-CWldA6G5.d.ts → index-C0oUWDlb.d.ts} +3 -3
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +1 -1
- package/dist/esm/internal/index.d.ts +10 -6
- package/dist/esm/internal/index.js +1 -1
- package/dist/esm/jsx-dev-runtime.js +1 -1
- package/dist/esm/{jsx-runtime-P2HN3TPO.js → jsx-runtime-5ZWEWA4A.js} +1 -1
- package/dist/esm/jsx-runtime.js +1 -1
- package/dist/esm/langchain/index.d.ts +15 -1
- package/dist/esm/langchain/index.js +1 -1
- package/dist/esm/servers/express.d.ts +6 -6
- package/dist/esm/servers/express.js +1 -1
- package/dist/esm/servers/h3.d.ts +6 -6
- package/dist/esm/servers/h3.js +1 -1
- package/dist/esm/servers/hono.d.ts +6 -6
- package/dist/esm/servers/hono.js +1 -1
- package/dist/esm/servers/lambda.d.ts +6 -6
- package/dist/esm/servers/lambda.js +1 -1
- package/dist/esm/servers/nest.d.ts +8 -8
- package/dist/esm/servers/nest.js +1 -1
- package/dist/esm/servers/next.d.ts +6 -6
- package/dist/esm/servers/next.js +1 -1
- package/dist/esm/servers/nuxt.d.ts +6 -6
- package/dist/esm/servers/nuxt.js +1 -1
- package/dist/esm/servers/remix.d.ts +6 -6
- package/dist/esm/servers/remix.js +1 -1
- package/dist/esm/servers/sveltekit.d.ts +6 -6
- package/dist/esm/servers/sveltekit.js +1 -1
- package/dist/esm/step-resolver.d.ts +17 -4
- package/dist/esm/step-resolver.js +1 -1
- package/dist/esm/{subscriber.types-CmybpXhA.d.ts → subscriber.types-g7VnI_ZQ.d.ts} +67 -2
- package/dist/esm/validators.js +1 -1
- package/langchain/package.json +4 -0
- package/nest/package.json +2 -1
- package/package.json +2 -2
- package/dist/esm/chunk-LHU5A7DI.js +0 -1
- /package/dist/esm/{chunk-3ZWME5KT.js → chunk-7C3QBYLB.js} +0 -0
- /package/dist/esm/{chunk-XEHQJMMQ.js → chunk-RBTQQ5IZ.js} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { P as PostActionEnum } from '../health-check.types-
|
|
2
|
-
export { b as CancelEventTriggerResponse, c as ChannelPreference, C as ClientOptions, d as CodeResult, a as CronExpression, D as DiscoverAgentOutput, e as DiscoverOutput, f as DiscoverProviderOutput, g as DiscoverStepOutput, h as DiscoverWorkflowOutput, i as Event, j as EventTriggerParams, k as EventTriggerResponse, l as EventTriggerResult, m as Execute, E as ExecuteInput, n as ExecuteOutput, o as ExecuteOutputMetadata, p as ExecuteOutputOptions, G as GetActionEnum, H as HealthCheck, L as Logger, S as SeverityLevelEnum, q as State, r as StepType, W as Workflow, s as WorkflowChannelEnum, t as WorkflowOptions, u as WorkflowPreference, v as WorkflowPreferences } from '../health-check.types-
|
|
3
|
-
export { e as ActionStep, A as ActionStepEnum, f as ChannelStep, c as ChannelStepEnum, g as ChatOutput, h as ChatOutputUnvalidated, i as ChatResult, a as ContextPayload, C as ContextResolved, j as ContextValue, k as CustomStep, D as DelayDynamicOutput, l as DelayDynamicOutputUnvalidated, m as DelayOutput, n as DelayOutputUnvalidated, o as DelayRegularOutput, q as DelayRegularOutputUnvalidated, r as DelayResult, s as DelayTimedOutput, t as DelayTimedOutputUnvalidated, u as DigestOutput, v as DigestOutputUnvalidated, w as DigestRegularOutput, x as DigestRegularOutputUnvalidated, y as DigestResult, z as DigestTimedOutput, B as DigestTimedOutputUnvalidated, F as EmailOutput, G as EmailOutputUnvalidated, H as EmailResult, E as EnvironmentSystemVariables, I as InAppOutput, J as InAppOutputUnvalidated, K as InAppResult, L as JobStatusEnum, P as PushOutput, M as PushOutputUnvalidated, N as PushResult, O as Skip, Q as SmsOutput, R as SmsOutputUnvalidated, T as SmsResult, b as Step, U as StepContext, d as StepOptions, V as StepOutput, S as Subscriber, X as ThrottleOutput, Y as ThrottleOutputUnvalidated, Z as ThrottleResult, _ as
|
|
1
|
+
import { P as PostActionEnum } from '../health-check.types-CtWQ_YSy.cjs';
|
|
2
|
+
export { b as CancelEventTriggerResponse, c as ChannelPreference, C as ClientOptions, d as CodeResult, a as CronExpression, D as DiscoverAgentOutput, e as DiscoverOutput, f as DiscoverProviderOutput, g as DiscoverStepOutput, h as DiscoverWorkflowOutput, i as Event, j as EventTriggerParams, k as EventTriggerResponse, l as EventTriggerResult, m as Execute, E as ExecuteInput, n as ExecuteOutput, o as ExecuteOutputMetadata, p as ExecuteOutputOptions, G as GetActionEnum, H as HealthCheck, L as Logger, S as SeverityLevelEnum, q as State, r as StepType, W as Workflow, s as WorkflowChannelEnum, t as WorkflowOptions, u as WorkflowPreference, v as WorkflowPreferences } from '../health-check.types-CtWQ_YSy.cjs';
|
|
3
|
+
export { e as ActionStep, A as ActionStepEnum, f as ChannelStep, c as ChannelStepEnum, g as ChatOutput, h as ChatOutputUnvalidated, i as ChatResult, a as ContextPayload, C as ContextResolved, j as ContextValue, k as CustomStep, D as DelayDynamicOutput, l as DelayDynamicOutputUnvalidated, m as DelayOutput, n as DelayOutputUnvalidated, o as DelayRegularOutput, q as DelayRegularOutputUnvalidated, r as DelayResult, s as DelayTimedOutput, t as DelayTimedOutputUnvalidated, u as DigestOutput, v as DigestOutputUnvalidated, w as DigestRegularOutput, x as DigestRegularOutputUnvalidated, y as DigestResult, z as DigestTimedOutput, B as DigestTimedOutputUnvalidated, F as EmailOutput, G as EmailOutputUnvalidated, H as EmailResult, E as EnvironmentSystemVariables, I as InAppOutput, J as InAppOutputUnvalidated, K as InAppResult, L as JobStatusEnum, P as PushOutput, M as PushOutputUnvalidated, N as PushResult, O as Skip, Q as SmsOutput, R as SmsOutputUnvalidated, T as SmsResult, b as Step, U as StepContext, d as StepOptions, V as StepOutput, S as Subscriber, X as ThrottleOutput, Y as ThrottleOutputUnvalidated, Z as ThrottleResult, _ as ToolOutput, $ as ToolOutputUnvalidated, a0 as actionStepSchemas, a1 as channelStepSchemas } from '../subscriber.types-CyNKT0nZ.cjs';
|
|
4
4
|
import { Filter, LiquidOptions, Liquid } from 'liquidjs';
|
|
5
5
|
import { Emoji } from 'chat';
|
|
6
|
-
import {
|
|
7
|
-
export {
|
|
6
|
+
import { j as AgentHandlerContext, D as ToolResult, E as ToolApprovalRequestPayload, T as ToolApprovalCard, R as ReplyHandle, o as AgentMessageContext, G as AgentEventEnum, a as AgentAction, m as AgentMessage, q as AgentReaction, g as AgentConversation, t as AgentSubscriber, e as AgentContextPayload, l as AgentHistoryEntry, p as AgentPlatformContext, H as TypingControl, J as ToolApprovalControl, K as AgentBridgeRequest, w as ToolApprovalConfig, M as MessageContent, F as FileRef, L as AgentReplyPayload, S as SentMessageInfo, z as TriggerRecipientsPayload } from '../agent.types-B5VnP69G.cjs';
|
|
7
|
+
export { N as DeleteMessagePayload, O as EditPayload, P as MetadataSignal, Q as ParsedApprovalAction, U as ReplyContent, V as Signal, X as TriggerSignal, Y as buildApprovalActionId, Z as parseApprovalActionId } from '../agent.types-B5VnP69G.cjs';
|
|
8
8
|
export { a as FromSchema, F as FromSchemaUnvalidated, J as JsonSchema, S as Schema, Z as ZodSchema, b as ZodSchemaMinimal } from '../base.schema.types-BApIn9jr.cjs';
|
|
9
9
|
export { S as SupportedFrameworkName } from '../server.types-Cc6o5eYH.cjs';
|
|
10
10
|
export { A as Awaitable, C as ConditionalPartial, D as DeepPartial, b as DeepRequired, E as Either, I as Indexable, c as PickOptional, d as PickOptionalKeys, e as PickRequired, P as PickRequiredKeys, a as Prettify } from '../util.types-DaFfsxgy.cjs';
|
|
@@ -137,6 +137,15 @@ declare enum ResourceEnum {
|
|
|
137
137
|
STEP = "step"
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
declare const RUNTIME_CONTEXT_BRAND: unique symbol;
|
|
141
|
+
interface AgentRuntimeContext extends AgentHandlerContext {
|
|
142
|
+
readonly [RUNTIME_CONTEXT_BRAND]: true;
|
|
143
|
+
emitToolResult(result: ToolResult): void;
|
|
144
|
+
emitToolApprovalRequest(request: ToolApprovalRequestPayload): void;
|
|
145
|
+
replyApprovalCard(card: ToolApprovalCard): Promise<ReplyHandle>;
|
|
146
|
+
asMessageContext(): AgentMessageContext;
|
|
147
|
+
}
|
|
148
|
+
|
|
140
149
|
/**
|
|
141
150
|
* Check if the object is a native error.
|
|
142
151
|
*
|
|
@@ -422,15 +431,6 @@ type FilterValidators = {
|
|
|
422
431
|
};
|
|
423
432
|
declare const FILTER_VALIDATORS: FilterValidators;
|
|
424
433
|
|
|
425
|
-
declare const RUNTIME_CONTEXT_BRAND: unique symbol;
|
|
426
|
-
interface AgentRuntimeContext extends AgentHandlerContext {
|
|
427
|
-
readonly [RUNTIME_CONTEXT_BRAND]: true;
|
|
428
|
-
emitToolResult(result: ToolResult): void;
|
|
429
|
-
emitToolApprovalRequest(request: ToolApprovalRequestPayload): void;
|
|
430
|
-
replyApprovalCard(card: ToolApprovalCard): Promise<ReplyHandle>;
|
|
431
|
-
asMessageContext(): AgentMessageContext;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
434
|
interface ReplyPoster {
|
|
435
435
|
post(body: AgentReplyPayload): Promise<SentMessageInfo | null>;
|
|
436
436
|
}
|
|
@@ -456,6 +456,7 @@ declare class AgentContextImpl implements AgentRuntimeContext {
|
|
|
456
456
|
readonly reaction: AgentReaction | null;
|
|
457
457
|
readonly conversation: AgentConversation;
|
|
458
458
|
readonly subscriber: AgentSubscriber | null;
|
|
459
|
+
readonly context: AgentContextPayload | null;
|
|
459
460
|
readonly history: AgentHistoryEntry[];
|
|
460
461
|
readonly platform: string;
|
|
461
462
|
readonly platformContext: AgentPlatformContext;
|
|
@@ -521,4 +522,7 @@ declare class AgentContextImpl implements AgentRuntimeContext {
|
|
|
521
522
|
*/
|
|
522
523
|
declare function createLiquidEngine(options?: LiquidOptions): Liquid;
|
|
523
524
|
|
|
524
|
-
|
|
525
|
+
declare function repairJsonString(value: string): string;
|
|
526
|
+
declare function compileJsonControlValues(values: Record<string, unknown>, context: Record<string, unknown>, liquidEngine?: ReturnType<typeof createLiquidEngine>): Promise<Record<string, unknown>>;
|
|
527
|
+
|
|
528
|
+
export { AgentBridgeRequest, AgentContextImpl, AgentEventEnum, AgentReplyPayload, type AgentRuntimeContext, BadRequestError, BridgeError, ConflictError, ErrorCodeEnum, ExecutionEventControlsInvalidError, ExecutionEventPayloadInvalidError, ExecutionProviderOutputInvalidError, ExecutionStateControlsInvalidError, ExecutionStateCorruptError, ExecutionStateOutputInvalidError, ExecutionStateResultInvalidError, FILTER_VALIDATORS, ForbiddenError, FrameworkError, HttpHeaderKeysEnum, HttpMethodEnum, HttpQueryKeysEnum, HttpStatusEnum, InvalidActionError, type LiquidFilterIssue, MethodNotAllowedError, MissingSecretKeyError, NotFoundError, NovuApiEndpointsEnum, PlatformError, PostActionEnum, ProviderExecutionFailedError, ProviderNotFoundError, ResourceConflictError, ResourceEnum, ResourceExecutionFailed, ResourceNotFoundError, SIGNATURE_TIMESTAMP_TOLERANCE, SIGNATURE_TIMESTAMP_TOLERANCE_MINUTES, SentMessageInfo, ServerError, SignatureExpiredError, SignatureInvalidError, SignatureMismatchError, SignatureNotFoundError, SignatureVersionInvalidError, SigningKeyNotFoundError, StepAlreadyExistsError, StepControlCompilationFailedError, StepExecutionFailedError, StepNotFoundError, ToolApprovalRequestPayload, ToolResult, UnauthorizedError, WorkflowAlreadyExistsError, WorkflowNotFoundError, WorkflowPayloadInvalidError, compileJsonControlValues, createLiquidEngine, digest, isFrameworkError, isNativeError, pluralize, repairJsonString, toSentence, toSentenceArgsValidator };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var v=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var W=(e,o)=>{for(var t in o)v(e,t,{get:o[t],enumerable:!0})},Z=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let
|
|
1
|
+
"use strict";var v=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var W=(e,o)=>{for(var t in o)v(e,t,{get:o[t],enumerable:!0})},Z=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of Q(o))!K.call(e,a)&&a!==t&&v(e,a,{get:()=>o[a],enumerable:!(n=G(o,a))||n.enumerable});return e};var ee=e=>Z(v({},"__esModule",{value:!0}),e);var he={};W(he,{NovuToolApprovalRequired:()=>g,agent:()=>J,toLangChainMessages:()=>m});module.exports=ee(he);var d=require("@langchain/core/messages");var c=require("@langchain/core/messages"),h="tool_approval_request",E="tool_approval_decision",N="tool_result",oe=JSON.stringify({type:"execution-denied"});function T(e){var t;let o=e.toolData;if(!(!o||typeof o.approvalId!="string"||typeof o.toolCallId!="string"))return{approvalId:o.approvalId,toolCallId:o.toolCallId,name:(t=o.toolName)!=null?t:"tool",input:o.input}}function P(e){let o=e.toolData;if(!(!o||typeof o.approvalId!="string"||typeof o.approved!="boolean"))return{approvalId:o.approvalId,approved:o.approved}}function L(e){let o=e.toolData;if(!(!o||typeof o.toolCallId!="string"))return{toolCallId:o.toolCallId,toolName:o.toolName,output:o.output}}function S(e,o){let t=new Set,n=new Map,a=new Map;for(let r of e)if(r.type===h){let s=T(r);s&&a.set(s.approvalId,s.toolCallId)}else if(r.type===E){let s=P(r);s&&!s.approved&&t.add(s.approvalId)}else if(r.type===N){let s=L(r);s&&n.set(s.toolCallId,s)}if(o)for(let[r,s]of o)n.set(r,s);return{deniedApprovalIds:t,toolResults:n,approvalIdToToolCallId:a}}function te(e,o){return o.deniedApprovalIds.has(e.approvalId)?"denied":o.toolResults.has(e.toolCallId)?"resolved":"in-flight"}function x(e){var o;return new c.AIMessage({content:"",tool_calls:[{id:e.toolCallId,name:e.name,args:(o=e.input)!=null?o:{},type:"tool_call"}]})}function ne(e){return typeof e=="string"?e:JSON.stringify(e)}function ae(e){var o;return new c.ToolMessage({content:ne(e.output),tool_call_id:e.toolCallId,name:(o=e.toolName)!=null?o:"tool"})}function re(e){return new c.ToolMessage({content:oe,tool_call_id:e.toolCallId,name:e.name,status:"error"})}function H(e,o){let t=T(e);if(!t)return[];let n=te(t,o);switch(n){case"denied":return[x(t),re(t)];case"resolved":{let a=o.toolResults.get(t.toolCallId);return a?[x(t),ae(a)]:[]}case"in-flight":return[];default:return n}}function _(e){let o=new Set,t=new Set,n=[];for(let a of e)if(a.type===h){let r=T(a);r&&n.push({approvalId:r.approvalId,toolCallId:r.toolCallId,toolName:r.name,input:r.input})}else if(a.type===E){let r=P(a);r!=null&&r.approved&&o.add(r.approvalId)}else if(a.type===N){let r=L(a);r&&t.add(r.toolCallId)}return n.filter(a=>o.has(a.approvalId)&&!t.has(a.toolCallId)).map(({toolCallId:a,toolName:r,input:s})=>({toolCallId:a,toolName:r,input:s}))}var se="message",le="tool_approval_request";function k(e){return e==="agent"||e==="assistant"}function ie(e){let o=new Set;for(let t of e)!k(t.role)&&t.role!=="system"&&t.senderName&&o.add(t.senderName);return o.size}function pe(e,o){if(!e.content.trim())return;if(k(e.role))return new d.AIMessage(e.content);let n=o&&e.senderName?`${e.senderName}: ${e.content}`:e.content;return new d.HumanMessage(n)}function ue(e,o,t){switch(e.type){case se:{let n=pe(e,o);return n?[n]:[]}case le:return H(e,t);default:return[]}}function m(e,o,t){let n=ie(e)>1,a=S(e,t),r=e.flatMap(s=>ue(s,n,a));return o?[new d.SystemMessage(o),...r]:r}var de=Symbol.for("novu.agent.runtimeContext");function ge(e){return e[de]===!0}function y(e){if(!ge(e))throw new Error("Agent context must be created by Novu dispatch");return e}var f=require("@langchain/core/messages"),Y=require("langchain");function q(e){return"type"in e&&e.type==="card"}function b(e){return typeof e=="object"&&e!==null&&e.type==="tool-approval-card"}var B=require("@langchain/core/messages"),D=require("langchain");var ce="tool-approval";function R(e,o){return`${ce}:${e}:${o}`}async function O(e,o,t,n){var p,u;let a=n!=null?n:o.id,r={approve:R("approve",a),deny:R("deny",a)},s=F=>({type:"tool-approval-card",...F}),l=(u=(p=t==null?void 0:t.renderApproval)==null?void 0:p.call(t,{toolCall:o,actionIds:r,approvalCard:s}))!=null?u:s(),i={approvalId:a,toolCallId:o.id,name:o.name,input:o.input};if(e.emitToolApprovalRequest(i),b(l)){await e.replyApprovalCard(l);return}await e.reply(l)}var g=class extends Error{constructor(o){super(`Tool "${o.toolName}" requires approval`),this.name="NovuToolApprovalRequired",this.toolCallId=o.toolCallId,this.toolName=o.toolName,this.input=o.input}},fe=10;function U(e){let o=e;for(let t=0;t<fe&&o!=null;t+=1){if(o instanceof g)return o;o=o.cause}}function j(e){return(0,D.createMiddleware)({name:"novu-tool-approval",wrapToolCall:async(o,t)=>{let{id:n,name:a,args:r}=o.toolCall,s=r!=null?r:{};if(e({id:n,name:a,args:s}))throw new g({toolCallId:n!=null?n:a,toolName:a,input:s});return t(o)}})}async function $(e,o,t){let n={id:o.toolCallId,name:o.toolName,input:o.input};await O(e,n,t)}function me(e){return(0,B.isBaseMessage)(e)?e.content:e}function ye(e){let o=new Map;for(let t of e!=null?e:[])o.set(t.name,t);return o}async function V(e,o){var r;let t=_(o.history),n=new Map;if(t.length===0)return n;let a=ye(e);for(let s of t){let l=a.get(s.toolName);if(!l)continue;let i=me(await l.invoke((r=s.input)!=null?r:{}));n.set(s.toolCallId,{toolCallId:s.toolCallId,toolName:s.toolName,output:i}),o.emitToolResult({toolCallId:s.toolCallId,toolName:s.toolName,output:i,preview:`Tool "${s.toolName}" result`})}return n}var X=require("@langchain/core/messages");function Ae(e){var t;let o=new Set;for(let n of e.history)n.type==="tool_approval_request"&&((t=n.toolData)!=null&&t.toolCallId)&&o.add(n.toolData.toolCallId);return o}function Ce(e,o){var n;let t=new Set(o);for(let a of e.history)a.type==="tool_result"&&((n=a.toolData)!=null&&n.toolCallId)&&t.add(a.toolData.toolCallId);return t}function ve(e){return typeof e=="string"?e:JSON.stringify(e)}function I(e,o,t=new Set){var r;let n=Ae(o);if(n.size===0)return;let a=Ce(o,t);for(let s of e){if(!(0,X.isToolMessage)(s))continue;let l=s.tool_call_id;!n.has(l)||a.has(l)||(a.add(l),o.emitToolResult({toolCallId:l,toolName:s.name,output:ve(s.content),preview:`Tool "${(r=s.name)!=null?r:l}" result`}))}}function z(e){if(typeof e!="object"||e===null)return!1;let o=e.model;return typeof o=="string"||typeof o=="object"&&o!==null}function Te(e){return typeof e=="object"&&e!==null&&Array.isArray(e.messages)}function A(e){return typeof e!="object"||e===null||q(e)?!1:(0,f.isBaseMessage)(e)||z(e)||Te(e)}function Re(e){return typeof e=="string"?e:e.map(o=>{let t=o;return t.type==="text"&&typeof t.text=="string"?t.text:""}).join("")}function w(e){for(let o=e.length-1;o>=0;o-=1){let t=e[o];if((0,f.isAIMessage)(t))return Re(t.content).trim()}return""}async function M(e,o,t){var a;if(!e){await o.typing.stop();return}let n=t&&(a=await t(e))!=null?a:e;await o.reply(n)}async function Ie(e,o,t){var i;let n=await V(e.tools,o),a=m(o.history,void 0,n),r=[];e.needsApproval&&r.push(j(e.needsApproval)),e.middleware&&r.push(...e.middleware);let s=(0,Y.createAgent)({model:e.model,tools:(i=e.tools)!=null?i:[],...e.system?{prompt:e.system}:{},...r.length>0?{middleware:r}:{}}),l;try{l=await s.invoke({messages:a},e.invokeConfig)}catch(p){let u=U(p);if(u){await $(o,u,t);return}throw p}I(l.messages,o,new Set(n.keys())),await M(w(l.messages),o,e.formatReply)}async function C(e,o,t){if(z(e)){await Ie(e,o,t);return}if((0,f.isBaseMessage)(e)){await M(w([e]),o);return}I(e.messages,o),await M(w(e.messages),o)}var we={text:"",platformMessageId:"",author:{userId:"",fullName:"",userName:"",isBot:!1},timestamp:""};function Me(e){return typeof e=="object"&&e!==null&&"messageId"in e&&"platformThreadId"in e}function xe(e,o){let t=typeof o=="function"?{onMessage:o}:o;if(typeof t.onMessage!="function")throw new Error(`agent('${e}') requires an onMessage handler`);return t}function J(e,o){if(!e)throw new Error("agent() requires a non-empty agentId");let t=xe(e,o),n=t.toolApproval,a=typeof t.onToolApproval=="function",r=async l=>{let i=y(l),p=await t.onMessage(we,i.asMessageContext());A(p)&&await C(p,i,n)},s={onMessage:async(l,i)=>{let p=await t.onMessage(l,i);if(A(p)){await C(p,y(i),n);return}return p},onToolApproval:async(l,i)=>{let p=y(i);if(t.onToolApproval){let u=await t.onToolApproval(l,i);if(A(u)){await C(u,p,n);return}u!=null&&!Me(u)&&await p.reply(u)}await r(i)},...n&&{toolApproval:n},...t.onAction&&{onAction:t.onAction},...t.onReaction&&{onReaction:t.onReaction},...t.onResolve&&{onResolve:t.onResolve},...t.onError&&{onError:t.onError}};return{id:e,handlers:s,userOnToolApproval:a}}0&&(module.exports={NovuToolApprovalRequired,agent,toLangChainMessages});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseMessage } from '@langchain/core/messages';
|
|
2
|
-
import {
|
|
2
|
+
import { l as AgentHistoryEntry, M as MessageContent, k as AgentHandlers, m as AgentMessage, o as AgentMessageContext, x as ToolApprovalDecision, b as AgentActionContext, R as ReplyHandle, A as Agent } from '../agent.types-B5VnP69G.cjs';
|
|
3
3
|
import { LanguageModelLike } from '@langchain/core/language_models/base';
|
|
4
|
+
import { RunnableConfig } from '@langchain/core/runnables';
|
|
4
5
|
import { StructuredToolInterface } from '@langchain/core/tools';
|
|
5
6
|
import { AgentMiddleware } from 'langchain';
|
|
6
7
|
import { A as Awaitable } from '../util.types-DaFfsxgy.cjs';
|
|
@@ -49,6 +50,19 @@ interface LangChainAgentConfig {
|
|
|
49
50
|
needsApproval?: (toolCall: LangChainToolCall) => boolean;
|
|
50
51
|
/** Extra LangChain middleware, appended after Novu's approval middleware. */
|
|
51
52
|
middleware?: AgentMiddleware[];
|
|
53
|
+
/**
|
|
54
|
+
* Run config forwarded as the second argument to `agent.invoke(...)` (e.g.
|
|
55
|
+
* `signal`, `configurable`, `context`, `recursionLimit`, `callbacks`). Use this
|
|
56
|
+
* to control the LangGraph run for a turn.
|
|
57
|
+
*/
|
|
58
|
+
invokeConfig?: RunnableConfig;
|
|
59
|
+
/**
|
|
60
|
+
* Optional post-run reply formatter. Receives the model's final text and returns
|
|
61
|
+
* the content to deliver — a string or a {@link MessageContent} card. Return
|
|
62
|
+
* `void`/`undefined` to deliver the final text unchanged. Runs only when the
|
|
63
|
+
* model produced a non-empty final text.
|
|
64
|
+
*/
|
|
65
|
+
formatReply?: (finalText: string) => Awaitable<MessageContent | void>;
|
|
52
66
|
}
|
|
53
67
|
/**
|
|
54
68
|
* Result of a LangChain agent/graph you invoked yourself (e.g. `await agent.invoke(...)`).
|