@dnotifier-realtime/dnotifier 1.1.27 → 1.1.30
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/agent-runtime/backendClient.d.ts +19 -2
- package/dist/agent-runtime/backendClient.js +1 -1
- package/dist/agent-runtime/descriptors.js +1 -1
- package/dist/agent-runtime/errors.js +1 -1
- package/dist/agent-runtime/ids.js +1 -1
- package/dist/agent-runtime/index.js +1 -1
- package/dist/agent-runtime/localCompletions.js +1 -1
- package/dist/agent-runtime/mcp/client.js +1 -1
- package/dist/agent-runtime/mcp/registry.js +1 -1
- package/dist/agent-runtime/observability.js +1 -1
- package/dist/agent-runtime/permissions.js +1 -1
- package/dist/agent-runtime/runtime.js +1 -1
- package/dist/agent-runtime/schema.js +1 -1
- package/dist/agent-runtime/toolRegistry.js +1 -1
- package/dist/cjs/dnotifier.js +1 -1
- package/dist/cjs/providers/openai.js +1 -1
- package/dist/cjs/transport/httpTransport.js +1 -1
- package/dist/cjs/transport/websocketTransport.js +1 -1
- package/dist/cjs/utils/buffer.js +1 -1
- package/dist/cjs/utils/frame.js +1 -1
- package/dist/cjs/utils/id.js +1 -1
- package/dist/cjs/utils/payload.js +1 -1
- package/dist/config/endpoints.d.ts +5 -2
- package/dist/config/endpoints.js +1 -1
- package/dist/dnotifier.cjs +7 -7
- package/dist/dnotifier.d.ts +36 -7
- package/dist/dnotifier.js +1 -1
- package/dist/providers/openai.js +1 -1
- package/dist/transport/httpTransport.js +1 -1
- package/dist/transport/websocketTransport.js +1 -1
- package/dist/utils/buffer.js +1 -1
- package/dist/utils/frame.js +1 -1
- package/dist/utils/id.js +1 -1
- package/dist/utils/logs.js +1 -1
- package/dist/utils/payload.js +1 -1
- package/dist/workflow/agent.d.ts +6 -1
- package/dist/workflow/agent.js +1 -1
- package/dist/workflow/capabilities.d.ts +13 -0
- package/dist/workflow/capabilities.js +1 -0
- package/dist/workflow/context.d.ts +5 -0
- package/dist/workflow/context.js +1 -1
- package/dist/workflow/errors.js +1 -1
- package/dist/workflow/graphParents.js +1 -1
- package/dist/workflow/ids.js +1 -1
- package/dist/workflow/jsonPayload.js +1 -1
- package/dist/workflow/mockObservabilityClient.js +1 -1
- package/dist/workflow/observability.js +1 -1
- package/dist/workflow/remoteAgentClient.d.ts +2 -0
- package/dist/workflow/remoteAgentClient.js +1 -1
- package/dist/workflow/remoteAgentProtocol.d.ts +2 -5
- package/dist/workflow/remoteAgentProtocol.js +1 -1
- package/dist/workflow/runner.js +1 -1
- package/dist/workflow/stepTypes.js +1 -1
- package/dist/workflow/workflow.d.ts +6 -1
- package/dist/workflow/workflow.js +1 -1
- package/dist/workflow/workflowObservabilityClient.js +1 -1
- package/package.json +1 -1
package/dist/workflow/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WorkflowError}from'./errors.js';import{formatParentStepId,resolveRecordedParentStepId}from'./graphParents.js';import{STEP_TYPE_AGENT,STEP_TYPE_CUSTOM,toLogStepType}from'./stepTypes.js';import{isRemoteAgentRef}from'./remoteAgentProtocol.js';import{invokeRemoteAgent}from'./remoteAgentClient.js';import{runAgentLoop,workflowTraceFromContext}from'../agent-runtime/runtime.js';function usageFromResponse(_0x1ded5b){var _0x245c26,_0x1f824f,_0x24f784,_0x280fef,_0x54c362,_0x517b2,_0x34cf08,_0x2559da,_0x263ec1,_0x497c81,_0x20437b,_0x549648,_0x3e0f89;const _0x4ce29c=null!==(_0x24f784=null!==(_0x1f824f=null===(_0x245c26=null==_0x1ded5b?void 0x0:_0x1ded5b['data'])||void 0x0===_0x245c26?void 0x0:_0x245c26['usage'])&&void 0x0!==_0x1f824f?_0x1f824f:null==_0x1ded5b?void 0x0:_0x1ded5b['usage'])&&void 0x0!==_0x24f784?_0x24f784:null;return _0x4ce29c&&'object'==typeof _0x4ce29c?{'tokensIn':null!==(_0x517b2=null!==(_0x54c362=null!==(_0x280fef=_0x4ce29c['prompt_tokens'])&&void 0x0!==_0x280fef?_0x280fef:_0x4ce29c['input_tokens'])&&void 0x0!==_0x54c362?_0x54c362:_0x4ce29c['tokensIn'])&&void 0x0!==_0x517b2?_0x517b2:0x0,'tokensOut':null!==(_0x497c81=null!==(_0x263ec1=null!==(_0x2559da=null!==(_0x34cf08=_0x4ce29c['completion_tokens'])&&void 0x0!==_0x34cf08?_0x34cf08:_0x4ce29c['output_tokens'])&&void 0x0!==_0x2559da?_0x2559da:_0x4ce29c['total_tokens'])&&void 0x0!==_0x263ec1?_0x263ec1:_0x4ce29c['tokensOut'])&&void 0x0!==_0x497c81?_0x497c81:0x0,'model':null!==(_0x3e0f89=null!==(_0x549648=null===(_0x20437b=null==_0x1ded5b?void 0x0:_0x1ded5b['data'])||void 0x0===_0x20437b?void 0x0:_0x20437b['model'])&&void 0x0!==_0x549648?_0x549648:_0x4ce29c['model'])&&void 0x0!==_0x3e0f89?_0x3e0f89:null}:{'tokensIn':0x0,'tokensOut':0x0,'model':null};}function firstNonEmpty(..._0x593fef){for(const _0x4c6f23 of _0x593fef)if(null!=_0x4c6f23&&''!==String(_0x4c6f23)['trim']())return _0x4c6f23;return null;}function snapshot(_0x2bc78e){try{return void 0x0===_0x2bc78e?null:JSON['parse'](JSON['stringify'](_0x2bc78e));}catch{return String(_0x2bc78e);}}function apiInput(_0x3466b9){if(!_0x3466b9||'object'!=typeof _0x3466b9)return null!=_0x3466b9?_0x3466b9:null;const {label:_0xd8d002,dependsOn:_0x12ca4b,parentStepIds:_0x431eb4,branchKey:_0x29311c,siblingIndex:_0x291f4c,parentStepId:_0x45197f,input:_0x40ed26,..._0x1770b9}=_0x3466b9;return Object['keys'](_0x1770b9)['length']>0x0?_0x1770b9:null;}function resolveAgentEdgeStepId({agentStepId:_0x365ff6,output:_0x5a68ea,lastEdgeStepId:_0x2ca8ef=null}){var _0x8041b4,_0xc768f5;const _0x3b67f5=_0x5a68ea&&'object'==typeof _0x5a68ea&&'string'==typeof _0x5a68ea['lastStepId']&&''!==_0x5a68ea['lastStepId']['trim']()?_0x5a68ea['lastStepId']:null,_0xf063e1=null!=_0x2ca8ef&&''!==String(_0x2ca8ef)['trim']()?String(_0x2ca8ef):null;return null!==(_0xc768f5=null!==(_0x8041b4=null!=_0x3b67f5?_0x3b67f5:_0xf063e1)&&void 0x0!==_0x8041b4?_0x8041b4:_0x365ff6)&&void 0x0!==_0xc768f5?_0xc768f5:null;}function normalizeRunAgentsSpec(_0x5df5bc){if(Array['isArray'](_0x5df5bc))return _0x5df5bc['map']((_0x511e3c,_0x1e3980)=>{if('string'==typeof _0x511e3c)return{'name':_0x511e3c,'input':void 0x0,'key':String(_0x1e3980)};if(!_0x511e3c||'object'!=typeof _0x511e3c||!_0x511e3c['name'])throw new WorkflowError('runAgents\x20entry\x20requires\x20name');return{'name':_0x511e3c['name'],'input':_0x511e3c['input'],'key':String(_0x1e3980)};});if(_0x5df5bc&&'object'==typeof _0x5df5bc)return Object['entries'](_0x5df5bc)['map'](([_0x4d9cf6,_0x103b84])=>_0x103b84&&'object'==typeof _0x103b84&&'name'in _0x103b84?{'name':_0x103b84['name'],'input':_0x103b84['input'],'key':_0x4d9cf6}:{'name':_0x4d9cf6,'input':_0x103b84,'key':_0x4d9cf6});throw new WorkflowError('runAgents\x20expects\x20an\x20array\x20or\x20object\x20spec');}export{formatParentStepId}from'./graphParents.js';export class WorkflowContext{constructor({notifier:_0x3b163d,senderId:_0x24c83a,workflow:_0x4ec869,input:_0x3b0b51,state:_0xcd8e0b={},observability:_0x2547ec=null,executionId:_0x1f59c3=null,agentName:_0x38e309=null,entryStepId:_0x53b51f=null,traceParentStepId:_0x38971c=null,provider:_0x2dee20=null,model:_0x258779=null}){this['notifier']=_0x3b163d,this['senderId']=_0x24c83a,this['workflow']=_0x4ec869,this['input']=_0x3b0b51,this['state']=_0xcd8e0b,this['_observability']=_0x2547ec,this['_executionId']=_0x1f59c3,this['_observabilityEnabled']=Boolean(_0x4ec869['observability']&&_0x2547ec&&_0x1f59c3),this['agentName']=_0x38e309,this['_entryStepId']=_0x53b51f,this['_chainHeadStepId']=_0x53b51f,this['_traceParentStepId']=_0x38971c,this['_currentStepId']=null,this['rootStepId']=null,this['_terminalStepIds']=[],this['_lastEdgeStepId']=null,this['_aiProvider']=null!=_0x2dee20&&''!==_0x2dee20?_0x2dee20:null,this['_aiModel']=null!=_0x258779&&''!==_0x258779?_0x258779:null;}['getEndParentStepId'](){return this['_terminalStepIds']['length']>0x0?formatParentStepId(this['_terminalStepIds']):this['_entryStepId']?this['_entryStepId']:null;}['_markTerminalSteps'](_0x2311c4){this['_currentStepId']||(this['_terminalStepIds']=_0x2311c4['filter'](_0x36869a=>null!=_0x36869a&&''!==String(_0x36869a)['trim']()));}['_resolveParentStepId'](_0x5ea69d={}){return void 0x0!==_0x5ea69d['parentStepId']?_0x5ea69d['parentStepId']:this['_currentStepId']?this['_currentStepId']:this['_traceParentStepId']?this['_traceParentStepId']:this['_chainHeadStepId']?this['_chainHeadStepId']:this['_entryStepId']?this['_entryStepId']:null;}['exportTraceContext'](){var _0x40e4e1,_0x1eb6c3,_0x4f3f5b,_0x3087c0;return{'executionId':this['_executionId'],'workflowId':this['workflow']['name'],'parentStepId':null!==(_0x3087c0=null!==(_0x4f3f5b=null!==(_0x1eb6c3=null!==(_0x40e4e1=this['_currentStepId'])&&void 0x0!==_0x40e4e1?_0x40e4e1:this['_chainHeadStepId'])&&void 0x0!==_0x1eb6c3?_0x1eb6c3:this['_traceParentStepId'])&&void 0x0!==_0x4f3f5b?_0x4f3f5b:this['_entryStepId'])&&void 0x0!==_0x3087c0?_0x3087c0:null};}async['_invokeSdkApi'](_0x4ac71f,_0x5b0674,_0x4ff57c={}){var _0x5dd1a0,_0x548ef2,_0x73cd51,_0x5ead5e;const _0x469153=Date['now']();let _0x1a685f='ok',_0x4fb06e=null,_0xbf46f2=null;const _0x5cea4e=toLogStepType(_0x4ac71f);try{return _0x4fb06e=await _0x5b0674(),_0x4fb06e;}catch(_0x10dc21){throw _0x1a685f='error',_0xbf46f2={'message':null!==(_0x5dd1a0=null==_0x10dc21?void 0x0:_0x10dc21['message'])&&void 0x0!==_0x5dd1a0?_0x5dd1a0:String(_0x10dc21),'stack':null==_0x10dc21?void 0x0:_0x10dc21['stack']},_0x10dc21;}finally{if(this['_observabilityEnabled']){const _0x43d223=_0x4ff57c['usesTokens']?usageFromResponse(_0x4fb06e):{'tokensIn':0x0,'tokensOut':0x0,'model':null},_0x586dfb=firstNonEmpty(_0x4ff57c['model'],_0x43d223['model'],null===(_0x548ef2=this['notifier'])||void 0x0===_0x548ef2?void 0x0:_0x548ef2['currentModel']),_0x197c41=firstNonEmpty(_0x4ff57c['provider']),_0x3327a4=null!==(_0x73cd51=this['agentName'])&&void 0x0!==_0x73cd51?_0x73cd51:_0x4ac71f;await this['_observability']['recordStep'](this['_executionId'],{'apiName':_0x4ac71f,'agentName':this['agentName'],'kind':_0x3327a4,'type':_0x5cea4e,'label':null!==(_0x5ead5e=_0x4ff57c['label'])&&void 0x0!==_0x5ead5e?_0x5ead5e:_0x5cea4e,'status':_0x1a685f,'latencyMs':Date['now']()-_0x469153,'parentStepId':formatParentStepId(this['_currentStepId']),..._0x43d223,'model':_0x586dfb,'provider':_0x197c41,'input':snapshot(_0x4ff57c['input']),'output':snapshot(_0x4fb06e),'state':snapshot(this['state']),'error':_0xbf46f2});}}}async['_runAgentObserved'](_0x2d34a0,_0x356a95={}){var _0x505de1,_0x3ac5f8,_0x5b789a,_0x165b11,_0x496477,_0x38230d,_0x15fc25,_0x44022f,_0x32631c,_0x4278d2,_0x6a513c;const _0x3624d2=this['workflow']['getAgentRegistration'](_0x2d34a0);if(!_0x3624d2)throw new WorkflowError('Agent\x20not\x20found:\x20'+_0x2d34a0);const _0x4ca3ae=void 0x0!==_0x356a95['input']?_0x356a95['input']:this['input'],_0x31f237=resolveRecordedParentStepId({'parentStepId':_0x356a95['parentStepId'],'parentStepIds':_0x356a95['parentStepIds'],'dependsOn':_0x356a95['dependsOn'],'resolveParent':()=>this['_resolveParentStepId'](_0x356a95)}),_0x211505=this['_observabilityEnabled']?this['_observability']['allocateStepId']():null,_0x19475d=Date['now']();let _0x2fa294='ok',_0x100c7d=null,_0x13d80d=null;try{if(isRemoteAgentRef(_0x3624d2)){const _0xec914b=this['_executionId']?{'executionId':this['_executionId'],'workflowId':this['workflow']['name'],'parentStepId':null!==(_0x165b11=null!==(_0x5b789a=null!==(_0x3ac5f8=null!==(_0x505de1=null!=_0x211505?_0x211505:this['_currentStepId'])&&void 0x0!==_0x505de1?_0x505de1:this['_chainHeadStepId'])&&void 0x0!==_0x3ac5f8?_0x3ac5f8:this['_traceParentStepId'])&&void 0x0!==_0x5b789a?_0x5b789a:this['_entryStepId'])&&void 0x0!==_0x165b11?_0x165b11:null}:null,_0x242389=await invokeRemoteAgent({'notifier':this['notifier'],'senderId':this['senderId'],'receiverId':_0x3624d2['receiverId'],'agentName':_0x2d34a0,'input':_0x4ca3ae,'state':this['state'],'trace':_0xec914b,'timeoutMs':_0x356a95['timeoutMs']});return _0x242389['state']&&'object'==typeof _0x242389['state']&&Object['assign'](this['state'],_0x242389['state']),_0x100c7d=_0x242389['output'],{'output':_0x100c7d,'stepId':_0x211505,'edgeStepId':_0x211505};}const _0x1ca50a=_0x3624d2,_0x19b5a9=new WorkflowContext({'notifier':this['notifier'],'senderId':this['senderId'],'workflow':this['workflow'],'input':_0x4ca3ae,'state':this['state'],'observability':this['_observability'],'executionId':this['_executionId'],'agentName':_0x2d34a0,'entryStepId':this['_entryStepId'],'traceParentStepId':this['_traceParentStepId'],'provider':null!==(_0x496477=_0x1ca50a['provider'])&&void 0x0!==_0x496477?_0x496477:null,'model':null!==(_0x38230d=_0x1ca50a['model'])&&void 0x0!==_0x38230d?_0x38230d:null});return _0x19b5a9['_currentStepId']=_0x211505,_0x100c7d=await _0x1ca50a['run'](_0x19b5a9),_0x211505&&(_0x19b5a9['rootStepId']=_0x211505),{'output':_0x100c7d,'stepId':_0x211505,'edgeStepId':resolveAgentEdgeStepId({'agentStepId':_0x211505,'output':_0x100c7d,'lastEdgeStepId':_0x19b5a9['_lastEdgeStepId']})};}catch(_0x26a741){throw _0x2fa294='error',_0x13d80d={'message':null!==(_0x15fc25=null==_0x26a741?void 0x0:_0x26a741['message'])&&void 0x0!==_0x15fc25?_0x15fc25:String(_0x26a741),'stack':null==_0x26a741?void 0x0:_0x26a741['stack']},_0x26a741;}finally{if(this['_observabilityEnabled']&&_0x211505){const _0x1b377d=!isRemoteAgentRef(_0x3624d2)&&_0x3624d2?_0x3624d2:null;await this['_observability']['recordStep'](this['_executionId'],{'id':_0x211505,'parentStepId':_0x31f237,'branchKey':null!==(_0x44022f=_0x356a95['branchKey'])&&void 0x0!==_0x44022f?_0x44022f:null,'siblingIndex':null!==(_0x32631c=_0x356a95['siblingIndex'])&&void 0x0!==_0x32631c?_0x32631c:null,'agentName':_0x2d34a0,'kind':_0x2d34a0,'type':STEP_TYPE_AGENT,'label':_0x2d34a0,'status':_0x2fa294,'latencyMs':Date['now']()-_0x19475d,'model':null!==(_0x4278d2=null==_0x1b377d?void 0x0:_0x1b377d['model'])&&void 0x0!==_0x4278d2?_0x4278d2:null,'provider':null!==(_0x6a513c=null==_0x1b377d?void 0x0:_0x1b377d['provider'])&&void 0x0!==_0x6a513c?_0x6a513c:null,'input':snapshot(_0x4ca3ae),'output':snapshot(_0x100c7d),'state':snapshot(this['state']),'error':_0x13d80d}),this['rootStepId']=_0x211505,'ok'!==_0x2fa294||this['_currentStepId']||(this['_chainHeadStepId']=_0x211505);}}}async['runAgent'](_0x20b9d1,_0x88f04c={}){const {output:_0x2c1dc2,stepId:_0x17a1cf,edgeStepId:_0x363a8e}=await this['_runAgentObserved'](_0x20b9d1,_0x88f04c);if(!this['_currentStepId']){const _0x1a75c7=null!=_0x363a8e?_0x363a8e:_0x17a1cf;_0x1a75c7&&this['_markTerminalSteps']([_0x1a75c7]);}return _0x2c1dc2;}async['waitForMessage'](_0x16fa67={}){if(!this['notifier']||'function'!=typeof this['notifier']['_waitForInboundMessage'])throw new WorkflowError('waitForMessage\x20requires\x20a\x20DNotifier\x20instance');return this['notifier']['_waitForInboundMessage']({'timeoutMs':_0x16fa67['timeoutMs']});}async['runAgents'](_0x38e33d,_0x3cbef0={}){const _0x5a484b=normalizeRunAgentsSpec(_0x38e33d),_0x5dda2a=resolveRecordedParentStepId({'parentStepId':_0x3cbef0['parentStepId'],'resolveParent':()=>this['_resolveParentStepId'](_0x3cbef0)}),_0x5e1915=await Promise['all'](_0x5a484b['map']((_0xabfef5,_0x4e6e92)=>this['_runAgentObserved'](_0xabfef5['name'],{'input':_0xabfef5['input'],'parentStepId':_0x5dda2a,'siblingIndex':_0x4e6e92}))),_0x565d55=_0x5e1915['map'](_0x42b746=>_0x42b746['output']),_0x37c3bc=_0x5e1915['map'](_0xaabebe=>_0xaabebe['stepId']),_0x53e401=_0x5e1915['map'](_0x27448e=>{var _0x2aba86;return null!==(_0x2aba86=_0x27448e['edgeStepId'])&&void 0x0!==_0x2aba86?_0x2aba86:_0x27448e['stepId'];});if(this['_markTerminalSteps'](_0x53e401),Array['isArray'](_0x38e33d))return{'results':_0x565d55,'stepIds':_0x37c3bc};const _0x4e82ab={};return _0x5a484b['forEach']((_0x4ef383,_0x3da130)=>{_0x4e82ab[_0x4ef383['key']]=_0x565d55[_0x3da130];}),{'results':_0x4e82ab,'stepIds':_0x37c3bc};}async['sendAI'](_0x51b94c){var _0x219e2d,_0x388444,_0x20094f,_0x54547e,_0x2b4d1e,_0x5c916a;const _0x1e4742=null!==(_0x388444=null!==(_0x219e2d=null==_0x51b94c?void 0x0:_0x51b94c['provider'])&&void 0x0!==_0x219e2d?_0x219e2d:this['_aiProvider'])&&void 0x0!==_0x388444?_0x388444:void 0x0,_0x2ed521=null!==(_0x54547e=null!==(_0x20094f=null==_0x51b94c?void 0x0:_0x51b94c['model'])&&void 0x0!==_0x20094f?_0x20094f:this['_aiModel'])&&void 0x0!==_0x54547e?_0x54547e:void 0x0,_0x4366d8=this['agentName']?this['workflow']['getAgent'](this['agentName']):void 0x0;return(null==_0x4366d8?void 0x0:_0x4366d8['hasTools'])?this['_invokeSdkApi']('sendAI',()=>{var _0x3f54a2,_0x2845cf;return runAgentLoop({'notifier':this['notifier'],'agent':_0x4366d8,'input':null!==(_0x3f54a2=null==_0x51b94c?void 0x0:_0x51b94c['message'])&&void 0x0!==_0x3f54a2?_0x3f54a2:this['input'],'executionId':this['_executionId'],'userId':this['senderId'],'sessionId':null!==(_0x2845cf=null==_0x51b94c?void 0x0:_0x51b94c['sessionId'])&&void 0x0!==_0x2845cf?_0x2845cf:null,'signal':null==_0x51b94c?void 0x0:_0x51b94c['signal'],'maxToolRounds':null==_0x51b94c?void 0x0:_0x51b94c['maxToolRounds'],'provider':_0x1e4742,'model':_0x2ed521,'metadata':null==_0x51b94c?void 0x0:_0x51b94c['metadata'],'trace':workflowTraceFromContext(this)});},{'label':null==_0x51b94c?void 0x0:_0x51b94c['label'],'input':null!==(_0x2b4d1e=null==_0x51b94c?void 0x0:_0x51b94c['message'])&&void 0x0!==_0x2b4d1e?_0x2b4d1e:apiInput(_0x51b94c),'usesTokens':!0x0,'provider':_0x1e4742,'model':_0x2ed521}):this['_invokeSdkApi']('sendAI',()=>this['notifier']['sendAI']({'senderId':this['senderId'],..._0x51b94c,'provider':_0x1e4742,'model':_0x2ed521}),{'label':null==_0x51b94c?void 0x0:_0x51b94c['label'],'input':null!==(_0x5c916a=null==_0x51b94c?void 0x0:_0x51b94c['message'])&&void 0x0!==_0x5c916a?_0x5c916a:apiInput(_0x51b94c),'usesTokens':!0x0,'provider':_0x1e4742,'model':_0x2ed521});}async['fetchAIHistory'](_0x285404={}){return this['_invokeSdkApi']('fetchAIHistory',()=>this['notifier']['fetchAIHistory']({'senderId':this['senderId'],..._0x285404}),{'label':null==_0x285404?void 0x0:_0x285404['label'],'input':apiInput(_0x285404)});}async['search'](_0x1e2154){return this['_invokeSdkApi']('search',()=>this['notifier']['search']({'senderId':this['senderId'],'query':_0x1e2154['query'],'limit':_0x1e2154['limit'],'minSimilarity':_0x1e2154['minSimilarity'],'filterbySource':_0x1e2154['filterbySource']}),{'label':null==_0x1e2154?void 0x0:_0x1e2154['label'],'input':apiInput(_0x1e2154)});}async['addDocument'](_0x1f517a){return this['_invokeSdkApi']('addDocument',()=>this['notifier']['addDocument']({'senderId':this['senderId'],..._0x1f517a}),{'label':null==_0x1f517a?void 0x0:_0x1f517a['label'],'input':apiInput(_0x1f517a)});}async['updateDocument'](_0x33c10c){return this['_invokeSdkApi']('updateDocument',()=>this['notifier']['updateDocument']({'senderId':this['senderId'],..._0x33c10c}),{'label':null==_0x33c10c?void 0x0:_0x33c10c['label'],'input':apiInput(_0x33c10c)});}async['deleteDocument'](_0x539132){return this['_invokeSdkApi']('deleteDocument',()=>this['notifier']['deleteDocument']({'senderId':this['senderId'],..._0x539132}),{'label':null==_0x539132?void 0x0:_0x539132['label'],'input':apiInput(_0x539132)});}async['listDocuments'](_0x2952de={}){return this['_invokeSdkApi']('listDocuments',()=>this['notifier']['listDocuments']({'senderId':this['senderId'],..._0x2952de}),{'label':null==_0x2952de?void 0x0:_0x2952de['label'],'input':apiInput(_0x2952de)});}async['getDocument'](_0x51895b){return this['_invokeSdkApi']('getDocument',()=>this['notifier']['getDocument']({'senderId':this['senderId'],..._0x51895b}),{'label':null==_0x51895b?void 0x0:_0x51895b['label'],'input':apiInput(_0x51895b)});}async['recordStep'](_0x2e6bb2){var _0x13546e,_0x5ab43f,_0x34b891,_0x1b54e4,_0x4bb209,_0x30ef73,_0x44c892,_0x3ea7cf,_0x5a4237,_0x431cef,_0x5ad119,_0x2983c2;if(!this['_observabilityEnabled'])return;const _0x206d23=null!=_0x2e6bb2['type']?toLogStepType(_0x2e6bb2['type']):STEP_TYPE_CUSTOM;await this['_observability']['recordStep'](this['_executionId'],{..._0x2e6bb2,'apiName':null!==(_0x13546e=_0x2e6bb2['apiName'])&&void 0x0!==_0x13546e?_0x13546e:_0x2e6bb2['kind'],'agentName':null!==(_0x5ab43f=_0x2e6bb2['agentName'])&&void 0x0!==_0x5ab43f?_0x5ab43f:this['agentName'],'kind':null!==(_0x4bb209=null!==(_0x1b54e4=null!==(_0x34b891=_0x2e6bb2['agentName'])&&void 0x0!==_0x34b891?_0x34b891:this['agentName'])&&void 0x0!==_0x1b54e4?_0x1b54e4:_0x2e6bb2['kind'])&&void 0x0!==_0x4bb209?_0x4bb209:'custom','type':_0x206d23,'label':null!==(_0x30ef73=_0x2e6bb2['label'])&&void 0x0!==_0x30ef73?_0x30ef73:_0x206d23,'tokensIn':null!==(_0x44c892=_0x2e6bb2['tokensIn'])&&void 0x0!==_0x44c892?_0x44c892:0x0,'tokensOut':null!==(_0x3ea7cf=_0x2e6bb2['tokensOut'])&&void 0x0!==_0x3ea7cf?_0x3ea7cf:0x0,'model':null!==(_0x5a4237=_0x2e6bb2['model'])&&void 0x0!==_0x5a4237?_0x5a4237:null,'latencyMs':null!==(_0x431cef=_0x2e6bb2['latencyMs'])&&void 0x0!==_0x431cef?_0x431cef:0x0,'status':null!==(_0x5ad119=_0x2e6bb2['status'])&&void 0x0!==_0x5ad119?_0x5ad119:'ok','error':null!==(_0x2983c2=_0x2e6bb2['error'])&&void 0x0!==_0x2983c2?_0x2983c2:null,'parentStepId':null!=_0x2e6bb2['parentStepId']?formatParentStepId(_0x2e6bb2['parentStepId']):formatParentStepId(this['_currentStepId']),'input':snapshot(_0x2e6bb2['input']),'output':snapshot(_0x2e6bb2['output']),'state':snapshot(void 0x0!==_0x2e6bb2['state']?_0x2e6bb2['state']:this['state'])});}}
|
|
1
|
+
import{WorkflowError}from'./errors.js';import{formatParentStepId,resolveRecordedParentStepId}from'./graphParents.js';import{STEP_TYPE_AGENT,STEP_TYPE_CUSTOM,toLogStepType}from'./stepTypes.js';import{isRemoteAgentRef}from'./remoteAgentProtocol.js';import{invokeRemoteAgent}from'./remoteAgentClient.js';import{runAgentLoop,workflowTraceFromContext}from'../agent-runtime/runtime.js';function usageFromResponse(_0x5088c9){var _0x707e4e,_0xd5cc52,_0x2fa703,_0x1a09f5,_0x59b225,_0x1e7ab8,_0x4fcddd,_0x380d2e,_0xf45a29,_0x27c225,_0x55df66,_0x361d24,_0x48ac2b;const _0x253397=null!==(_0x2fa703=null!==(_0xd5cc52=null===(_0x707e4e=null==_0x5088c9?void 0x0:_0x5088c9['data'])||void 0x0===_0x707e4e?void 0x0:_0x707e4e['usage'])&&void 0x0!==_0xd5cc52?_0xd5cc52:null==_0x5088c9?void 0x0:_0x5088c9['usage'])&&void 0x0!==_0x2fa703?_0x2fa703:null;return _0x253397&&'object'==typeof _0x253397?{'tokensIn':null!==(_0x1e7ab8=null!==(_0x59b225=null!==(_0x1a09f5=_0x253397['prompt_tokens'])&&void 0x0!==_0x1a09f5?_0x1a09f5:_0x253397['input_tokens'])&&void 0x0!==_0x59b225?_0x59b225:_0x253397['tokensIn'])&&void 0x0!==_0x1e7ab8?_0x1e7ab8:0x0,'tokensOut':null!==(_0x27c225=null!==(_0xf45a29=null!==(_0x380d2e=null!==(_0x4fcddd=_0x253397['completion_tokens'])&&void 0x0!==_0x4fcddd?_0x4fcddd:_0x253397['output_tokens'])&&void 0x0!==_0x380d2e?_0x380d2e:_0x253397['total_tokens'])&&void 0x0!==_0xf45a29?_0xf45a29:_0x253397['tokensOut'])&&void 0x0!==_0x27c225?_0x27c225:0x0,'model':null!==(_0x48ac2b=null!==(_0x361d24=null===(_0x55df66=null==_0x5088c9?void 0x0:_0x5088c9['data'])||void 0x0===_0x55df66?void 0x0:_0x55df66['model'])&&void 0x0!==_0x361d24?_0x361d24:_0x253397['model'])&&void 0x0!==_0x48ac2b?_0x48ac2b:null}:{'tokensIn':0x0,'tokensOut':0x0,'model':null};}function firstNonEmpty(..._0x319848){for(const _0x2c62c1 of _0x319848)if(null!=_0x2c62c1&&''!==String(_0x2c62c1)['trim']())return _0x2c62c1;return null;}function snapshot(_0x3d7d4f){try{return void 0x0===_0x3d7d4f?null:JSON['parse'](JSON['stringify'](_0x3d7d4f));}catch{return String(_0x3d7d4f);}}function apiInput(_0x40fa7f){if(!_0x40fa7f||'object'!=typeof _0x40fa7f)return null!=_0x40fa7f?_0x40fa7f:null;const {label:_0x3cadf5,dependsOn:_0x243a7a,parentStepIds:_0x4ed89e,branchKey:_0x2ac16f,siblingIndex:_0x2c3ed5,parentStepId:_0x22e652,input:_0x523a61,..._0x746587}=_0x40fa7f;return Object['keys'](_0x746587)['length']>0x0?_0x746587:null;}function resolveAgentEdgeStepId({agentStepId:_0x52899c,output:_0x3aba14,lastEdgeStepId:_0x1b86b2=null}){var _0x15856a,_0x3c9584;const _0x468a20=_0x3aba14&&'object'==typeof _0x3aba14&&'string'==typeof _0x3aba14['lastStepId']&&''!==_0x3aba14['lastStepId']['trim']()?_0x3aba14['lastStepId']:null,_0x484d8c=null!=_0x1b86b2&&''!==String(_0x1b86b2)['trim']()?String(_0x1b86b2):null;return null!==(_0x3c9584=null!==(_0x15856a=null!=_0x468a20?_0x468a20:_0x484d8c)&&void 0x0!==_0x15856a?_0x15856a:_0x52899c)&&void 0x0!==_0x3c9584?_0x3c9584:null;}function normalizeRunAgentsSpec(_0x2cb461){if(Array['isArray'](_0x2cb461))return _0x2cb461['map']((_0x5ef4a4,_0x2b31c8)=>{if('string'==typeof _0x5ef4a4)return{'name':_0x5ef4a4,'input':void 0x0,'key':String(_0x2b31c8)};if(!_0x5ef4a4||'object'!=typeof _0x5ef4a4||!_0x5ef4a4['name'])throw new WorkflowError('runAgents\x20entry\x20requires\x20name');return{'name':_0x5ef4a4['name'],'input':_0x5ef4a4['input'],'key':String(_0x2b31c8)};});if(_0x2cb461&&'object'==typeof _0x2cb461)return Object['entries'](_0x2cb461)['map'](([_0x5d0fcc,_0x4966b0])=>_0x4966b0&&'object'==typeof _0x4966b0&&'name'in _0x4966b0?{'name':_0x4966b0['name'],'input':_0x4966b0['input'],'key':_0x5d0fcc}:{'name':_0x5d0fcc,'input':_0x4966b0,'key':_0x5d0fcc});throw new WorkflowError('runAgents\x20expects\x20an\x20array\x20or\x20object\x20spec');}export{formatParentStepId}from'./graphParents.js';export class WorkflowContext{constructor({notifier:_0x585bfa,senderId:_0x13d48e,workflow:_0x44cb0a,input:_0x4d58e5,state:_0x1970d3={},observability:_0x504bf4=null,executionId:_0x36fd7e=null,agentName:_0x139c7d=null,entryStepId:_0x570a69=null,traceParentStepId:_0x895407=null,provider:_0x22d203=null,model:_0x538c4e=null}){this['notifier']=_0x585bfa,this['senderId']=_0x13d48e,this['workflow']=_0x44cb0a,this['input']=_0x4d58e5,this['state']=_0x1970d3,this['_observability']=_0x504bf4,this['_executionId']=_0x36fd7e,this['_observabilityEnabled']=Boolean(_0x44cb0a['observability']&&_0x504bf4&&_0x36fd7e),this['agentName']=_0x139c7d,this['_entryStepId']=_0x570a69,this['_chainHeadStepId']=_0x570a69,this['_traceParentStepId']=_0x895407,this['_currentStepId']=null,this['rootStepId']=null,this['_terminalStepIds']=[],this['_lastEdgeStepId']=null,this['_aiProvider']=null!=_0x22d203&&''!==_0x22d203?_0x22d203:null,this['_aiModel']=null!=_0x538c4e&&''!==_0x538c4e?_0x538c4e:null;}['getEndParentStepId'](){return this['_terminalStepIds']['length']>0x0?formatParentStepId(this['_terminalStepIds']):this['_entryStepId']?this['_entryStepId']:null;}['_markTerminalSteps'](_0x54d3df){this['_currentStepId']||(this['_terminalStepIds']=_0x54d3df['filter'](_0x48a5de=>null!=_0x48a5de&&''!==String(_0x48a5de)['trim']()));}['_resolveParentStepId'](_0x39b845={}){return void 0x0!==_0x39b845['parentStepId']?_0x39b845['parentStepId']:this['_currentStepId']?this['_currentStepId']:this['_traceParentStepId']?this['_traceParentStepId']:this['_chainHeadStepId']?this['_chainHeadStepId']:this['_entryStepId']?this['_entryStepId']:null;}['exportTraceContext'](){var _0x467c86,_0x4adab4,_0x235a7d,_0x43a164;return{'executionId':this['_executionId'],'workflowId':this['workflow']['name'],'parentStepId':null!==(_0x43a164=null!==(_0x235a7d=null!==(_0x4adab4=null!==(_0x467c86=this['_currentStepId'])&&void 0x0!==_0x467c86?_0x467c86:this['_chainHeadStepId'])&&void 0x0!==_0x4adab4?_0x4adab4:this['_traceParentStepId'])&&void 0x0!==_0x235a7d?_0x235a7d:this['_entryStepId'])&&void 0x0!==_0x43a164?_0x43a164:null};}async['_invokeSdkApi'](_0x2fef73,_0x456c1b,_0x1659a0={}){var _0x353d50,_0x6961bf,_0x4e5b5e,_0x76fa71;const _0x58c730=Date['now']();let _0x19a000='ok',_0x5f8356=null,_0x408a5d=null;const _0x291db2=toLogStepType(_0x2fef73);try{return _0x5f8356=await _0x456c1b(),_0x5f8356;}catch(_0x1d1161){throw _0x19a000='error',_0x408a5d={'message':null!==(_0x353d50=null==_0x1d1161?void 0x0:_0x1d1161['message'])&&void 0x0!==_0x353d50?_0x353d50:String(_0x1d1161),'stack':null==_0x1d1161?void 0x0:_0x1d1161['stack']},_0x1d1161;}finally{if(this['_observabilityEnabled']){const _0x40f1e1=_0x1659a0['usesTokens']?usageFromResponse(_0x5f8356):{'tokensIn':0x0,'tokensOut':0x0,'model':null},_0x5d7c15=firstNonEmpty(_0x1659a0['model'],_0x40f1e1['model'],null===(_0x6961bf=this['notifier'])||void 0x0===_0x6961bf?void 0x0:_0x6961bf['currentModel']),_0x22d08f=firstNonEmpty(_0x1659a0['provider']),_0x1e66bc=null!==(_0x4e5b5e=this['agentName'])&&void 0x0!==_0x4e5b5e?_0x4e5b5e:_0x2fef73;await this['_observability']['recordStep'](this['_executionId'],{'apiName':_0x2fef73,'agentName':this['agentName'],'kind':_0x1e66bc,'type':_0x291db2,'label':null!==(_0x76fa71=_0x1659a0['label'])&&void 0x0!==_0x76fa71?_0x76fa71:_0x291db2,'status':_0x19a000,'latencyMs':Date['now']()-_0x58c730,'parentStepId':formatParentStepId(this['_currentStepId']),..._0x40f1e1,'model':_0x5d7c15,'provider':_0x22d08f,'input':snapshot(_0x1659a0['input']),'output':snapshot(_0x5f8356),'state':snapshot(this['state']),'error':_0x408a5d});}}}async['_runAgentObserved'](_0x52600b,_0x6a8fc={}){var _0x14dc1f,_0x155a87,_0x50e597,_0x6f9f72,_0xd3111c,_0xe56578,_0x5251ea,_0x22b594,_0x5e737a,_0x12ebfd,_0x168da5;const _0x52453f=this['workflow']['getAgentRegistration'](_0x52600b);if(!_0x52453f)throw new WorkflowError('Agent\x20not\x20found:\x20'+_0x52600b);const _0x2ce6aa=void 0x0!==_0x6a8fc['input']?_0x6a8fc['input']:this['input'],_0x1a23c1=resolveRecordedParentStepId({'parentStepId':_0x6a8fc['parentStepId'],'parentStepIds':_0x6a8fc['parentStepIds'],'dependsOn':_0x6a8fc['dependsOn'],'resolveParent':()=>this['_resolveParentStepId'](_0x6a8fc)}),_0xd86ff0=this['_observabilityEnabled']?this['_observability']['allocateStepId']():null,_0x16459e=Date['now']();let _0x568aa8='ok',_0x372674=null,_0x5b742a=null;try{if(isRemoteAgentRef(_0x52453f)){const _0x2f483d=this['_executionId']?{'executionId':this['_executionId'],'workflowId':this['workflow']['name'],'parentStepId':null!==(_0x6f9f72=null!==(_0x50e597=null!==(_0x155a87=null!==(_0x14dc1f=null!=_0xd86ff0?_0xd86ff0:this['_currentStepId'])&&void 0x0!==_0x14dc1f?_0x14dc1f:this['_chainHeadStepId'])&&void 0x0!==_0x155a87?_0x155a87:this['_traceParentStepId'])&&void 0x0!==_0x50e597?_0x50e597:this['_entryStepId'])&&void 0x0!==_0x6f9f72?_0x6f9f72:null}:null,_0x1500b7=await invokeRemoteAgent({'notifier':this['notifier'],'senderId':this['senderId'],'receiverId':_0x52453f['receiverId'],'agentName':_0x52600b,'input':_0x2ce6aa,'state':this['state'],'trace':_0x2f483d,'timeoutMs':_0x6a8fc['timeoutMs']});return _0x1500b7['state']&&'object'==typeof _0x1500b7['state']&&Object['assign'](this['state'],_0x1500b7['state']),_0x372674=_0x1500b7['output'],{'output':_0x372674,'stepId':_0xd86ff0,'edgeStepId':_0xd86ff0};}const _0xacd5a0=_0x52453f,_0x57c0b7=new WorkflowContext({'notifier':this['notifier'],'senderId':this['senderId'],'workflow':this['workflow'],'input':_0x2ce6aa,'state':this['state'],'observability':this['_observability'],'executionId':this['_executionId'],'agentName':_0x52600b,'entryStepId':this['_entryStepId'],'traceParentStepId':this['_traceParentStepId'],'provider':null!==(_0xd3111c=_0xacd5a0['provider'])&&void 0x0!==_0xd3111c?_0xd3111c:null,'model':null!==(_0xe56578=_0xacd5a0['model'])&&void 0x0!==_0xe56578?_0xe56578:null});return _0x57c0b7['_currentStepId']=_0xd86ff0,_0x372674=await _0xacd5a0['run'](_0x57c0b7),_0xd86ff0&&(_0x57c0b7['rootStepId']=_0xd86ff0),{'output':_0x372674,'stepId':_0xd86ff0,'edgeStepId':resolveAgentEdgeStepId({'agentStepId':_0xd86ff0,'output':_0x372674,'lastEdgeStepId':_0x57c0b7['_lastEdgeStepId']})};}catch(_0x246a59){throw _0x568aa8='error',_0x5b742a={'message':null!==(_0x5251ea=null==_0x246a59?void 0x0:_0x246a59['message'])&&void 0x0!==_0x5251ea?_0x5251ea:String(_0x246a59),'stack':null==_0x246a59?void 0x0:_0x246a59['stack']},_0x246a59;}finally{if(this['_observabilityEnabled']&&_0xd86ff0){const _0x29ff41=!isRemoteAgentRef(_0x52453f)&&_0x52453f?_0x52453f:null;await this['_observability']['recordStep'](this['_executionId'],{'id':_0xd86ff0,'parentStepId':_0x1a23c1,'branchKey':null!==(_0x22b594=_0x6a8fc['branchKey'])&&void 0x0!==_0x22b594?_0x22b594:null,'siblingIndex':null!==(_0x5e737a=_0x6a8fc['siblingIndex'])&&void 0x0!==_0x5e737a?_0x5e737a:null,'agentName':_0x52600b,'kind':_0x52600b,'type':STEP_TYPE_AGENT,'label':_0x52600b,'status':_0x568aa8,'latencyMs':Date['now']()-_0x16459e,'model':null!==(_0x12ebfd=null==_0x29ff41?void 0x0:_0x29ff41['model'])&&void 0x0!==_0x12ebfd?_0x12ebfd:null,'provider':null!==(_0x168da5=null==_0x29ff41?void 0x0:_0x29ff41['provider'])&&void 0x0!==_0x168da5?_0x168da5:null,'input':snapshot(_0x2ce6aa),'output':snapshot(_0x372674),'state':snapshot(this['state']),'error':_0x5b742a}),this['rootStepId']=_0xd86ff0,'ok'!==_0x568aa8||this['_currentStepId']||(this['_chainHeadStepId']=_0xd86ff0);}}}async['runAgent'](_0x466359,_0x2de767={}){const {output:_0x5939c6,stepId:_0x1c60c3,edgeStepId:_0x4c8f15}=await this['_runAgentObserved'](_0x466359,_0x2de767);if(!this['_currentStepId']){const _0x4d3111=null!=_0x4c8f15?_0x4c8f15:_0x1c60c3;_0x4d3111&&this['_markTerminalSteps']([_0x4d3111]);}return _0x5939c6;}async['waitForMessage'](_0x493f02={}){if(!this['notifier']||'function'!=typeof this['notifier']['_waitForInboundMessage'])throw new WorkflowError('waitForMessage\x20requires\x20a\x20DNotifier\x20instance');return this['notifier']['_waitForInboundMessage']({'timeoutMs':_0x493f02['timeoutMs']});}async['runAgents'](_0x53ff4c,_0x5d63a8={}){const _0x203a1f=normalizeRunAgentsSpec(_0x53ff4c),_0x123d41=resolveRecordedParentStepId({'parentStepId':_0x5d63a8['parentStepId'],'resolveParent':()=>this['_resolveParentStepId'](_0x5d63a8)}),_0x5a513c=await Promise['all'](_0x203a1f['map']((_0x11416b,_0x3d235d)=>this['_runAgentObserved'](_0x11416b['name'],{'input':_0x11416b['input'],'parentStepId':_0x123d41,'siblingIndex':_0x3d235d}))),_0x1d22e3=_0x5a513c['map'](_0xcd6dae=>_0xcd6dae['output']),_0x94c519=_0x5a513c['map'](_0xf95c35=>_0xf95c35['stepId']),_0x123bb5=_0x5a513c['map'](_0x396fea=>{var _0x332721;return null!==(_0x332721=_0x396fea['edgeStepId'])&&void 0x0!==_0x332721?_0x332721:_0x396fea['stepId'];});if(this['_markTerminalSteps'](_0x123bb5),Array['isArray'](_0x53ff4c))return{'results':_0x1d22e3,'stepIds':_0x94c519};const _0x351cd7={};return _0x203a1f['forEach']((_0x29fb6e,_0x5b385e)=>{_0x351cd7[_0x29fb6e['key']]=_0x1d22e3[_0x5b385e];}),{'results':_0x351cd7,'stepIds':_0x94c519};}async['sendAI'](_0x1cd4ea){var _0xb621cd,_0x49c239,_0x151005,_0x1e0296,_0x2d4265,_0x3f548b;const _0x408444=null!==(_0x49c239=null!==(_0xb621cd=null==_0x1cd4ea?void 0x0:_0x1cd4ea['provider'])&&void 0x0!==_0xb621cd?_0xb621cd:this['_aiProvider'])&&void 0x0!==_0x49c239?_0x49c239:void 0x0,_0x58e2d1=null!==(_0x1e0296=null!==(_0x151005=null==_0x1cd4ea?void 0x0:_0x1cd4ea['model'])&&void 0x0!==_0x151005?_0x151005:this['_aiModel'])&&void 0x0!==_0x1e0296?_0x1e0296:void 0x0,_0x4578b2=this['agentName']?this['workflow']['getAgent'](this['agentName']):void 0x0;return(null==_0x4578b2?void 0x0:_0x4578b2['hasTools'])?this['_invokeSdkApi']('sendAI',()=>{var _0x479f52,_0x5170d3;return runAgentLoop({'notifier':this['notifier'],'agent':_0x4578b2,'input':null!==(_0x479f52=null==_0x1cd4ea?void 0x0:_0x1cd4ea['message'])&&void 0x0!==_0x479f52?_0x479f52:this['input'],'executionId':this['_executionId'],'userId':this['senderId'],'sessionId':null!==(_0x5170d3=null==_0x1cd4ea?void 0x0:_0x1cd4ea['sessionId'])&&void 0x0!==_0x5170d3?_0x5170d3:null,'signal':null==_0x1cd4ea?void 0x0:_0x1cd4ea['signal'],'maxToolRounds':null==_0x1cd4ea?void 0x0:_0x1cd4ea['maxToolRounds'],'provider':_0x408444,'model':_0x58e2d1,'metadata':null==_0x1cd4ea?void 0x0:_0x1cd4ea['metadata'],'trace':workflowTraceFromContext(this)});},{'label':null==_0x1cd4ea?void 0x0:_0x1cd4ea['label'],'input':null!==(_0x2d4265=null==_0x1cd4ea?void 0x0:_0x1cd4ea['message'])&&void 0x0!==_0x2d4265?_0x2d4265:apiInput(_0x1cd4ea),'usesTokens':!0x0,'provider':_0x408444,'model':_0x58e2d1}):this['_invokeSdkApi']('sendAI',()=>this['notifier']['sendAI']({'senderId':this['senderId'],..._0x1cd4ea,'provider':_0x408444,'model':_0x58e2d1}),{'label':null==_0x1cd4ea?void 0x0:_0x1cd4ea['label'],'input':null!==(_0x3f548b=null==_0x1cd4ea?void 0x0:_0x1cd4ea['message'])&&void 0x0!==_0x3f548b?_0x3f548b:apiInput(_0x1cd4ea),'usesTokens':!0x0,'provider':_0x408444,'model':_0x58e2d1});}async['fetchAIHistory'](_0x3e78aa={}){return this['_invokeSdkApi']('fetchAIHistory',()=>this['notifier']['fetchAIHistory']({'senderId':this['senderId'],..._0x3e78aa}),{'label':null==_0x3e78aa?void 0x0:_0x3e78aa['label'],'input':apiInput(_0x3e78aa)});}async['search'](_0x508ce8){return this['_invokeSdkApi']('search',()=>this['notifier']['search']({'senderId':this['senderId'],..._0x508ce8}),{'label':null==_0x508ce8?void 0x0:_0x508ce8['label'],'input':apiInput(_0x508ce8)});}async['addDocument'](_0xbf5a38){return this['_invokeSdkApi']('addDocument',()=>this['notifier']['addDocument']({'senderId':this['senderId'],..._0xbf5a38}),{'label':null==_0xbf5a38?void 0x0:_0xbf5a38['label'],'input':apiInput(_0xbf5a38)});}async['updateDocument'](_0x87c025){return this['_invokeSdkApi']('updateDocument',()=>this['notifier']['updateDocument']({'senderId':this['senderId'],..._0x87c025}),{'label':null==_0x87c025?void 0x0:_0x87c025['label'],'input':apiInput(_0x87c025)});}async['deleteDocument'](_0x5c3ea1){return this['_invokeSdkApi']('deleteDocument',()=>this['notifier']['deleteDocument']({'senderId':this['senderId'],..._0x5c3ea1}),{'label':null==_0x5c3ea1?void 0x0:_0x5c3ea1['label'],'input':apiInput(_0x5c3ea1)});}async['listDocuments'](_0x348a28={}){return this['_invokeSdkApi']('listDocuments',()=>this['notifier']['listDocuments']({'senderId':this['senderId'],..._0x348a28}),{'label':null==_0x348a28?void 0x0:_0x348a28['label'],'input':apiInput(_0x348a28)});}async['getDocument'](_0x546df2){return this['_invokeSdkApi']('getDocument',()=>this['notifier']['getDocument']({'senderId':this['senderId'],..._0x546df2}),{'label':null==_0x546df2?void 0x0:_0x546df2['label'],'input':apiInput(_0x546df2)});}async['recordStep'](_0x16fcbf){var _0x34a917,_0x1136da,_0x508315,_0x254ce2,_0x22baf3,_0x5dcc21,_0x56056c,_0x3c4013,_0x26b84f,_0x4159f4,_0x284764,_0x2a769f;if(!this['_observabilityEnabled'])return;const _0x4f9b48=null!=_0x16fcbf['type']?toLogStepType(_0x16fcbf['type']):STEP_TYPE_CUSTOM;await this['_observability']['recordStep'](this['_executionId'],{..._0x16fcbf,'apiName':null!==(_0x34a917=_0x16fcbf['apiName'])&&void 0x0!==_0x34a917?_0x34a917:_0x16fcbf['kind'],'agentName':null!==(_0x1136da=_0x16fcbf['agentName'])&&void 0x0!==_0x1136da?_0x1136da:this['agentName'],'kind':null!==(_0x22baf3=null!==(_0x254ce2=null!==(_0x508315=_0x16fcbf['agentName'])&&void 0x0!==_0x508315?_0x508315:this['agentName'])&&void 0x0!==_0x254ce2?_0x254ce2:_0x16fcbf['kind'])&&void 0x0!==_0x22baf3?_0x22baf3:'custom','type':_0x4f9b48,'label':null!==(_0x5dcc21=_0x16fcbf['label'])&&void 0x0!==_0x5dcc21?_0x5dcc21:_0x4f9b48,'tokensIn':null!==(_0x56056c=_0x16fcbf['tokensIn'])&&void 0x0!==_0x56056c?_0x56056c:0x0,'tokensOut':null!==(_0x3c4013=_0x16fcbf['tokensOut'])&&void 0x0!==_0x3c4013?_0x3c4013:0x0,'model':null!==(_0x26b84f=_0x16fcbf['model'])&&void 0x0!==_0x26b84f?_0x26b84f:null,'latencyMs':null!==(_0x4159f4=_0x16fcbf['latencyMs'])&&void 0x0!==_0x4159f4?_0x4159f4:0x0,'status':null!==(_0x284764=_0x16fcbf['status'])&&void 0x0!==_0x284764?_0x284764:'ok','error':null!==(_0x2a769f=_0x16fcbf['error'])&&void 0x0!==_0x2a769f?_0x2a769f:null,'parentStepId':null!=_0x16fcbf['parentStepId']?formatParentStepId(_0x16fcbf['parentStepId']):formatParentStepId(this['_currentStepId']),'input':snapshot(_0x16fcbf['input']),'output':snapshot(_0x16fcbf['output']),'state':snapshot(void 0x0!==_0x16fcbf['state']?_0x16fcbf['state']:this['state'])});}}
|
package/dist/workflow/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export class WorkflowError extends Error{constructor(
|
|
1
|
+
export class WorkflowError extends Error{constructor(_0x2d6014,_0x4d9cb7={}){super(_0x2d6014),this['name']='WorkflowError',this['agentName']=_0x4d9cb7['agentName'],_0x4d9cb7['cause']&&(this['cause']=_0x4d9cb7['cause']);}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function formatParentStepId(
|
|
1
|
+
export function formatParentStepId(_0x3dbded){if(null==_0x3dbded)return null;if(Array['isArray'](_0x3dbded)){const _0x350cf9=_0x3dbded['filter'](_0x1ec297=>null!=_0x1ec297&&''!==String(_0x1ec297)['trim']());return _0x350cf9['length']>0x0?_0x350cf9['join'](','):null;}const _0xe5390f=String(_0x3dbded)['trim']();return''===_0xe5390f?null:_0xe5390f;}export function resolveGraphParentStepId(_0x5046e5){var _0x2d8050;const _0x481d8c=null!==(_0x2d8050=_0x5046e5['parentStepIds'])&&void 0x0!==_0x2d8050?_0x2d8050:_0x5046e5['dependsOn'];return(null==_0x481d8c?void 0x0:_0x481d8c['length'])?formatParentStepId(_0x481d8c):formatParentStepId(_0x5046e5['parentStepId']);}export function resolveRecordedParentStepId(_0x4f0561={}){var _0x183745;const _0x1b5d39=null!==(_0x183745=_0x4f0561['parentStepIds'])&&void 0x0!==_0x183745?_0x183745:_0x4f0561['dependsOn'];return(null==_0x1b5d39?void 0x0:_0x1b5d39['length'])?formatParentStepId(_0x1b5d39):void 0x0!==_0x4f0561['parentStepId']?formatParentStepId(_0x4f0561['parentStepId']):_0x4f0561['resolveParent']?formatParentStepId(_0x4f0561['resolveParent']()):null;}
|
package/dist/workflow/ids.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function randomUUID(){const
|
|
1
|
+
export function randomUUID(){const _0x55ada4='undefined'!=typeof globalThis?globalThis['crypto']:void 0x0;if(_0x55ada4&&'function'==typeof _0x55ada4['randomUUID'])return _0x55ada4['randomUUID']();if(_0x55ada4&&_0x55ada4['getRandomValues']){const _0x227f48=new Uint8Array(0x10);_0x55ada4['getRandomValues'](_0x227f48),_0x227f48[0x6]=0xf&_0x227f48[0x6]|0x40,_0x227f48[0x8]=0x3f&_0x227f48[0x8]|0x80;const _0x4e3614=[..._0x227f48]['map'](_0x4b5340=>_0x4b5340['toString'](0x10)['padStart'](0x2,'0'))['join']('');return _0x4e3614['slice'](0x0,0x8)+'-'+_0x4e3614['slice'](0x8,0xc)+'-'+_0x4e3614['slice'](0xc,0x10)+'-'+_0x4e3614['slice'](0x10,0x14)+'-'+_0x4e3614['slice'](0x14);}return'id_'+Date['now']()+'_'+Math['random']()['toString'](0x24)['slice'](0x2,0xa);}export function shortId(_0x51c76d){return _0x51c76d+'_'+randomUUID()['replace'](/-/g,'')['slice'](0x0,0xc);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function toJsonColumn(
|
|
1
|
+
export function toJsonColumn(_0x7171dd){if(null==_0x7171dd)return null;if('string'==typeof _0x7171dd){const _0x3d64a1=_0x7171dd['trim']();if(''===_0x3d64a1)return{};if(_0x3d64a1['startsWith']('{')||_0x3d64a1['startsWith']('['))try{return JSON['parse'](_0x3d64a1);}catch{return{'text':_0x7171dd};}return{'text':_0x7171dd};}if('number'==typeof _0x7171dd||'boolean'==typeof _0x7171dd)return _0x7171dd;try{return JSON['parse'](JSON['stringify'](_0x7171dd,(_0xe6bec0,_0x37baed)=>'bigint'==typeof _0x37baed?_0x37baed['toString']():_0x37baed));}catch{return{'text':String(_0x7171dd)};}}export function setJsonColumn(_0x243ac3,_0x1589fe,_0x57350c){const _0x9b7890=toJsonColumn(_0x57350c);null!==_0x9b7890&&(_0x243ac3[_0x1589fe]=_0x9b7890);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HttpTransport}from'../transport/httpTransport.js';import{DNotifierEndpoints}from'../config/endpoints.js';import{shortId}from'./ids.js';const globalMockStore={'workflows':new Map(),'executions':new Map(),'stepsByExecution':new Map(),'errorCountByWorkflow':new Map()};export class MockWorkflowObservabilityClient{constructor({appId:
|
|
1
|
+
import{HttpTransport}from'../transport/httpTransport.js';import{DNotifierEndpoints}from'../config/endpoints.js';import{shortId}from'./ids.js';const globalMockStore={'workflows':new Map(),'executions':new Map(),'stepsByExecution':new Map(),'errorCountByWorkflow':new Map()};export class MockWorkflowObservabilityClient{constructor({appId:_0x53fb50=null,token:_0x24aabc=null,httpEnabled:_0x118541=!0x1}={}){this['appId']=_0x53fb50,this['token']=_0x24aabc,this['httpEnabled']=Boolean(_0x118541),this['workflows']=globalMockStore['workflows'],this['executions']=globalMockStore['executions'],this['stepsByExecution']=globalMockStore['stepsByExecution'],this['errorCountByWorkflow']=globalMockStore['errorCountByWorkflow'];}['configure']({appId:_0x433c11,token:_0x2759d1}={}){void 0x0!==_0x433c11&&(this['appId']=_0x433c11),void 0x0!==_0x2759d1&&(this['token']=_0x2759d1);}['_transport'](_0x3ec44d){const _0x21509f=this['token']?{'authorization':''+this['token']}:{};return new HttpTransport({'url':_0x3ec44d,'headers':_0x21509f});}async['_maybeHttp'](_0x4efaa1,_0x1019d4,_0x552415){var _0x46dc3d;if(this['httpEnabled'])try{const _0x1901b6=this['_transport'](_0x1019d4);'POST'===_0x4efaa1&&await _0x1901b6['send'](_0x552415);}catch(_0x5bd00b){console['warn']('[WorkflowObservability]\x20mock\x20HTTP\x20failed:',null!==(_0x46dc3d=null==_0x5bd00b?void 0x0:_0x5bd00b['message'])&&void 0x0!==_0x46dc3d?_0x46dc3d:_0x5bd00b);}}async['registerWorkflow'](_0x5535be){var _0x49132a;const _0x278478=(null!==(_0x49132a=this['appId'])&&void 0x0!==_0x49132a?_0x49132a:'app')+':'+_0x5535be['workflowId'];return this['workflows']['has'](_0x278478)||this['workflows']['set'](_0x278478,{..._0x5535be,'registeredAt':new Date()['toISOString']()}),await this['_maybeHttp']('POST',DNotifierEndpoints['workflowMockRegisterUrl'],_0x5535be),{'ok':!0x0};}async['createExecution'](_0x1f9abe){var _0x2865c8;const _0x3b6e9c=null!==(_0x2865c8=_0x1f9abe['id'])&&void 0x0!==_0x2865c8?_0x2865c8:shortId('exec'),_0x25d982={..._0x1f9abe,'id':_0x3b6e9c,'status':'in_progress','stepCount':0x0,'steps':[]};return this['executions']['set'](_0x3b6e9c,_0x25d982),this['stepsByExecution']['set'](_0x3b6e9c,[]),await this['_maybeHttp']('POST',DNotifierEndpoints['workflowMockExecutionsUrl'],_0x25d982),{'executionId':_0x3b6e9c,'record':_0x25d982};}async['updateExecution'](_0x222e3b,_0x4a03fc){var _0x515603;const _0x3243c9=this['executions']['get'](_0x222e3b);if(!_0x3243c9)return{'ok':!0x1};const _0x20ab37={..._0x3243c9,..._0x4a03fc};if(this['executions']['set'](_0x222e3b,_0x20ab37),'error'===_0x4a03fc['status']&&_0x20ab37['workflowId']){const _0x4b750e=_0x20ab37['workflowId'];this['errorCountByWorkflow']['set'](_0x4b750e,(null!==(_0x515603=this['errorCountByWorkflow']['get'](_0x4b750e))&&void 0x0!==_0x515603?_0x515603:0x0)+0x1);}return await this['_maybeHttp']('POST',DNotifierEndpoints['workflowMockExecutionUrl'](_0x222e3b),_0x20ab37),{'ok':!0x0,'record':_0x20ab37};}async['addStep'](_0x2a5e5c,_0x3df5b7){var _0x1777d4,_0x345abd;const _0x3f303c=null!==(_0x1777d4=this['stepsByExecution']['get'](_0x2a5e5c))&&void 0x0!==_0x1777d4?_0x1777d4:[];_0x3f303c['push'](_0x3df5b7),this['stepsByExecution']['set'](_0x2a5e5c,_0x3f303c);const _0x265ed8=this['executions']['get'](_0x2a5e5c);return _0x265ed8&&(_0x265ed8['stepCount']=_0x3f303c['length'],_0x265ed8['steps']=_0x3f303c,this['executions']['set'](_0x2a5e5c,_0x265ed8)),'error'===_0x3df5b7['status']&&(null==_0x265ed8?void 0x0:_0x265ed8['workflowId'])&&this['errorCountByWorkflow']['set'](_0x265ed8['workflowId'],(null!==(_0x345abd=this['errorCountByWorkflow']['get'](_0x265ed8['workflowId']))&&void 0x0!==_0x345abd?_0x345abd:0x0)+0x1),await this['_maybeHttp']('POST',DNotifierEndpoints['workflowMockStepsUrl'](_0x2a5e5c),_0x3df5b7),{'ok':!0x0};}['getDashboardSnapshot'](){return{'totalWorkflows':this['workflows']['size'],'executions':[...this['executions']['values']()],'stepsByExecution':Object['fromEntries'](this['stepsByExecution']),'errorCountByWorkflow':Object['fromEntries'](this['errorCountByWorkflow'])};}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WorkflowObservabilityClient}from'./workflowObservabilityClient.js';import{shortId}from'./ids.js';import{resolveGraphParentStepId}from'./graphParents.js';import{resolveStepType}from'./stepTypes.js';export class WorkflowObservability{constructor({appId:
|
|
1
|
+
import{WorkflowObservabilityClient}from'./workflowObservabilityClient.js';import{shortId}from'./ids.js';import{resolveGraphParentStepId}from'./graphParents.js';import{resolveStepType}from'./stepTypes.js';export class WorkflowObservability{constructor({appId:_0x3ac2a1,token:_0x5bab0f=null,client:_0x49c01c,appendOnly:_0x4fa5a2=!0x1}){this['appId']=_0x3ac2a1,this['token']=_0x5bab0f,this['client']=null!=_0x49c01c?_0x49c01c:new WorkflowObservabilityClient({'appId':_0x3ac2a1,'token':_0x5bab0f}),this['client']['configure']({'appId':_0x3ac2a1,'token':_0x5bab0f}),this['_registeredWorkflowNames']=new Set(),this['_stepCounter']=0x0,this['_appendOnly']=Boolean(_0x4fa5a2);}['allocateStepId'](){return shortId('step');}async['registerWorkflow'](_0x3bdef5){var _0x217a4a;if(!this['_registeredWorkflowNames']['has'](_0x3bdef5['name'])){this['_registeredWorkflowNames']['add'](_0x3bdef5['name']);try{await this['client']['registerWorkflow']({'appId':this['appId'],'workflowId':_0x3bdef5['name'],'name':_0x3bdef5['name'],'description':null!==(_0x217a4a=_0x3bdef5['description'])&&void 0x0!==_0x217a4a?_0x217a4a:null});}catch{}}}async['startExecution'](_0x2513b5){var _0x20d5ad;if(this['_appendOnly'])throw new Error('startExecution\x20is\x20not\x20allowed\x20in\x20append-only\x20workflow\x20observability\x20mode');const _0xe26bd9=shortId('exec'),_0x5804cc='number'==typeof _0x2513b5['startedAtMs']&&Number['isFinite'](_0x2513b5['startedAtMs'])?_0x2513b5['startedAtMs']:Date['now'](),_0x514258='string'==typeof _0x2513b5['startedAt']&&_0x2513b5['startedAt']['trim']()?_0x2513b5['startedAt']:new Date(_0x5804cc)['toISOString']();try{await this['client']['createExecution']({'id':_0xe26bd9,'appId':this['appId'],'workflowId':_0x2513b5['workflowId'],'userId':_0x2513b5['userId'],'input':null!==(_0x20d5ad=_0x2513b5['input'])&&void 0x0!==_0x20d5ad?_0x20d5ad:null,'startedAt':_0x514258});}catch{}return this['_stepCounter']=0x0,{'executionId':_0xe26bd9,'startedAt':_0x514258,'startedAtMs':_0x5804cc};}async['recordStep'](_0x24e2b7,_0x54f63b){var _0x455aef,_0x125a28,_0x325226,_0x144755,_0x2c0be3,_0x3d9f5f,_0x1d1f02,_0x544581,_0x5ebdbd;if(!_0x24e2b7)return null;this['_stepCounter']+=0x1;const _0x2ae537=null!==(_0x455aef=_0x54f63b['id'])&&void 0x0!==_0x455aef?_0x455aef:this['allocateStepId'](),_0x1b8cd8=resolveStepType(_0x54f63b),_0x42424c=null!==(_0x144755=null!==(_0x325226=null!==(_0x125a28=_0x54f63b['agentName'])&&void 0x0!==_0x125a28?_0x125a28:_0x54f63b['kind'])&&void 0x0!==_0x325226?_0x325226:_0x54f63b['apiName'])&&void 0x0!==_0x144755?_0x144755:null,_0x4023db=resolveGraphParentStepId(_0x54f63b),_0x263cd1={..._0x54f63b,'id':_0x2ae537,'executionId':_0x24e2b7,'executedAt':null!==(_0x2c0be3=_0x54f63b['executedAt'])&&void 0x0!==_0x2c0be3?_0x2c0be3:new Date()['toISOString'](),'apiName':null!==(_0x3d9f5f=_0x54f63b['apiName'])&&void 0x0!==_0x3d9f5f?_0x3d9f5f:null,'agentName':null!==(_0x1d1f02=_0x54f63b['agentName'])&&void 0x0!==_0x1d1f02?_0x1d1f02:null,'kind':_0x42424c,'type':_0x1b8cd8,'step_type':_0x1b8cd8,'parentStepId':_0x4023db,'siblingIndex':null!==(_0x544581=_0x54f63b['siblingIndex'])&&void 0x0!==_0x544581?_0x544581:null,'branchKey':null!==(_0x5ebdbd=_0x54f63b['branchKey'])&&void 0x0!==_0x5ebdbd?_0x5ebdbd:null};delete _0x263cd1['dependsOn'],delete _0x263cd1['parentStepIds'];try{await this['client']['addStep'](_0x24e2b7,_0x263cd1);}catch{}return _0x263cd1;}async['completeExecution'](_0xfaf603){var _0x75359f,_0x57ddf3;if(!this['_appendOnly']&&_0xfaf603['executionId'])try{await this['client']['updateExecution'](_0xfaf603['executionId'],{'status':_0xfaf603['status'],'endedAt':_0xfaf603['endedAt'],'durationMs':_0xfaf603['durationMs'],'stepCount':_0xfaf603['stepCount'],'error':null!==(_0x75359f=_0xfaf603['error'])&&void 0x0!==_0x75359f?_0x75359f:null,'result':null!==(_0x57ddf3=_0xfaf603['result'])&&void 0x0!==_0x57ddf3?_0x57ddf3:null});}catch{}}['getStepCount'](){return this['_stepCounter'];}}export function createWorkflowObservability(_0x2a4c8a){return new WorkflowObservability(_0x2a4c8a);}
|
|
@@ -16,6 +16,7 @@ export function sendRemoteAgentResult(notifier: import("../dnotifier.js").DNotif
|
|
|
16
16
|
senderId: string;
|
|
17
17
|
receiverId: string;
|
|
18
18
|
correlationId: string;
|
|
19
|
+
agentName?: string;
|
|
19
20
|
output?: any;
|
|
20
21
|
state?: object | null;
|
|
21
22
|
}): Promise<void>;
|
|
@@ -23,6 +24,7 @@ export function sendRemoteAgentError(notifier: import("../dnotifier.js").DNotifi
|
|
|
23
24
|
senderId: string;
|
|
24
25
|
receiverId: string;
|
|
25
26
|
correlationId: string;
|
|
27
|
+
agentName?: string;
|
|
26
28
|
message: string;
|
|
27
29
|
}): Promise<void>;
|
|
28
30
|
export function isRemoteAgentReply(data: any): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WorkflowError}from'./errors.js';import{createErrorEnvelope,createInvokeEnvelope,createResultEnvelope,REMOTE_AGENT_OP}from'./remoteAgentProtocol.js';const DEFAULT_TIMEOUT_MS=0x1d4c0;function correlationId(){const
|
|
1
|
+
import{WorkflowError}from'./errors.js';import{createErrorEnvelope,createInvokeEnvelope,createResultEnvelope,REMOTE_AGENT_OP}from'./remoteAgentProtocol.js';const DEFAULT_TIMEOUT_MS=0x1d4c0;function correlationId(){const _0x5a46db='undefined'!=typeof globalThis?globalThis['crypto']:void 0x0;if(_0x5a46db&&'function'==typeof _0x5a46db['randomUUID'])return _0x5a46db['randomUUID']();if(_0x5a46db&&_0x5a46db['getRandomValues']){const _0x1ace1b=new Uint8Array(0x10);_0x5a46db['getRandomValues'](_0x1ace1b),_0x1ace1b[0x6]=0xf&_0x1ace1b[0x6]|0x40,_0x1ace1b[0x8]=0x3f&_0x1ace1b[0x8]|0x80;const _0x2a0196=[..._0x1ace1b]['map'](_0x2f7615=>_0x2f7615['toString'](0x10)['padStart'](0x2,'0'))['join']('');return _0x2a0196['slice'](0x0,0x8)+'-'+_0x2a0196['slice'](0x8,0xc)+'-'+_0x2a0196['slice'](0xc,0x10)+'-'+_0x2a0196['slice'](0x10,0x14)+'-'+_0x2a0196['slice'](0x14);}return'corr_'+Date['now']()+'_'+Math['random']()['toString'](0x24)['slice'](0x2,0xa);}export function bareUserId(_0x29e663,_0x347c87){if(!_0x347c87||'string'!=typeof _0x347c87)return'';const _0x13d7bf=_0x29e663+':';if(_0x347c87['startsWith'](_0x13d7bf))return _0x347c87['slice'](_0x13d7bf['length']);const _0x3cef8b=_0x347c87['indexOf'](':');return _0x3cef8b>=0x0?_0x347c87['slice'](_0x3cef8b+0x1):_0x347c87;}export async function invokeRemoteAgent(_0xe3ba63){const {notifier:_0x28b0f8,senderId:_0x38c5c5,receiverId:_0x1ad86b,agentName:_0x52848b,input:_0x326783,state:_0x454923,trace:_0x135279=null,timeoutMs:_0x1081ce=DEFAULT_TIMEOUT_MS}=_0xe3ba63;if(!(null==_0x28b0f8?void 0x0:_0x28b0f8['isConnected']))throw new WorkflowError('Remote\x20agent\x20invoke\x20requires\x20a\x20connected\x20notifier');if(!_0x1ad86b)throw new WorkflowError('Remote\x20agent\x20\x22'+_0x52848b+'\x22\x20is\x20missing\x20receiverId');const _0x371636=correlationId(),_0x4c593d=createInvokeEnvelope({'correlationId':_0x371636,'agentName':_0x52848b,'input':_0x326783,'state':null!=_0x454923?_0x454923:null,'trace':_0x135279,'replyTo':_0x38c5c5}),_0x573dd9=_0x28b0f8['_awaitRemoteAgentReply'](_0x371636,{'timeoutMs':_0x1081ce,'agentName':_0x52848b});return await _0x28b0f8['send']({'senderId':_0x38c5c5,'receiverId':_0x1ad86b,'data':_0x4c593d,'saveHistory':!0x1}),_0x573dd9;}export async function sendRemoteAgentResult(_0x58cfac,_0x56063f){var _0x540ef1;await _0x58cfac['send']({'senderId':_0x56063f['senderId'],'receiverId':_0x56063f['receiverId'],'data':createResultEnvelope({'correlationId':_0x56063f['correlationId'],'agentName':_0x56063f['agentName'],'output':_0x56063f['output'],'state':null!==(_0x540ef1=_0x56063f['state'])&&void 0x0!==_0x540ef1?_0x540ef1:null}),'saveHistory':!0x1});}export async function sendRemoteAgentError(_0x13b8de,_0x18e32b){await _0x13b8de['send']({'senderId':_0x18e32b['senderId'],'receiverId':_0x18e32b['receiverId'],'data':createErrorEnvelope({'correlationId':_0x18e32b['correlationId'],'agentName':_0x18e32b['agentName'],'message':_0x18e32b['message']}),'saveHistory':!0x1});}export function isRemoteAgentReply(_0x2961cf){return null!=_0x2961cf&&'object'==typeof _0x2961cf&&(_0x2961cf['op']===REMOTE_AGENT_OP['RESULT']||_0x2961cf['op']===REMOTE_AGENT_OP['ERROR']);}export{DEFAULT_TIMEOUT_MS};
|
|
@@ -21,25 +21,22 @@ export function createInvokeEnvelope(params: {
|
|
|
21
21
|
};
|
|
22
22
|
export function createResultEnvelope(params: {
|
|
23
23
|
correlationId: string;
|
|
24
|
+
agentName?: string;
|
|
24
25
|
output?: any;
|
|
25
26
|
state?: object | null;
|
|
26
27
|
}): {
|
|
27
28
|
__dnotifier: string;
|
|
28
29
|
op: string;
|
|
29
30
|
correlationId: string;
|
|
30
|
-
output: any;
|
|
31
|
-
state: object | null;
|
|
32
31
|
};
|
|
33
32
|
export function createErrorEnvelope(params: {
|
|
34
33
|
correlationId: string;
|
|
34
|
+
agentName?: string;
|
|
35
35
|
message: string;
|
|
36
36
|
}): {
|
|
37
37
|
__dnotifier: string;
|
|
38
38
|
op: string;
|
|
39
39
|
correlationId: string;
|
|
40
|
-
error: {
|
|
41
|
-
message: string;
|
|
42
|
-
};
|
|
43
40
|
};
|
|
44
41
|
export const REMOTE_AGENT_KIND: "dnotifier.remoteAgent";
|
|
45
42
|
export namespace REMOTE_AGENT_OP {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const REMOTE_AGENT_KIND='dnotifier.remoteAgent';export const REMOTE_AGENT_OP={'INVOKE':'invoke','RESULT':'result','ERROR':'error'};export function isRemoteAgentEnvelope(
|
|
1
|
+
export const REMOTE_AGENT_KIND='dnotifier.remoteAgent';export const REMOTE_AGENT_OP={'INVOKE':'invoke','RESULT':'result','ERROR':'error'};export function isRemoteAgentEnvelope(_0xbcc4e9){return null!=_0xbcc4e9&&'object'==typeof _0xbcc4e9&&_0xbcc4e9['__dnotifier']===REMOTE_AGENT_KIND&&'string'==typeof _0xbcc4e9['op'];}export function isRemoteAgentRef(_0x5a11fb){return null!=_0x5a11fb&&'object'==typeof _0x5a11fb&&'string'==typeof _0x5a11fb['receiverId']&&''!==_0x5a11fb['receiverId']['trim']()&&'function'!=typeof _0x5a11fb['run'];}export function createInvokeEnvelope(_0x309b9a){var _0x233bc4,_0x516a63,_0x5b0153;return{'__dnotifier':REMOTE_AGENT_KIND,'op':REMOTE_AGENT_OP['INVOKE'],'correlationId':_0x309b9a['correlationId'],'agentName':_0x309b9a['agentName'],'input':null!==(_0x233bc4=_0x309b9a['input'])&&void 0x0!==_0x233bc4?_0x233bc4:null,'state':null!==(_0x516a63=_0x309b9a['state'])&&void 0x0!==_0x516a63?_0x516a63:null,'trace':null!==(_0x5b0153=_0x309b9a['trace'])&&void 0x0!==_0x5b0153?_0x5b0153:null,'replyTo':_0x309b9a['replyTo']};}export function createResultEnvelope(_0x1832da){var _0x1ee1eb,_0x33cab1;const _0xcb09cf={'__dnotifier':REMOTE_AGENT_KIND,'op':REMOTE_AGENT_OP['RESULT'],'correlationId':_0x1832da['correlationId']};return _0x1832da['agentName']&&(_0xcb09cf['agentName']=_0x1832da['agentName']),_0xcb09cf['output']=null!==(_0x1ee1eb=_0x1832da['output'])&&void 0x0!==_0x1ee1eb?_0x1ee1eb:null,_0xcb09cf['state']=null!==(_0x33cab1=_0x1832da['state'])&&void 0x0!==_0x33cab1?_0x33cab1:null,_0xcb09cf;}export function createErrorEnvelope(_0x19fef0){const _0x480a8c={'__dnotifier':REMOTE_AGENT_KIND,'op':REMOTE_AGENT_OP['ERROR'],'correlationId':_0x19fef0['correlationId']};return _0x19fef0['agentName']&&(_0x480a8c['agentName']=_0x19fef0['agentName']),_0x480a8c['error']={'message':_0x19fef0['message']},_0x480a8c;}
|
package/dist/workflow/runner.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WorkflowContext}from'./context.js';import{createWorkflowObservability}from'./observability.js';import{WorkflowError}from'./errors.js';import{STEP_TYPE_END,STEP_TYPE_ENTRY}from'./stepTypes.js';function snapshot(
|
|
1
|
+
import{WorkflowContext}from'./context.js';import{createWorkflowObservability}from'./observability.js';import{WorkflowError}from'./errors.js';import{STEP_TYPE_END,STEP_TYPE_ENTRY}from'./stepTypes.js';function snapshot(_0xeded5){try{return void 0x0===_0xeded5?null:JSON['parse'](JSON['stringify'](_0xeded5));}catch{return String(_0xeded5);}}export class WorkflowRunner{constructor({notifier:_0x35f264,senderId:_0x1a119f,workflow:_0x127fa5}){if(!_0x35f264)throw new WorkflowError('WorkflowRunner\x20requires\x20a\x20DNotifier\x20instance');if(!_0x1a119f)throw new WorkflowError('WorkflowRunner\x20requires\x20senderId');if(!_0x127fa5)throw new WorkflowError('WorkflowRunner\x20requires\x20a\x20workflow');this['notifier']=_0x35f264,this['senderId']=_0x1a119f,this['workflow']=_0x127fa5;}async['run'](_0x141d81){var _0x848894,_0x3ef59e,_0x11a01f;const _0xf1974=null==_0x141d81?void 0x0:_0x141d81['input'],_0x4e0816={};let _0x1860f4=null,_0x59a6d7=null,_0x1d55c1=null;const _0xcc526f=Date['now']();if(this['workflow']['observability']){_0x1860f4=createWorkflowObservability({'appId':this['notifier']['appId'],'token':null!==(_0x848894=this['notifier']['authToken'])&&void 0x0!==_0x848894?_0x848894:null}),await _0x1860f4['registerWorkflow'](this['workflow']);const _0x3f9795=await _0x1860f4['startExecution']({'workflowId':this['workflow']['name'],'userId':this['senderId'],'input':_0xf1974,'startedAtMs':_0xcc526f,'startedAt':new Date(_0xcc526f)['toISOString']()});_0x59a6d7=_0x3f9795['executionId'],_0x1d55c1=_0x3f9795['startedAt'];}let _0x332611=null;if(_0x1860f4&&_0x59a6d7){const _0xb0a912=await _0x1860f4['recordStep'](_0x59a6d7,{'type':STEP_TYPE_ENTRY,'kind':'entry','label':this['workflow']['name'],'status':'ok','latencyMs':0x0,'parentStepId':null,'input':snapshot(_0xf1974),'state':snapshot(_0x4e0816)});_0x332611=null!==(_0x3ef59e=null==_0xb0a912?void 0x0:_0xb0a912['id'])&&void 0x0!==_0x3ef59e?_0x3ef59e:null;}const _0x50e275=new WorkflowContext({'notifier':this['notifier'],'senderId':this['senderId'],'workflow':this['workflow'],'input':_0xf1974,'state':_0x4e0816,'observability':_0x1860f4,'executionId':_0x59a6d7,'entryStepId':_0x332611});let _0x1b1eb9,_0x359a30='ok',_0x181bd1=null;try{_0x1b1eb9=await this['workflow']['entry'](_0x50e275);}catch(_0x5b4786){throw _0x359a30='error',_0x181bd1={'message':null!==(_0x11a01f=null==_0x5b4786?void 0x0:_0x5b4786['message'])&&void 0x0!==_0x11a01f?_0x11a01f:String(_0x5b4786),'stack':null==_0x5b4786?void 0x0:_0x5b4786['stack']},_0x5b4786;}finally{if(_0x1860f4&&_0x59a6d7){await _0x1860f4['recordStep'](_0x59a6d7,{'type':STEP_TYPE_END,'kind':'end','label':this['workflow']['name'],'status':_0x359a30,'latencyMs':0x0,'parentStepId':_0x50e275['getEndParentStepId'](),'output':snapshot('ok'===_0x359a30?_0x1b1eb9:null),'state':snapshot(_0x50e275['state']),'error':_0x181bd1});const _0x29406f=Date['now'](),_0x85aeb6=new Date(_0x29406f)['toISOString'](),_0x42298f=_0x1860f4['getStepCount']();await _0x1860f4['completeExecution']({'executionId':_0x59a6d7,'status':_0x359a30,'endedAt':_0x85aeb6,'durationMs':_0x29406f-_0xcc526f,'stepCount':_0x42298f,'error':_0x181bd1,'result':'ok'===_0x359a30?_0x1b1eb9:null,'startedAt':_0x1d55c1});}}const _0x4e7a45={'result':_0x1b1eb9,'state':_0x4e0816};return _0x59a6d7&&(_0x4e7a45['executionId']=_0x59a6d7),_0x4e7a45;}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const STEP_TYPE_AGENT='Agent';export const STEP_TYPE_PARALLEL='Parallel';export const STEP_TYPE_ENTRY='Entry';export const STEP_TYPE_END='End';export const STEP_TYPE_CUSTOM='Custom';export const STEP_TYPE_TOOL='Tool';export const STRUCTURAL_STEP_TYPES=['Agent','Parallel','Entry','End','Custom','Tool'];export const SDK_API_STEP_TYPES=['sendAI','fetchAIHistory','search','addDocument','updateDocument','deleteDocument','listDocuments','getDocument'];export const LOG_TYPE_BY_API={'sendAI':'AI-LLM','fetchAIHistory':'AI\x20History','search':'Vector\x20Search','semanticSearch':'Vector\x20Search','addDocument':'Document\x20Add','updateDocument':'Document\x20Update','deleteDocument':'Document\x20Delete','listDocuments':'Document\x20List','getDocument':'Document\x20Get','agent':'Agent','tool':'Tool'};const LEGACY_KIND_TO_API={'ai_call':'sendAI','vector_call':'search'};export function toLogStepType(
|
|
1
|
+
export const STEP_TYPE_AGENT='Agent';export const STEP_TYPE_PARALLEL='Parallel';export const STEP_TYPE_ENTRY='Entry';export const STEP_TYPE_END='End';export const STEP_TYPE_CUSTOM='Custom';export const STEP_TYPE_TOOL='Tool';export const STRUCTURAL_STEP_TYPES=['Agent','Parallel','Entry','End','Custom','Tool'];export const SDK_API_STEP_TYPES=['sendAI','fetchAIHistory','search','addDocument','updateDocument','deleteDocument','listDocuments','getDocument'];export const LOG_TYPE_BY_API={'sendAI':'AI-LLM','fetchAIHistory':'AI\x20History','search':'Vector\x20Search','semanticSearch':'Vector\x20Search','addDocument':'Document\x20Add','updateDocument':'Document\x20Update','deleteDocument':'Document\x20Delete','listDocuments':'Document\x20List','getDocument':'Document\x20Get','agent':'Agent','tool':'Tool'};const LEGACY_KIND_TO_API={'ai_call':'sendAI','vector_call':'search'};export function toLogStepType(_0x9f4a08){if(null==_0x9f4a08||''===String(_0x9f4a08)['trim']())return'Custom';const _0x5e871b=String(_0x9f4a08);if(LOG_TYPE_BY_API[_0x5e871b])return LOG_TYPE_BY_API[_0x5e871b];const _0x7a2b96=_0x5e871b['toLowerCase']();for(const [_0x5f5d0a,_0x544370]of Object['entries'](LOG_TYPE_BY_API))if(_0x5f5d0a['toLowerCase']()===_0x7a2b96)return _0x544370;return _0x5e871b;}export function resolveApiName(_0x19f73b){const _0x1c8edd=null==_0x19f73b?void 0x0:_0x19f73b['kind'];if(null==_0x1c8edd||''===String(_0x1c8edd)['trim']())return null;const _0x2ec68c=String(_0x1c8edd);return LEGACY_KIND_TO_API[_0x2ec68c]?LEGACY_KIND_TO_API[_0x2ec68c]:'agent'===_0x2ec68c||SDK_API_STEP_TYPES['includes'](_0x2ec68c)||'semanticSearch'===_0x2ec68c?_0x2ec68c:null;}export function resolveStepType(_0x3a3600){if(null!=(null==_0x3a3600?void 0x0:_0x3a3600['type'])&&''!==String(_0x3a3600['type'])['trim']()){const _0x1250db=String(_0x3a3600['type'])['trim']();return STRUCTURAL_STEP_TYPES['includes'](_0x1250db)||Object['values'](LOG_TYPE_BY_API)['includes'](_0x1250db)?_0x1250db:toLogStepType(_0x1250db);}const _0x270c41=resolveApiName(_0x3a3600);return _0x270c41?toLogStepType(_0x270c41):'Custom';}
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
export class Workflow {
|
|
2
|
-
constructor({ name, description, observability, entry }: {
|
|
2
|
+
constructor({ name, description, observability, capabilities, entry }: {
|
|
3
3
|
name: string;
|
|
4
4
|
description?: string;
|
|
5
5
|
observability?: boolean;
|
|
6
|
+
capabilities?: Partial<import("./capabilities.js").Capabilities> | string[];
|
|
6
7
|
entry: (ctx: import("./context.js").WorkflowContext) => Promise<any>;
|
|
7
8
|
});
|
|
8
9
|
name: string;
|
|
9
10
|
description: string | undefined;
|
|
10
11
|
observability: boolean;
|
|
12
|
+
capabilities: import("./capabilities.js").Capabilities;
|
|
11
13
|
entry: (ctx: import("./context.js").WorkflowContext) => Promise<any>;
|
|
12
14
|
_agents: Map<string, AgentRegistration>;
|
|
13
15
|
_registeredWithObservability: boolean;
|
|
14
16
|
_listenNotifier: import("../dnotifier.js").DNotifier | null;
|
|
17
|
+
_backendRegistrations: WeakMap<object, string>;
|
|
18
|
+
_syncBackendRegistration(notifier: import("../dnotifier.js").DNotifier): void;
|
|
15
19
|
registerAgent(name: string, agentOrRemote: AgentRegistration): this;
|
|
16
20
|
registerAgents(agents: Record<string, AgentRegistration>): this;
|
|
17
21
|
getAgent(name: string): import("./agent.js").Agent | undefined;
|
|
18
22
|
getAgentRegistration(name: string): AgentRegistration | undefined;
|
|
19
23
|
hasLocalAgent(name: string): boolean;
|
|
20
24
|
listen(notifier: import("../dnotifier.js").DNotifier): this;
|
|
25
|
+
stopListening(): this;
|
|
21
26
|
_handleRemoteInvoke(notifier: import("../dnotifier.js").DNotifier, msg: {
|
|
22
27
|
metadata: object;
|
|
23
28
|
payload: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WorkflowError}from'./errors.js';import{isRemoteAgentRef}from'./remoteAgentProtocol.js';import{bareUserId,sendRemoteAgentError,sendRemoteAgentResult}from'./remoteAgentClient.js';import{WorkflowContext}from'./context.js';import{createWorkflowObservability}from'./observability.js';function normalizeDescription(
|
|
1
|
+
import{Agent}from'./agent.js';import{normalizeCapabilities}from'./capabilities.js';import{agentBackendId}from'../agent-runtime/ids.js';import{WorkflowError}from'./errors.js';import{isRemoteAgentRef}from'./remoteAgentProtocol.js';import{bareUserId,sendRemoteAgentError,sendRemoteAgentResult}from'./remoteAgentClient.js';import{WorkflowContext}from'./context.js';import{createWorkflowObservability}from'./observability.js';function normalizeDescription(_0x224fd9){if(null==_0x224fd9||''===_0x224fd9)return;if('string'!=typeof _0x224fd9)throw new WorkflowError('Workflow\x20description\x20must\x20be\x20a\x20string');const _0xad5464=_0x224fd9['trim']();if(_0xad5464['length']>0x64)throw new WorkflowError('Workflow\x20description\x20must\x20be\x20at\x20most\x20100\x20characters');return _0xad5464['length']>0x0?_0xad5464:void 0x0;}export class Workflow{constructor({name:_0x175b36,description:_0x310d88,observability:_0x373c4a=!0x1,capabilities:_0x5e58f4,entry:_0x40ee6d}){if(!_0x175b36||'string'!=typeof _0x175b36)throw new WorkflowError('Workflow\x20name\x20is\x20required');if('function'!=typeof _0x40ee6d)throw new WorkflowError('Workflow\x20entry\x20must\x20be\x20a\x20function');this['name']=_0x175b36['trim'](),this['description']=normalizeDescription(_0x310d88),this['observability']=Boolean(_0x373c4a),this['capabilities']=normalizeCapabilities(_0x5e58f4),this['entry']=_0x40ee6d,this['_agents']=new Map(),this['_registeredWithObservability']=!0x1,this['_listenNotifier']=null,this['_backendRegistrations']=new WeakMap();}['_syncBackendRegistration'](_0x58650e){var _0x30db3e,_0x47701f,_0x5cdfe9;const _0x107107=null===(_0x30db3e=null==_0x58650e?void 0x0:_0x58650e['_agentServices'])||void 0x0===_0x30db3e?void 0x0:_0x30db3e['sync'];if(!_0x107107||'function'!=typeof _0x107107['enqueueWorkflow'])return;for(const _0x40c2c1 of this['_agents']['values']())_0x40c2c1 instanceof Agent&&_0x107107['enqueueAgent'](_0x40c2c1);const _0x3c0e7e={'workflowId':this['name'],'name':this['name'],'description':null!==(_0x47701f=this['description'])&&void 0x0!==_0x47701f?_0x47701f:'','agentIds':[...this['_agents']]['map'](([_0x12d493,_0x4b1823])=>agentBackendId(_0x4b1823 instanceof Agent?_0x4b1823['name']:_0x12d493)),'hostUserId':null!==(_0x5cdfe9=_0x58650e['userId'])&&void 0x0!==_0x5cdfe9?_0x5cdfe9:null,'capabilities':this['capabilities']},_0xf4b644=JSON['stringify'](_0x3c0e7e);this['_backendRegistrations']['get'](_0x58650e)!==_0xf4b644&&(this['_backendRegistrations']['set'](_0x58650e,_0xf4b644),_0x107107['enqueueWorkflow'](_0x3c0e7e));}['registerAgent'](_0x4b96f3,_0x1cf700){if(!_0x4b96f3||'string'!=typeof _0x4b96f3)throw new WorkflowError('Agent\x20registration\x20name\x20is\x20required');if(isRemoteAgentRef(_0x1cf700))this['_agents']['set'](_0x4b96f3,{'receiverId':_0x1cf700['receiverId']['trim']()});else{if(!_0x1cf700||'function'!=typeof _0x1cf700['run'])throw new WorkflowError('Invalid\x20agent\x20for\x20\x22'+_0x4b96f3+'\x22\x20(expected\x20Agent\x20or\x20{\x20receiverId\x20})');this['_agents']['set'](_0x4b96f3,_0x1cf700);}return this['_listenNotifier']&&this['_syncBackendRegistration'](this['_listenNotifier']),this;}['registerAgents'](_0xe6fefa){for(const [_0x55dc0d,_0x43bf24]of Object['entries'](_0xe6fefa))this['registerAgent'](_0x55dc0d,_0x43bf24);return this;}['getAgent'](_0x12ffca){const _0x57d857=this['_agents']['get'](_0x12ffca);if(_0x57d857&&!isRemoteAgentRef(_0x57d857))return _0x57d857;}['getAgentRegistration'](_0x42b3df){return this['_agents']['get'](_0x42b3df);}['hasLocalAgent'](_0x13f7db){return Boolean(this['getAgent'](_0x13f7db));}['listen'](_0x483bb0){if(!_0x483bb0)throw new WorkflowError('workflow.listen\x20requires\x20a\x20DNotifier\x20instance');return this['_listenNotifier']&&this['_listenNotifier']!==_0x483bb0&&this['_listenNotifier']['_unregisterWorkflowListener'](this),this['_listenNotifier']=_0x483bb0,_0x483bb0['_registerWorkflowListener'](this),this['_syncBackendRegistration'](_0x483bb0),this;}['stopListening'](){var _0x2cbec8;return null===(_0x2cbec8=this['_listenNotifier'])||void 0x0===_0x2cbec8||_0x2cbec8['_unregisterWorkflowListener'](this),this['_listenNotifier']=null,this;}async['_handleRemoteInvoke'](_0x3066d2,_0x39868a,_0x4b6878){var _0x30701c,_0x5b97ed,_0x3dd161,_0x2f8993,_0x117ade,_0x14e7df,_0x44636d,_0x1aaa68;const _0x169a4f=_0x4b6878['agentName'],_0x3f2d27=_0x4b6878['correlationId'],_0xcdb5f3='string'==typeof _0x4b6878['replyTo']&&_0x4b6878['replyTo']['trim']()||bareUserId(_0x3066d2['appId'],null===(_0x30701c=null==_0x39868a?void 0x0:_0x39868a['metadata'])||void 0x0===_0x30701c?void 0x0:_0x30701c['sender']);if(!_0x3f2d27||!_0xcdb5f3)return;if(!this['hasLocalAgent'](_0x169a4f))return void await sendRemoteAgentError(_0x3066d2,{'senderId':_0x3066d2['userId'],'receiverId':_0xcdb5f3,'correlationId':_0x3f2d27,'agentName':_0x169a4f,'message':'Agent\x20not\x20hosted:\x20'+_0x169a4f});const _0x387ed5=_0x4b6878['state']&&'object'==typeof _0x4b6878['state']&&!Array['isArray'](_0x4b6878['state'])?{..._0x4b6878['state']}:{};let _0x2b6c4c=null;const _0x30e0fa=null!==(_0x3dd161=null===(_0x5b97ed=_0x4b6878['trace'])||void 0x0===_0x5b97ed?void 0x0:_0x5b97ed['executionId'])&&void 0x0!==_0x3dd161?_0x3dd161:null;_0x30e0fa&&this['observability']&&(_0x2b6c4c=createWorkflowObservability({'appId':_0x3066d2['appId'],'token':null!==(_0x2f8993=_0x3066d2['authToken'])&&void 0x0!==_0x2f8993?_0x2f8993:null,'appendOnly':!0x0}),await _0x2b6c4c['registerWorkflow'](this));const _0x22afb7=new WorkflowContext({'notifier':_0x3066d2,'senderId':_0x3066d2['userId'],'workflow':this,'input':null!==(_0x117ade=_0x4b6878['input'])&&void 0x0!==_0x117ade?_0x117ade:null,'state':_0x387ed5,'observability':_0x2b6c4c,'executionId':_0x30e0fa,'traceParentStepId':null!==(_0x44636d=null===(_0x14e7df=_0x4b6878['trace'])||void 0x0===_0x14e7df?void 0x0:_0x14e7df['parentStepId'])&&void 0x0!==_0x44636d?_0x44636d:null});try{const _0x5239cf=await _0x22afb7['runAgent'](_0x169a4f,{'input':void 0x0!==_0x4b6878['input']?_0x4b6878['input']:_0x22afb7['input']});await sendRemoteAgentResult(_0x3066d2,{'senderId':_0x3066d2['userId'],'receiverId':_0xcdb5f3,'correlationId':_0x3f2d27,'agentName':_0x169a4f,'output':_0x5239cf,'state':_0x22afb7['state']});}catch(_0x4f81b3){await sendRemoteAgentError(_0x3066d2,{'senderId':_0x3066d2['userId'],'receiverId':_0xcdb5f3,'correlationId':_0x3f2d27,'agentName':_0x169a4f,'message':null!==(_0x1aaa68=null==_0x4f81b3?void 0x0:_0x4f81b3['message'])&&void 0x0!==_0x1aaa68?_0x1aaa68:String(_0x4f81b3)});}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HttpTransport}from'../transport/httpTransport.js';import{DNotifierEndpoints}from'../config/endpoints.js';import{shortId}from'./ids.js';import{setJsonColumn}from'./jsonPayload.js';import{resolveStepType}from'./stepTypes.js';export class WorkflowObservabilityClient{constructor({appId:
|
|
1
|
+
import{HttpTransport}from'../transport/httpTransport.js';import{DNotifierEndpoints}from'../config/endpoints.js';import{shortId}from'./ids.js';import{setJsonColumn}from'./jsonPayload.js';import{resolveStepType}from'./stepTypes.js';export class WorkflowObservabilityClient{constructor({appId:_0xb5d20f=null,token:_0xd9b1df=null,requestTimeoutMs:_0x3beda9=0x1388}={}){this['appId']=_0xb5d20f,this['token']=_0xd9b1df,this['requestTimeoutMs']=_0x3beda9;}['configure']({appId:_0x5dabb7,token:_0x4f8997,requestTimeoutMs:_0x2a4651}={}){void 0x0!==_0x5dabb7&&(this['appId']=_0x5dabb7),void 0x0!==_0x4f8997&&(this['token']=_0x4f8997),void 0x0!==_0x2a4651&&(this['requestTimeoutMs']=_0x2a4651);}['_transport'](_0xcf69a0){const _0x4a0d97=this['token']?{'authorization':''+this['token']}:{};return new HttpTransport({'url':_0xcf69a0,'headers':_0x4a0d97,'timeoutMs':this['requestTimeoutMs']});}async['_post'](_0x90fbe0,_0x45cae0){if(this['token'])try{await this['_transport'](_0x90fbe0)['send'](_0x45cae0);}catch{}}async['registerWorkflow'](_0x34ab9d){const _0x22c66f={'appId':_0x34ab9d['appId'],'workflowId':_0x34ab9d['workflowId'],'name':_0x34ab9d['name']};return null!=_0x34ab9d['description']&&''!==_0x34ab9d['description']&&(_0x22c66f['description']=_0x34ab9d['description']),await this['_post'](DNotifierEndpoints['workflowRegisterUrl'],_0x22c66f),{'ok':!0x0};}async['createExecution'](_0x39dbb7){var _0x3cd5fe;const _0x2a3d72=null!==(_0x3cd5fe=_0x39dbb7['id'])&&void 0x0!==_0x3cd5fe?_0x3cd5fe:shortId('exec'),_0x11c622={'id':_0x2a3d72,'appId':_0x39dbb7['appId'],'workflowId':_0x39dbb7['workflowId'],'userId':_0x39dbb7['userId'],'status':'in_progress','stepCount':0x0,'startedAt':_0x39dbb7['startedAt']};return setJsonColumn(_0x11c622,'input',_0x39dbb7['input']),await this['_post'](DNotifierEndpoints['workflowExecutionsUrl'],_0x11c622),{'executionId':_0x2a3d72,'record':_0x11c622};}async['updateExecution'](_0x3c8859,_0x4ab95e){const _0x2068c3={'id':_0x3c8859,'status':_0x4ab95e['status'],'endedAt':_0x4ab95e['endedAt'],'durationMs':_0x4ab95e['durationMs'],'stepCount':_0x4ab95e['stepCount']};return setJsonColumn(_0x2068c3,'error',_0x4ab95e['error']),setJsonColumn(_0x2068c3,'result',_0x4ab95e['result']),await this['_post'](DNotifierEndpoints['workflowExecutionCompleteUrl'](_0x3c8859),_0x2068c3),{'ok':!0x0,'record':_0x2068c3};}async['addStep'](_0xb64d79,_0x5891f8){var _0x1f1da8,_0x487421,_0x3fc577,_0x16163e,_0x1cac01,_0x174c30;const _0x5b8a29=resolveStepType(_0x5891f8),_0x37ad71=null!==(_0x3fc577=null!==(_0x487421=null!==(_0x1f1da8=_0x5891f8['agentName'])&&void 0x0!==_0x1f1da8?_0x1f1da8:_0x5891f8['kind'])&&void 0x0!==_0x487421?_0x487421:_0x5891f8['apiName'])&&void 0x0!==_0x3fc577?_0x3fc577:null,_0x202f18={'id':_0x5891f8['id'],'executionId':_0xb64d79,'kind':_0x37ad71,'label':_0x5891f8['label'],'type':_0x5b8a29,'step_type':_0x5b8a29,'status':_0x5891f8['status'],'executedAt':_0x5891f8['executedAt'],'latencyMs':null!==(_0x16163e=_0x5891f8['latencyMs'])&&void 0x0!==_0x16163e?_0x16163e:0x0,'tokensIn':null!==(_0x1cac01=_0x5891f8['tokensIn'])&&void 0x0!==_0x1cac01?_0x1cac01:0x0,'tokensOut':null!==(_0x174c30=_0x5891f8['tokensOut'])&&void 0x0!==_0x174c30?_0x174c30:0x0};return null!=_0x5891f8['apiName']&&''!==_0x5891f8['apiName']&&(_0x202f18['apiName']=_0x5891f8['apiName']),null!=_0x5891f8['agentName']&&''!==_0x5891f8['agentName']&&(_0x202f18['agentName']=_0x5891f8['agentName']),null!=_0x5891f8['model']&&''!==_0x5891f8['model']&&(_0x202f18['model']='string'==typeof _0x5891f8['model']?_0x5891f8['model']:String(_0x5891f8['model'])),null!=_0x5891f8['provider']&&''!==_0x5891f8['provider']&&(_0x202f18['provider']='string'==typeof _0x5891f8['provider']?_0x5891f8['provider']:String(_0x5891f8['provider'])),setJsonColumn(_0x202f18,'input',_0x5891f8['input']),setJsonColumn(_0x202f18,'output',_0x5891f8['output']),setJsonColumn(_0x202f18,'state',_0x5891f8['state']),setJsonColumn(_0x202f18,'error',_0x5891f8['error']),null!=_0x5891f8['parentStepId']&&''!==_0x5891f8['parentStepId']&&(_0x202f18['parentStepId']=_0x5891f8['parentStepId']),null!=_0x5891f8['siblingIndex']&&''!==_0x5891f8['siblingIndex']&&(_0x202f18['siblingIndex']=_0x5891f8['siblingIndex']),null!=_0x5891f8['branchKey']&&''!==_0x5891f8['branchKey']&&(_0x202f18['branchKey']=_0x5891f8['branchKey']),await this['_post'](DNotifierEndpoints['workflowExecutionStepsUrl'](_0xb64d79),_0x202f18),{'ok':!0x0};}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnotifier-realtime/dnotifier",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.30",
|
|
4
4
|
"description": "Official JavaScript SDK for DNotifier — AI agents, multi-agent workflows, RAG, and observability",
|
|
5
5
|
"main": "dist/dnotifier.js",
|
|
6
6
|
"types": "dist/dnotifier.d.ts",
|