agentix-cli 0.80.1 → 0.81.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/mac-voice/Sources/AgentXVoice/CallModel.swift +11 -0
- package/apps/mac-voice/Sources/AgentXVoice/Calls.swift +7 -4
- package/apps/mac-voice/Sources/AgentXVoice/main.swift +15 -3
- package/dist/{App-KVH5POXZ.js → App-HF6W6CV2.js} +2 -2
- package/dist/{App-KVH5POXZ.js.map → App-HF6W6CV2.js.map} +1 -1
- package/dist/ChatApp-74VBWP7R.js +7 -0
- package/dist/{ChatApp-LD4TXJWP.js.map → ChatApp-74VBWP7R.js.map} +1 -1
- package/dist/{agent-FUMJM6OW.js → agent-75URYGWI.js} +2 -2
- package/dist/{board-dashboard-OS5J3F73.js → board-dashboard-TWEF5XVE.js} +186 -169
- package/dist/board-dashboard-TWEF5XVE.js.map +1 -0
- package/dist/{chunk-MYRSNJJ4.js → chunk-3FCYKGU6.js} +2 -2
- package/dist/{chunk-R42S57G6.js → chunk-4KJ3PCAI.js} +2 -2
- package/dist/{chunk-PE55MMLK.js → chunk-5GXCOHDM.js} +2 -2
- package/dist/{chunk-PE55MMLK.js.map → chunk-5GXCOHDM.js.map} +1 -1
- package/dist/{chunk-BJPIRNP6.js → chunk-74FSHUB3.js} +2 -2
- package/dist/{chunk-H7253EHW.js → chunk-ATXE3EMV.js} +2 -2
- package/dist/{chunk-TEFMZY6B.js → chunk-BB3ESU74.js} +2 -2
- package/dist/{chunk-XESESMKN.js → chunk-BDM4VTBR.js} +39 -39
- package/dist/{chunk-XESESMKN.js.map → chunk-BDM4VTBR.js.map} +1 -1
- package/dist/chunk-BYD5B3P3.js +9 -0
- package/dist/{chunk-Z3IP66SL.js.map → chunk-BYD5B3P3.js.map} +1 -1
- package/dist/chunk-ES7Z64Z5.js +22 -0
- package/dist/chunk-ES7Z64Z5.js.map +1 -0
- package/dist/{chunk-WP6KLXTP.js → chunk-GLQLCBJS.js} +4 -4
- package/dist/chunk-GLQLCBJS.js.map +1 -0
- package/dist/{chunk-UB63NQQL.js → chunk-GUAJNZIX.js} +2 -2
- package/dist/{chunk-UXSYVMPK.js → chunk-HUQRPEDP.js} +2 -2
- package/dist/chunk-JG3O5GL6.js +5 -0
- package/dist/{chunk-MOQNLS5Z.js.map → chunk-JG3O5GL6.js.map} +1 -1
- package/dist/chunk-JXF54PT7.js +2 -0
- package/dist/chunk-JXF54PT7.js.map +1 -0
- package/dist/chunk-LLNPKE7H.js +11 -0
- package/dist/chunk-LLNPKE7H.js.map +1 -0
- package/dist/chunk-LTHQXWZN.js +51 -0
- package/dist/chunk-LTHQXWZN.js.map +1 -0
- package/dist/{chunk-ZR3NZLJL.js → chunk-LUL4ILAQ.js} +2 -2
- package/dist/{chunk-N6EWZGIX.js → chunk-PN6XHTG5.js} +6 -6
- package/dist/{chunk-N6EWZGIX.js.map → chunk-PN6XHTG5.js.map} +1 -1
- package/dist/{chunk-BEHC3X42.js → chunk-R64DAHBH.js} +242 -211
- package/dist/chunk-R64DAHBH.js.map +1 -0
- package/dist/{chunk-7IGSJGXI.js → chunk-TW4L6RP2.js} +2 -2
- package/dist/chunk-UCKKAWLZ.js +2 -0
- package/dist/chunk-UCKKAWLZ.js.map +1 -0
- package/dist/chunk-V4GXHBOH.js +152 -0
- package/dist/chunk-V4GXHBOH.js.map +1 -0
- package/dist/{chunk-3UN6CXRL.js → chunk-VVW4JYV6.js} +24 -24
- package/dist/chunk-VVW4JYV6.js.map +1 -0
- package/dist/{chunk-BVZFYBBP.js → chunk-WWU2D65N.js} +2 -2
- package/dist/chunk-XF65CDNS.js +5 -0
- package/dist/{chunk-UR3ZIDMA.js.map → chunk-XF65CDNS.js.map} +1 -1
- package/dist/{chunk-YCI3KUYF.js → chunk-XQ7MVPWP.js} +7 -7
- package/dist/chunk-XQ7MVPWP.js.map +1 -0
- package/dist/{chunk-Z3XUGXPD.js → chunk-ZUAV3PTL.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/client-JDY2FZUF.js +2 -0
- package/dist/config-JCETBKWT.js +2 -0
- package/dist/config-mutator-YQWTY47O.js +2 -0
- package/dist/doctor-6EWW7NC2.js +2 -0
- package/dist/{facts-U7BUYRXN.js → facts-5T5GRUTG.js} +6 -6
- package/dist/{facts-U7BUYRXN.js.map → facts-5T5GRUTG.js.map} +1 -1
- package/dist/{failure-candidates-RIXA3Y6D.js → failure-candidates-PBPF45GN.js} +2 -2
- package/dist/index.d.ts +619 -499
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/{chunk-AF46YOLU.js → program-7UH4FCA3.js} +194 -184
- package/dist/program-7UH4FCA3.js.map +1 -0
- package/dist/promote-ZZWMGVO2.js +2 -0
- package/dist/query-OQBB7EFS.js +2 -0
- package/dist/registry-MDWD7EAO.js +2 -0
- package/dist/request-planner-HX44G2SX.js +2 -0
- package/dist/{request-planner-H74KHFGJ.js.map → request-planner-HX44G2SX.js.map} +1 -1
- package/dist/review-candidates-FBDLPU6H.js +4 -0
- package/dist/{review-candidates-IPJWEXR2.js.map → review-candidates-FBDLPU6H.js.map} +1 -1
- package/dist/routing-3SZHWHUA.js +2 -0
- package/dist/schedule-tool-5FULSHWJ.js +2 -0
- package/dist/scheduler-ITOKSMYT.js +2 -0
- package/dist/seat-2HJG3UNW.js +2 -0
- package/dist/select-UKAOL7QB.js +2 -0
- package/dist/{select-BUWOD47K.js.map → select-UKAOL7QB.js.map} +1 -1
- package/dist/set-enabled-ADFSNG5A.js +2 -0
- package/dist/{set-enabled-XWSFTICB.js.map → set-enabled-ADFSNG5A.js.map} +1 -1
- package/dist/signal-exit-WL7G3EEZ.js +2 -0
- package/dist/signal-exit-WL7G3EEZ.js.map +1 -0
- package/dist/{surface-usage-HVVP22SA.js → surface-usage-O5L4KLGS.js} +2 -2
- package/dist/{tool-VOA4HSVP.js → tool-GPCJM7U5.js} +2 -2
- package/dist/{tool-VOA4HSVP.js.map → tool-GPCJM7U5.js.map} +1 -1
- package/dist/{tool-GUINJ2BQ.js → tool-VKQIDEG7.js} +2 -2
- package/dist/{tool-GUINJ2BQ.js.map → tool-VKQIDEG7.js.map} +1 -1
- package/dist/wiki-QUVWB4IN.js +2 -0
- package/package.json +1 -1
- package/dist/ChatApp-LD4TXJWP.js +0 -7
- package/dist/board-dashboard-OS5J3F73.js.map +0 -1
- package/dist/chunk-3UN6CXRL.js.map +0 -1
- package/dist/chunk-42Y3BXXS.js +0 -15
- package/dist/chunk-42Y3BXXS.js.map +0 -1
- package/dist/chunk-6JJ3GODZ.js +0 -57
- package/dist/chunk-6JJ3GODZ.js.map +0 -1
- package/dist/chunk-AF46YOLU.js.map +0 -1
- package/dist/chunk-API4IZZG.js +0 -2
- package/dist/chunk-API4IZZG.js.map +0 -1
- package/dist/chunk-BEHC3X42.js.map +0 -1
- package/dist/chunk-MOQNLS5Z.js +0 -5
- package/dist/chunk-NOAAK2XI.js +0 -152
- package/dist/chunk-NOAAK2XI.js.map +0 -1
- package/dist/chunk-OVN5LVJY.js +0 -11
- package/dist/chunk-OVN5LVJY.js.map +0 -1
- package/dist/chunk-UR3ZIDMA.js +0 -5
- package/dist/chunk-WP6KLXTP.js.map +0 -1
- package/dist/chunk-YCI3KUYF.js.map +0 -1
- package/dist/chunk-Z3IP66SL.js +0 -9
- package/dist/client-TJ5YZOEE.js +0 -2
- package/dist/config-4WZ7Y34V.js +0 -2
- package/dist/config-mutator-5Z7EEB5N.js +0 -2
- package/dist/doctor-7K3NRBNN.js +0 -2
- package/dist/program-KMQNX6YK.js +0 -2
- package/dist/promote-NDC3X54P.js +0 -2
- package/dist/query-F7BD3JPE.js +0 -2
- package/dist/registry-5NBHBVY3.js +0 -2
- package/dist/request-planner-H74KHFGJ.js +0 -2
- package/dist/review-candidates-IPJWEXR2.js +0 -4
- package/dist/routing-3RSG7SKW.js +0 -2
- package/dist/schedule-tool-7NYAK43U.js +0 -2
- package/dist/scheduler-24O7PADJ.js +0 -2
- package/dist/seat-TOM2WHQR.js +0 -2
- package/dist/select-BUWOD47K.js +0 -2
- package/dist/set-enabled-XWSFTICB.js +0 -2
- package/dist/wiki-VFME4T2H.js +0 -2
- package/dist/wiki-VFME4T2H.js.map +0 -1
- /package/dist/{agent-FUMJM6OW.js.map → agent-75URYGWI.js.map} +0 -0
- /package/dist/{chunk-MYRSNJJ4.js.map → chunk-3FCYKGU6.js.map} +0 -0
- /package/dist/{chunk-R42S57G6.js.map → chunk-4KJ3PCAI.js.map} +0 -0
- /package/dist/{chunk-BJPIRNP6.js.map → chunk-74FSHUB3.js.map} +0 -0
- /package/dist/{chunk-H7253EHW.js.map → chunk-ATXE3EMV.js.map} +0 -0
- /package/dist/{chunk-TEFMZY6B.js.map → chunk-BB3ESU74.js.map} +0 -0
- /package/dist/{chunk-UB63NQQL.js.map → chunk-GUAJNZIX.js.map} +0 -0
- /package/dist/{chunk-UXSYVMPK.js.map → chunk-HUQRPEDP.js.map} +0 -0
- /package/dist/{chunk-ZR3NZLJL.js.map → chunk-LUL4ILAQ.js.map} +0 -0
- /package/dist/{chunk-7IGSJGXI.js.map → chunk-TW4L6RP2.js.map} +0 -0
- /package/dist/{chunk-BVZFYBBP.js.map → chunk-WWU2D65N.js.map} +0 -0
- /package/dist/{chunk-Z3XUGXPD.js.map → chunk-ZUAV3PTL.js.map} +0 -0
- /package/dist/{client-TJ5YZOEE.js.map → client-JDY2FZUF.js.map} +0 -0
- /package/dist/{config-4WZ7Y34V.js.map → config-JCETBKWT.js.map} +0 -0
- /package/dist/{config-mutator-5Z7EEB5N.js.map → config-mutator-YQWTY47O.js.map} +0 -0
- /package/dist/{doctor-7K3NRBNN.js.map → doctor-6EWW7NC2.js.map} +0 -0
- /package/dist/{failure-candidates-RIXA3Y6D.js.map → failure-candidates-PBPF45GN.js.map} +0 -0
- /package/dist/{program-KMQNX6YK.js.map → promote-ZZWMGVO2.js.map} +0 -0
- /package/dist/{promote-NDC3X54P.js.map → query-OQBB7EFS.js.map} +0 -0
- /package/dist/{query-F7BD3JPE.js.map → registry-MDWD7EAO.js.map} +0 -0
- /package/dist/{registry-5NBHBVY3.js.map → routing-3SZHWHUA.js.map} +0 -0
- /package/dist/{routing-3RSG7SKW.js.map → schedule-tool-5FULSHWJ.js.map} +0 -0
- /package/dist/{schedule-tool-7NYAK43U.js.map → scheduler-ITOKSMYT.js.map} +0 -0
- /package/dist/{scheduler-24O7PADJ.js.map → seat-2HJG3UNW.js.map} +0 -0
- /package/dist/{seat-TOM2WHQR.js.map → surface-usage-O5L4KLGS.js.map} +0 -0
- /package/dist/{surface-usage-HVVP22SA.js.map → wiki-QUVWB4IN.js.map} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{a as D,b as _}from"./chunk-RKPAVWXF.js";import{a as q,b as O,c as R,d as B,f as b,g as S,h as E,i as w,j as y}from"./chunk-
|
|
1
|
+
import{a as D,b as _}from"./chunk-RKPAVWXF.js";import{a as q,b as O,c as R,d as B,f as b,g as S,h as E,i as w,j as y}from"./chunk-BB3ESU74.js";import{a as T,b as C,c as I,d as x,e as P}from"./chunk-XF65CDNS.js";import{existsSync as X,readFileSync as F}from"fs";var J=new Set(["cron","heartbeat","api","a2a","mesh"]),M=160;function s(n){return typeof n=="string"&&n.trim()?n.trim():void 0}function A(n,e=M){let t=n.replace(/\s+/g," ").trim();return t.length>e?`${t.slice(0,e-1)}\u2026`:t}function V(n){let e=T(n);if(!X(e))throw new Error(`config not found at ${e}`);return JSON.parse(F(e,"utf-8"))}function W(n,e){return n?.agents?.[e]?.admin===!0}function Y(n,e,t){return W(n,t.agentId)||e?.createdBy===t.agentId}function Z(n,e){let t=e?.createdBy?`agent "${e.createdBy}"`:"the operator";return`Not allowed: "${n}" was created by ${t}. Agents manage only schedules they created (unless configured admin).`}function K(n,e){let t=s(n.notify);if(t!=="none"){if(t&&t!=="here"){let r=t.split(":");return r.length<2||!r[0]||!r[1]?"invalid":{channel:r[0],chatId:r.slice(1).join(":")}}if(e.channel&&e.chatId&&!J.has(e.channel))return{channel:e.channel,chatId:e.chatId,...e.accountId?{accountId:e.accountId}:{}}}}function Q(n,e,t){let r=e.timezone||"UTC",u=e.enabled&&!y(e)?w(E(e.schedule,r,t),r):"\u2014",h=e.approval?`pending ${e.approval.action} approval`:e.enabled?"active":"paused",p=[`- ${n} [${h}] ${e.schedule} \u2014 ${S(e.schedule)} (${r})`,` agent: ${e.agent}; created by: ${e.createdBy||"operator"}; next: ${u}`];return e.notify&&p.push(` notify: ${e.notify.channel} ${e.notify.chatId}`),e.command?p.push(` command: ${A(String(e.command))}`):e.prompt&&p.push(` prompt: ${A(String(e.prompt))}`),p.join(`
|
|
2
2
|
`)}async function k(n,e,t){let r=n?.notifications?.destination;if(!r?.channel||!r?.chatId)return"No operator notification destination is configured (notifications.destination); the operator must check `agentx schedule list`.";if(!e.notifyOperator)return"Operator notification is unavailable in this context.";try{return await e.notifyOperator({channel:r.channel,chatId:r.chatId,accountId:r.accountId},t),"The operator has been notified."}catch(u){return`Could not notify the operator (${u?.message??u}); the request is still recorded.`}}async function re(n,e,t={}){let r=(s(n.action)||"list").toLowerCase(),u=t.now?t.now():new Date,h;try{h=V(t.configPath)}catch(a){return`Error: ${a.message}`}let p=h.crons||{};if(r==="list"){let a=n.mine===!0,l=Object.entries(p).filter(([,i])=>!a||e&&i?.createdBy===e.agentId);return l.length?l.map(([i,f])=>Q(i,f,u)).join(`
|
|
3
3
|
`):a?"You have no schedules.":"No schedules."}if(!e?.agentId)return"Error: caller agent is unknown (AGENTX_AGENT_ID not set). Pass callerAgentId.";if(!h.agents?.[e.agentId])return`Error: caller "${e.agentId}" is not an agent on this node.`;let o=s(n.id),m=a=>C(a,{configPath:t.configPath,reload:t.reload});if(r==="create"){let a=s(n.when),l=s(n.prompt);if(!a||!l)return"Error: create needs `when` (plain English) and `prompt`.";let i=D(a);if(!i)return`Error: couldn't parse "${a}". ${O}.`;let f=s(n.agent)||e.agentId;if(!h.agents?.[f])return`Error: agent "${f}" not found on this node.`;let g=s(n.timezone)||q;if(!B(g))return`Error: unknown timezone "${g}".`;let d=o||_(i.matched,f);if(!R(d))return`Error: invalid id "${d}" (letters, digits, "-" and "_" only).`;if(p[d])return`Error: a schedule "${d}" already exists. Pick another \`id\`.`;let $=K(n,e);if($==="invalid")return'Error: `notify` must be "here", "none", or "channel:chatId".';let z={action:"create",requestedBy:e.agentId,requestedAt:u.toISOString()},L=b({parsed:i,agent:f,prompt:l,timezone:g,notify:$,enabled:!1,createdBy:e.agentId,approval:z}),v=await m(U=>I(U,`crons.${d}`,L));if(!v.success)return`Error: ${v.error}`;let N=w(E(i.cron,g,u),g),G=[`Schedule approval requested by ${e.agentId}`,`Create: ${d}`,`When: ${i.human} \u2014 cron \`${i.cron}\` (${g})`,`Next fire: ${N}`,`Agent: ${f}`,$?`Notify: ${$.channel} ${$.chatId}`:"Notify: none",`Prompt: ${A(l,400)}`,"",`Approve: agentx schedule approve ${d}`,`Reject: agentx schedule reject ${d}`].join(`
|
|
4
4
|
`),H=await k(h,t,G);return[`Requested schedule "${d}": ${i.human} (cron ${i.cron}, ${g}); next fire would be ${N}.`,"It is saved DISABLED and will not run until the operator approves it.",H].join(`
|
|
5
5
|
`)}if(!o)return`Error: ${r} needs \`id\`.`;let c=p[o];if(!c)return`Error: schedule "${o}" not found.`;if(!Y(h,c,e))return Z(o,c);if(r==="pause"||r==="resume"){let a=r==="resume";if(a&&y(c))return`"${o}" is still awaiting operator approval; it can't be resumed until approved.`;if(c.enabled===a)return`"${o}" is already ${a?"active":"paused"}.`;let l=await m(i=>I(i,`crons.${o}.enabled`,a));return l.success?`"${o}" ${a?"resumed":"paused"}.`:`Error: ${l.error}`}if(r==="delete"){if(y(c)&&c.approval.requestedBy===e.agentId){let d=await m($=>P($,`crons.${o}`));return d.success?`Withdrew the pending request "${o}".`:`Error: ${d.error}`}if(y(c))return`"${o}" is a creation request still awaiting approval; only its requester or the operator (\`agentx schedule reject ${o}\`) can drop it.`;if(c.approval?.action==="delete")return`Deletion of "${o}" is already awaiting approval.`;let a={action:"delete",requestedBy:e.agentId,requestedAt:u.toISOString()},l=await m(d=>{if(!x(d,`crons.${o}`))throw new Error(`schedule "${o}" not found`);I(d,`crons.${o}.approval`,a)});if(!l.success)return`Error: ${l.error}`;let i=c.timezone||"UTC",f=[`Schedule approval requested by ${e.agentId}`,`Delete: ${o}`,`When: ${S(c.schedule)} \u2014 cron \`${c.schedule}\` (${i})`,`Next fire: ${c.enabled?w(E(c.schedule,i,u),i):"\u2014 (paused)"}`,`Agent: ${c.agent}`,"",`Approve: agentx schedule approve ${o}`,`Reject: agentx schedule reject ${o}`].join(`
|
|
6
6
|
`),g=await k(h,t,f);return[`Deletion of "${o}" requested. It keeps its current state until the operator approves.`,g].join(`
|
|
7
7
|
`)}return`Error: unknown action "${r}". Use list, create, pause, resume or delete.`}function oe(n,e=process.env){let t=s(e.AGENTX_AGENT_ID)||s(n.callerAgentId);if(!t)return null;let r=!!(s(e.AGENTX_CHANNEL)&&s(e.AGENTX_CHAT_ID)),u=s(r?e.AGENTX_CHANNEL:n.channel),h=s(r?e.AGENTX_CHAT_ID:n.chatId),p=s(n.accountId);return{agentId:t,channel:u,chatId:h,...p?{accountId:p}:{}}}export{re as a,oe as b};
|
|
8
|
-
//# sourceMappingURL=chunk-
|
|
8
|
+
//# sourceMappingURL=chunk-TW4L6RP2.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a}from"./chunk-QIJLFPWE.js";function r(n){if(!n||typeof n!="object")return null;let t=n;if(t.kind!=="human"&&t.kind!=="agent"||typeof t.channel!="string"||!t.channel)return null;let e={kind:t.kind,channel:t.channel.slice(0,40)};return typeof t.chatId=="string"&&(e.chatId=t.chatId.slice(0,200)),typeof t.sender=="string"&&(e.sender=t.sender.slice(0,120)),typeof t.agentId=="string"&&(e.agentId=t.agentId.slice(0,80)),typeof t.person=="string"&&t.person&&(e.person=t.person.slice(0,40)),e}function p(n){return r(n?.initiator)}function d(n){if(typeof n!="string")return!1;let t=n.trim().toLowerCase();return t==="agent"||u.some(e=>t.startsWith(e))}function o(n){let t=r(n?.initiator);if(t)return t.kind;let e=(n?.channel||"api").toLowerCase();return l.has(e)||d(n?.sender)?"agent":s.has(e)?"human":"agent"}function c(n,t){let e=r(n?.initiator);if(e)return e;let i={kind:o(n),channel:n?.channel||"api"};return n?.chatId&&(i.chatId=String(n.chatId)),n?.sender&&(i.sender=String(n.sender)),t&&(i.agentId=t),typeof n?.person=="string"&&n.person&&(i.person=n.person),i}function f(n){return n?r(n.initiator)!==null||!!n.delegation:!1}function h(n){return!n||f(n)?!1:o(n)==="human"}var s,l,u,g=a(()=>{"use strict";s=new Set(["telegram","whatsapp","slack","discord","gitlab","github","app","voice","dashboard","webrtc"]),l=new Set(["a2a","mcp","mesh","api","cron","workflow","events","reminder","heartbeat","system","internal","business"]),u=["agent:","cron:","workflow:","mesh:","system:","internal:"]});export{s as a,p as b,d as c,o as d,c as e,f,h as g,g as h};
|
|
2
|
+
//# sourceMappingURL=chunk-UCKKAWLZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/a2a/initiator.ts"],"sourcesContent":["// --- Who started this work: a person or an agent ---\n//\n// One place answers \"is the root of this chain a human?\" so every caller\n// (A2A delegation today, the activity graph and ledger next) agrees. Keep\n// all human-vs-agent detection here; do not re-derive it from\n// `senderAgentId` at call sites, because relays such as the phone app set\n// fields that look agent-shaped for a turn a person started.\n//\n// The rules, in order:\n// 1. A propagated root (`context.initiator`) wins. It is stamped on the\n// first hop of a delegation and travels with the context, including\n// across mesh peers (sendTask forwards the context verbatim).\n// 2. Machine channels (cron, workflow, a2a, mcp, mesh, api, ...) are agent.\n// 3. A machine-shaped sender (\"agent:x\", \"cron:y\", ...) is agent. This is\n// how router bot-to-bot chains and callback turns are marked, and how\n// the GitHub/GitLab adapters mark an agent's comment posted with a\n// person's account (forgeSender in channels/outbound-marker.ts).\n// 4. Channels a person types or speaks on are human.\n// 5. Anything else is agent: unknown traffic keeps today's behaviour.\n\nexport type InitiatorKind = \"human\" | \"agent\"\n\n/** The root of a chain, carried in `context.initiator` on every hop after\n * the first. Only small identifying fields: it crosses the mesh. */\nexport interface RootInitiator {\n kind: InitiatorKind\n /** Channel the root turn arrived on (telegram, app, cron, ...). */\n channel: string\n chatId?: string\n sender?: string\n /** The agent that was talking to the person when the chain started. */\n agentId?: string\n /** The known person behind the root turn (people, #384). */\n person?: string\n}\n\n/** The subset of AgentTask.context this module reads. */\nexport interface InitiatorContext {\n channel?: string\n chatId?: string\n sender?: string\n initiator?: unknown\n delegation?: unknown\n person?: unknown\n [k: string]: unknown\n}\n\n/** Channels a person writes or speaks on. */\nexport const HUMAN_CHANNELS: ReadonlySet<string> = new Set([\n \"telegram\", \"whatsapp\", \"slack\", \"discord\",\n \"gitlab\", \"github\",\n \"app\", \"voice\", \"dashboard\", \"webrtc\",\n])\n\n/** Channels only software writes on. `api` is here on purpose: a bare API\n * call has no conversation to come back to. */\nexport const AGENT_CHANNELS: ReadonlySet<string> = new Set([\n \"a2a\", \"mcp\", \"mesh\", \"api\",\n \"cron\", \"workflow\", \"events\", \"reminder\", \"heartbeat\",\n \"system\", \"internal\", \"business\",\n])\n\nconst AGENT_SENDER_PREFIXES = [\"agent:\", \"cron:\", \"workflow:\", \"mesh:\", \"system:\", \"internal:\"]\n\nfunction validRoot(v: unknown): RootInitiator | null {\n if (!v || typeof v !== \"object\") return null\n const o = v as Record<string, unknown>\n if (o.kind !== \"human\" && o.kind !== \"agent\") return null\n if (typeof o.channel !== \"string\" || !o.channel) return null\n const root: RootInitiator = { kind: o.kind, channel: o.channel.slice(0, 40) }\n if (typeof o.chatId === \"string\") root.chatId = o.chatId.slice(0, 200)\n if (typeof o.sender === \"string\") root.sender = o.sender.slice(0, 120)\n if (typeof o.agentId === \"string\") root.agentId = o.agentId.slice(0, 80)\n if (typeof o.person === \"string\" && o.person) root.person = o.person.slice(0, 40)\n return root\n}\n\n/** The root a delegated hop carries in `context.initiator`, or null on a\n * turn that is itself a root (read-only views such as the activity map). */\nexport function propagatedRootOf(ctx: InitiatorContext | undefined | null): RootInitiator | null {\n return validRoot(ctx?.initiator)\n}\n\n/** True for senders that name software rather than a person. */\nexport function isAgentSender(sender: unknown): boolean {\n if (typeof sender !== \"string\") return false\n const s = sender.trim().toLowerCase()\n return s === \"agent\" || AGENT_SENDER_PREFIXES.some((p) => s.startsWith(p))\n}\n\n/** Human or agent, for the chain this turn belongs to. */\nexport function classifyInitiator(ctx: InitiatorContext | undefined | null): InitiatorKind {\n const root = validRoot(ctx?.initiator)\n if (root) return root.kind\n const channel = (ctx?.channel || \"api\").toLowerCase()\n if (AGENT_CHANNELS.has(channel)) return \"agent\"\n if (isAgentSender(ctx?.sender)) return \"agent\"\n if (HUMAN_CHANNELS.has(channel)) return \"human\"\n return \"agent\"\n}\n\n/** The root to stamp on the next hop. An existing root is passed on\n * unchanged; otherwise this turn is the root. */\nexport function rootInitiatorOf(ctx: InitiatorContext | undefined | null, agentId?: string): RootInitiator {\n const existing = validRoot(ctx?.initiator)\n if (existing) return existing\n const root: RootInitiator = { kind: classifyInitiator(ctx), channel: ctx?.channel || \"api\" }\n if (ctx?.chatId) root.chatId = String(ctx.chatId)\n if (ctx?.sender) root.sender = String(ctx.sender)\n if (agentId) root.agentId = agentId\n if (typeof ctx?.person === \"string\" && ctx.person) root.person = ctx.person\n return root\n}\n\n/** True for a delegated hop (it carries a valid root) or a callback turn\n * (it carries `delegation`). Neither may hand work off asynchronously:\n * a hop has a caller waiting on its answer, and a callback must not fan\n * out into another callback. */\nexport function isInsideDelegation(ctx: InitiatorContext | undefined | null): boolean {\n if (!ctx) return false\n return validRoot(ctx.initiator) !== null || !!ctx.delegation\n}\n\n/** Is this turn the one talking to the person? Only that turn may hand\n * work off and end: a delegated turn (it carries a root) has a caller\n * waiting on its answer, and a callback turn (it carries `delegation`)\n * must not fan out again. */\nexport function isHumanFacingTurn(ctx: InitiatorContext | undefined | null): boolean {\n if (!ctx || isInsideDelegation(ctx)) return false\n return classifyInitiator(ctx) === \"human\"\n}\n"],"mappings":"mCAgEA,SAASA,EAAUC,EAAkC,CACnD,GAAI,CAACA,GAAK,OAAOA,GAAM,SAAU,OAAO,KACxC,IAAMC,EAAID,EAEV,GADIC,EAAE,OAAS,SAAWA,EAAE,OAAS,SACjC,OAAOA,EAAE,SAAY,UAAY,CAACA,EAAE,QAAS,OAAO,KACxD,IAAMC,EAAsB,CAAE,KAAMD,EAAE,KAAM,QAASA,EAAE,QAAQ,MAAM,EAAG,EAAE,CAAE,EAC5E,OAAI,OAAOA,EAAE,QAAW,WAAUC,EAAK,OAASD,EAAE,OAAO,MAAM,EAAG,GAAG,GACjE,OAAOA,EAAE,QAAW,WAAUC,EAAK,OAASD,EAAE,OAAO,MAAM,EAAG,GAAG,GACjE,OAAOA,EAAE,SAAY,WAAUC,EAAK,QAAUD,EAAE,QAAQ,MAAM,EAAG,EAAE,GACnE,OAAOA,EAAE,QAAW,UAAYA,EAAE,SAAQC,EAAK,OAASD,EAAE,OAAO,MAAM,EAAG,EAAE,GACzEC,CACT,CAIO,SAASC,EAAiBC,EAAgE,CAC/F,OAAOL,EAAUK,GAAK,SAAS,CACjC,CAGO,SAASC,EAAcC,EAA0B,CACtD,GAAI,OAAOA,GAAW,SAAU,MAAO,GACvC,IAAMC,EAAID,EAAO,KAAK,EAAE,YAAY,EACpC,OAAOC,IAAM,SAAWC,EAAsB,KAAMC,GAAMF,EAAE,WAAWE,CAAC,CAAC,CAC3E,CAGO,SAASC,EAAkBN,EAAyD,CACzF,IAAMF,EAAOH,EAAUK,GAAK,SAAS,EACrC,GAAIF,EAAM,OAAOA,EAAK,KACtB,IAAMS,GAAWP,GAAK,SAAW,OAAO,YAAY,EAEpD,OADIQ,EAAe,IAAID,CAAO,GAC1BN,EAAcD,GAAK,MAAM,EAAU,QACnCS,EAAe,IAAIF,CAAO,EAAU,QACjC,OACT,CAIO,SAASG,EAAgBV,EAA0CW,EAAiC,CACzG,IAAMC,EAAWjB,EAAUK,GAAK,SAAS,EACzC,GAAIY,EAAU,OAAOA,EACrB,IAAMd,EAAsB,CAAE,KAAMQ,EAAkBN,CAAG,EAAG,QAASA,GAAK,SAAW,KAAM,EAC3F,OAAIA,GAAK,SAAQF,EAAK,OAAS,OAAOE,EAAI,MAAM,GAC5CA,GAAK,SAAQF,EAAK,OAAS,OAAOE,EAAI,MAAM,GAC5CW,IAASb,EAAK,QAAUa,GACxB,OAAOX,GAAK,QAAW,UAAYA,EAAI,SAAQF,EAAK,OAASE,EAAI,QAC9DF,CACT,CAMO,SAASe,EAAmBb,EAAmD,CACpF,OAAKA,EACEL,EAAUK,EAAI,SAAS,IAAM,MAAQ,CAAC,CAACA,EAAI,WADjC,EAEnB,CAMO,SAASc,EAAkBd,EAAmD,CACnF,MAAI,CAACA,GAAOa,EAAmBb,CAAG,EAAU,GACrCM,EAAkBN,CAAG,IAAM,OACpC,CAlIA,IAgDaS,EAQAD,EAMPJ,EA9DNW,EAAAC,EAAA,kBAgDaP,EAAsC,IAAI,IAAI,CACzD,WAAY,WAAY,QAAS,UACjC,SAAU,SACV,MAAO,QAAS,YAAa,QAC/B,CAAC,EAIYD,EAAsC,IAAI,IAAI,CACzD,MAAO,MAAO,OAAQ,MACtB,OAAQ,WAAY,SAAU,WAAY,YAC1C,SAAU,WAAY,UACxB,CAAC,EAEKJ,EAAwB,CAAC,SAAU,QAAS,YAAa,QAAS,UAAW,WAAW","names":["validRoot","v","o","root","propagatedRootOf","ctx","isAgentSender","sender","s","AGENT_SENDER_PREFIXES","p","classifyInitiator","channel","AGENT_CHANNELS","HUMAN_CHANNELS","rootInitiatorOf","agentId","existing","isInsideDelegation","isHumanFacingTurn","init_initiator","__esmMin"]}
|