@hugex/ai 2.9.16 → 2.9.17
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/{chunk-P6H7GK2Z.js → chunk-RRS7SUF3.js} +1 -1
- package/dist/chunk-TGWG3SEO.js +3 -0
- package/dist/client.js +1 -1
- package/dist/common.js +1 -1
- package/dist/httpTool-MRMZWSXQ.js +1 -0
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-PEF6QKTR.js +0 -3
- package/dist/httpTool-633KS35I.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{f as N}from"./chunk-
|
|
1
|
+
import{f as N}from"./chunk-TGWG3SEO.js";import{a as J}from"./chunk-V6JSMX5A.js";import{tool as ot}from"ai";import{z as M}from"zod";import{z as p}from"zod";function j(t){if(t&&typeof t=="object"&&!t.type)return p.object({});if(t.type==="object")if(t.properties){let e={},o=t.required||[];for(let[r,n]of Object.entries(t.properties)){let a=j(n),c=n!=null&&typeof n=="object"&&Object.prototype.hasOwnProperty.call(n,"default");e[r]=c?a.default(n.default):o.includes(r)?a:a.optional()}return p.object(e)}else return p.object({});else if(t.type==="array"&&t.items){let e=j(t.items);return p.array(e)}else{if(t.type==="string")return p.string();if(t.type==="number"||t.type==="integer")return p.number();if(t.type==="boolean")return p.boolean()}return p.any()}var W=/\{\{\s*secrets\.[A-Z][A-Z0-9_]*\s*\}\}/,xt=t=>W.test(t),rt=/\{\{\s*auth\.[A-Z][A-Z0-9_]*\s*\}\}/;var E=t=>W.test(t)||rt.test(t),w=t=>{let e=t.indexOf("?");return e===-1?t:`${t.slice(0,e)}?[redacted-query]`};var st=256*1024,it=3e4,ct=/\{\{\s*([^}]+?)\s*\}\}/g,at=t=>{let e=t.toLowerCase();return e.includes("token")||e.includes("secret")||e.includes("key")||e.includes("password")||e.includes("access")||e==="authorization"},ut=t=>{let e={};for(let o in t)e[o]=at(o)?"[REDACTED]":t[o];return e},I=(t,e)=>{let o=t.indexOf(".");if(o===-1)return e[t];let r=t.slice(0,o),n=t.slice(o+1);if(r in e)return N(e[r],n)},H=(t,e,o)=>t&&t.replace(ct,(r,n)=>{let a=String(n).trim();if(a.startsWith("secrets.")){let f=a.slice(8);return Object.prototype.hasOwnProperty.call(o.secrets,f)?o.secrets[f]:r}if(a.startsWith("auth.")){let f=a.slice(5);return Object.prototype.hasOwnProperty.call(o.auth,f)?o.auth[f]:r}let c=I(a,e);return c==null?"":typeof c=="string"?c:JSON.stringify(c)}),dt=/\{\{\s*((?:secrets|auth)\.[^}\s]+)\s*\}\}/g,lt=(...t)=>{let e=new Set;for(let o of t){if(o==null)continue;let r=typeof o=="string"?o:JSON.stringify(o);for(let n of r.matchAll(dt))e.add(n[1])}return[...e]},T=(t,e,o)=>{if(t==null)return t;if(typeof t=="string"){let r=t.match(/^\s*\{\{\s*([^}]+?)\s*\}\}\s*$/);if(r){let n=r[1].trim();if(n.startsWith("secrets.")){let c=n.slice(8);return Object.prototype.hasOwnProperty.call(o.secrets,c)?o.secrets[c]:t}if(n.startsWith("auth.")){let c=n.slice(5);return Object.prototype.hasOwnProperty.call(o.auth,c)?o.auth[c]:t}return I(n,e)}return H(t,e,o)}if(Array.isArray(t))return t.map(r=>T(r,e,o));if(typeof t=="object"){let r={};for(let n in t)r[n]=T(t[n],e,o);return r}return t},ft=(t,e)=>t?e?/^https?:\/\//i.test(e)?e:t.endsWith("/")&&e.startsWith("/")?t+e.slice(1):!t.endsWith("/")&&!e.startsWith("/")?`${t}/${e}`:t+e:t:e||"",pt=(t,e)=>{if(!e)return t;let o=new URL(t);for(let r in e){let n=e[r];n!==void 0&&(Array.isArray(n)?o.searchParams.set(r,n.join(",")):o.searchParams.set(r,String(n)))}return o.toString()},K=t=>{if(!t)return{};let e={};for(let o in t)t[o]!==void 0&&(e[o]=t[o]);return e},yt=t=>{let e={};for(let o in t){let r=t[o];r!=null&&(e[o]=typeof r=="string"?r:String(r))}return e},gt=(t,e,o)=>{if(!(!t||t.type==="none"||!t.value)){if(t.type==="bearer"){e.Authorization=`Bearer ${t.value}`;return}if(t.type==="apiKey"){let r=t.in||"header",n=t.param||t.header||"X-API-Key";r==="query"?o[n]=t.value:e[n]=t.value}}},mt=(t,e)=>{let o=new TextEncoder().encode(t);if(o.byteLength<=e)return{text:t,truncated:!1};let r=o.slice(0,e);return{text:new TextDecoder("utf-8",{fatal:!1}).decode(r),truncated:!0}};function ht(t,e,o,r){var Z;if(t.kind!=="http")throw new Error(`customHttpTool: unsupported kind '${t.kind}' for tool '${t.name}'`);let n=t.execution||{},a=n.actions&&typeof n.actions=="object"?Object.keys(n.actions):[],c=((Z=n.router)==null?void 0:Z.field)||"action",f=t.inputSchema&&typeof t.inputSchema=="object"&&Object.keys(t.inputSchema).length>0?j(t.inputSchema):M.object({});if(a.length>0&&f instanceof M.ZodObject){let m=M.enum(a);f=f.extend({[c]:m})}let G=t.description||t.label||t.name,y=t.output||{},Q=Number.isFinite(y.maxBytes)&&y.maxBytes>0?y.maxBytes:st;return ot({description:G,inputSchema:f,execute:async m=>{var z;let h={secrets:e.secrets??{},auth:e.userAuth??{}},b={input:m??{},...o.context||{}},u=n,i;if(n.actions&&typeof n.actions=="object"){let s=((z=n.router)==null?void 0:z.field)||"action";if(i=m==null?void 0:m[s],!i||!n.actions[i])return{type:"error",error:`unknown action '${i}' for tool '${t.name}'`,natural:`Tool ${t.name} could not run: missing or unknown action.`};u=n.actions[i]}let C=u.url||ft(n.baseUrl,u.path);if(!C)return{type:"error",error:"missing url",natural:`Tool ${t.name} has no URL configured.`};let V=E(C),F=H(C,b,h),X={...n.headers||{},...u.headers||{}},g=yt(K(T(X,b,h))),Y={...n.query||{},...u.query||{}},P=K(T(Y,b,h)),$=(u.method||n.method||"GET").toUpperCase(),k,v=u.body!==void 0||n.body!==void 0;if($!=="GET"&&$!=="HEAD"&&v){let s=u.body!==void 0?u.body:n.body,d=typeof s=="string"?H(s,b,h):T(s,b,h);k=typeof d=="string"?d:JSON.stringify(d),!g["Content-Type"]&&!g["content-type"]&&(g["Content-Type"]="application/json")}let R=u.auth||n.auth,A=R?{...R,value:R.value?H(String(R.value),b,h):R.value}:void 0;gt(A,g,P);let S=pt(F,P),tt=V?w(S):S,U=lt(F,g,P,k,A==null?void 0:A.value);if(U.length>0){let s=U.map(d=>`{{ ${d} }}`).join(", ");return r==null||r({type:`error:tool:${t.name}:credentials`,content:{tool:t.name,action:i,missing:U}}),{type:"error",error:`unresolved credentials: ${s}`,natural:`Tool ${t.name} could not run because ${s} has no value in this execution. Connect the credential or use a tenant secret so unattended runs can resolve it.`}}let et=Math.min(Number.isFinite(u.timeoutMs)&&u.timeoutMs>0?u.timeoutMs:Number.isFinite(n.timeoutMs)&&n.timeoutMs>0?n.timeoutMs:15e3,it),D={tool:t.name,action:i,stage:"request",url:tt,method:$,headers:ut(g)};JSON.stringify(D),r==null||r({type:`info:tool:${t.name}:request`,content:D});let q=new AbortController,nt=setTimeout(()=>q.abort(),et);try{let s=await fetch(S,{method:$,headers:g,body:k,signal:q.signal}),d=s.headers.get("content-type")||"",O=await s.text(),{text:x,truncated:_}=mt(O,Q),l;if(y.contentType==="text"?l=x:d.includes("application/json")||y.contentType==="json"?(l=J(x),l===null&&x&&(l=x)):l=x,y.jsonPath&&l!==null&&typeof l=="object"&&(l=N(l,y.jsonPath)),!s.ok){let B={tool:t.name,action:i,stage:"http_error",status:s.status};return JSON.stringify(B),r==null||r({type:`error:tool:${t.name}:http`,content:B}),{type:"error",status:s.status,error:`HTTP ${s.status}: ${s.statusText}`,result:l,truncated:_,natural:`${t.name}${i?`:${i}`:""} failed with HTTP ${s.status}.`}}let L={tool:t.name,action:i,stage:"finish",status:s.status,truncated:_};return JSON.stringify(L),r==null||r({type:`info:tool:${t.name}:finish`,content:L}),{type:i||t.name,status:s.status,result:l,truncated:_,natural:`${t.name}${i?`:${i}`:""} completed (HTTP ${s.status}).`}}catch(s){let d=String((s==null?void 0:s.message)??s),O={tool:t.name,action:i,stage:"error",error:d};return JSON.stringify(O),r==null||r({type:`error:tool:${t.name}:execution`,content:O}),{type:"error",error:d,natural:`${t.name}${i?`:${i}`:""} failed: ${d}`}}finally{clearTimeout(nt)}}})}var St=ht;export{xt as a,w as b,j as c,ht as d,St as e};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var S=(u=>(u.START_NODE="startNode",u.CLASSIFIER_NODE="classifierNode",u.MEMO_NODE="memoNode",u.LLM_NODE="llmNode",u.ANSWER_NODE="answerNode",u.API_NODE="apiNode",u))(S||{});var T=/^[a-zA-Z][a-zA-Z0-9_]*$/,v=["string","number","boolean","json"];function F(e){let t=e==null?void 0:e.inputs;if(!Array.isArray(t))return[];let o=[],n=new Set;for(let r of t){let s=typeof(r==null?void 0:r.name)=="string"?r.name.trim():"";if(!s||!T.test(s)||n.has(s))continue;n.add(s);let u=v.includes(r==null?void 0:r.type)?r.type:"string";o.push({name:s,label:typeof(r==null?void 0:r.label)=="string"&&r.label.trim()?r.label.trim():void 0,type:u,required:(r==null?void 0:r.required)===!0,default:(r==null?void 0:r.default)??void 0})}return o}function M(e,t){let o=e.label||e.name;switch(e.type){case"number":{let n=typeof t=="number"?t:Number(String(t).trim());return Number.isFinite(n)?{value:n}:{error:`"${o}" must be a number`}}case"boolean":{if(typeof t=="boolean")return{value:t};let n=String(t).trim().toLowerCase();return["true","1","yes","si","s\xED"].includes(n)?{value:!0}:["false","0","no"].includes(n)?{value:!1}:{error:`"${o}" must be true or false`}}case"json":{if(typeof t=="object")return{value:t};try{return{value:JSON.parse(String(t))}}catch{return{error:`"${o}" must be valid JSON`}}}default:return{value:typeof t=="string"?t:String(t)}}}function h(e){return e==null||typeof e=="string"&&e.trim()===""}function C(e,t){let o={},n=[],r=t??{};for(let s of e){let u=r[s.name],d=h(u)?s.default:u;if(h(d)){s.required&&n.push(`"${s.label||s.name}" is required`);continue}let{value:p,error:O}=M(s,d);O?n.push(O):o[s.name]=p}return{values:o,errors:n}}function P(e){return typeof e=="string"?e:e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}function J(e,t,o){let n=t.user_input;if(typeof n=="string"&&n.trim())return n;let r=e.filter(u=>u.name!=="user_input"&&t[u.name]!==void 0).map(u=>`- ${u.label||u.name}: ${P(t[u.name])}`),s=(o==null?void 0:o.trim())||"Automated execution";return r.length>0?`${s}
|
|
2
|
+
${r.join(`
|
|
3
|
+
`)}`:s}function D(e,t){if(!t)return e;if(e==null)return;let o=t.split("."),n=e;for(let r of o){if(n==null)return;n=n[r]}return n}function L(e){switch(e){case"startNode":return[{name:"user_input",path:"user_input",label:"User input",source:"default"},{name:"images",path:"images",label:"User images",type:"image",source:"default"},{name:"files",path:"files",label:"User docs",type:"file",source:"default"}];case"llmNode":return[{name:"output",path:"",label:"LLM text",source:"default"}];case"apiNode":return[{name:"ok",path:"ok",source:"default"},{name:"status",path:"status",source:"default"},{name:"data",path:"data",source:"default"}];case"classifierNode":return[{name:"classification",path:"classification",source:"default"}];case"memoNode":return[{name:"context",path:"",label:"Retrieved context",source:"default"}];case"answerNode":return[];default:return[]}}function $(e){return e.type!=="startNode"?[]:F(e.data).map(t=>({name:t.name,path:t.name,label:t.label,type:t.type==="json"?"object":t.type,source:"default"}))}function A(e){var r;let t=L(e.type),o=((r=e.data)==null?void 0:r.outVars)||[],n=[...t,...$(e).filter(s=>!t.some(u=>u.name===s.name))];for(let s of o){let u=n.findIndex(d=>d.name===s.name);u>=0?n[u]={...s,source:"user"}:n.push({...s,source:"user"})}return n}function j(e,t){var l,N,a,g,y,i,c;if(e==="user_input")return(l=t.context)==null?void 0:l.user_input;if(e==="images")return(N=t.context)==null?void 0:N.user_images;if(e==="classified_id")return(a=t.context)==null?void 0:a.classified_id;if(e==="files"||e==="file_content")return((g=t.context)==null?void 0:g.files)||((y=t.context)==null?void 0:y.file_content);let o=e.indexOf(".");if(o===-1)return t.nodes.find(E=>E.id===e)?(i=t.results)==null?void 0:i[e]:Object.prototype.hasOwnProperty.call(t.context??{},e)?t.context[e]:void 0;let n=e.substring(0,o),r=e.substring(o+1),s=t.nodes.find(f=>f.id===n);if(!s)return;let u=A(s),d=r.split(".")[0],p=u.find(f=>f.name===d);if(!p)return;let O=(c=t.results)==null?void 0:c[n],m=D(O,p.path??"");if((m==null||m==="")&&s.type==="startNode"){let f=p.path||p.name;f&&Object.prototype.hasOwnProperty.call(t.context??{},f)&&(m=t.context[f])}let x=r.substring(d.length+1);return x?D(m,x):m}var w="\0__ORA_OB__\0",V="\0__ORA_CB__\0";function q(e,t,o,n){var m,x;if(!e)return e;let r=(n==null?void 0:n.serializeNonStrings)??!1,s=e.replace(/\\\{\{/g,w).replace(/\\\}\}/g,V),u={...o.context||{}};if((m=t.data)!=null&&m.varMapping&&Array.isArray(t.data.varMapping))for(let l of t.data.varMapping){let N=l.var||l.to,a=l.from;if(N&&a){let g=!1,y=!1;if(a==="images")g=!0;else if(a==="files"||a==="file_content")y=!0;else{let c=a.indexOf(".");if(c!==-1){let f=a.substring(0,c),E=a.substring(c+1).split(".")[0],I=o.nodes.find(b=>b.id===f);if(I){let _=A(I).find(R=>R.name===E);(_==null?void 0:_.type)==="image"&&(g=!0),(_==null?void 0:_.type)==="file"&&(y=!0)}}}if(g||y)continue;let i=j(a,o);(i==null||i==="")&&(i=l.default??""),u[N]=i}}let d=/\{\{\s*([^}]+?)\s*\}\}/g,p=l=>r?JSON.stringify(l).slice(1,-1):l;s=s.replace(d,(l,N)=>{var g,y;let a=N.trim();if(a.startsWith("secrets.")){let i=a.slice(8);return o.secrets?Object.prototype.hasOwnProperty.call(o.secrets,i)?p(o.secrets[i]):((y=n==null?void 0:n.onError)==null||y.call(n,`Secret "${i}" is not defined for this tenant`),l):((g=n==null?void 0:n.onError)==null||g.call(n,`Secret reference {{ ${a} }} cannot be resolved (no secrets context)`),l)}if(Object.prototype.hasOwnProperty.call(u,a)){let i=u[a],c;return typeof i=="string"?c=p(i):typeof i=="object"&&i!==null?c=r?JSON.stringify(i):JSON.stringify(i,null,2):i!=null?c=r?JSON.stringify(i):String(i):c="",c}return l});let O=s.match(/\{\{\s*[^}]+\s*\}\}/g);return O&&((x=n==null?void 0:n.onError)==null||x.call(n,`Mismatch detected: Unmatched placeholders found: ${O}`)),s=s.split(w).join("{{").split(V).join("}}"),s}export{S as a,T as b,F as c,C as d,J as e,D as f,L as g,A as h,j as i,q as j};
|
package/dist/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as u,b as Q,c as T,d as X,e as z,f as Ee,g as Te,h as Ie}from"./chunk-76OHKISD.js";import{a as $,b as L,c as Y,d as k,e as K,f as Se,g as fe,h as Ae,i as Re,j as Me}from"./chunk-
|
|
1
|
+
import{a as u,b as Q,c as T,d as X,e as z,f as Ee,g as Te,h as Ie}from"./chunk-76OHKISD.js";import{a as $,b as L,c as Y,d as k,e as K,f as Se,g as fe,h as Ae,i as Re,j as Me}from"./chunk-TGWG3SEO.js";import{a as B,b as W,c as Z,d as ee,e as te,f as ne,g as se,h as oe,i as re,j as ae,k as ie,l as ge,m as le,n as pe,o as ce,p as ue,q as de,r as ve,s as ye,t as me}from"./chunk-GRZ6ZRHM.js";import{a as G}from"./chunk-U56YWPSI.js";import"./chunk-3TXHFKDN.js";import{useAgent as U}from"agents/react";import{useCallback as d,useEffect as P,useMemo as J,useRef as m}from"react";import{create as F}from"zustand";import{devtools as D}from"zustand/middleware";var H={messages:[],events:[],eventsVisible:!1,status:"connecting",typingMessage:null,reasoningMessage:null,reasoningMessages:[],isReasoning:!1,stepInfo:null,approvals:[],error:null,flowConfig:null,composioAuth:null};function C(n){return F()(D((t,y)=>({...H,initHistory:e=>t({messages:e}),addEvent:e=>t(o=>({events:[...o.events,{...e,ts:Date.now()}]})),clearEvents:()=>t({events:[]}),setMessages:e=>{t({messages:e})},addMessage:e=>{t(o=>({messages:[...o.messages,e]}))},setTyping:e=>t({typingMessage:e}),appendTyping:(e,o)=>{let r=y().typingMessage;r&&r.id===e?t({typingMessage:{id:e,text:r.text+o}}):t({typingMessage:{id:e,text:o}})},clearTyping:()=>t({typingMessage:null}),setReasoning:e=>t({reasoningMessage:e}),appendReasoning:(e,o)=>{let r=y().reasoningMessage;r&&r.id===e?t({reasoningMessage:{id:e,text:r.text+o}}):t({reasoningMessage:{id:e,text:o}})},commitReasoning:e=>{t(o=>{var r;return(r=o.reasoningMessage)!=null&&r.text?{reasoningMessages:[...o.reasoningMessages,{...o.reasoningMessage,ts:e??Date.now()}],reasoningMessage:null,isReasoning:!1}:{reasoningMessage:null,isReasoning:!1}})},clearReasoning:()=>t({reasoningMessage:null,isReasoning:!1}),setReasoningMessages:e=>t({reasoningMessages:e}),setReasoningActive:e=>t({isReasoning:e}),setStep:e=>t({stepInfo:e}),clearStep:()=>t({stepInfo:null}),setStatus:e=>t({status:e}),toggleEvents:()=>t(e=>({eventsVisible:!e.eventsVisible})),clearHistory:()=>t({messages:[],typingMessage:null,reasoningMessage:null,reasoningMessages:[],isReasoning:!1,stepInfo:null}),addApprovalRequest:e=>{let o={id:`approval-${Date.now()}-${Math.random()}`,toolCallId:e.toolCallId,toolName:e.toolName,args:e.args??{},description:e.description,ts:Date.now(),status:"pending"};t(r=>({approvals:[...r.approvals,o]}))},updateApprovalStatus:({toolCallId:e,status:o})=>{t(r=>({approvals:r.approvals.map(v=>v.toolCallId===e?{...v,status:o}:v)}))},removeApproval:e=>{t(o=>({approvals:o.approvals.filter(r=>r.toolCallId!==e)}))},setError:e=>t({error:e}),setFlowConfig:e=>t({flowConfig:e}),setComposioAuth:e=>t({composioAuth:e}),clearComposioAuth:()=>t({composioAuth:null})}),{name:n,enabled:!0}))}var j=C("agent-store"),I=new Map;function h(n){if(!n)return j;let t=I.get(n);return t||(t=C(`agent-store:${n}`),I.set(n,t)),t}function qe(n){let t=J(()=>h(n==null?void 0:n.storeKey),[n==null?void 0:n.storeKey]),y=t(s=>s.typingMessage),e=m(null),o=m(null),r=m(null),v=m(0),S=m(null),f=()=>(v.current=Math.max(Date.now(),v.current+1),v.current);P(()=>{e.current=y},[y]);let A=d(s=>{var g;let i=s.trim().slice(0,T);!i||typeof((g=S.current)==null?void 0:g.send)!="function"||S.current.send(u.USER_IDENTITY+":"+i)},[]),l=U({host:n==null?void 0:n.host,basePath:(n==null?void 0:n.basePath)??"/api/agents/base",agent:n==null?void 0:n.agent,name:n==null?void 0:n.name,query:n==null?void 0:n.query,onMessage:s=>{if(typeof s.data!="string")return;let[i,g]=s.data.split("::");if(!i||!g)return;let a=t.getState(),R={[u.SERVER_HISTORY]:p=>{let c=JSON.parse(p);a.setMessages(c.messages),a.setReasoningMessages([])},[u.SERVER_EVENT]:p=>{var E;let c=JSON.parse(p);if((c==null?void 0:c.type)==="info:composio:auth_required"&&((E=c==null?void 0:c.content)!=null&&E.redirectUrl)){let M=c.content;a.setComposioAuth({toolkit:M.toolkit,redirectUrl:M.redirectUrl,toolRowId:M.toolRowId})}a.addEvent({type:"server",...c})},[u.SERVER_ERROR]:p=>{a.setError(p),a.addEvent({type:"error",content:p})},[u.SERVER_TEXT_STREAM]:p=>{o.current?a.appendTyping(o.current,p):(o.current=String(Date.now()),a.setTyping({id:o.current,text:p}))},[u.SERVER_TEXT_STREAM_COMPLETE]:p=>{if(a.setReasoningActive(!1),o.current&&a.typingMessage){let c=a.typingMessage.text;a.addMessage({role:"assistant",type:"text",content:c,id:o.current,ts:f()}),a.clearTyping(),o.current=null}},[u.SERVER_REASONING_STREAM]:p=>{a.setReasoningActive(!0),r.current?a.appendReasoning(r.current,p):(r.current=String(Date.now()),a.setReasoning({id:r.current,text:p}))},[u.SERVER_REASONING_STREAM_COMPLETE]:()=>{a.commitReasoning(f()),r.current=null},[u.SERVER_CONFIG]:p=>{a.setFlowConfig(JSON.parse(p))}};R[i]&&R[i](g)},onOpen:()=>{let s=t.getState();s.setStatus("connected"),s.clearTyping(),o.current=null,s.clearReasoning(),r.current=null,s.clearStep(),s.addEvent({type:"connection",content:"Connected to Agent Server"}),n!=null&&n.user&&A(n.user)},onClose:()=>{let s=t.getState();s.setStatus("disconnected"),s.setFlowConfig(null),s.addEvent({type:"connection",content:"Connection closed"})}});S.current=l;let x=d((s,i,g)=>{let a=s.trim();if(!a&&(!i||i.length===0)&&(!g||g.length===0))return;let p=((i==null?void 0:i.length)??0)>0||((g==null?void 0:g.length)??0)>0?JSON.stringify({text:a,images:i,documents:g}):a;l.send(u.USER_MESSAGE+":"+p);let c=t.getState();r.current=null,c.clearReasoning(),c.addMessage({id:String(Date.now())+Math.random(),role:"user",type:"text",content:a,images:i,ts:f()})},[l]),w=d(()=>{t.getState().clearHistory(),l.send(u.USER_CLEAR_HISTORY+":1")},[l]),_=d((s,i)=>{let g=s.trim();g&&l.send(u.USER_AUTH+":"+JSON.stringify({name:g,value:i}))},[l]),b=d(s=>{A(s)},[A]),N=d(()=>t.getState().toggleEvents(),[]),O=d(()=>t.getState().clearEvents(),[]),q=d(s=>{let i=t.getState();i.updateApprovalStatus({toolCallId:s,status:"approved"});let g=JSON.stringify({type:"tool_approval",toolCallId:s,approved:!0});typeof(l==null?void 0:l.send)=="function"&&l.send(g),i.addEvent({type:"approval",content:`Approved tool call ${s}`,ts:Date.now()})},[l]),V=d(s=>{let i=t.getState();i.updateApprovalStatus({toolCallId:s,status:"rejected"});let g=JSON.stringify({type:"tool_approval",toolCallId:s,approved:!1});typeof(l==null?void 0:l.send)=="function"&&l.send(g),i.addEvent({type:"approval",content:`Rejected tool call ${s}`,ts:Date.now()})},[l]);return{connection:l,store:t,send:x,clearHistory:w,sendAuth:_,setIdentity:b,toggleEventsVisible:N,clearEvents:O,approve:q,reject:V}}export{L as FLOW_INPUT_NAME_RE,B as GENERATION_PARAM_KEYS,Z as GENERATION_PRESETS,T as MAX_USER_IDENTITY_LENGTH,Te as MODEL_REGISTRY_SNAPSHOT,$ as NodeType,W as PRESET_PARAM_KEYS,ce as REASONING_EFFORT_LEVELS,Ee as TOOL_REGISTRY_SNAPSHOT,ne as applyPresetToOverrides,me as buildReasoningProviderOptions,K as buildTriggerMessageText,ee as deriveParamSupport,h as getAgentStore,fe as getDefaultOutVars,Ae as getEffectiveOutVars,Y as getFlowInputDefs,Ie as getModelEntry,G as logc,u as messageTypes,oe as normalizeEffectiveParams,k as normalizeFlowInputs,ue as normalizeReasoning,ie as openAiReasoningParamSupport,ae as openAiStandardParamSupport,z as parseUserAuth,Q as parseUserMessage,se as pickNodeOverrides,de as reasoningEffortLevels,ve as reasoningExposable,Re as resolveOutVarRef,te as resolvePreset,ye as resolveReasoningEffort,Me as resolveTemplate,X as sanitizeUserIdentity,pe as stripUnsupportedFromNodeData,re as toStreamTextSettings,qe as useAgent,j as useAgentStore,Se as walkPath,le as workersAiParamSupport,ge as xaiParamSupport};
|
package/dist/common.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as b,b as h,c as i,d as j,e as k,f as K,g as L,h as M}from"./chunk-76OHKISD.js";import{a as c,b as d,c as e,d as f,e as g,f as F,g as G,h as H,i as I,j as J}from"./chunk-
|
|
1
|
+
import{a as b,b as h,c as i,d as j,e as k,f as K,g as L,h as M}from"./chunk-76OHKISD.js";import{a as c,b as d,c as e,d as f,e as g,f as F,g as G,h as H,i as I,j as J}from"./chunk-TGWG3SEO.js";import{a as l,b as m,c as n,d as o,e as p,f as q,g as r,h as s,i as t,j as u,k as v,l as w,m as x,n as y,o as z,p as A,q as B,r as C,s as D,t as E}from"./chunk-GRZ6ZRHM.js";import{a}from"./chunk-U56YWPSI.js";import"./chunk-3TXHFKDN.js";export{d as FLOW_INPUT_NAME_RE,l as GENERATION_PARAM_KEYS,n as GENERATION_PRESETS,i as MAX_USER_IDENTITY_LENGTH,L as MODEL_REGISTRY_SNAPSHOT,c as NodeType,m as PRESET_PARAM_KEYS,z as REASONING_EFFORT_LEVELS,K as TOOL_REGISTRY_SNAPSHOT,q as applyPresetToOverrides,E as buildReasoningProviderOptions,g as buildTriggerMessageText,o as deriveParamSupport,G as getDefaultOutVars,H as getEffectiveOutVars,e as getFlowInputDefs,M as getModelEntry,a as logc,b as messageTypes,s as normalizeEffectiveParams,f as normalizeFlowInputs,A as normalizeReasoning,v as openAiReasoningParamSupport,u as openAiStandardParamSupport,k as parseUserAuth,h as parseUserMessage,r as pickNodeOverrides,B as reasoningEffortLevels,C as reasoningExposable,I as resolveOutVarRef,p as resolvePreset,D as resolveReasoningEffort,J as resolveTemplate,j as sanitizeUserIdentity,y as stripUnsupportedFromNodeData,t as toStreamTextSettings,F as walkPath,x as workersAiParamSupport,w as xaiParamSupport};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as a,e as b}from"./chunk-RRS7SUF3.js";import"./chunk-TGWG3SEO.js";import"./chunk-V6JSMX5A.js";import"./chunk-U56YWPSI.js";import"./chunk-3TXHFKDN.js";export{a as customHttpTool,b as default};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as et,b as Tt,c as se,d as ne}from"./chunk-
|
|
1
|
+
import{a as et,b as Tt,c as se,d as ne}from"./chunk-RRS7SUF3.js";import{a as ie,b as ae}from"./chunk-4FUIFBZO.js";import{a as re}from"./chunk-YHXUBVN2.js";import{a as is,b as lt,c as as,d as dt,e as xt,f as zt,g as Wt,h as Yt,i as Bt,j as Qt,k as It,l as Zt}from"./chunk-57TCP6J4.js";import{a as D,b as ct,c as Jo,d as tt,e as Vt,f as ee,g as ls,h as ds}from"./chunk-76OHKISD.js";import{a as Q,b as Xo,c as Z,d as Ht,e as qt,f as vt,g as cs,h as G,i as v,j as te}from"./chunk-TGWG3SEO.js";import{a as So,b as Go,c as zo,d as Wo,e as Yo,f as Bo,g as Kt,h as Qo,i as Xt,j as Zo,k as vo,l as ts,m as es,n as os,o as ss,p as ns,q as rs,r as Jt,s as St,t as Gt}from"./chunk-GRZ6ZRHM.js";import{a as Eo}from"./chunk-RYHQGPX5.js";import{a as Lo}from"./chunk-R6EKV3WR.js";import{a as qo}from"./chunk-6HY7QUMP.js";import{a as jo,b as Ho}from"./chunk-V6JSMX5A.js";import{a as S,b as B,c as Vo,d as jt,e as Ko}from"./chunk-G3SGJ7XJ.js";import{a as oe}from"./chunk-4WAWR4LB.js";import{a as at}from"./chunk-U56YWPSI.js";import{a as it}from"./chunk-3TXHFKDN.js";import{Agent as Io}from"agents";import{nanoid as To}from"nanoid";var k=(o,e,s)=>{o.send(e+"::"+s)};async function Ye(o){o.sql`CREATE TABLE IF NOT EXISTS messages (id TEXT PRIMARY KEY, role TEXT NOT NULL, type TEXT NOT NULL, content TEXT NOT NULL, ts INTEGER NOT NULL)`}async function ce(o,e){o.sql`INSERT INTO messages (id, role, type, content, ts) VALUES (${e.id}, ${e.role}, ${e.type}, ${e.content}, ${e.ts})`}async function X(o){return o.sql`SELECT id, role, type, content, ts FROM messages ORDER BY ts ASC`}async function ut(o){o.sql`DELETE FROM messages`}async function Be(o){o.sql`CREATE TABLE IF NOT EXISTS context (
|
|
2
2
|
ref TEXT PRIMARY KEY,
|
|
3
3
|
domain TEXT NOT NULL,
|
|
4
4
|
description TEXT NOT NULL,
|
|
@@ -27,7 +27,7 @@ ${u.map(w=>{let x=w.keywords??w["keywords/topics"]??"",R=Array.isArray(x)?x.join
|
|
|
27
27
|
|
|
28
28
|
Select the best matching category id.`;try{let w=Date.now(),x=u.map($=>String($.id)),R="gpt_4_1_mini",T=await lt(R,o);if(!T)throw new Error(`Model '${R}' not found in registry`);let{modelHandle:P,effectiveParams:A}=T,M=await so({model:P,messages:[{role:"system",content:m},{role:"user",content:a}],schema:Te.object({classification:Te.enum(x).describe("The id of the best matching category")}),temperature:A.temperature??0}),b=Date.now()-w,F=M.object.classification;i==null||i({type:"class_telemetry",payload:{nodeId:e.id,totalLatency:b,model:M.response.modelId,usage:M.usage,options:x}}),i==null||i({type:"class_result",payload:{result:M}}),n==null||n(e.id,{classification:F}),s.context=s.context||{},s.context.classified_id=F,r==null||r(s),t==null||t({type:"node:execution",content:{nodeId:e.id,nodeType:e.type,status:"success"}})}catch(w){t==null||t({type:"node:execution",content:{nodeId:e.id,nodeType:e.type,status:"error",error:String(w)}})}}import{stepCountIs as io,streamText as ao}from"ai";import{nanoid as co}from"nanoid";import"zod";function Ne(o,e){var t,n,r,i,l,d;let s="";if((t=o.data)!=null&&t.varMapping&&Array.isArray(o.data.varMapping))for(let f of o.data.varMapping){let u=f.from;if(!u)continue;let p=!1;if(u==="files"||u==="file_content")p=!0;else{let c=u.indexOf(".");if(c!==-1){let m=u.substring(0,c),a=u.substring(c+1).split(".")[0],g=(i=(r=(n=e.flowData)==null?void 0:n.state)==null?void 0:r.nodes)==null?void 0:i.find(y=>y.id===m);if(g){let h=G(g).find(w=>w.name===a);(h==null?void 0:h.type)==="file"&&(p=!0)}}}if(p){let c=v(u,{context:e.context||{},results:e.results||{},nodes:((d=(l=e.flowData)==null?void 0:l.state)==null?void 0:d.nodes)||[]});typeof c=="string"&&c.trim()&&(s+=(s?`
|
|
29
29
|
|
|
30
|
-
`:"")+c)}}return s}function Ce(o,e){var t,n,r,i,l,d;let s=[];if((t=o.data)!=null&&t.varMapping&&Array.isArray(o.data.varMapping))for(let f of o.data.varMapping){let u=f.from;if(!u)continue;let p=!1;if(u==="images")p=!0;else{let c=u.indexOf(".");if(c!==-1){let m=u.substring(0,c),a=u.substring(c+1).split(".")[0],g=(i=(r=(n=e.flowData)==null?void 0:n.state)==null?void 0:r.nodes)==null?void 0:i.find(y=>y.id===m);if(g){let h=G(g).find(w=>w.name===a);(h==null?void 0:h.type)==="image"&&(p=!0)}}}if(p){let c=v(u,{context:e.context||{},results:e.results||{},nodes:((d=(l=e.flowData)==null?void 0:l.state)==null?void 0:d.nodes)||[]});Array.isArray(c)&&s.push(...c)}}return s}var no=it({"../tools/composioTool.ts":()=>import("./composioTool-44B637WM.js"),"../tools/convertTempMessure.ts":()=>import("./convertTempMessure-5CAGRLBY.js"),"../tools/httpTool.ts":()=>import("./httpTool-633KS35I.js"),"../tools/recall.ts":()=>import("./recall-IABRCSHY.js"),"../tools/skillTool.ts":()=>import("./skillTool-BSQFKZGK.js"),"../tools/tempTool.ts":()=>import("./tempTool-2RXAF56M.js"),"../tools/twitter.ts":()=>import("./twitter-OMDEG7T2.js"),"../tools/vectorize.ts":()=>import("./vectorize-UJXIDL2E.js")});var ro=it({});function Mt(o,e,s,t,n){var i;if(!((i=t.memoryConfig)!=null&&i.enabled)||!t.memoryConfig.toolCache||!s.cacheable||!e||typeof e.execute!="function")return e;let r=e.execute.bind(e);return e.execute=async(l,...d)=>{var c;if(!t.getContextIndex)return r(l,...d);let f=await xt(l),p=(await t.getContextIndex()).find(m=>{if(m.domain!=="tool")return!1;let a=It(m.meta);return a.toolName===o&&a.paramsHash===f});if(p){let m=await((c=t.getContext)==null?void 0:c.call(t,p.ref));if((m==null?void 0:m.data)!=null&&It(m.meta).truncated!==!0){n==null||n({type:"info:memory:cacheHit",content:{ref:m.ref,toolName:o}});try{return JSON.parse(m.data)}catch{return m.data}}}return r(l,...d)},e}async function lo(o,e,s,t){var u,p;if(!((u=s.memoryConfig)!=null&&u.enabled)||!s.setContext||s.cycle==null)return;let n=o.toolCalls??[],r=o.toolResults??[];if(!n.length||!r.length)return;let i=new Map;for(let c of r)c!=null&&c.toolCallId&&i.set(c.toolCallId,c);let l=Array.isArray((p=e==null?void 0:e.data)==null?void 0:p.tools)?e.data.tools:[],d=new Map;for(let c of l)c&&typeof c.id=="string"&&d.set(c.id,c);let f=new Map;for(let c of Object.values(s.toolDefs??{}))c&&c.name&&f.set(c.name,c);for(let c of n){let m=c.toolCallId,a=c.toolName,g=i.get(m);if(!a||!g||a==="readSkillRef")continue;let y=c.args??c.input,h=g.result??g.output,w=!1,x="",R="tool",T="",P=f.get(a);P&&P.kind==="skill"&&(w=!0,x=`skill:${a}`,R="skill",T=`Skill instructions for ${a}`),x||(x=await Wt(a,y),T=zt(y,h));let A=d.get(a)??l.find(F=>F.id===a),M=await xt(y),b=typeof h=="string"?h:JSON.stringify(h??null);await s.setContext({ref:x,domain:R,description:T,data:b,cycle:s.cycle,meta:JSON.stringify({toolName:a,paramsHash:M,cacheable:(A==null?void 0:A.cacheable)===!0})}),t==null||t({type:"info:memory:updated",content:{ref:x}})}}async function uo(o,e,s,t){var p;let n=Array.isArray((p=s==null?void 0:s.data)==null?void 0:p.tools)?s.data.tools:[];if(n.length===0)return{};let r={},i=c=>{var x,R;let m=typeof(c==null?void 0:c.description)=="string"?c.description:"",a=c==null?void 0:c.inputSchema,g;try{let T=(a==null?void 0:a.shape)??(typeof((x=a==null?void 0:a._def)==null?void 0:x.shape)=="function"?a._def.shape():(R=a==null?void 0:a._def)==null?void 0:R.shape);T&&typeof T=="object"&&(g=T)}catch{}let y=g?Object.keys(g):[],h=m?`description="${m.length>120?m.slice(0,120)+"\u2026":m}"`:"description=(none)",w=y.length?`inputSchema={${y.join(", ")}}`:"inputSchema=(none)";return`${h} ${w}`},l=(()=>{let c=[],m=[],a=[],g=[];for(let h=0;h<n.length;h++){let w=n[h];!w||typeof w!="object"||typeof w.id!="string"?g.push(h):w.kind==="builtin"?c.push(w.id):w.kind==="skill"?a.push(w.id):w.kind==="http"||w.kind==="mcp"||w.kind==="composio"?m.push(w.id):g.push(h)}let y=[];return c.length&&y.push(`builtin[${c.join(", ")}]`),m.length&&y.push(`custom[${m.join(", ")}]`),a.length&&y.push(`skill[${a.join(", ")}]`),g.length&&y.push(`invalid@[${g.join(", ")}]`),y.join(" ")||"(none)"})();console.log(`[tools] node ${s.id} requested (${n.length}): ${l}`);let d=!1,f=async()=>{if(d&&o.toolDefs)return o.toolDefs;if(!o.env)return o.toolDefs=o.toolDefs||{},d=!0,o.toolDefs;try{let c=await re(o.env),m={};for(let a of c)a&&a.id&&(m[a.id]=a);o.toolDefs=m}catch(c){t==null||t({type:"error:llmNodeRunner",content:`Failed to load custom tool defs: ${String(c)}`}),o.toolDefs=o.toolDefs||{}}return d=!0,o.toolDefs},u=[];for(let c=0;c<n.length;c++){let m=n[c];if(!m||typeof m!="object"||typeof m.id!="string"||m.kind!=="builtin"&&m.kind!=="http"&&m.kind!=="mcp"&&m.kind!=="composio"&&m.kind!=="skill"){t==null||t({type:"error:llmNodeRunner",content:`Invalid tool descriptor at index ${c}: expected { kind: 'http'|'mcp'|'composio'|'builtin'|'skill', id: string, params?: any }`});continue}let a=m;if(a.kind!=="builtin"){let y=(await f())[a.id];if(!y){console.error(`[tools] \u2717 custom '${a.id}': not found for tenant`),t==null||t({type:"error:llmNodeRunner",content:`custom tool '${a.id}' not found for this tenant`});continue}if(a.kind==="composio"){try{let w=await oe(y,o,e,t),x=Object.keys(w);for(let[R,T]of Object.entries(w))r[R]=Mt(R,T,a,o,t);console.log(`[tools] \u2713 composio '${a.id}' \u2192 ${x.length} tool(s)`)}catch(w){console.error(`[tools] \u2717 composio '${a.id}': ${String(w)}`),t==null||t({type:"error:llmNodeRunner",content:`Error loading composio tool '${a.id}': ${String(w)}`})}continue}if(a.kind==="skill"){if(y.kind!=="skill"){console.error(`[tools] \u2717 skill '${a.id}': row is of kind '${y.kind}', not 'skill'`),t==null||t({type:"error:llmNodeRunner",content:`tool '${a.id}' is not a skill`});continue}let w=y.name;if(r[w]){t==null||t({type:"warn:llmNodeRunner",content:`tool name collision on '${w}' \u2014 builtin/other already registered, skipping skill '${a.id}'`});continue}try{r[w]=ie(y,o,e,t),u.push(y);let x=typeof y.execution=="string"?JSON.parse(y.execution):y.execution||{},R=Array.isArray(x.references)?x.references.map(T=>T==null?void 0:T.name):[];console.log(`[tools] \u2713 skill '${a.id}' \u2192 '${w}' (refs: ${R.join(", ")||"none"})`),t==null||t({type:"info:skill:registered",content:{skill:w,refCount:R.length,refs:R}})}catch(x){console.error(`[tools] \u2717 skill '${a.id}': ${String(x)}`),t==null||t({type:"error:llmNodeRunner",content:`Error loading skill tool '${a.id}': ${String(x)}`})}continue}let h=y.name;if(r[h]){t==null||t({type:"warn:llmNodeRunner",content:`tool name collision on '${h}' \u2014 builtin already registered, skipping custom tool '${a.id}'`});continue}try{let w=ne(y,o,e,t);r[h]=Mt(h,w,a,o,t),console.log(`[tools] \u2713 custom '${a.id}' \u2192 '${h}'`),console.log(`[tools] ${i(r[h])}`)}catch(w){console.error(`[tools] \u2717 custom '${a.id}': ${String(w)}`),t==null||t({type:"error:llmNodeRunner",content:`Error loading custom tool '${a.id}': ${String(w)}`})}continue}if(!ee[a.id]){console.error(`[tools] \u2717 builtin '${a.id}': not in registry`),t==null||t({type:"error:llmNodeRunner",content:`Tool '${a.id}' not found in registry`});continue}try{let g;try{g=await no(`../tools/${a.id}.ts`)}catch{g=await ro(`../tools/${a.id}.js`)}let y;if(g[a.id])y=g[a.id];else if(g.default)y=g.default;else if(g.create)y=g.create;else{let A=Object.values(g);A.length>0&&(y=A[0])}if(!y){t==null||t({type:"error:llmNodeRunner",content:`No factory export found for tool '${a.id}'`});continue}let h,w,x={};if(a.params&&typeof a.params=="object"){if(typeof a.params.description=="string"?h=a.params.description:a.params.description!==void 0&&(t==null||t({type:"error:llmNodeRunner",content:`Invalid description for tool '${a.id}' \u2014 must be a string`})),a.params.inputSchema!==void 0){let A=a.params.inputSchema;typeof A=="object"&&(typeof A.safeParse=="function"||A._def)?w=A:typeof A=="object"&&A!==null&&A.type==="object"&&A.properties?(w=se(A),w||t==null||t({type:"error:llmNodeRunner",content:`Invalid inputSchema for tool '${a.id}' \u2014 must be a Zod schema or JSON Schema object`})):t==null||t({type:"error:llmNodeRunner",content:`Invalid inputSchema for tool '${a.id}' \u2014 must be a Zod schema or JSON Schema object`})}a.params.defaults!==void 0?typeof a.params.defaults=="object"&&a.params.defaults!==null&&!Array.isArray(a.params.defaults)?x=a.params.defaults:(t==null||t({type:"error:llmNodeRunner",content:`Invalid defaults for tool '${a.id}' \u2014 must be an object`}),x={}):a.params.source!==void 0||a.params.target!==void 0?(t==null||t({type:"error:llmNodeRunner",content:`Invalid params for tool '${a.id}' \u2014 legacy top-level source/target not supported; use params.defaults instead`}),x={}):x={}}let R=y(o,e,x,t);h&&R&&typeof R=="object"&&(R.description=h),w&&R&&typeof R=="object"&&(R.inputSchema=w),r[a.id]=Mt(a.id,R,a,o,t);let T=[];h&&T.push("description"),w&&T.push("inputSchema"),Object.keys(x).length&&T.push(`defaults(${Object.keys(x).join(",")})`);let P=T.length?` [overrides: ${T.join(", ")}]`:"";console.log(`[tools] \u2713 builtin '${a.id}'${P}`),console.log(`[tools] ${i(R)}`)}catch(g){console.error(`[tools] \u2717 builtin '${a.id}': ${String(g)}`),t==null||t({type:"error:llmNodeRunner",content:`Error loading tool '${a.id}': ${String(g)}`});continue}}if(u.length>0)if(r.readSkillRef)t==null||t({type:"warn:llmNodeRunner",content:"tool name collision on 'readSkillRef' \u2014 builtin/other already registered, skipping readSkillRef tool"});else try{r.readSkillRef=ae(o,u,e,t),console.log(`[tools] \u2713 registered readSkillRef tool for ${u.length} skill(s)`),t==null||t({type:"info:skill:readSkillRefRegistered",content:{skills:u.map(c=>c.name)}})}catch(c){console.error(`[tools] \u2717 failed to load readSkillRef tool: ${String(c)}`)}return r}async function Dt(o,e,s,t,n,r,i){var M,b,F,$,j;`${e.id}`,t==null||t({type:"node:execution",content:{nodeId:e.id,nodeType:e.type,status:"start"}});let l=!1;try{let I=(M=s.flowData)==null?void 0:M.state;if(I&&I.edges&&I.nodes){let _=I.edges.filter(U=>U.source===e.id);if(_.length>0){let U=I.nodes.find(H=>H.id===_[0].target);U&&U.type==="answerNode"&&(l=!0)}}}catch(I){console.error("Error determining next node for streaming:",I)}let d=W(e.data.template,e,s,t,{sessionEnv:o});(!d||!d.trim())&&(d="Answer straight forward to the user, dont offer any other option to continue");let f=d,u="";if((b=o.memoryConfig)!=null&&b.enabled){let I=await((F=o.getContextIndex)==null?void 0:F.call(o))??[];u=Bt(I),d+=u}let p=W(e.data.user_template||"",e,s,t,{sessionEnv:o}),c=I=>I&&Object.fromEntries(Object.keys(I).map(_=>[_,"[redacted]"])),m=o!=null&&o.secrets||o!=null&&o.userAuth?{...o,secrets:c(o.secrets),userAuth:c(o.userAuth)}:o,a=W(e.data.template,e,s,void 0,{sessionEnv:m})||f;a+=u;let g=W(e.data.user_template||"",e,s,void 0,{sessionEnv:m});t==null||t({type:`info:llmNodeRunner:${e.id}`,content:a}),t==null||t({type:`info:llmNodeRunner:${e.id}`,content:g});let y=($=e==null?void 0:e.data)==null?void 0:$.window_size,h=Number(y);(!Number.isInteger(h)||h<=0)&&(h=5);let w=Ce(e,s),x=Ne(e,s),T=(await((j=o.getMessages)==null?void 0:j.call(o))??[]).slice(-h),P=T.filter(I=>I&&typeof I.role=="string"&&typeof I.content=="string");P.length!==T.length&&console.warn(`Filtered ${T.length-P.length} invalid messages from history`);let A=fo(P,p,w,x);await po(d,A,o.conn,t,e,l,n,s,r,o,i)}async function po(o,e,s,t,n,r,i,l,d,f,u){var c;let p=Date.now();if(!((c=f.env)!=null&&c.AI))throw new Error("AI binding is required for LLM node");return new Promise(async(m,a)=>{var j,I,_,U,H,E,J;let g,y={},h,w="none",x=!1,R,T=!1,P=!1,A=0,M=0,b=(j=n==null?void 0:n.data)==null?void 0:j.sendReasoning,F=b!==!1;try{let L=(I=n==null?void 0:n.data)==null?void 0:I.model,Y=Array.isArray(L)?L[0]:L||"gpt_5_nano",N=Kt(n==null?void 0:n.data),O=await lt(Y,f,N);if(!O)throw new Error(`Model '${Y}' not found in registry`);g=O.modelHandle,y=O.effectiveParams||{},w=O.reasoning.kind;let C=St(O.reasoning,(_=n==null?void 0:n.data)==null?void 0:_.reasoningEffort);x=F&&Jt(O.reasoning);let V=typeof((U=n==null?void 0:n.data)==null?void 0:U.reasoningMaxTokens)=="number"?n.data.reasoningMaxTokens:void 0;h=Gt(O.provider,{effort:C,exposeReasoning:x,maxTokens:V}),C&&(t==null||t({type:"info:llmNodeRunner:reasoningEffort",content:C})),console.log(`[reasoning] ${JSON.stringify({model:Y,provider:O.provider,capability:O.reasoning,requestedEffort:((H=n==null?void 0:n.data)==null?void 0:H.reasoningEffort)??null,resolvedEffort:C??null,sendReasoning:F,exposeReasoning:x,providerOptions:h??null},null,2)}`);for(let q of O.paramAdjustments??[])t==null||t({type:"warn:llmNodeRunner",content:q});t==null||t({type:"info:llmNodeRunner:model",content:Y}),t==null||t({type:"info:llmNodeRunner:generationParams",content:{...(E=n==null?void 0:n.data)!=null&&E.generationPreset?{preset:n.data.generationPreset}:{},...y,...w!=="none"?{reasoning:w,configuredSendReasoning:b,sendReasoning:F,exposeReasoning:x,...C?{effort:C}:{}}:{}}})}catch(L){throw t==null||t({type:"error:llmNodeRunner",content:`Model error: ${String(L)}`}),L}let $=await uo(f,l,n,t);if((J=f.memoryConfig)!=null&&J.enabled){let{recall:L}=await import("./recall-IABRCSHY.js");$.recall=L(f,l,void 0,t)}console.log(`[tools] node ${n.id} loaded ${Object.keys($).length}: ${Object.keys($).join(", ")||"(none)"}`),t==null||t({type:"info:llmNodeRunner:toolsLoaded",content:{nodeId:n.id,tools:Object.keys($)}});try{let L=ao({model:g,system:o,messages:e,stopWhen:(()=>{var q;let O=!!$.readSkillRef?10:5,C=Number(((q=n.data)==null?void 0:q.max_steps)??O),V=Number.isFinite(C)?Math.max(1,Math.min(30,C)):O;return io(V)})(),...Xt(y),...h?{providerOptions:h}:{},tools:$,onFinish:async N=>{var Et,Lt;let O=N.text||"",C=N.reasoningText??((Et=N.reasoning)==null?void 0:Et.text)??"";if(console.log(`[reasoning] done: deltas=${A} chars=${M} result.reasoningText=${C.length} finishReason=${N.finishReason??"n/a"} reasoningTokens=${((Lt=N.usage)==null?void 0:Lt.reasoningTokens)??"n/a"}`),F&&x&&!T&&C&&s){T=!0;try{k(s,D.SERVER_REASONING_STREAM,C)}catch(We){console.warn("Failed to send finished reasoning over connection",We)}}let V={id:co(),role:"assistant",type:"text",content:O,ts:Date.now()};r&&(f.setMessages?await f.setMessages(V):t==null||t({type:"error:llmNodeRunner",content:"setMessages callback missing"})),s&&F&&T&&!P&&(P=!0,k(s,D.SERVER_REASONING_STREAM_COMPLETE,JSON.stringify({}))),r&&s&&k(s,D.SERVER_TEXT_STREAM_COMPLETE,JSON.stringify({})),i==null||i((n==null?void 0:n.id)||"llm_result",O),t==null||t({type:"info:llmNodeRunner:onFinish",content:JSON.stringify(N)});let q=Date.now()-p,ze=R?R-p:void 0;u==null||u({type:"llm_telemetry",payload:{nodeId:n.id,totalLatency:q,timeToFirstToken:ze,model:N.response.modelId,usage:N.usage}}),u==null||u({type:"llm_result",payload:{result:N}})},onStepFinish:async N=>{let O=(C,V=200)=>{let q=typeof C=="string"?C:JSON.stringify(C);return q?q.length>V?`${q.slice(0,V)}\u2026(+${q.length-V})`:q:""};if(N.toolCalls&&N.toolCalls.length>0){for(let C of N.toolCalls)console.log(`[tools] \u2192 ${C.toolName}(${O(C.args??C.input)})`);t==null||t({type:`info:llmNodeRunner:toolCalls:${n.id}`,content:JSON.stringify(N.toolCalls)})}if(N.toolResults&&N.toolResults.length>0){for(let C of N.toolResults)console.log(`[tools] \u2190 ${C.toolName} \u2192 ${O(C.result??C.output)}`);t==null||t({type:`info:llmNodeRunner:toolResults:${n.id}`,content:JSON.stringify(N.toolResults)})}await lo(N,n,f,t)},experimental_onToolCallStart:N=>{var O;t==null||t({type:"tool:execution",content:{nodeId:n.id,toolName:(O=N==null?void 0:N.toolCall)==null?void 0:O.toolName,status:"start"}})},experimental_onToolCallFinish:N=>{var O,C;t==null||t({type:"tool:execution",content:{nodeId:n.id,toolName:(O=N==null?void 0:N.toolCall)==null?void 0:O.toolName,status:((C=N==null?void 0:N.toolOutput)==null?void 0:C.type)==="tool-error"?"error":"success"}})},onError:N=>{t==null||t({type:"error:llmNodeRunner",content:"Execution error"}),a(N)},onChunk:N=>{if(N.chunk.type==="reasoning-delta"){let C=N.chunk.text??N.chunk.delta??"";if(C&&(T=!0,A+=1,M+=C.length,A===1&&console.log("[reasoning] \u2713 first reasoning-delta received")),F&&s&&C)try{k(s,D.SERVER_REASONING_STREAM,C)}catch(V){console.warn("Failed to send reasoning chunk over connection",V)}return}if(N.chunk.type==="text-delta"){if(R||(R=Date.now()),s&&F&&T&&!P){P=!0;try{k(s,D.SERVER_REASONING_STREAM_COMPLETE,JSON.stringify({}))}catch(C){console.warn("Failed to send reasoning complete over connection",C)}}return}u==null||u({type:N.chunk.type,payload:{nodeId:n.id,chunk:N.chunk}});let O=`llm_chunk:${N.chunk.type}`;t==null||t({type:O,content:{...N}})}}),Y=async()=>{let N="";for await(let O of L.fullStream)if(O.type==="text-delta"){if(N+=O.text,r&&s)try{k(s,D.SERVER_TEXT_STREAM,O.text)}catch(C){console.warn("Failed to send chunk over connection",C)}}else if(O.type==="finish-step"&&O.finishReason==="tool-calls"){if(r&&s&&N.trim())try{k(s,D.SERVER_TEXT_STREAM_COMPLETE,JSON.stringify({}))}catch(C){console.warn("Failed to flush text segment over connection",C)}N=""}};await Promise.all([L,Y()]),m(),t==null||t({type:"node:execution",content:{nodeId:n.id,nodeType:n.type,status:"success"}})}catch(L){t==null||t({type:"node:execution",content:{nodeId:n.id,nodeType:n.type,status:"error",error:String(L)}}),a(L)}})}function fo(o,e,s,t){let n=!!(s&&s.length>0),r=!!t,i=n||r,d=o.length>0&&o[o.length-1].role==="user"?o[o.length-1]:void 0,f=u=>{let p=[],c="";if(r&&(c+=`[Attached files]
|
|
30
|
+
`:"")+c)}}return s}function Ce(o,e){var t,n,r,i,l,d;let s=[];if((t=o.data)!=null&&t.varMapping&&Array.isArray(o.data.varMapping))for(let f of o.data.varMapping){let u=f.from;if(!u)continue;let p=!1;if(u==="images")p=!0;else{let c=u.indexOf(".");if(c!==-1){let m=u.substring(0,c),a=u.substring(c+1).split(".")[0],g=(i=(r=(n=e.flowData)==null?void 0:n.state)==null?void 0:r.nodes)==null?void 0:i.find(y=>y.id===m);if(g){let h=G(g).find(w=>w.name===a);(h==null?void 0:h.type)==="image"&&(p=!0)}}}if(p){let c=v(u,{context:e.context||{},results:e.results||{},nodes:((d=(l=e.flowData)==null?void 0:l.state)==null?void 0:d.nodes)||[]});Array.isArray(c)&&s.push(...c)}}return s}var no=it({"../tools/composioTool.ts":()=>import("./composioTool-44B637WM.js"),"../tools/convertTempMessure.ts":()=>import("./convertTempMessure-5CAGRLBY.js"),"../tools/httpTool.ts":()=>import("./httpTool-MRMZWSXQ.js"),"../tools/recall.ts":()=>import("./recall-IABRCSHY.js"),"../tools/skillTool.ts":()=>import("./skillTool-BSQFKZGK.js"),"../tools/tempTool.ts":()=>import("./tempTool-2RXAF56M.js"),"../tools/twitter.ts":()=>import("./twitter-OMDEG7T2.js"),"../tools/vectorize.ts":()=>import("./vectorize-UJXIDL2E.js")});var ro=it({});function Mt(o,e,s,t,n){var i;if(!((i=t.memoryConfig)!=null&&i.enabled)||!t.memoryConfig.toolCache||!s.cacheable||!e||typeof e.execute!="function")return e;let r=e.execute.bind(e);return e.execute=async(l,...d)=>{var c;if(!t.getContextIndex)return r(l,...d);let f=await xt(l),p=(await t.getContextIndex()).find(m=>{if(m.domain!=="tool")return!1;let a=It(m.meta);return a.toolName===o&&a.paramsHash===f});if(p){let m=await((c=t.getContext)==null?void 0:c.call(t,p.ref));if((m==null?void 0:m.data)!=null&&It(m.meta).truncated!==!0){n==null||n({type:"info:memory:cacheHit",content:{ref:m.ref,toolName:o}});try{return JSON.parse(m.data)}catch{return m.data}}}return r(l,...d)},e}async function lo(o,e,s,t){var u,p;if(!((u=s.memoryConfig)!=null&&u.enabled)||!s.setContext||s.cycle==null)return;let n=o.toolCalls??[],r=o.toolResults??[];if(!n.length||!r.length)return;let i=new Map;for(let c of r)c!=null&&c.toolCallId&&i.set(c.toolCallId,c);let l=Array.isArray((p=e==null?void 0:e.data)==null?void 0:p.tools)?e.data.tools:[],d=new Map;for(let c of l)c&&typeof c.id=="string"&&d.set(c.id,c);let f=new Map;for(let c of Object.values(s.toolDefs??{}))c&&c.name&&f.set(c.name,c);for(let c of n){let m=c.toolCallId,a=c.toolName,g=i.get(m);if(!a||!g||a==="readSkillRef")continue;let y=c.args??c.input,h=g.result??g.output,w=!1,x="",R="tool",T="",P=f.get(a);P&&P.kind==="skill"&&(w=!0,x=`skill:${a}`,R="skill",T=`Skill instructions for ${a}`),x||(x=await Wt(a,y),T=zt(y,h));let A=d.get(a)??l.find(F=>F.id===a),M=await xt(y),b=typeof h=="string"?h:JSON.stringify(h??null);await s.setContext({ref:x,domain:R,description:T,data:b,cycle:s.cycle,meta:JSON.stringify({toolName:a,paramsHash:M,cacheable:(A==null?void 0:A.cacheable)===!0})}),t==null||t({type:"info:memory:updated",content:{ref:x}})}}async function uo(o,e,s,t){var p;let n=Array.isArray((p=s==null?void 0:s.data)==null?void 0:p.tools)?s.data.tools:[];if(n.length===0)return{};let r={},i=c=>{var x,R;let m=typeof(c==null?void 0:c.description)=="string"?c.description:"",a=c==null?void 0:c.inputSchema,g;try{let T=(a==null?void 0:a.shape)??(typeof((x=a==null?void 0:a._def)==null?void 0:x.shape)=="function"?a._def.shape():(R=a==null?void 0:a._def)==null?void 0:R.shape);T&&typeof T=="object"&&(g=T)}catch{}let y=g?Object.keys(g):[],h=m?`description="${m.length>120?m.slice(0,120)+"\u2026":m}"`:"description=(none)",w=y.length?`inputSchema={${y.join(", ")}}`:"inputSchema=(none)";return`${h} ${w}`},l=(()=>{let c=[],m=[],a=[],g=[];for(let h=0;h<n.length;h++){let w=n[h];!w||typeof w!="object"||typeof w.id!="string"?g.push(h):w.kind==="builtin"?c.push(w.id):w.kind==="skill"?a.push(w.id):w.kind==="http"||w.kind==="mcp"||w.kind==="composio"?m.push(w.id):g.push(h)}let y=[];return c.length&&y.push(`builtin[${c.join(", ")}]`),m.length&&y.push(`custom[${m.join(", ")}]`),a.length&&y.push(`skill[${a.join(", ")}]`),g.length&&y.push(`invalid@[${g.join(", ")}]`),y.join(" ")||"(none)"})();console.log(`[tools] node ${s.id} requested (${n.length}): ${l}`);let d=!1,f=async()=>{if(d&&o.toolDefs)return o.toolDefs;if(!o.env)return o.toolDefs=o.toolDefs||{},d=!0,o.toolDefs;try{let c=await re(o.env),m={};for(let a of c)a&&a.id&&(m[a.id]=a);o.toolDefs=m}catch(c){t==null||t({type:"error:llmNodeRunner",content:`Failed to load custom tool defs: ${String(c)}`}),o.toolDefs=o.toolDefs||{}}return d=!0,o.toolDefs},u=[];for(let c=0;c<n.length;c++){let m=n[c];if(!m||typeof m!="object"||typeof m.id!="string"||m.kind!=="builtin"&&m.kind!=="http"&&m.kind!=="mcp"&&m.kind!=="composio"&&m.kind!=="skill"){t==null||t({type:"error:llmNodeRunner",content:`Invalid tool descriptor at index ${c}: expected { kind: 'http'|'mcp'|'composio'|'builtin'|'skill', id: string, params?: any }`});continue}let a=m;if(a.kind!=="builtin"){let y=(await f())[a.id];if(!y){console.error(`[tools] \u2717 custom '${a.id}': not found for tenant`),t==null||t({type:"error:llmNodeRunner",content:`custom tool '${a.id}' not found for this tenant`});continue}if(a.kind==="composio"){try{let w=await oe(y,o,e,t),x=Object.keys(w);for(let[R,T]of Object.entries(w))r[R]=Mt(R,T,a,o,t);console.log(`[tools] \u2713 composio '${a.id}' \u2192 ${x.length} tool(s)`)}catch(w){console.error(`[tools] \u2717 composio '${a.id}': ${String(w)}`),t==null||t({type:"error:llmNodeRunner",content:`Error loading composio tool '${a.id}': ${String(w)}`})}continue}if(a.kind==="skill"){if(y.kind!=="skill"){console.error(`[tools] \u2717 skill '${a.id}': row is of kind '${y.kind}', not 'skill'`),t==null||t({type:"error:llmNodeRunner",content:`tool '${a.id}' is not a skill`});continue}let w=y.name;if(r[w]){t==null||t({type:"warn:llmNodeRunner",content:`tool name collision on '${w}' \u2014 builtin/other already registered, skipping skill '${a.id}'`});continue}try{r[w]=ie(y,o,e,t),u.push(y);let x=typeof y.execution=="string"?JSON.parse(y.execution):y.execution||{},R=Array.isArray(x.references)?x.references.map(T=>T==null?void 0:T.name):[];console.log(`[tools] \u2713 skill '${a.id}' \u2192 '${w}' (refs: ${R.join(", ")||"none"})`),t==null||t({type:"info:skill:registered",content:{skill:w,refCount:R.length,refs:R}})}catch(x){console.error(`[tools] \u2717 skill '${a.id}': ${String(x)}`),t==null||t({type:"error:llmNodeRunner",content:`Error loading skill tool '${a.id}': ${String(x)}`})}continue}let h=y.name;if(r[h]){t==null||t({type:"warn:llmNodeRunner",content:`tool name collision on '${h}' \u2014 builtin already registered, skipping custom tool '${a.id}'`});continue}try{let w=ne(y,o,e,t);r[h]=Mt(h,w,a,o,t),console.log(`[tools] \u2713 custom '${a.id}' \u2192 '${h}'`),console.log(`[tools] ${i(r[h])}`)}catch(w){console.error(`[tools] \u2717 custom '${a.id}': ${String(w)}`),t==null||t({type:"error:llmNodeRunner",content:`Error loading custom tool '${a.id}': ${String(w)}`})}continue}if(!ee[a.id]){console.error(`[tools] \u2717 builtin '${a.id}': not in registry`),t==null||t({type:"error:llmNodeRunner",content:`Tool '${a.id}' not found in registry`});continue}try{let g;try{g=await no(`../tools/${a.id}.ts`)}catch{g=await ro(`../tools/${a.id}.js`)}let y;if(g[a.id])y=g[a.id];else if(g.default)y=g.default;else if(g.create)y=g.create;else{let A=Object.values(g);A.length>0&&(y=A[0])}if(!y){t==null||t({type:"error:llmNodeRunner",content:`No factory export found for tool '${a.id}'`});continue}let h,w,x={};if(a.params&&typeof a.params=="object"){if(typeof a.params.description=="string"?h=a.params.description:a.params.description!==void 0&&(t==null||t({type:"error:llmNodeRunner",content:`Invalid description for tool '${a.id}' \u2014 must be a string`})),a.params.inputSchema!==void 0){let A=a.params.inputSchema;typeof A=="object"&&(typeof A.safeParse=="function"||A._def)?w=A:typeof A=="object"&&A!==null&&A.type==="object"&&A.properties?(w=se(A),w||t==null||t({type:"error:llmNodeRunner",content:`Invalid inputSchema for tool '${a.id}' \u2014 must be a Zod schema or JSON Schema object`})):t==null||t({type:"error:llmNodeRunner",content:`Invalid inputSchema for tool '${a.id}' \u2014 must be a Zod schema or JSON Schema object`})}a.params.defaults!==void 0?typeof a.params.defaults=="object"&&a.params.defaults!==null&&!Array.isArray(a.params.defaults)?x=a.params.defaults:(t==null||t({type:"error:llmNodeRunner",content:`Invalid defaults for tool '${a.id}' \u2014 must be an object`}),x={}):a.params.source!==void 0||a.params.target!==void 0?(t==null||t({type:"error:llmNodeRunner",content:`Invalid params for tool '${a.id}' \u2014 legacy top-level source/target not supported; use params.defaults instead`}),x={}):x={}}let R=y(o,e,x,t);h&&R&&typeof R=="object"&&(R.description=h),w&&R&&typeof R=="object"&&(R.inputSchema=w),r[a.id]=Mt(a.id,R,a,o,t);let T=[];h&&T.push("description"),w&&T.push("inputSchema"),Object.keys(x).length&&T.push(`defaults(${Object.keys(x).join(",")})`);let P=T.length?` [overrides: ${T.join(", ")}]`:"";console.log(`[tools] \u2713 builtin '${a.id}'${P}`),console.log(`[tools] ${i(R)}`)}catch(g){console.error(`[tools] \u2717 builtin '${a.id}': ${String(g)}`),t==null||t({type:"error:llmNodeRunner",content:`Error loading tool '${a.id}': ${String(g)}`});continue}}if(u.length>0)if(r.readSkillRef)t==null||t({type:"warn:llmNodeRunner",content:"tool name collision on 'readSkillRef' \u2014 builtin/other already registered, skipping readSkillRef tool"});else try{r.readSkillRef=ae(o,u,e,t),console.log(`[tools] \u2713 registered readSkillRef tool for ${u.length} skill(s)`),t==null||t({type:"info:skill:readSkillRefRegistered",content:{skills:u.map(c=>c.name)}})}catch(c){console.error(`[tools] \u2717 failed to load readSkillRef tool: ${String(c)}`)}return r}async function Dt(o,e,s,t,n,r,i){var M,b,F,$,j;`${e.id}`,t==null||t({type:"node:execution",content:{nodeId:e.id,nodeType:e.type,status:"start"}});let l=!1;try{let I=(M=s.flowData)==null?void 0:M.state;if(I&&I.edges&&I.nodes){let _=I.edges.filter(U=>U.source===e.id);if(_.length>0){let U=I.nodes.find(H=>H.id===_[0].target);U&&U.type==="answerNode"&&(l=!0)}}}catch(I){console.error("Error determining next node for streaming:",I)}let d=W(e.data.template,e,s,t,{sessionEnv:o});(!d||!d.trim())&&(d="Answer straight forward to the user, dont offer any other option to continue");let f=d,u="";if((b=o.memoryConfig)!=null&&b.enabled){let I=await((F=o.getContextIndex)==null?void 0:F.call(o))??[];u=Bt(I),d+=u}let p=W(e.data.user_template||"",e,s,t,{sessionEnv:o}),c=I=>I&&Object.fromEntries(Object.keys(I).map(_=>[_,"[redacted]"])),m=o!=null&&o.secrets||o!=null&&o.userAuth?{...o,secrets:c(o.secrets),userAuth:c(o.userAuth)}:o,a=W(e.data.template,e,s,void 0,{sessionEnv:m})||f;a+=u;let g=W(e.data.user_template||"",e,s,void 0,{sessionEnv:m});t==null||t({type:`info:llmNodeRunner:${e.id}`,content:a}),t==null||t({type:`info:llmNodeRunner:${e.id}`,content:g});let y=($=e==null?void 0:e.data)==null?void 0:$.window_size,h=Number(y);(!Number.isInteger(h)||h<=0)&&(h=5);let w=Ce(e,s),x=Ne(e,s),T=(await((j=o.getMessages)==null?void 0:j.call(o))??[]).slice(-h),P=T.filter(I=>I&&typeof I.role=="string"&&typeof I.content=="string");P.length!==T.length&&console.warn(`Filtered ${T.length-P.length} invalid messages from history`);let A=fo(P,p,w,x);await po(d,A,o.conn,t,e,l,n,s,r,o,i)}async function po(o,e,s,t,n,r,i,l,d,f,u){var c;let p=Date.now();if(!((c=f.env)!=null&&c.AI))throw new Error("AI binding is required for LLM node");return new Promise(async(m,a)=>{var j,I,_,U,H,E,J;let g,y={},h,w="none",x=!1,R,T=!1,P=!1,A=0,M=0,b=(j=n==null?void 0:n.data)==null?void 0:j.sendReasoning,F=b!==!1;try{let L=(I=n==null?void 0:n.data)==null?void 0:I.model,Y=Array.isArray(L)?L[0]:L||"gpt_5_nano",N=Kt(n==null?void 0:n.data),O=await lt(Y,f,N);if(!O)throw new Error(`Model '${Y}' not found in registry`);g=O.modelHandle,y=O.effectiveParams||{},w=O.reasoning.kind;let C=St(O.reasoning,(_=n==null?void 0:n.data)==null?void 0:_.reasoningEffort);x=F&&Jt(O.reasoning);let V=typeof((U=n==null?void 0:n.data)==null?void 0:U.reasoningMaxTokens)=="number"?n.data.reasoningMaxTokens:void 0;h=Gt(O.provider,{effort:C,exposeReasoning:x,maxTokens:V}),C&&(t==null||t({type:"info:llmNodeRunner:reasoningEffort",content:C})),console.log(`[reasoning] ${JSON.stringify({model:Y,provider:O.provider,capability:O.reasoning,requestedEffort:((H=n==null?void 0:n.data)==null?void 0:H.reasoningEffort)??null,resolvedEffort:C??null,sendReasoning:F,exposeReasoning:x,providerOptions:h??null},null,2)}`);for(let q of O.paramAdjustments??[])t==null||t({type:"warn:llmNodeRunner",content:q});t==null||t({type:"info:llmNodeRunner:model",content:Y}),t==null||t({type:"info:llmNodeRunner:generationParams",content:{...(E=n==null?void 0:n.data)!=null&&E.generationPreset?{preset:n.data.generationPreset}:{},...y,...w!=="none"?{reasoning:w,configuredSendReasoning:b,sendReasoning:F,exposeReasoning:x,...C?{effort:C}:{}}:{}}})}catch(L){throw t==null||t({type:"error:llmNodeRunner",content:`Model error: ${String(L)}`}),L}let $=await uo(f,l,n,t);if((J=f.memoryConfig)!=null&&J.enabled){let{recall:L}=await import("./recall-IABRCSHY.js");$.recall=L(f,l,void 0,t)}console.log(`[tools] node ${n.id} loaded ${Object.keys($).length}: ${Object.keys($).join(", ")||"(none)"}`),t==null||t({type:"info:llmNodeRunner:toolsLoaded",content:{nodeId:n.id,tools:Object.keys($)}});try{let L=ao({model:g,system:o,messages:e,stopWhen:(()=>{var q;let O=!!$.readSkillRef?10:5,C=Number(((q=n.data)==null?void 0:q.max_steps)??O),V=Number.isFinite(C)?Math.max(1,Math.min(30,C)):O;return io(V)})(),...Xt(y),...h?{providerOptions:h}:{},tools:$,onFinish:async N=>{var Et,Lt;let O=N.text||"",C=N.reasoningText??((Et=N.reasoning)==null?void 0:Et.text)??"";if(console.log(`[reasoning] done: deltas=${A} chars=${M} result.reasoningText=${C.length} finishReason=${N.finishReason??"n/a"} reasoningTokens=${((Lt=N.usage)==null?void 0:Lt.reasoningTokens)??"n/a"}`),F&&x&&!T&&C&&s){T=!0;try{k(s,D.SERVER_REASONING_STREAM,C)}catch(We){console.warn("Failed to send finished reasoning over connection",We)}}let V={id:co(),role:"assistant",type:"text",content:O,ts:Date.now()};r&&(f.setMessages?await f.setMessages(V):t==null||t({type:"error:llmNodeRunner",content:"setMessages callback missing"})),s&&F&&T&&!P&&(P=!0,k(s,D.SERVER_REASONING_STREAM_COMPLETE,JSON.stringify({}))),r&&s&&k(s,D.SERVER_TEXT_STREAM_COMPLETE,JSON.stringify({})),i==null||i((n==null?void 0:n.id)||"llm_result",O),t==null||t({type:"info:llmNodeRunner:onFinish",content:JSON.stringify(N)});let q=Date.now()-p,ze=R?R-p:void 0;u==null||u({type:"llm_telemetry",payload:{nodeId:n.id,totalLatency:q,timeToFirstToken:ze,model:N.response.modelId,usage:N.usage}}),u==null||u({type:"llm_result",payload:{result:N}})},onStepFinish:async N=>{let O=(C,V=200)=>{let q=typeof C=="string"?C:JSON.stringify(C);return q?q.length>V?`${q.slice(0,V)}\u2026(+${q.length-V})`:q:""};if(N.toolCalls&&N.toolCalls.length>0){for(let C of N.toolCalls)console.log(`[tools] \u2192 ${C.toolName}(${O(C.args??C.input)})`);t==null||t({type:`info:llmNodeRunner:toolCalls:${n.id}`,content:JSON.stringify(N.toolCalls)})}if(N.toolResults&&N.toolResults.length>0){for(let C of N.toolResults)console.log(`[tools] \u2190 ${C.toolName} \u2192 ${O(C.result??C.output)}`);t==null||t({type:`info:llmNodeRunner:toolResults:${n.id}`,content:JSON.stringify(N.toolResults)})}await lo(N,n,f,t)},experimental_onToolCallStart:N=>{var O;t==null||t({type:"tool:execution",content:{nodeId:n.id,toolName:(O=N==null?void 0:N.toolCall)==null?void 0:O.toolName,status:"start"}})},experimental_onToolCallFinish:N=>{var O,C;t==null||t({type:"tool:execution",content:{nodeId:n.id,toolName:(O=N==null?void 0:N.toolCall)==null?void 0:O.toolName,status:((C=N==null?void 0:N.toolOutput)==null?void 0:C.type)==="tool-error"?"error":"success"}})},onError:N=>{t==null||t({type:"error:llmNodeRunner",content:"Execution error"}),a(N)},onChunk:N=>{if(N.chunk.type==="reasoning-delta"){let C=N.chunk.text??N.chunk.delta??"";if(C&&(T=!0,A+=1,M+=C.length,A===1&&console.log("[reasoning] \u2713 first reasoning-delta received")),F&&s&&C)try{k(s,D.SERVER_REASONING_STREAM,C)}catch(V){console.warn("Failed to send reasoning chunk over connection",V)}return}if(N.chunk.type==="text-delta"){if(R||(R=Date.now()),s&&F&&T&&!P){P=!0;try{k(s,D.SERVER_REASONING_STREAM_COMPLETE,JSON.stringify({}))}catch(C){console.warn("Failed to send reasoning complete over connection",C)}}return}u==null||u({type:N.chunk.type,payload:{nodeId:n.id,chunk:N.chunk}});let O=`llm_chunk:${N.chunk.type}`;t==null||t({type:O,content:{...N}})}}),Y=async()=>{let N="";for await(let O of L.fullStream)if(O.type==="text-delta"){if(N+=O.text,r&&s)try{k(s,D.SERVER_TEXT_STREAM,O.text)}catch(C){console.warn("Failed to send chunk over connection",C)}}else if(O.type==="finish-step"&&O.finishReason==="tool-calls"){if(r&&s&&N.trim())try{k(s,D.SERVER_TEXT_STREAM_COMPLETE,JSON.stringify({}))}catch(C){console.warn("Failed to flush text segment over connection",C)}N=""}};await Promise.all([L,Y()]),m(),t==null||t({type:"node:execution",content:{nodeId:n.id,nodeType:n.type,status:"success"}})}catch(L){t==null||t({type:"node:execution",content:{nodeId:n.id,nodeType:n.type,status:"error",error:String(L)}}),a(L)}})}function fo(o,e,s,t){let n=!!(s&&s.length>0),r=!!t,i=n||r,d=o.length>0&&o[o.length-1].role==="user"?o[o.length-1]:void 0,f=u=>{let p=[],c="";if(r&&(c+=`[Attached files]
|
|
31
31
|
${t}
|
|
32
32
|
[End of attached files]
|
|
33
33
|
|
package/package.json
CHANGED
package/dist/chunk-PEF6QKTR.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var b=(u=>(u.START_NODE="startNode",u.CLASSIFIER_NODE="classifierNode",u.MEMO_NODE="memoNode",u.LLM_NODE="llmNode",u.ANSWER_NODE="answerNode",u.API_NODE="apiNode",u))(b||{});var R=/^[a-zA-Z][a-zA-Z0-9_]*$/,T=["string","number","boolean","json"];function S(e){let t=e==null?void 0:e.inputs;if(!Array.isArray(t))return[];let o=[],n=new Set;for(let r of t){let s=typeof(r==null?void 0:r.name)=="string"?r.name.trim():"";if(!s||!R.test(s)||n.has(s))continue;n.add(s);let u=T.includes(r==null?void 0:r.type)?r.type:"string";o.push({name:s,label:typeof(r==null?void 0:r.label)=="string"&&r.label.trim()?r.label.trim():void 0,type:u,required:(r==null?void 0:r.required)===!0,default:(r==null?void 0:r.default)??void 0})}return o}function v(e,t){let o=e.label||e.name;switch(e.type){case"number":{let n=typeof t=="number"?t:Number(String(t).trim());return Number.isFinite(n)?{value:n}:{error:`"${o}" must be a number`}}case"boolean":{if(typeof t=="boolean")return{value:t};let n=String(t).trim().toLowerCase();return["true","1","yes","si","s\xED"].includes(n)?{value:!0}:["false","0","no"].includes(n)?{value:!1}:{error:`"${o}" must be true or false`}}case"json":{if(typeof t=="object")return{value:t};try{return{value:JSON.parse(String(t))}}catch{return{error:`"${o}" must be valid JSON`}}}default:return{value:typeof t=="string"?t:String(t)}}}function h(e){return e==null||typeof e=="string"&&e.trim()===""}function k(e,t){let o={},n=[],r=t??{};for(let s of e){let u=r[s.name],d=h(u)?s.default:u;if(h(d)){s.required&&n.push(`"${s.label||s.name}" is required`);continue}let{value:p,error:O}=v(s,d);O?n.push(O):o[s.name]=p}return{values:o,errors:n}}function M(e){return typeof e=="string"?e:e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}function C(e,t,o){let n=t.user_input;if(typeof n=="string"&&n.trim())return n;let r=e.filter(u=>u.name!=="user_input"&&t[u.name]!==void 0).map(u=>`- ${u.label||u.name}: ${M(t[u.name])}`),s=(o==null?void 0:o.trim())||"Automated execution";return r.length>0?`${s}
|
|
2
|
-
${r.join(`
|
|
3
|
-
`)}`:s}function F(e,t){if(!t)return e;if(e==null)return;let o=t.split("."),n=e;for(let r of o){if(n==null)return;n=n[r]}return n}function P(e){switch(e){case"startNode":return[{name:"user_input",path:"user_input",label:"User input",source:"default"},{name:"images",path:"images",label:"User images",type:"image",source:"default"},{name:"files",path:"files",label:"User docs",type:"file",source:"default"}];case"llmNode":return[{name:"output",path:"",label:"LLM text",source:"default"}];case"apiNode":return[{name:"ok",path:"ok",source:"default"},{name:"status",path:"status",source:"default"},{name:"data",path:"data",source:"default"}];case"classifierNode":return[{name:"classification",path:"classification",source:"default"}];case"memoNode":return[{name:"context",path:"",label:"Retrieved context",source:"default"}];case"answerNode":return[];default:return[]}}function L(e){return e.type!=="startNode"?[]:S(e.data).map(t=>({name:t.name,path:t.name,label:t.label,type:t.type==="json"?"object":t.type,source:"default"}))}function V(e){var r;let t=P(e.type),o=((r=e.data)==null?void 0:r.outVars)||[],n=[...t,...L(e).filter(s=>!t.some(u=>u.name===s.name))];for(let s of o){let u=n.findIndex(d=>d.name===s.name);u>=0?n[u]={...s,source:"user"}:n.push({...s,source:"user"})}return n}function $(e,t){var N,a,g,y,i,l,x;if(e==="user_input")return(N=t.context)==null?void 0:N.user_input;if(e==="images")return(a=t.context)==null?void 0:a.user_images;if(e==="classified_id")return(g=t.context)==null?void 0:g.classified_id;if(e==="files"||e==="file_content")return((y=t.context)==null?void 0:y.files)||((i=t.context)==null?void 0:i.file_content);let o=e.indexOf(".");if(o===-1)return t.nodes.find(E=>E.id===e)?(l=t.results)==null?void 0:l[e]:Object.prototype.hasOwnProperty.call(t.context??{},e)?t.context[e]:void 0;let n=e.substring(0,o),r=e.substring(o+1),s=t.nodes.find(f=>f.id===n);if(!s)return;let u=V(s),d=r.split(".")[0],p=u.find(f=>f.name===d);if(!p)return;let O=(x=t.results)==null?void 0:x[n],m=F(O,p.path??"");if((m==null||m==="")&&s.type==="startNode"){let f=p.path||p.name;f&&Object.prototype.hasOwnProperty.call(t.context??{},f)&&(m=t.context[f])}let c=r.substring(d.length+1);return c?F(m,c):m}var D="\0__ORA_OB__\0",w="\0__ORA_CB__\0";function W(e,t,o,n){var O,m;if(!e)return e;let r=(n==null?void 0:n.serializeNonStrings)??!1,s=e.replace(/\\\{\{/g,D).replace(/\\\}\}/g,w),u={...o.context||{}};if((O=t.data)!=null&&O.varMapping&&Array.isArray(t.data.varMapping))for(let c of t.data.varMapping){let N=c.var||c.to,a=c.from;if(N&&a){let g=!1,y=!1;if(a==="images")g=!0;else if(a==="files"||a==="file_content")y=!0;else{let l=a.indexOf(".");if(l!==-1){let x=a.substring(0,l),f=a.substring(l+1).split(".")[0],E=o.nodes.find(I=>I.id===x);if(E){let _=V(E).find(A=>A.name===f);(_==null?void 0:_.type)==="image"&&(g=!0),(_==null?void 0:_.type)==="file"&&(y=!0)}}}if(g||y)continue;let i=$(a,o);(i==null||i==="")&&(i=c.default??""),u[N]=i}}let d=/\{\{\s*([^}]+?)\s*\}\}/g;s=s.replace(d,(c,N)=>{var g,y;let a=N.trim();if(a.startsWith("secrets.")){let i=a.slice(8);return o.secrets?Object.prototype.hasOwnProperty.call(o.secrets,i)?o.secrets[i]:((y=n==null?void 0:n.onError)==null||y.call(n,`Secret "${i}" is not defined for this tenant`),c):((g=n==null?void 0:n.onError)==null||g.call(n,`Secret reference {{ ${a} }} cannot be resolved (no secrets context)`),c)}if(Object.prototype.hasOwnProperty.call(u,a)){let i=u[a],l;return typeof i=="string"?l=i:typeof i=="object"&&i!==null?l=r?JSON.stringify(i):JSON.stringify(i,null,2):i!=null?l=r?JSON.stringify(i):String(i):l="",l}return c});let p=s.match(/\{\{\s*[^}]+\s*\}\}/g);return p&&((m=n==null?void 0:n.onError)==null||m.call(n,`Mismatch detected: Unmatched placeholders found: ${p}`)),s=s.split(D).join("{{").split(w).join("}}"),s}export{b as a,R as b,S as c,k as d,C as e,F as f,P as g,V as h,$ as i,W as j};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as a,e as b}from"./chunk-P6H7GK2Z.js";import"./chunk-PEF6QKTR.js";import"./chunk-V6JSMX5A.js";import"./chunk-U56YWPSI.js";import"./chunk-3TXHFKDN.js";export{a as customHttpTool,b as default};
|