@madh-io/alfred-ai 0.13.2 → 0.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bundle/index.js +2 -2
  2. package/package.json +1 -1
package/bundle/index.js CHANGED
@@ -1206,8 +1206,8 @@ Regeln:
1206
1206
  - Leere Punkte: "\u2014"
1207
1207
  - Sprache: Deutsch (oder Sprache des Gespr\xE4chs)`,n}}});var an,Ma=_(()=>{"use strict";an=class{static{u(this,"CalendarWatcher")}calendarProvider;notifRepo;adapters;defaultChatId;defaultPlatform;config;logger;activityLogger;timer=null;tickIntervalMs=6e4;minutesBefore;lastCleanup=0;constructor(e,t,s,r,n,o,i,a){this.calendarProvider=e,this.notifRepo=t,this.adapters=s,this.defaultChatId=r,this.defaultPlatform=n,this.config=o,this.logger=i,this.activityLogger=a,this.minutesBefore=o.minutesBefore??15}start(){this.timer=setInterval(()=>this.tick(),this.tickIntervalMs),this.logger.info({minutesBefore:this.minutesBefore},"Calendar watcher started")}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.logger.info("Calendar watcher stopped")}async tick(){try{let e=Date.now();if(e-this.lastCleanup>36e5){let n=new Date(e-864e5).toISOString();this.notifRepo.cleanup(n),this.lastCleanup=e}let t=new Date,s=new Date(t.getTime()+this.minutesBefore*6e4),r=await this.calendarProvider.listEvents(t,s);for(let n of r)await this.processEvent(n)}catch(e){this.logger.error({err:e},"Calendar watcher tick failed")}}async processEvent(e){if(e.allDay||this.notifRepo.wasNotified(e.id,this.defaultChatId))return;let t=Date.now(),r=(e.start.getTime()-t)/6e4;if(r>this.minutesBefore||r<0)return;let n=[],o=Math.round(r),i=e.start.toLocaleTimeString("de-DE",{hour:"2-digit",minute:"2-digit"});if(n.push(`\u{1F4C5} In ${o} Min: ${e.title}`),n.push(`Zeit: ${i} \u2013 ${e.end.toLocaleTimeString("de-DE",{hour:"2-digit",minute:"2-digit"})}`),e.location&&n.push(`Ort: ${e.location}`),e.description){let c=e.description.slice(0,200);n.push(`
1208
1208
  ${c}`)}let a=this.adapters.get(this.defaultPlatform);if(a)try{await a.sendMessage(this.defaultChatId,n.join(`
