@novu/framework 2.11.2 → 2.12.1
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 +1 -0
- package/dist/cjs/index.cjs +3 -3
- package/dist/cjs/internal/index.cjs +1 -1
- package/dist/cjs/internal/index.d.cts +10 -10
- package/dist/cjs/{server.types-BRWsA1CA.d.cts → server.types-Cc6o5eYH.d.cts} +1 -1
- package/dist/cjs/servers/express.cjs +3 -3
- package/dist/cjs/servers/express.d.cts +1 -1
- package/dist/cjs/servers/h3.cjs +3 -3
- package/dist/cjs/servers/h3.d.cts +1 -1
- package/dist/cjs/servers/hono.cjs +564 -0
- package/dist/cjs/servers/hono.d.cts +41 -0
- package/dist/cjs/servers/lambda.cjs +3 -3
- package/dist/cjs/servers/lambda.d.cts +1 -1
- package/dist/cjs/servers/nest.cjs +3 -3
- package/dist/cjs/servers/nest.d.cts +1 -1
- package/dist/cjs/servers/next.cjs +3 -3
- package/dist/cjs/servers/next.d.cts +1 -1
- package/dist/cjs/servers/nuxt.cjs +3 -3
- package/dist/cjs/servers/nuxt.d.cts +1 -1
- package/dist/cjs/servers/remix.cjs +3 -3
- package/dist/cjs/servers/remix.d.cts +1 -1
- package/dist/cjs/servers/sveltekit.cjs +3 -3
- package/dist/cjs/servers/sveltekit.d.cts +1 -1
- package/dist/esm/chunk-T4QVGWWK.js +1 -0
- package/dist/esm/{chunk-EZ22F362.js → chunk-XC7ATSSO.js} +3 -3
- package/dist/esm/index.js +1 -1
- package/dist/esm/internal/index.d.ts +1 -1
- package/dist/esm/internal/index.js +1 -1
- package/dist/esm/{server.types-BRWsA1CA.d.ts → server.types-Cc6o5eYH.d.ts} +1 -1
- package/dist/esm/servers/express.d.ts +1 -1
- package/dist/esm/servers/express.js +1 -1
- package/dist/esm/servers/h3.d.ts +1 -1
- package/dist/esm/servers/h3.js +1 -1
- package/dist/esm/servers/hono.d.ts +41 -0
- package/dist/esm/servers/hono.js +1 -0
- package/dist/esm/servers/lambda.d.ts +1 -1
- package/dist/esm/servers/lambda.js +1 -1
- package/dist/esm/servers/nest.d.ts +1 -1
- package/dist/esm/servers/nest.js +1 -1
- package/dist/esm/servers/next.d.ts +1 -1
- package/dist/esm/servers/next.js +1 -1
- package/dist/esm/servers/nuxt.d.ts +1 -1
- package/dist/esm/servers/nuxt.js +1 -1
- package/dist/esm/servers/remix.d.ts +1 -1
- package/dist/esm/servers/remix.js +1 -1
- package/dist/esm/servers/sveltekit.d.ts +1 -1
- package/dist/esm/servers/sveltekit.js +1 -1
- package/hono/package.json +3 -0
- package/package.json +18 -1
- package/dist/esm/chunk-E2MET7IR.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novu/framework",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.1",
|
|
4
4
|
"description": "The Code-First Notifications Workflow SDK.",
|
|
5
5
|
"main": "./dist/cjs/index.cjs",
|
|
6
6
|
"types": "./dist/cjs/index.d.cts",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"dist",
|
|
19
19
|
"express",
|
|
20
20
|
"h3",
|
|
21
|
+
"hono",
|
|
21
22
|
"internal",
|
|
22
23
|
"lambda",
|
|
23
24
|
"nest",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"next",
|
|
49
50
|
"nuxt",
|
|
50
51
|
"h3",
|
|
52
|
+
"hono",
|
|
51
53
|
"express"
|
|
52
54
|
],
|
|
53
55
|
"author": "Novu Team <engineering@novu.co>",
|
|
@@ -133,6 +135,16 @@
|
|
|
133
135
|
"default": "./dist/esm/servers/h3.js"
|
|
134
136
|
}
|
|
135
137
|
},
|
|
138
|
+
"./hono": {
|
|
139
|
+
"require": {
|
|
140
|
+
"types": "./dist/cjs/servers/hono.d.cts",
|
|
141
|
+
"default": "./dist/cjs/servers/hono.cjs"
|
|
142
|
+
},
|
|
143
|
+
"import": {
|
|
144
|
+
"types": "./dist/esm/servers/hono.d.ts",
|
|
145
|
+
"default": "./dist/esm/servers/hono.js"
|
|
146
|
+
}
|
|
147
|
+
},
|
|
136
148
|
"./lambda": {
|
|
137
149
|
"require": {
|
|
138
150
|
"types": "./dist/cjs/servers/lambda.d.cts",
|
|
@@ -233,6 +245,7 @@
|
|
|
233
245
|
"aws-lambda": ">=1.0.7",
|
|
234
246
|
"express": ">=4.19.2",
|
|
235
247
|
"h3": ">=1.8.1",
|
|
248
|
+
"hono": ">=4.0.0",
|
|
236
249
|
"langchain": ">=1.0.0",
|
|
237
250
|
"next": ">=12.0.0",
|
|
238
251
|
"zod": ">=3.0.0",
|
|
@@ -263,6 +276,9 @@
|
|
|
263
276
|
"h3": {
|
|
264
277
|
"optional": true
|
|
265
278
|
},
|
|
279
|
+
"hono": {
|
|
280
|
+
"optional": true
|
|
281
|
+
},
|
|
266
282
|
"aws-lambda": {
|
|
267
283
|
"optional": true
|
|
268
284
|
},
|
|
@@ -295,6 +311,7 @@
|
|
|
295
311
|
"aws-lambda": "^1.0.7",
|
|
296
312
|
"express": "^4.19.2",
|
|
297
313
|
"h3": "^1.11.1",
|
|
314
|
+
"hono": "^4.12.25",
|
|
298
315
|
"langchain": "^1.2.16",
|
|
299
316
|
"madge": "^8.0.0",
|
|
300
317
|
"next": "^16.2.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as N,g,i as U,q as D,r as F,s as c,t as h,u as T,v as M}from"./chunk-FRWG7YTE.js";import{a as $,c as L,f as H}from"./chunk-W6DIBD4Z.js";var B=class extends T{constructor(n){super("Unknown BridgeError",{cause:n});this.statusCode=500;this.code="BridgeError"}};var W=class extends c{constructor(n,o){super(`Workflow with id: \`${n}\` has a corrupt state. Step with id: \`${o}\` does not exist. Please provide the missing state.`);this.code="ExecutionStateCorruptError";this.data={workflowId:n,stepId:o}}},q=class extends c{constructor(n,o){super(`Workflow with id: \`${n}\` has invalid \`payload\`. Please provide the correct event payload.`);this.code="ExecutionEventPayloadInvalidError";this.data=o}},V=class extends c{constructor(n,o){super(`Workflow with id: \`${n}\` has invalid \`controls\`. Please provide the correct event controls.`);this.code="ExecutionEventControlInvalidError";this.data=o}},G=class extends c{constructor(n,o,r){super(`Workflow with id: \`${n}\` has an invalid state. Step with id: \`${o}\` has invalid \`controls\`. Please provide the correct step controls.`);this.code="ExecutionStateControlInvalidError";this.data=r}},X=class extends c{constructor(n,o,r){super(`Workflow with id: \`${n}\` has an invalid state. Step with id: \`${o}\` has invalid output. Please provide the correct step output.`);this.code="ExecutionStateOutputInvalidError";this.data=r}},K=class extends c{constructor(n,o,r){super(`Workflow with id: \`${n}\` has an invalid state. Step with id: \`${o}\` has invalid result. Please provide the correct step result.`);this.code="ExecutionStateResultInvalidError";this.data=r}},z=class extends c{constructor(n,o,r){super(`Workflow with id: \`${n}\` has invalid controls syntax in step with id: \`${o}\`. Please correct step control syntax.`);this.code="StepControlCompilationFailedError";this.data=r}},Y=class extends c{constructor(n,o,r,s){super(`Workflow with id: \`${n}\` has an invalid state. Step with id: \`${o}\` and provider with id: \`${r}\` has invalid output. Please provide the correct provider output.`);this.code="ExecutionProviderOutputInvalidError";this.data=s}},Q=class extends c{constructor(n,o){super(`Workflow with id: \`${n}\` has invalid \`payload\`. Please provide the correct payload.`);this.code="WorkflowPayloadInvalidError";this.data=o}};var Z=e=>Object.values(g).includes(e==null?void 0:e.code),it=e=>!Z(e)&&typeof e.statusCode=="number"&&e.statusCode>=400&&e.statusCode<500;var b=e=>Object.values(e).map(t=>`\`${t}\``).join(", "),E=e=>e.replaceAll(/(\w)(\w*)/g,(t,n,o)=>n.toUpperCase()+o.toLowerCase()).replaceAll(/[\s-]+/g,"");var J=class extends D{constructor(){super(...arguments);this.code="MethodNotAllowedError";this.statusCode=405;this.message=`Method not allowed. Please use one of ${b(U)}`}},ee=class extends c{constructor(n,o){super(`Invalid query string: \`action\`=\`${n}\`. Please use one of ${b(o)}`);this.code="InvalidActionError"}},te=class extends c{constructor(){super("Missing secret key. Set the `NOVU_SECRET_KEY` environment variable or pass `secretKey` to the client options.");this.code="MissingSecretKeyError"}};var ne=class extends Error{constructor(t,n,o){super(),this.data={message:o},this.statusCode=t,this.code=n}};var y=class extends M{constructor(t,n){super(`${E(t)} with id: \`${n}\` already exists. Please use a different id.`)}},m=class extends F{constructor(t,n){super(`${E(t)} with id: \`${n}\` does not exist. Please provide a valid id.`)}},R=class extends T{constructor(n,o,r,s){super(`Failed to ${r} ${E(n)} with id: \`${o}\``,{cause:s});this.statusCode=502}};var re=class extends m{constructor(n){super("provider",n);this.code="ProviderNotFoundError"}},oe=class extends R{constructor(n,o,r){super("provider",n,o,r);this.code="ProviderExecutionFailedError"}};var ae=class extends h{constructor(){super("Signature does not match the expected signature. Please ensure the signature provided in the `novu-signature` header is correct and try again.");this.code="SignatureMismatchError"}},ie=class extends h{constructor(){super("Signature not found. Please provide a signature in the `novu-signature` header");this.code="SignatureNotFoundError"}},le=class extends h{constructor(){super("Signature is invalid. Please provide a valid signature in the `novu-signature` header");this.code="SignatureInvalidError"}},pe=class extends h{constructor(){super(`Signature expired. Please provide a signature with a timestamp no older than ${5} minutes in the \`novu-signature\` header`);this.code="SignatureExpiredError"}},de=class extends h{constructor(){super("Signature key not found. Please provide a valid key in the Client constructor `config.secretKey`");this.code="SigningKeyNotFoundError"}},ce=class extends h{constructor(){super("Signature version is invalid. Please provide a signature version with version `v1` in the `novu-signature` header");this.code="SignatureVersionInvalidError"}};var ue=class extends m{constructor(n){super("step",n);this.code="StepNotFoundError"}},ge=class extends y{constructor(n){super("step",n);this.code="StepAlreadyExistsError"}},me=class extends R{constructor(n,o,r){super("step",n,o,r);this.code="StepExecutionFailedError"}};var fe=class extends m{constructor(n){super("workflow",n);this.code="WorkflowNotFoundError"}},he=class extends y{constructor(n){super("workflow",n);this.code="WorkflowAlreadyExistsError"}};function Fe(e,t){let n={...e};for(let o of Object.keys(t)){let r=t[o];r&&typeof r=="object"&&!Array.isArray(r)?n[o]=Fe(n[o]||{},r):(Array.isArray(r),n[o]=r)}return n}function C(e,t){let n=t.split(".").reduce((o,r)=>{if(o&&typeof o=="object")return o[r]},e);if(n==null)return"";if(typeof n=="string")return n;if(typeof n=="number"||typeof n=="boolean")return String(n);if(typeof n=="object"){let o=JSON.stringify(n);return o==="{}"?"":o}return""}function ye(e,t=2,n,o=", "){if(!Array.isArray(e)||e.length===0)return"";let r=n?e.map(i=>typeof i!="object"||!i?"":C(i,n)):e;if(r.length===1)return r[0];if(r.length===2)return`${r[0]} and ${r[1]}`;if(r.length===3&&t>=3)return`${r[0]}, ${o}${r[1]} and ${r[2]}`;let s=r.slice(0,t),p=r.length-t;return`${s.join(o)} and ${p} ${p===1?"other":"others"}`}import Me from"pluralize";function Re(e,t="",n="",o="true"){if(e==null)return"";let r=0;if(Array.isArray(e)?r=e.length:typeof e=="object"?r=Object.keys(e).length:typeof e=="string"?r=+e:typeof e=="number"?r=e:r=Number(e),Number.isNaN(r)&&(r=0),r<=0)return"";let s;return n?s=r===1?t:n:s=Me(t,r),o==="true"?`${r} ${s}`:s}import{TokenKind as Ae}from"liquidjs";import $e from"pluralize";import{z as f}from"zod";var xe="",_e=2,ve="other",Te=", ",Ee=" and ",Ce=", and ",Se={0:"keyPath",1:"limit",2:"overflowSuffix",3:"wordsConnector",4:"twoWordsConnector",5:"lastWordConnector"};function we(e,t=xe,n=_e,o=ve,r=Te,s=Ee,p=Ce){if(!Array.isArray(e)||e.length===0)return"";let i=t?e.map(u=>typeof u!="object"||!u?"":C(u,t)):e,l=i.length;if(l===1)return i[0];if(l===2)return`${i[0]}${s}${i[1]}`;if(n>=l){let u=i.slice(0,l-1),k=i[l-1];return`${u.join(r)}${p}${k}`}let a=i.slice(0,n),d=l-n,v=n===1?s:p;return`${a.join(r)}${v}${d} ${$e(o,d)}`}function on(e={},...t){let{requireKeyPath:n=!1}=e,o=[];if(t.length<1)return o.push({message:"Expected at least 1 argument",begin:0,end:0,value:""}),o;let r=f.object({keyPath:n?f.string().min(1,"must be non-empty"):f.string().optional().default(xe),limit:f.number().optional().default(_e).refine(i=>i>=0,"must be greater than or equal to 0"),overflowSuffix:f.string().optional().default(ve),wordsConnector:f.string().optional().default(Te),twoWordsConnector:f.string().optional().default(Ee),lastWordConnector:f.string().optional().default(Ce)}),s={};t.forEach((i,l)=>{if(!Array.isArray(i)){let a=i.getText();(i.kind===Ae.Quoted||i.kind===Ae.Number)&&(a=i.content);let d=Se[l];s[d]=a}});let p=r.safeParse(s);if(!p.success)for(let i of p.error.issues){let l="string";"type"in i&&(l=i.type);let a=i.path[0],d=Object.entries(Se).find(([k,De])=>De===a),v=d?parseInt(d[0],10):null,u=typeof v=="number"?t[v]:null;u&&!Array.isArray(u)&&o.push({message:`"toSentence" expects a ${l}${i.message?` that ${i.message}`:""} for argument "${a}"`,begin:u.begin,end:u.end,value:u.getText()})}return o}import{Liquid as Le}from"liquidjs";function He(e){return Array.isArray(e)||typeof e=="object"&&e!==null?Oe(e):typeof e=="string"?e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t"):e==null?"":String(e)}var Oe=(e,t=0)=>Array.isArray(e)||typeof e=="object"&&e!==null?JSON.stringify(e,null,t).replace(/"/g,"'").replace(/\n/g,"\\n"):e==null?"":String(e);function un(e){let t=new Le({outputEscape:He,...e});return t.registerFilter("json",(n,o)=>Oe(n,o)),t.registerFilter("digest",ye),t.registerFilter("toSentence",we),t.registerFilter("pluralize",Re),t}var Be={400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",408:"Request Timeout",409:"Conflict",422:"Unprocessable Entity",429:"Too Many Requests",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout"};function w(e){return typeof e=="string"&&e.trim()?e:!e||typeof e!="object"?null:w(e.message)}function je(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!="object")return null;let n=t,o=w(n.message);if(o)return o;let r=w(n.error);if(r)return r;let s=n.errors;return Array.isArray(s)?w(s[0]):null}function We(e,t){var r;let n=(r=Be[e])!=null?r:e,o=je(t);return o?`Delivery failed: ${n}: ${o}`:`Delivery failed: ${n}`}var A=class extends Error{constructor(t,n){super(t),this.name="AgentError",this.cause=n==null?void 0:n.cause,this.delivery=n==null?void 0:n.delivery}},O=class extends A{constructor(t,n){let o={statusCode:t,responseBody:n};super(We(t,n),{delivery:o}),this.name="AgentDeliveryError",this.statusCode=t,this.responseBody=n}};function mn(e){return e instanceof A?e:e instanceof Error?new A(e.message,{cause:e}):new A("Turn failed",{cause:e})}var qe=(r=>(r.ON_MESSAGE="onMessage",r.ON_ACTION="onAction",r.ON_RESOLVE="onResolve",r.ON_REACTION="onReaction",r))(qe||{}),I=class{constructor(){this.__novuPendingApproval=!0}};function hn(e){return typeof e=="object"&&e!==null&&"suppress"in e&&e.suppress===!0}var Ve=5*1024*1024,Ge=5*1024*1024,Ie=32768,Xe=/^[A-Za-z0-9+/]*={0,2}$/;function _(e,t){return e.filename?`"${e.filename}"`:`at index ${t}`}function ke(){return globalThis.Buffer}function Ke(e){var t,n,o;return(o=(n=(t=ke())==null?void 0:t.isBuffer)==null?void 0:n.call(t,e))!=null?o:!1}function ze(e){return typeof Blob!="undefined"&&e instanceof Blob}function P(e){let t=ke();if(t)return t.from(e).toString("base64");if(typeof btoa!="function")throw new Error("Unable to encode file data: base64 encoding is not available in this runtime.");let n="";for(let o=0;o<e.length;o+=Ie){let r=e.subarray(o,o+Ie);n+=String.fromCharCode(...r)}return btoa(n)}function Ne(e){let t=e.replace(/\s/g,""),n=t.length%4;if(!t||n===1||!Xe.test(t))return null;let o=t.endsWith("==")?2:t.endsWith("=")?1:0;return Math.floor(t.length*3/4)-o}function S(e,t,n){if(e>Ve)throw new Error(`Invalid file ${_(t,n)}: inline data must be 5 MB or smaller. Use a publicly-accessible URL for larger files.`)}async function Ye(e,t,n){if(typeof e=="string"){let o=Ne(e);if(o===null)throw new Error(`Invalid file ${_(t,n)}: data must be a base64-encoded string.`);return S(o,t,n),e}if(Ke(e))return S(e.byteLength,t,n),e.toString("base64");if(e instanceof Uint8Array)return S(e.byteLength,t,n),P(e);if(e instanceof ArrayBuffer)return S(e.byteLength,t,n),P(new Uint8Array(e));if(ze(e))return S(e.size,t,n),P(new Uint8Array(await e.arrayBuffer()));throw new Error(`Invalid file ${_(t,n)}: data must be a base64 string, Buffer, Uint8Array, ArrayBuffer, or Blob.`)}async function Qe(e){if(!(e!=null&&e.length))return;let t=[],n=0;for(let[o,r]of e.entries()){let s=r.data,p=r.url,i=s!=null,l=p!=null;if(i===l)throw new Error(`Invalid file ${_(r,o)}: provide exactly one of data or url.`);if(i){let a=await Ye(s,r,o),d=Ne(a);if(n+=d!=null?d:0,n>Ge)throw new Error("Invalid files: total inline data must be 5 MB or smaller. Use publicly-accessible URLs for larger files.");t.push({...r,data:a});continue}if(l&&typeof p!="string")throw new Error(`Invalid file ${_(r,o)}: url must be a string.`);t.push(r)}return t}async function Ue(e,t){let n=await Qe(t);if(typeof e=="string")return n?{markdown:e,files:n}:{markdown:e};let{isJSX:o,toCardElement:r}=await import("./jsx-runtime-7EPQR56T.js");if(o(e)){let s=r(e);if(s)return n?{card:s,files:n}:{card:s}}if(L(e))return n?{card:e,files:n}:{card:e};throw new Error("Invalid message content \u2014 expected string or CardElement")}var x=class{constructor(t,n,o,r,s){this.conversationId=o;this.integrationIdentifier=r;this.poster=s;this.editedByHandler=!1;this.messageId=t,this.platformThreadId=n}async edit(t,n){this.editedByHandler=!0;let o=await this.poster.post({conversationId:this.conversationId,integrationIdentifier:this.integrationIdentifier,edit:{messageId:this.messageId,content:await Ue(t,n==null?void 0:n.files)}});if(!o)throw new Error("Agent edit did not return a message handle");return this.messageId=o.messageId,this.platformThreadId=o.platformThreadId,this}async delete(){await this.poster.post({conversationId:this.conversationId,integrationIdentifier:this.integrationIdentifier,deleteMessages:[{messageId:this.messageId}]})}},Pe;Pe=$;var be=class{constructor(t,n,o){this[Pe]=!0;this._signals=[];this._toolResults=[];this._pendingToolApprovalRequest=null;this._pendingReactions=[];this._pendingDeletes=[];this._resolveSignal=null;var i,l;this.event=t.event,this.action=(i=t.action)!=null?i:null,this.message=t.message,this.reaction=t.reaction,this.conversation=t.conversation,this.subscriber=t.subscriber,this.history=t.history,this.platform=t.platform,this.platformContext=t.platformContext,this._replyUrl=t.replyUrl,this._conversationId=t.conversationId,this._integrationIdentifier=t.integrationIdentifier,this._secretKey=n,this._poster={post:a=>this._post(a)},this._toolApprovalConfig=o,this._metadataState={...(l=t.conversation.metadata)!=null?l:{}};let r=this;this.metadata={get(a){return r._metadataState[a]},set(a,d){r._metadataState[a]=d,r._signals.push({type:"metadata",action:"set",key:a,value:d})},delete(a){delete r._metadataState[a],r._signals.push({type:"metadata",action:"delete",key:a})},clear(){r._metadataState={},r._signals.push({type:"metadata",action:"clear"})},get current(){return{...r._metadataState}}};let s=a=>this._post({conversationId:this._conversationId,integrationIdentifier:this._integrationIdentifier,typing:a}).then(()=>{}),p=(a=>s(a===void 0?{}:{status:a}));p.stop=()=>s("stop"),this.typing=p,this.toolApproval={request:async a=>(await H(this,a,this._toolApprovalConfig),new I)}}asMessageContext(){return this}async reply(t,n){let o=await Ue(t,n==null?void 0:n.files),r={conversationId:this._conversationId,integrationIdentifier:this._integrationIdentifier,reply:o};this._drainSideEffects(r);let s=await this._post(r);if(!s)throw new Error("Agent reply did not return a message handle");return new x(s.messageId,s.platformThreadId,this._conversationId,this._integrationIdentifier,this._poster)}async replyApprovalCard(t){let n={conversationId:this._conversationId,integrationIdentifier:this._integrationIdentifier,reply:{toolApprovalCard:t}};this._drainSideEffects(n);let o=await this._post(n);if(!o)throw new Error("Agent approval card reply did not return a message handle");return new x(o.messageId,o.platformThreadId,this._conversationId,this._integrationIdentifier,this._poster)}createReplyHandle(t){return new x(t,"",this._conversationId,this._integrationIdentifier,this._poster)}resolve(t){this._resolveSignal={summary:t}}trigger(t,n){this._signals.push({...n,type:"trigger",workflowId:t})}emitToolApprovalRequest(t){if(this._pendingToolApprovalRequest)throw new Error("Only one tool approval request can be queued before the next reply");this._pendingToolApprovalRequest=t}emitToolResult(t){this._toolResults.push(t)}addReaction(t,n){this._pendingReactions.push({messageId:t,emojiName:n})}deleteMessage(t){this._pendingDeletes.push({messageId:t})}async reportTurnError(){try{await this._post({conversationId:this._conversationId,integrationIdentifier:this._integrationIdentifier,error:!0})}catch(t){console.error("[agent] Failed to report turn error:",t)}}async flush(){if(!this._hasPendingSideEffects())return;let t={conversationId:this._conversationId,integrationIdentifier:this._integrationIdentifier};this._drainSideEffects(t),await this._post(t)}_hasPendingSideEffects(){return!!(this._pendingToolApprovalRequest||this._signals.length||this._toolResults.length||this._resolveSignal||this._pendingReactions.length||this._pendingDeletes.length)}_drainSideEffects(t){this._pendingToolApprovalRequest&&(t.toolApprovalRequest=this._pendingToolApprovalRequest,this._pendingToolApprovalRequest=null),this._signals.length&&(t.signals=this._signals,this._signals=[]),this._toolResults.length&&(t.toolResults=this._toolResults,this._toolResults=[]),this._pendingReactions.length&&(t.addReactions=this._pendingReactions,this._pendingReactions=[]),this._pendingDeletes.length&&(t.deleteMessages=this._pendingDeletes,this._pendingDeletes=[]),this._resolveSignal&&(t.resolve=this._resolveSignal,this._resolveSignal=null)}async _post(t){let n=await fetch(this._replyUrl,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`ApiKey ${this._secretKey}`},body:JSON.stringify(t)});if(!n.ok){let r=await n.text().catch(()=>"");throw new O(n.status,r)}let o=await n.text().catch(()=>"");if(!o)return null;try{let r=JSON.parse(o),s=r&&typeof r=="object"&&"data"in r?r.data:r;if(s&&typeof s.messageId=="string"&&typeof s.platformThreadId=="string")return{messageId:s.messageId,platformThreadId:s.platformThreadId}}catch{}return null}};var En={type:"object",properties:{},required:[],additionalProperties:!1};var Ze=(a=>(a.PENDING="pending",a.QUEUED="queued",a.RUNNING="running",a.COMPLETED="completed",a.FAILED="failed",a.DELAYED="delayed",a.CANCELED="canceled",a.MERGED="merged",a.SKIPPED="skipped",a))(Ze||{});var Je=(r=>(r.NONE="none",r.LOW="low",r.MEDIUM="medium",r.HIGH="high",r))(Je||{});export{B as a,W as b,q as c,V as d,G as e,X as f,K as g,z as h,Y as i,Q as j,Z as k,it as l,J as m,ee as n,te as o,ne as p,y as q,m as r,R as s,re as t,oe as u,ae as v,ie as w,le as x,pe as y,de as z,ce as A,ue as B,ge as C,me as D,fe as E,he as F,Fe as G,ye as H,Re as I,we as J,on as K,un as L,A as M,O as N,mn as O,qe as P,I as Q,hn as R,be as S,En as T,Ze as U,Je as V};
|