1209
- `)),this.notifRepo.markNotified(e.id,this.defaultChatId,this.defaultPlatform,e.start.toISOString()),this.logger.info({eventId:e.id,title:e.title},"Calendar vorlauf notification sent"),this.activityLogger?.logCalendarNotify({eventId:e.id,eventTitle:e.title,platform:this.defaultPlatform,chatId:this.defaultChatId,outcome:"success"})}catch(c){this.logger.error({err:c,eventId:e.id},"Failed to send calendar notification"),this.activityLogger?.logCalendarNotify({eventId:e.id,eventTitle:e.title,platform:this.defaultPlatform,chatId:this.defaultChatId,outcome:"error",error:c instanceof Error?c.message:String(c)})}}}});var cn,Oa=_(()=>{"use strict";cn=class{static{u(this,"TodoWatcher")}todoRepo;notifRepo;adapters;defaultChatId;defaultPlatform;logger;activityLogger;timer=null;tickIntervalMs=6e4;minutesBefore;overdueCheck;lastOverdueCheck=0;constructor(e,t,s,r,n,o,i,a){this.todoRepo=e,this.notifRepo=t,this.adapters=s,this.defaultChatId=r,this.defaultPlatform=n,this.logger=i,this.activityLogger=a,this.minutesBefore=o.minutesBefore??30,this.overdueCheck=o.overdueCheck??!0}start(){this.timer=setInterval(()=>this.tick(),this.tickIntervalMs),this.logger.info({minutesBefore:this.minutesBefore},"Todo watcher started")}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.logger.info("Todo watcher stopped")}async tick(){try{let e=new Date(Date.now()+this.minutesBefore*6e4),t=this.todoRepo.getDueInWindow(e.toISOString());for(let r of t)await this.notify(r.id,r.title,r.dueDate,r.list,r.priority,"upcoming");let s=Date.now();if(this.overdueCheck&&s-this.lastOverdueCheck>36e5){this.lastOverdueCheck=s;let r=this.todoRepo.getOverdue();for(let n of r)await this.notify(n.id,n.title,n.dueDate,n.list,n.priority,"overdue")}}catch(e){this.logger.error({err:e},"Todo watcher tick failed")}}async notify(e,t,s,r,n,o){let i=`todo:${o}:${e}`;if(this.notifRepo.wasNotified(i,this.defaultChatId))return;let c=new Date(s).toLocaleString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}),p=[`${o==="overdue"?"\u26A0\uFE0F":"\u2705"} **${o==="overdue"?"\xDCberf\xE4llig":"Bald f\xE4llig"}:** ${t}`,`F\xE4llig: ${c}`];r!=="default"&&p.push(`Liste: ${r}`),n!=="normal"&&p.push(`Priorit\xE4t: ${n}`);let f=this.adapters.get(this.defaultPlatform);if(f)try{await f.sendMessage(this.defaultChatId,p.join(`
1210
- `)),this.notifRepo.markNotified(i,this.defaultChatId,this.defaultPlatform,s),this.logger.info({todoId:e,title:t,kind:o},"Todo reminder sent"),this.activityLogger?.logCalendarNotify({eventId:i,eventTitle:`[Todo] ${t}`,platform:this.defaultPlatform,chatId:this.defaultChatId,outcome:"success"})}catch(g){this.logger.error({err:g,todoId:e},"Failed to send todo reminder"),this.activityLogger?.logCalendarNotify({eventId:i,eventTitle:`[Todo] ${t}`,platform:this.defaultPlatform,chatId:this.defaultChatId,outcome:"error",error:g instanceof Error?g.message:String(g)})}}}});var ln,Ua=_(()=>{"use strict";ln=class{static{u(this,"ActivityLogger")}repo;logger;constructor(e,t){this.repo=e,this.logger=t}logSkillExec(e){this.safe(()=>this.repo.log({eventType:"skill_exec",source:"user",userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.skillName,outcome:e.outcome,durationMs:e.durationMs,errorMessage:e.error,details:e.details}))}logWatchTrigger(e){this.safe(()=>this.repo.log({eventType:"watch_trigger",source:"watch",sourceId:e.watchId,platform:e.platform,chatId:e.chatId,action:e.watchName,outcome:e.outcome,errorMessage:e.error,details:{value:e.value}}))}logWatchAction(e){this.safe(()=>this.repo.log({eventType:"watch_action",source:"watch",sourceId:e.watchId,platform:e.platform,chatId:e.chatId,action:e.skillName,outcome:e.outcome,errorMessage:e.error,details:{watchName:e.watchName}}))}logConfirmation(e){this.safe(()=>this.repo.log({eventType:"confirmation",source:e.source,sourceId:e.sourceId,userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.skillName,outcome:e.outcome,errorMessage:e.error,details:{confirmationId:e.confirmationId,description:e.description}}))}logScheduledExec(e){this.safe(()=>this.repo.log({eventType:"scheduled_exec",source:"scheduled",sourceId:e.actionId,userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.actionName,outcome:e.outcome,durationMs:e.durationMs,errorMessage:e.error,details:e.skillName?{skillName:e.skillName}:void 0}))}logBackgroundTask(e){this.safe(()=>this.repo.log({eventType:"background_task",source:"background",sourceId:e.taskId,userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.skillName,outcome:e.outcome,durationMs:e.durationMs,errorMessage:e.error}))}logCalendarNotify(e){this.safe(()=>this.repo.log({eventType:"calendar_notify",source:"system",sourceId:e.eventId,platform:e.platform,chatId:e.chatId,action:e.eventTitle,outcome:e.outcome,errorMessage:e.error}))}logWorkflowExec(e){this.safe(()=>this.repo.log({eventType:"workflow_exec",source:"workflow",sourceId:e.chainId,userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.chainName,outcome:e.outcome,errorMessage:e.error,details:{executionId:e.executionId,...e.details}}))}logAgentLifecycle(e){this.safe(()=>this.repo.log({eventType:"agent_lifecycle",source:"background",sourceId:e.taskId,userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.event,outcome:"success",details:{skillName:e.skillName,...e.details}}))}logSkillHealth(e){this.safe(()=>this.repo.log({eventType:"skill_health",source:"system",action:e.skillName,outcome:e.outcome,details:e.details}))}safe(e){try{e()}catch(t){this.logger.warn({err:t},"Failed to write activity log entry")}}}});var Gh,dn,Pa=_(()=>{"use strict";Gh=[{fails:20,durationMinutes:1440},{fails:10,durationMinutes:120},{fails:5,durationMinutes:30}],dn=class{static{u(this,"SkillHealthTracker")}healthRepo;logger;activityLogger;constructor(e,t,s){this.healthRepo=e,this.logger=t,this.activityLogger=s}isDisabled(e){try{return this.healthRepo.isDisabled(e)?this.healthRepo.getByName(e):void 0}catch{return}}recordSuccess(e){try{this.healthRepo.recordSuccess(e)}catch(t){this.logger.debug({err:t,skillName:e},"Failed to record skill success")}}recordFailure(e,t){try{let s=this.healthRepo.recordFailure(e,t);for(let r of Gh)if(s.consecutiveFails>=r.fails&&!s.disabledUntil){let n=new Date(Date.now()+r.durationMinutes*6e4).toISOString();this.healthRepo.disable(e,n),this.logger.warn({skillName:e,consecutiveFails:s.consecutiveFails,disabledUntil:n},"Skill auto-disabled due to repeated failures"),this.activityLogger?.logSkillHealth({skillName:e,outcome:"disabled",details:{consecutiveFails:s.consecutiveFails,disabledUntil:n,lastError:t}});break}}catch(s){this.logger.debug({err:s,skillName:e},"Failed to record skill failure")}}forceEnable(e){try{this.healthRepo.enable(e),this.logger.info({skillName:e},"Skill force-enabled by user"),this.activityLogger?.logSkillHealth({skillName:e,outcome:"re-enabled",details:{reason:"force-enable"}})}catch(t){this.logger.warn({err:t,skillName:e},"Failed to force-enable skill")}}getDashboard(){try{return this.healthRepo.getAll()}catch{return[]}}checkReEnables(){try{let e=this.healthRepo.getAll(),t=new Date;for(let s of e)s.disabledUntil&&new Date(s.disabledUntil)<=t&&(this.healthRepo.enable(s.skillName),this.logger.info({skillName:s.skillName},"Skill auto-re-enabled after cooldown"),this.activityLogger?.logSkillHealth({skillName:s.skillName,outcome:"re-enabled",details:{reason:"cooldown-expired"}}))}catch(e){this.logger.warn({err:e},"Failed to check re-enables")}}}});var un,Fa=_(()=>{"use strict";ho();un=class{static{u(this,"WorkflowRunner")}workflowRepo;skillRegistry;skillSandbox;logger;activityLogger;healthTracker;constructor(e,t,s,r,n,o){this.workflowRepo=e,this.skillRegistry=t,this.skillSandbox=s,this.logger=r,this.activityLogger=n,this.healthTracker=o}async run(e,t,s){let r=this.workflowRepo.createExecution(e.id,e.steps.length),n=[],o=s??{};for(let i=0;i<e.steps.length;i++){let a=e.steps[i];if(this.healthTracker?.isDisabled(a.skillName)){let h=`Skill "${a.skillName}" is temporarily disabled`;if(a.onError==="skip"){n.push({skillName:a.skillName,success:!1,error:h});continue}return this.finishExecution(r.id,"failed",i,n,h),{executionId:r.id,status:"failed",stepsCompleted:i,totalSteps:e.steps.length,stepResults:n,error:h}}let c=this.skillRegistry.get(a.skillName);if(!c){let h=`Skill "${a.skillName}" not found`;if(a.onError==="skip"){n.push({skillName:a.skillName,success:!1,error:h});continue}return this.finishExecution(r.id,"failed",i,n,h),{executionId:r.id,status:"failed",stepsCompleted:i,totalSteps:e.steps.length,stepResults:n,error:h}}let d={prev:o,steps:n.map(h=>h.data)};s&&(d.trigger=s);let m=Ht(a.inputMapping,d),p=a.onError==="retry"?(a.maxRetries??1)+1:1,f,g=!1;for(let h=0;h<p;h++)try{let y=await this.skillSandbox.execute(c,m,t);if(y.success){o=y.data,n.push({skillName:a.skillName,success:!0,data:y.data}),this.healthTracker?.recordSuccess(a.skillName),g=!0;break}else f=y.error??"Unknown error",this.healthTracker?.recordFailure(a.skillName,f)}catch(y){f=y instanceof Error?y.message:String(y),this.healthTracker?.recordFailure(a.skillName,f)}if(!g){if(n.push({skillName:a.skillName,success:!1,error:f}),a.onError==="skip")continue;let h=i>0?"partial":"failed";return this.finishExecution(r.id,h,i,n,f),this.logWorkflow(e,r.id,h,i,f),{executionId:r.id,status:h,stepsCompleted:i,totalSteps:e.steps.length,stepResults:n,error:f}}this.workflowRepo.updateExecution(r.id,{stepsCompleted:i+1,stepResults:JSON.stringify(n)})}return this.finishExecution(r.id,"completed",e.steps.length,n),this.logWorkflow(e,r.id,"completed",e.steps.length),{executionId:r.id,status:"completed",stepsCompleted:e.steps.length,totalSteps:e.steps.length,stepResults:n}}finishExecution(e,t,s,r,n){this.workflowRepo.updateExecution(e,{status:t,stepsCompleted:s,stepResults:JSON.stringify(r),error:n,completedAt:new Date().toISOString()})}logWorkflow(e,t,s,r,n){this.activityLogger?.logWorkflowExec({chainId:e.id,chainName:e.name,executionId:t,platform:e.platform,chatId:e.chatId,userId:e.userId,outcome:s==="completed"?"success":"error",error:n,details:{stepsCompleted:r,totalSteps:e.steps.length}})}}});import Xh from"node:crypto";var Vh,Kh,mn,ja=_(()=>{"use strict";ut();Vh=[7,12,18],Kh=1024,mn=class{static{u(this,"ReasoningEngine")}calendarProvider;todoRepo;watchRepo;memoryRepo;activityRepo;skillHealthRepo;notifRepo;skillRegistry;skillSandbox;llm;adapters;userRepo;defaultChatId;defaultPlatform;logger;activityLogger;tickTimer;lastRunHour=-1;enabled;schedule;tier;deduplicationHours;constructor(e,t,s,r,n,o,i,a,c,d,m,p,f,g,h,y,k){this.calendarProvider=e,this.todoRepo=t,this.watchRepo=s,this.memoryRepo=r,this.activityRepo=n,this.skillHealthRepo=o,this.notifRepo=i,this.skillRegistry=a,this.skillSandbox=c,this.llm=d,this.adapters=m,this.userRepo=p,this.defaultChatId=f,this.defaultPlatform=g,this.logger=y,this.activityLogger=k,this.enabled=h?.enabled!==!1,this.schedule=h?.schedule??"morning_noon_evening",this.tier=h?.tier??"fast",this.deduplicationHours=h?.deduplicationHours??12}start(){if(!this.enabled){this.logger.info("Reasoning engine disabled");return}this.tickTimer=setInterval(()=>this.tick(),6e4),this.logger.info({schedule:this.schedule,tier:this.tier},"Reasoning engine started")}stop(){this.tickTimer&&(clearInterval(this.tickTimer),this.tickTimer=void 0)}shouldRun(){let e=new Date,t=e.getHours(),s=e.getMinutes();switch(this.schedule){case"morning_noon_evening":return!!(Vh.includes(t)&&s===0&&this.lastRunHour!==t);case"hourly":return s===0&&this.lastRunHour!==t;case"half_hourly":return(s===0||s===30)&&this.lastRunHour!==t*100+s;default:return!1}}markRun(){let e=new Date;this.schedule==="half_hourly"?this.lastRunHour=e.getHours()*100+e.getMinutes():this.lastRunHour=e.getHours()}async tick(){if(this.shouldRun()){this.markRun();try{this.logger.info("Reasoning pass starting");let e=Date.now(),t=await this.collectContext(),s=this.buildPrompt(t),n=(await this.llm.complete({messages:[{role:"user",content:s}],maxTokens:Kh,tier:this.tier})).content.trim(),o=Date.now()-e;if(!n||n==="KEINE_INSIGHTS"||n.length<10){this.logger.info({durationMs:o},"Reasoning pass: no insights"),this.activityLogger?.logScheduledExec({actionId:"reasoning-engine",actionName:"Reasoning Engine",platform:this.defaultPlatform,chatId:this.defaultChatId,userId:this.defaultChatId,outcome:"success",durationMs:o});return}let i=this.parseInsights(n),a=i.filter(m=>!this.wasRecentlySent(m));if(a.length===0){this.logger.info({durationMs:o,total:i.length},"Reasoning pass: all insights deduplicated");return}let c=`\u{1F4A1} **Alfred Insights**
1209
+ `)),this.notifRepo.markNotified(e.id,this.defaultChatId,this.defaultPlatform,e.start.toISOString()),this.logger.info({eventId:e.id,title:e.title},"Calendar vorlauf notification sent"),this.activityLogger?.logCalendarNotify({eventId:e.id,eventTitle:e.title,platform:this.defaultPlatform,chatId:this.defaultChatId,outcome:"success"})}catch(c){this.logger.error({err:c,eventId:e.id},"Failed to send calendar notification"),this.activityLogger?.logCalendarNotify({eventId:e.id,eventTitle:e.title,platform:this.defaultPlatform,chatId:this.defaultChatId,outcome:"error",error:c instanceof Error?c.message:String(c)})}}}});var cn,Oa=_(()=>{"use strict";cn=class{static{u(this,"TodoWatcher")}todoRepo;notifRepo;adapters;defaultChatId;defaultPlatform;logger;activityLogger;timer=null;tickIntervalMs=6e4;minutesBefore;overdueCheck;lastOverdueCheck=0;constructor(e,t,s,r,n,o,i,a){this.todoRepo=e,this.notifRepo=t,this.adapters=s,this.defaultChatId=r,this.defaultPlatform=n,this.logger=i,this.activityLogger=a,this.minutesBefore=o.minutesBefore??30,this.overdueCheck=o.overdueCheck??!0}start(){this.timer=setInterval(()=>this.tick(),this.tickIntervalMs),this.logger.info({minutesBefore:this.minutesBefore},"Todo watcher started")}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.logger.info("Todo watcher stopped")}async tick(){try{let e=new Date(Date.now()+this.minutesBefore*6e4),t=this.todoRepo.getDueInWindow(e.toISOString());for(let r of t)await this.notify(r.id,r.title,r.dueDate,r.list,r.priority,"upcoming");let s=Date.now();if(this.overdueCheck&&s-this.lastOverdueCheck>36e5){this.lastOverdueCheck=s;let r=this.todoRepo.getOverdue();for(let n of r)await this.notify(n.id,n.title,n.dueDate,n.list,n.priority,"overdue")}}catch(e){this.logger.error({err:e},"Todo watcher tick failed")}}async notify(e,t,s,r,n,o){let i=o==="overdue"?`todo:${o}:${e}:${new Date().toISOString().slice(0,10)}`:`todo:${o}:${e}`;if(this.notifRepo.wasNotified(i,this.defaultChatId))return;let c=new Date(s).toLocaleString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}),p=[`${o==="overdue"?"\u26A0\uFE0F":"\u2705"} **${o==="overdue"?"\xDCberf\xE4llig":"Bald f\xE4llig"}:** ${t}`,`F\xE4llig: ${c}`];r!=="default"&&p.push(`Liste: ${r}`),n!=="normal"&&p.push(`Priorit\xE4t: ${n}`);let f=this.adapters.get(this.defaultPlatform);if(!f)return;let g=o==="overdue"?new Date().toISOString():s;try{await f.sendMessage(this.defaultChatId,p.join(`
1210
+ `)),this.notifRepo.markNotified(i,this.defaultChatId,this.defaultPlatform,g),this.logger.info({todoId:e,title:t,kind:o},"Todo reminder sent"),this.activityLogger?.logCalendarNotify({eventId:i,eventTitle:`[Todo] ${t}`,platform:this.defaultPlatform,chatId:this.defaultChatId,outcome:"success"})}catch(h){this.logger.error({err:h,todoId:e},"Failed to send todo reminder"),this.activityLogger?.logCalendarNotify({eventId:i,eventTitle:`[Todo] ${t}`,platform:this.defaultPlatform,chatId:this.defaultChatId,outcome:"error",error:h instanceof Error?h.message:String(h)})}}}});var ln,Ua=_(()=>{"use strict";ln=class{static{u(this,"ActivityLogger")}repo;logger;constructor(e,t){this.repo=e,this.logger=t}logSkillExec(e){this.safe(()=>this.repo.log({eventType:"skill_exec",source:"user",userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.skillName,outcome:e.outcome,durationMs:e.durationMs,errorMessage:e.error,details:e.details}))}logWatchTrigger(e){this.safe(()=>this.repo.log({eventType:"watch_trigger",source:"watch",sourceId:e.watchId,platform:e.platform,chatId:e.chatId,action:e.watchName,outcome:e.outcome,errorMessage:e.error,details:{value:e.value}}))}logWatchAction(e){this.safe(()=>this.repo.log({eventType:"watch_action",source:"watch",sourceId:e.watchId,platform:e.platform,chatId:e.chatId,action:e.skillName,outcome:e.outcome,errorMessage:e.error,details:{watchName:e.watchName}}))}logConfirmation(e){this.safe(()=>this.repo.log({eventType:"confirmation",source:e.source,sourceId:e.sourceId,userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.skillName,outcome:e.outcome,errorMessage:e.error,details:{confirmationId:e.confirmationId,description:e.description}}))}logScheduledExec(e){this.safe(()=>this.repo.log({eventType:"scheduled_exec",source:"scheduled",sourceId:e.actionId,userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.actionName,outcome:e.outcome,durationMs:e.durationMs,errorMessage:e.error,details:e.skillName?{skillName:e.skillName}:void 0}))}logBackgroundTask(e){this.safe(()=>this.repo.log({eventType:"background_task",source:"background",sourceId:e.taskId,userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.skillName,outcome:e.outcome,durationMs:e.durationMs,errorMessage:e.error}))}logCalendarNotify(e){this.safe(()=>this.repo.log({eventType:"calendar_notify",source:"system",sourceId:e.eventId,platform:e.platform,chatId:e.chatId,action:e.eventTitle,outcome:e.outcome,errorMessage:e.error}))}logWorkflowExec(e){this.safe(()=>this.repo.log({eventType:"workflow_exec",source:"workflow",sourceId:e.chainId,userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.chainName,outcome:e.outcome,errorMessage:e.error,details:{executionId:e.executionId,...e.details}}))}logAgentLifecycle(e){this.safe(()=>this.repo.log({eventType:"agent_lifecycle",source:"background",sourceId:e.taskId,userId:e.userId,platform:e.platform,chatId:e.chatId,action:e.event,outcome:"success",details:{skillName:e.skillName,...e.details}}))}logSkillHealth(e){this.safe(()=>this.repo.log({eventType:"skill_health",source:"system",action:e.skillName,outcome:e.outcome,details:e.details}))}safe(e){try{e()}catch(t){this.logger.warn({err:t},"Failed to write activity log entry")}}}});var Gh,dn,Pa=_(()=>{"use strict";Gh=[{fails:20,durationMinutes:1440},{fails:10,durationMinutes:120},{fails:5,durationMinutes:30}],dn=class{static{u(this,"SkillHealthTracker")}healthRepo;logger;activityLogger;constructor(e,t,s){this.healthRepo=e,this.logger=t,this.activityLogger=s}isDisabled(e){try{return this.healthRepo.isDisabled(e)?this.healthRepo.getByName(e):void 0}catch{return}}recordSuccess(e){try{this.healthRepo.recordSuccess(e)}catch(t){this.logger.debug({err:t,skillName:e},"Failed to record skill success")}}recordFailure(e,t){try{let s=this.healthRepo.recordFailure(e,t);for(let r of Gh)if(s.consecutiveFails>=r.fails&&!s.disabledUntil){let n=new Date(Date.now()+r.durationMinutes*6e4).toISOString();this.healthRepo.disable(e,n),this.logger.warn({skillName:e,consecutiveFails:s.consecutiveFails,disabledUntil:n},"Skill auto-disabled due to repeated failures"),this.activityLogger?.logSkillHealth({skillName:e,outcome:"disabled",details:{consecutiveFails:s.consecutiveFails,disabledUntil:n,lastError:t}});break}}catch(s){this.logger.debug({err:s,skillName:e},"Failed to record skill failure")}}forceEnable(e){try{this.healthRepo.enable(e),this.logger.info({skillName:e},"Skill force-enabled by user"),this.activityLogger?.logSkillHealth({skillName:e,outcome:"re-enabled",details:{reason:"force-enable"}})}catch(t){this.logger.warn({err:t,skillName:e},"Failed to force-enable skill")}}getDashboard(){try{return this.healthRepo.getAll()}catch{return[]}}checkReEnables(){try{let e=this.healthRepo.getAll(),t=new Date;for(let s of e)s.disabledUntil&&new Date(s.disabledUntil)<=t&&(this.healthRepo.enable(s.skillName),this.logger.info({skillName:s.skillName},"Skill auto-re-enabled after cooldown"),this.activityLogger?.logSkillHealth({skillName:s.skillName,outcome:"re-enabled",details:{reason:"cooldown-expired"}}))}catch(e){this.logger.warn({err:e},"Failed to check re-enables")}}}});var un,Fa=_(()=>{"use strict";ho();un=class{static{u(this,"WorkflowRunner")}workflowRepo;skillRegistry;skillSandbox;logger;activityLogger;healthTracker;constructor(e,t,s,r,n,o){this.workflowRepo=e,this.skillRegistry=t,this.skillSandbox=s,this.logger=r,this.activityLogger=n,this.healthTracker=o}async run(e,t,s){let r=this.workflowRepo.createExecution(e.id,e.steps.length),n=[],o=s??{};for(let i=0;i<e.steps.length;i++){let a=e.steps[i];if(this.healthTracker?.isDisabled(a.skillName)){let h=`Skill "${a.skillName}" is temporarily disabled`;if(a.onError==="skip"){n.push({skillName:a.skillName,success:!1,error:h});continue}return this.finishExecution(r.id,"failed",i,n,h),{executionId:r.id,status:"failed",stepsCompleted:i,totalSteps:e.steps.length,stepResults:n,error:h}}let c=this.skillRegistry.get(a.skillName);if(!c){let h=`Skill "${a.skillName}" not found`;if(a.onError==="skip"){n.push({skillName:a.skillName,success:!1,error:h});continue}return this.finishExecution(r.id,"failed",i,n,h),{executionId:r.id,status:"failed",stepsCompleted:i,totalSteps:e.steps.length,stepResults:n,error:h}}let d={prev:o,steps:n.map(h=>h.data)};s&&(d.trigger=s);let m=Ht(a.inputMapping,d),p=a.onError==="retry"?(a.maxRetries??1)+1:1,f,g=!1;for(let h=0;h<p;h++)try{let y=await this.skillSandbox.execute(c,m,t);if(y.success){o=y.data,n.push({skillName:a.skillName,success:!0,data:y.data}),this.healthTracker?.recordSuccess(a.skillName),g=!0;break}else f=y.error??"Unknown error",this.healthTracker?.recordFailure(a.skillName,f)}catch(y){f=y instanceof Error?y.message:String(y),this.healthTracker?.recordFailure(a.skillName,f)}if(!g){if(n.push({skillName:a.skillName,success:!1,error:f}),a.onError==="skip")continue;let h=i>0?"partial":"failed";return this.finishExecution(r.id,h,i,n,f),this.logWorkflow(e,r.id,h,i,f),{executionId:r.id,status:h,stepsCompleted:i,totalSteps:e.steps.length,stepResults:n,error:f}}this.workflowRepo.updateExecution(r.id,{stepsCompleted:i+1,stepResults:JSON.stringify(n)})}return this.finishExecution(r.id,"completed",e.steps.length,n),this.logWorkflow(e,r.id,"completed",e.steps.length),{executionId:r.id,status:"completed",stepsCompleted:e.steps.length,totalSteps:e.steps.length,stepResults:n}}finishExecution(e,t,s,r,n){this.workflowRepo.updateExecution(e,{status:t,stepsCompleted:s,stepResults:JSON.stringify(r),error:n,completedAt:new Date().toISOString()})}logWorkflow(e,t,s,r,n){this.activityLogger?.logWorkflowExec({chainId:e.id,chainName:e.name,executionId:t,platform:e.platform,chatId:e.chatId,userId:e.userId,outcome:s==="completed"?"success":"error",error:n,details:{stepsCompleted:r,totalSteps:e.steps.length}})}}});import Xh from"node:crypto";var Vh,Kh,mn,ja=_(()=>{"use strict";ut();Vh=[7,12,18],Kh=1024,mn=class{static{u(this,"ReasoningEngine")}calendarProvider;todoRepo;watchRepo;memoryRepo;activityRepo;skillHealthRepo;notifRepo;skillRegistry;skillSandbox;llm;adapters;userRepo;defaultChatId;defaultPlatform;logger;activityLogger;tickTimer;lastRunHour=-1;enabled;schedule;tier;deduplicationHours;constructor(e,t,s,r,n,o,i,a,c,d,m,p,f,g,h,y,k){this.calendarProvider=e,this.todoRepo=t,this.watchRepo=s,this.memoryRepo=r,this.activityRepo=n,this.skillHealthRepo=o,this.notifRepo=i,this.skillRegistry=a,this.skillSandbox=c,this.llm=d,this.adapters=m,this.userRepo=p,this.defaultChatId=f,this.defaultPlatform=g,this.logger=y,this.activityLogger=k,this.enabled=h?.enabled!==!1,this.schedule=h?.schedule??"morning_noon_evening",this.tier=h?.tier??"fast",this.deduplicationHours=h?.deduplicationHours??12}start(){if(!this.enabled){this.logger.info("Reasoning engine disabled");return}this.tickTimer=setInterval(()=>this.tick(),6e4),this.logger.info({schedule:this.schedule,tier:this.tier},"Reasoning engine started")}stop(){this.tickTimer&&(clearInterval(this.tickTimer),this.tickTimer=void 0)}shouldRun(){let e=new Date,t=e.getHours(),s=e.getMinutes();switch(this.schedule){case"morning_noon_evening":return!!(Vh.includes(t)&&s===0&&this.lastRunHour!==t);case"hourly":return s===0&&this.lastRunHour!==t;case"half_hourly":return(s===0||s===30)&&this.lastRunHour!==t*100+s;default:return!1}}markRun(){let e=new Date;this.schedule==="half_hourly"?this.lastRunHour=e.getHours()*100+e.getMinutes():this.lastRunHour=e.getHours()}async tick(){if(this.shouldRun()){this.markRun();try{this.logger.info("Reasoning pass starting");let e=Date.now(),t=await this.collectContext(),s=this.buildPrompt(t),n=(await this.llm.complete({messages:[{role:"user",content:s}],maxTokens:Kh,tier:this.tier})).content.trim(),o=Date.now()-e;if(!n||n==="KEINE_INSIGHTS"||n.length<10){this.logger.info({durationMs:o},"Reasoning pass: no insights"),this.activityLogger?.logScheduledExec({actionId:"reasoning-engine",actionName:"Reasoning Engine",platform:this.defaultPlatform,chatId:this.defaultChatId,userId:this.defaultChatId,outcome:"success",durationMs:o});return}let i=this.parseInsights(n),a=i.filter(m=>!this.wasRecentlySent(m));if(a.length===0){this.logger.info({durationMs:o,total:i.length},"Reasoning pass: all insights deduplicated");return}let c=`\u{1F4A1} **Alfred Insights**
1211
1211
 
1212
1212
  ${a.join(`
1213
1213
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madh-io/alfred-ai",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "description": "Alfred — Personal AI Assistant across Telegram, Discord, WhatsApp, Matrix & Signal",
5
5
  "type": "module",
6
6
  "bin": {