@useorgx/openclaw-plugin 0.4.8 → 0.4.9

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 (125) hide show
  1. package/dashboard/dist/assets/B5NEElEI.css +1 -0
  2. package/dashboard/dist/assets/BhapSNAs.js +215 -0
  3. package/dashboard/dist/assets/{BNeJ0kpF.js → iFdvE7lx.js} +1 -1
  4. package/dashboard/dist/assets/{CUV9IHHi.js → jRJsmpYM.js} +1 -1
  5. package/dashboard/dist/index.html +2 -2
  6. package/dist/activity-store.js +4 -18
  7. package/dist/agent-context-store.js +5 -25
  8. package/dist/agent-run-store.js +5 -25
  9. package/dist/agent-suite.js +1 -8
  10. package/dist/auth/flows.d.ts +47 -0
  11. package/dist/auth/flows.js +169 -0
  12. package/dist/auth-store.js +6 -26
  13. package/dist/byok-store.js +5 -19
  14. package/dist/cli/orgx.d.ts +66 -0
  15. package/dist/cli/orgx.js +91 -0
  16. package/dist/config/refresh.d.ts +32 -0
  17. package/dist/config/refresh.js +55 -0
  18. package/dist/config/resolution.d.ts +37 -0
  19. package/dist/config/resolution.js +178 -0
  20. package/dist/contracts/shared-types.d.ts +147 -0
  21. package/dist/contracts/shared-types.js +3 -0
  22. package/dist/contracts/types.d.ts +1 -134
  23. package/dist/contracts/types.js +5 -0
  24. package/dist/entities/auto-assignment.d.ts +36 -0
  25. package/dist/entities/auto-assignment.js +115 -0
  26. package/dist/entity-comment-store.js +5 -25
  27. package/dist/hash-utils.d.ts +2 -0
  28. package/dist/hash-utils.js +12 -0
  29. package/dist/http/helpers/activity-headline.d.ts +10 -0
  30. package/dist/http/helpers/activity-headline.js +192 -0
  31. package/dist/http/helpers/artifact-fallback.d.ts +13 -0
  32. package/dist/http/helpers/artifact-fallback.js +148 -0
  33. package/dist/http/helpers/auto-continue-engine.d.ts +298 -0
  34. package/dist/http/helpers/auto-continue-engine.js +1218 -0
  35. package/dist/http/helpers/autopilot-operations.d.ts +157 -0
  36. package/dist/http/helpers/autopilot-operations.js +403 -0
  37. package/dist/http/helpers/autopilot-runtime.d.ts +42 -0
  38. package/dist/http/helpers/autopilot-runtime.js +319 -0
  39. package/dist/http/helpers/autopilot-slice-utils.d.ts +38 -0
  40. package/dist/http/helpers/autopilot-slice-utils.js +476 -0
  41. package/dist/http/helpers/decision-mapper.d.ts +12 -0
  42. package/dist/http/helpers/decision-mapper.js +44 -0
  43. package/dist/http/helpers/dispatch-lifecycle.d.ts +102 -0
  44. package/dist/http/helpers/dispatch-lifecycle.js +604 -0
  45. package/dist/http/helpers/hash-utils.d.ts +1 -0
  46. package/dist/http/helpers/hash-utils.js +1 -0
  47. package/dist/http/helpers/kickoff-context.d.ts +12 -0
  48. package/dist/http/helpers/kickoff-context.js +154 -0
  49. package/dist/http/helpers/mission-control.d.ts +94 -0
  50. package/dist/http/helpers/mission-control.js +894 -0
  51. package/dist/http/helpers/openclaw-cli.d.ts +37 -0
  52. package/dist/http/helpers/openclaw-cli.js +283 -0
  53. package/dist/http/helpers/runtime-sse.d.ts +20 -0
  54. package/dist/http/helpers/runtime-sse.js +110 -0
  55. package/dist/http/helpers/value-utils.d.ts +6 -0
  56. package/dist/http/helpers/value-utils.js +67 -0
  57. package/dist/http/index.d.ts +88 -0
  58. package/dist/http/index.js +2353 -0
  59. package/dist/http/router.d.ts +23 -0
  60. package/dist/http/router.js +23 -0
  61. package/dist/http/routes/agent-control.d.ts +79 -0
  62. package/dist/http/routes/agent-control.js +684 -0
  63. package/dist/http/routes/agent-suite.d.ts +29 -0
  64. package/dist/http/routes/agent-suite.js +198 -0
  65. package/dist/http/routes/agents-catalog.d.ts +40 -0
  66. package/dist/http/routes/agents-catalog.js +83 -0
  67. package/dist/http/routes/billing.d.ts +23 -0
  68. package/dist/http/routes/billing.js +55 -0
  69. package/dist/http/routes/debug.d.ts +14 -0
  70. package/dist/http/routes/debug.js +21 -0
  71. package/dist/http/routes/decision-actions.d.ts +13 -0
  72. package/dist/http/routes/decision-actions.js +66 -0
  73. package/dist/http/routes/delegation.d.ts +19 -0
  74. package/dist/http/routes/delegation.js +32 -0
  75. package/dist/http/routes/entities.d.ts +47 -0
  76. package/dist/http/routes/entities.js +152 -0
  77. package/dist/http/routes/entity-dynamic.d.ts +25 -0
  78. package/dist/http/routes/entity-dynamic.js +191 -0
  79. package/dist/http/routes/health.d.ts +22 -0
  80. package/dist/http/routes/health.js +49 -0
  81. package/dist/http/routes/live-legacy.d.ts +110 -0
  82. package/dist/http/routes/live-legacy.js +598 -0
  83. package/dist/http/routes/live-misc.d.ts +69 -0
  84. package/dist/http/routes/live-misc.js +206 -0
  85. package/dist/http/routes/live-snapshot.d.ts +90 -0
  86. package/dist/http/routes/live-snapshot.js +297 -0
  87. package/dist/http/routes/mission-control-actions.d.ts +83 -0
  88. package/dist/http/routes/mission-control-actions.js +541 -0
  89. package/dist/http/routes/mission-control-read.d.ts +28 -0
  90. package/dist/http/routes/mission-control-read.js +67 -0
  91. package/dist/http/routes/onboarding.d.ts +34 -0
  92. package/dist/http/routes/onboarding.js +101 -0
  93. package/dist/http/routes/run-control.d.ts +24 -0
  94. package/dist/http/routes/run-control.js +86 -0
  95. package/dist/http/routes/runtime-hooks.d.ts +69 -0
  96. package/dist/http/routes/runtime-hooks.js +437 -0
  97. package/dist/http/routes/settings-byok.d.ts +23 -0
  98. package/dist/http/routes/settings-byok.js +163 -0
  99. package/dist/http/routes/summary.d.ts +18 -0
  100. package/dist/http/routes/summary.js +42 -0
  101. package/dist/http/routes/work-artifacts.d.ts +9 -0
  102. package/dist/http/routes/work-artifacts.js +36 -0
  103. package/dist/http/shared-state.d.ts +16 -0
  104. package/dist/http/shared-state.js +1 -0
  105. package/dist/http-handler.d.ts +1 -88
  106. package/dist/http-handler.js +1 -10605
  107. package/dist/index.js +108 -2243
  108. package/dist/json-utils.d.ts +1 -0
  109. package/dist/json-utils.js +8 -0
  110. package/dist/next-up-queue-store.js +4 -18
  111. package/dist/runtime-instance-store.js +5 -31
  112. package/dist/services/background.d.ts +23 -0
  113. package/dist/services/background.js +23 -0
  114. package/dist/services/instrumentation.d.ts +29 -0
  115. package/dist/services/instrumentation.js +136 -0
  116. package/dist/snapshot-store.js +5 -25
  117. package/dist/stores/json-store.d.ts +11 -0
  118. package/dist/stores/json-store.js +42 -0
  119. package/dist/sync/outbox-replay.d.ts +55 -0
  120. package/dist/sync/outbox-replay.js +514 -0
  121. package/dist/tools/core-tools.d.ts +76 -0
  122. package/dist/tools/core-tools.js +1005 -0
  123. package/package.json +1 -1
  124. package/dashboard/dist/assets/BzkiMPmM.js +0 -215
  125. package/dashboard/dist/assets/Ie7d9Iq2.css +0 -1
@@ -1 +1 @@
1
- import{r as x,j as e}from"./B3ziCA02.js";import{v as z,P as F,w as C,x as _,y as X,M as Y,a as P}from"./BzkiMPmM.js";import"./C-KIc3Wc.js";import"./sAhvFnpk.js";import"./CpJsfbXo.js";const Z=/^[0-9a-f-]{20,}$/i,W=new Set(["running","active","queued","pending","in_progress","working","planning","handoff","review"]),H=new Set(["agent execution failed","execution failed","run failed","failed"]);function $(i){return(i??"").trim().toLowerCase()}function ee(i){return(i??"").trim().replace(/\s+/g," ").toLowerCase()}function te(i){return H.has(ee(i))}function re(i){if(i.runId)return i.runId;const t=i.metadata;if(!t)return null;const d=["runId","run_id","sessionId","session_id","agentRunId"];for(const s of d){const l=t[s];if(typeof l=="string"&&l.trim().length>0)return l.trim()}return null}function ae(i){const t=$(i.status);if(t==="blocked"||t==="failed"||t==="completed"||t==="cancelled")return t;const d=$(i.phase);if(d==="blocked")return"blocked";if(d==="handoff")return"handoff";if(d==="completed")return"completed";if(d==="review")return"review";const s=$(i.state);return s==="error"?"failed":s==="stopped"?"paused":s==="stale"?"queued":W.has(t)?t:i.blockers.length>0?"blocked":t||"unknown"}function ie(i,t,d){const s=[i.blockerReason??null,...i.blockers,t==="blocked"||t==="failed"||t==="handoff"?d:null].map(l=>typeof l=="string"?l.trim():"").filter(l=>l.length>0);return s.length>0?s.find(b=>!te(b))??s[0]:t==="handoff"?"Waiting for handoff acceptance by the next agent.":t==="blocked"?"Blocked without an explicit reason from runtime.":t==="failed"?"Run failed without explicit error details.":null}const oe=x.memo(function({session:t,activity:d,initiatives:s=[],onContinueHighestPriority:l,onDispatchSession:b,onPauseSession:y,onResumeSession:j,onCancelSession:v,onCreateCheckpoint:N,onRollbackSession:k,onStartInitiative:B,onStartWorkstream:w}){const[a,T]=x.useState(null),[I,E]=x.useState(null),[f,q]=x.useState(!1),h=x.useMemo(()=>t?d.filter(r=>re(r)===t.runId).sort((r,o)=>Date.parse(o.timestamp)-Date.parse(r.timestamp)).slice(0,8):[],[d,t]),R=x.useMemo(()=>{var p;if(!t)return[];const r=[],o=t.initiativeId??t.groupId;if(o){const n=s.find(L=>L.id===o);n?r.push({label:"Initiative",value:n.name}):t.groupLabel&&t.groupLabel.trim().length>0&&r.push({label:"Initiative",value:t.groupLabel})}if(t.workstreamId){let n=null;for(const L of s){const U=(p=L.workstreams)==null?void 0:p.find(K=>K.id===t.workstreamId);if(U){n=U.name;break}}!n&&!Z.test(t.workstreamId)&&(n=t.workstreamId),n&&r.push({label:"Workstream",value:n})}const u=t.phase??null;return u&&r.push({label:"Milestone",value:String(u)}),t.title&&r.push({label:"Task",value:t.title}),r},[s,t]),g=x.useMemo(()=>{var p,n;if(!t)return null;const r=((p=h[0])==null?void 0:p.summary)??((n=h[0])==null?void 0:n.description)??null,u=t.lastEventSummary??r??null;return u&&u.trim().length>0?u.trim():null},[h,t]),D=x.useMemo(()=>{var r;return t?z(t.agentName,t.title,t.lastEventSummary,g,(r=h[0])==null?void 0:r.metadata):z()},[h,t,g]),c=async(r,o,u)=>{if(!(!u||a)){T(r),E(null);try{await u(),E(`${o} requested.`)}catch(p){E(p instanceof Error?p.message:`${o} failed.`)}finally{T(null)}}};if(!t)return e.jsxs(F,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsx("button",{onClick:()=>q(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":f?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:C("transition-transform",f?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:C("transition-all",f?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"space-y-2 overflow-y-auto p-4 text-body text-secondary",children:[e.jsx("p",{children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>c("continue-priority","Continue highest priority",l),disabled:!l||!!a,className:"rounded-md border border-strong bg-white/[0.04] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:a==="continue-priority"?"Dispatching…":"Continue highest priority"}),I&&e.jsx("p",{className:"text-caption text-secondary",children:I})]})})]});const A=t.progress===null?null:Math.round(t.progress),m=ae(t),M=ie(t,m,g),G=m==="handoff"?"Handoff":m==="blocked"?"Blocker reason":m==="failed"?"Failure reason":"Status note",O=["running","active","queued","pending"].includes(m),V=["paused","blocked","queued","pending"].includes(m),Q=!["completed","archived","cancelled"].includes(m),S=!["archived","cancelled"].includes(m),J=[{label:"Started",value:t.startedAt?_(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?_(t.updatedAt):"—"},{label:"ETA",value:t.eta??"—"},{label:"Checkpoints",value:t.checkpointCount!==null&&t.checkpointCount!==void 0?String(t.checkpointCount):"—"}];return e.jsxs(F,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"chip text-caption uppercase",children:m}),e.jsx("button",{onClick:()=>q(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":f?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:C("transition-transform",f?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]})]}),e.jsx("div",{className:C("transition-all",f?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"space-y-3 overflow-y-auto p-4",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(X,{provider:D.id,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-body font-medium text-white",children:t.title}),e.jsxs("p",{className:"mt-0.5 text-caption text-secondary",children:[t.agentName??"Unassigned"," · ",D.label]})]})]}),R.length>0&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-2.5",children:[e.jsx("p",{className:"mb-1.5 text-micro uppercase tracking-[0.1em] text-muted",children:"Breadcrumb"}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-caption",children:R.map((r,o)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.02] px-1.5 py-0.5 text-secondary",children:r.value}),o<R.length-1&&e.jsx("span",{className:"text-caption text-muted",children:"›"})]},`${r.label}-${r.value}`))})]}),g&&e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2",children:e.jsx(Y,{text:g,mode:"block"})}),(t.phase||t.state||M)&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.phase&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 uppercase tracking-[0.08em] text-muted",children:["phase: ",t.phase]}),t.state&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 uppercase tracking-[0.08em] text-muted",children:["runtime: ",t.state]})]}),M&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:G}),e.jsx("p",{className:"text-body text-secondary",children:M})]})]}),A!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-caption text-secondary",children:[e.jsx("span",{children:"Progress"}),e.jsxs("span",{children:[A,"%"]})]}),e.jsx("div",{className:"h-2 rounded-full bg-white/[0.08]",children:e.jsx("div",{className:"h-2 rounded-full",style:{width:`${A}%`,background:`linear-gradient(90deg, ${P.lime}, ${P.teal})`}})})]}),e.jsx("dl",{className:"grid grid-cols-1 gap-1 text-caption text-secondary sm:grid-cols-2",children:J.map(r=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:r.label}),e.jsx("dd",{className:"font-medium",children:r.value})]},r.label))}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.12em] text-muted",children:"Quick actions"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>c("continue-priority","Continue highest priority",l),disabled:!l||!!a,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:a==="continue-priority"?"Dispatching…":"Continue Priority"}),e.jsx("button",{onClick:()=>c("dispatch-session","Dispatch session",()=>b==null?void 0:b(t)),disabled:!b||!!a,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:a==="dispatch-session"?"Dispatching…":"Dispatch Session"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.12em] text-muted",children:"Session controls"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>c("pause-session","Pause session",()=>y==null?void 0:y(t)),disabled:!y||!O||!!a,className:"rounded-md border border-amber-400/30 bg-amber-400/10 px-3 py-2 text-caption font-semibold text-amber-300 transition-colors hover:bg-amber-400/20 disabled:opacity-45",children:a==="pause-session"?"Pausing…":"Pause"}),e.jsx("button",{onClick:()=>c("resume-session","Resume session",()=>j==null?void 0:j(t)),disabled:!j||!V||!!a,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:a==="resume-session"?"Resuming…":"Resume"}),e.jsx("button",{onClick:()=>c("checkpoint-session","Checkpoint created",()=>N==null?void 0:N(t)),disabled:!N||!!a,className:"rounded-md border border-sky-400/30 bg-sky-400/10 px-3 py-2 text-caption font-semibold text-sky-300 transition-colors hover:bg-sky-400/20 disabled:opacity-45",children:a==="checkpoint-session"?"Creating…":"Checkpoint"}),e.jsx("button",{onClick:()=>c("rollback-session","Rollback requested",()=>k==null?void 0:k(t)),disabled:!k||!S||!!a,className:"rounded-md border border-fuchsia-400/30 bg-fuchsia-400/10 px-3 py-2 text-caption font-semibold text-fuchsia-300 transition-colors hover:bg-fuchsia-400/20 disabled:opacity-45",children:a==="rollback-session"?"Rolling back…":"Rollback"}),e.jsx("button",{onClick:()=>c("cancel-session","Cancel session",()=>v==null?void 0:v(t)),disabled:!v||!Q||!!a,className:"col-span-2 rounded-md border border-red-400/30 bg-red-400/10 px-3 py-2 text-caption font-semibold text-red-300 transition-colors hover:bg-red-400/20 disabled:opacity-45",children:a==="cancel-session"?"Cancelling…":"Cancel session"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.12em] text-muted",children:"Planning"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>c("start-initiative","Start initiative",B),disabled:!B||!!a,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:a==="start-initiative"?"Creating…":"New initiative"}),e.jsx("button",{onClick:()=>c("start-workstream","Start workstream",()=>w==null?void 0:w(t.initiativeId)),disabled:!w||!!a,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:a==="start-workstream"?"Creating…":"New workstream"})]})]})]}),I&&e.jsx("p",{className:"rounded-md border border-white/[0.08] bg-white/[0.02] px-2.5 py-1.5 text-caption text-secondary",children:I}),t.blockers.length>0&&e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-3",children:[e.jsx("h3",{className:"mb-1 text-caption uppercase tracking-[0.12em] text-red-200/70",children:"Blockers"}),e.jsx("ul",{className:"space-y-1 text-body text-red-100/90",children:t.blockers.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-caption uppercase tracking-[0.12em] text-secondary",children:"Recent Messages"}),h.length===0&&e.jsx("p",{className:"text-body text-secondary",children:"No recent messages for this run."}),e.jsx("div",{className:"space-y-2",children:h.map(r=>e.jsxs("article",{className:"rounded-lg border border-subtle bg-white/[0.02] px-2.5 py-2",children:[e.jsx("p",{className:"text-caption text-bright",children:r.title}),(r.summary||r.description)&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-caption text-secondary",children:r.summary??r.description}),e.jsxs("p",{className:"mt-1 text-micro text-muted",children:[new Date(r.timestamp).toLocaleString()," · ",_(r.timestamp)]})]},r.id))})]})]})})]})});export{oe as SessionInspector};
1
+ import{r as x,j as e}from"./B3ziCA02.js";import{v as z,P as F,w as C,x as _,y as X,M as Y,a as P}from"./BhapSNAs.js";import"./C-KIc3Wc.js";import"./sAhvFnpk.js";import"./CpJsfbXo.js";const Z=/^[0-9a-f-]{20,}$/i,W=new Set(["running","active","queued","pending","in_progress","working","planning","handoff","review"]),H=new Set(["agent execution failed","execution failed","run failed","failed"]);function $(i){return(i??"").trim().toLowerCase()}function ee(i){return(i??"").trim().replace(/\s+/g," ").toLowerCase()}function te(i){return H.has(ee(i))}function re(i){if(i.runId)return i.runId;const t=i.metadata;if(!t)return null;const d=["runId","run_id","sessionId","session_id","agentRunId"];for(const s of d){const l=t[s];if(typeof l=="string"&&l.trim().length>0)return l.trim()}return null}function ae(i){const t=$(i.status);if(t==="blocked"||t==="failed"||t==="completed"||t==="cancelled")return t;const d=$(i.phase);if(d==="blocked")return"blocked";if(d==="handoff")return"handoff";if(d==="completed")return"completed";if(d==="review")return"review";const s=$(i.state);return s==="error"?"failed":s==="stopped"?"paused":s==="stale"?"queued":W.has(t)?t:i.blockers.length>0?"blocked":t||"unknown"}function ie(i,t,d){const s=[i.blockerReason??null,...i.blockers,t==="blocked"||t==="failed"||t==="handoff"?d:null].map(l=>typeof l=="string"?l.trim():"").filter(l=>l.length>0);return s.length>0?s.find(b=>!te(b))??s[0]:t==="handoff"?"Waiting for handoff acceptance by the next agent.":t==="blocked"?"Blocked without an explicit reason from runtime.":t==="failed"?"Run failed without explicit error details.":null}const oe=x.memo(function({session:t,activity:d,initiatives:s=[],onContinueHighestPriority:l,onDispatchSession:b,onPauseSession:y,onResumeSession:j,onCancelSession:v,onCreateCheckpoint:N,onRollbackSession:k,onStartInitiative:B,onStartWorkstream:w}){const[a,T]=x.useState(null),[I,E]=x.useState(null),[f,q]=x.useState(!1),h=x.useMemo(()=>t?d.filter(r=>re(r)===t.runId).sort((r,o)=>Date.parse(o.timestamp)-Date.parse(r.timestamp)).slice(0,8):[],[d,t]),R=x.useMemo(()=>{var p;if(!t)return[];const r=[],o=t.initiativeId??t.groupId;if(o){const n=s.find(L=>L.id===o);n?r.push({label:"Initiative",value:n.name}):t.groupLabel&&t.groupLabel.trim().length>0&&r.push({label:"Initiative",value:t.groupLabel})}if(t.workstreamId){let n=null;for(const L of s){const U=(p=L.workstreams)==null?void 0:p.find(K=>K.id===t.workstreamId);if(U){n=U.name;break}}!n&&!Z.test(t.workstreamId)&&(n=t.workstreamId),n&&r.push({label:"Workstream",value:n})}const u=t.phase??null;return u&&r.push({label:"Milestone",value:String(u)}),t.title&&r.push({label:"Task",value:t.title}),r},[s,t]),g=x.useMemo(()=>{var p,n;if(!t)return null;const r=((p=h[0])==null?void 0:p.summary)??((n=h[0])==null?void 0:n.description)??null,u=t.lastEventSummary??r??null;return u&&u.trim().length>0?u.trim():null},[h,t]),D=x.useMemo(()=>{var r;return t?z(t.agentName,t.title,t.lastEventSummary,g,(r=h[0])==null?void 0:r.metadata):z()},[h,t,g]),c=async(r,o,u)=>{if(!(!u||a)){T(r),E(null);try{await u(),E(`${o} requested.`)}catch(p){E(p instanceof Error?p.message:`${o} failed.`)}finally{T(null)}}};if(!t)return e.jsxs(F,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsx("button",{onClick:()=>q(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":f?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:C("transition-transform",f?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:C("transition-all",f?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"space-y-2 overflow-y-auto p-4 text-body text-secondary",children:[e.jsx("p",{children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>c("continue-priority","Continue highest priority",l),disabled:!l||!!a,className:"rounded-md border border-strong bg-white/[0.04] px-3 py-1.5 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:a==="continue-priority"?"Dispatching…":"Continue highest priority"}),I&&e.jsx("p",{className:"text-caption text-secondary",children:I})]})})]});const A=t.progress===null?null:Math.round(t.progress),m=ae(t),M=ie(t,m,g),G=m==="handoff"?"Handoff":m==="blocked"?"Blocker reason":m==="failed"?"Failure reason":"Status note",O=["running","active","queued","pending"].includes(m),V=["paused","blocked","queued","pending"].includes(m),Q=!["completed","archived","cancelled"].includes(m),S=!["archived","cancelled"].includes(m),J=[{label:"Started",value:t.startedAt?_(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?_(t.updatedAt):"—"},{label:"ETA",value:t.eta??"—"},{label:"Checkpoints",value:t.checkpointCount!==null&&t.checkpointCount!==void 0?String(t.checkpointCount):"—"}];return e.jsxs(F,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-subtle px-4 py-3.5",children:[e.jsx("h2",{className:"text-heading font-semibold text-white",children:"Session Detail"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"chip text-caption uppercase",children:m}),e.jsx("button",{onClick:()=>q(r=>!r),className:"text-muted transition-colors hover:text-primary","aria-label":f?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:C("transition-transform",f?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]})]}),e.jsx("div",{className:C("transition-all",f?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"space-y-3 overflow-y-auto p-4",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(X,{provider:D.id,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-body font-medium text-white",children:t.title}),e.jsxs("p",{className:"mt-0.5 text-caption text-secondary",children:[t.agentName??"Unassigned"," · ",D.label]})]})]}),R.length>0&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] p-2.5",children:[e.jsx("p",{className:"mb-1.5 text-micro uppercase tracking-[0.1em] text-muted",children:"Breadcrumb"}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-caption",children:R.map((r,o)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.02] px-1.5 py-0.5 text-secondary",children:r.value}),o<R.length-1&&e.jsx("span",{className:"text-caption text-muted",children:"›"})]},`${r.label}-${r.value}`))})]}),g&&e.jsx("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2",children:e.jsx(Y,{text:g,mode:"block"})}),(t.phase||t.state||M)&&e.jsxs("div",{className:"rounded-xl border border-subtle bg-white/[0.02] px-3 py-2 text-caption text-secondary",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.phase&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 uppercase tracking-[0.08em] text-muted",children:["phase: ",t.phase]}),t.state&&e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.03] px-2 py-0.5 uppercase tracking-[0.08em] text-muted",children:["runtime: ",t.state]})]}),M&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx("p",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:G}),e.jsx("p",{className:"text-body text-secondary",children:M})]})]}),A!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-caption text-secondary",children:[e.jsx("span",{children:"Progress"}),e.jsxs("span",{children:[A,"%"]})]}),e.jsx("div",{className:"h-2 rounded-full bg-white/[0.08]",children:e.jsx("div",{className:"h-2 rounded-full",style:{width:`${A}%`,background:`linear-gradient(90deg, ${P.lime}, ${P.teal})`}})})]}),e.jsx("dl",{className:"grid grid-cols-1 gap-1 text-caption text-secondary sm:grid-cols-2",children:J.map(r=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-muted",children:r.label}),e.jsx("dd",{className:"font-medium",children:r.value})]},r.label))}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.12em] text-muted",children:"Quick actions"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>c("continue-priority","Continue highest priority",l),disabled:!l||!!a,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:a==="continue-priority"?"Dispatching…":"Continue Priority"}),e.jsx("button",{onClick:()=>c("dispatch-session","Dispatch session",()=>b==null?void 0:b(t)),disabled:!b||!!a,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:a==="dispatch-session"?"Dispatching…":"Dispatch Session"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.12em] text-muted",children:"Session controls"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>c("pause-session","Pause session",()=>y==null?void 0:y(t)),disabled:!y||!O||!!a,className:"rounded-md border border-amber-400/30 bg-amber-400/10 px-3 py-2 text-caption font-semibold text-amber-300 transition-colors hover:bg-amber-400/20 disabled:opacity-45",children:a==="pause-session"?"Pausing…":"Pause"}),e.jsx("button",{onClick:()=>c("resume-session","Resume session",()=>j==null?void 0:j(t)),disabled:!j||!V||!!a,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-caption font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:a==="resume-session"?"Resuming…":"Resume"}),e.jsx("button",{onClick:()=>c("checkpoint-session","Checkpoint created",()=>N==null?void 0:N(t)),disabled:!N||!!a,className:"rounded-md border border-sky-400/30 bg-sky-400/10 px-3 py-2 text-caption font-semibold text-sky-300 transition-colors hover:bg-sky-400/20 disabled:opacity-45",children:a==="checkpoint-session"?"Creating…":"Checkpoint"}),e.jsx("button",{onClick:()=>c("rollback-session","Rollback requested",()=>k==null?void 0:k(t)),disabled:!k||!S||!!a,className:"rounded-md border border-fuchsia-400/30 bg-fuchsia-400/10 px-3 py-2 text-caption font-semibold text-fuchsia-300 transition-colors hover:bg-fuchsia-400/20 disabled:opacity-45",children:a==="rollback-session"?"Rolling back…":"Rollback"}),e.jsx("button",{onClick:()=>c("cancel-session","Cancel session",()=>v==null?void 0:v(t)),disabled:!v||!Q||!!a,className:"col-span-2 rounded-md border border-red-400/30 bg-red-400/10 px-3 py-2 text-caption font-semibold text-red-300 transition-colors hover:bg-red-400/20 disabled:opacity-45",children:a==="cancel-session"?"Cancelling…":"Cancel session"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-micro uppercase tracking-[0.12em] text-muted",children:"Planning"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>c("start-initiative","Start initiative",B),disabled:!B||!!a,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:a==="start-initiative"?"Creating…":"New initiative"}),e.jsx("button",{onClick:()=>c("start-workstream","Start workstream",()=>w==null?void 0:w(t.initiativeId)),disabled:!w||!!a,className:"rounded-md border border-strong bg-white/[0.03] px-3 py-2 text-caption text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:a==="start-workstream"?"Creating…":"New workstream"})]})]})]}),I&&e.jsx("p",{className:"rounded-md border border-white/[0.08] bg-white/[0.02] px-2.5 py-1.5 text-caption text-secondary",children:I}),t.blockers.length>0&&e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-3",children:[e.jsx("h3",{className:"mb-1 text-caption uppercase tracking-[0.12em] text-red-200/70",children:"Blockers"}),e.jsx("ul",{className:"space-y-1 text-body text-red-100/90",children:t.blockers.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-caption uppercase tracking-[0.12em] text-secondary",children:"Recent Messages"}),h.length===0&&e.jsx("p",{className:"text-body text-secondary",children:"No recent messages for this run."}),e.jsx("div",{className:"space-y-2",children:h.map(r=>e.jsxs("article",{className:"rounded-lg border border-subtle bg-white/[0.02] px-2.5 py-2",children:[e.jsx("p",{className:"text-caption text-bright",children:r.title}),(r.summary||r.description)&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-caption text-secondary",children:r.summary??r.description}),e.jsxs("p",{className:"mt-1 text-micro text-muted",children:[new Date(r.timestamp).toLocaleString()," · ",_(r.timestamp)]})]},r.id))})]})]})})]})});export{oe as SessionInspector};
@@ -9,12 +9,12 @@
9
9
  <meta name="googlebot" content="noindex, nofollow, noarchive, nosnippet, noimageindex" />
10
10
  <meta name="copyright" content="OrgX. All rights reserved." />
11
11
  <title>OrgX Live Dashboard</title>
12
- <script type="module" crossorigin src="/orgx/live/assets/BzkiMPmM.js"></script>
12
+ <script type="module" crossorigin src="/orgx/live/assets/BhapSNAs.js"></script>
13
13
  <link rel="modulepreload" crossorigin href="/orgx/live/assets/C-KIc3Wc.js">
14
14
  <link rel="modulepreload" crossorigin href="/orgx/live/assets/sAhvFnpk.js">
15
15
  <link rel="modulepreload" crossorigin href="/orgx/live/assets/B3ziCA02.js">
16
16
  <link rel="modulepreload" crossorigin href="/orgx/live/assets/CpJsfbXo.js">
17
- <link rel="stylesheet" crossorigin href="/orgx/live/assets/Ie7d9Iq2.css">
17
+ <link rel="stylesheet" crossorigin href="/orgx/live/assets/B5NEElEI.css">
18
18
  </head>
19
19
  <body class="bg-[#080808] text-white antialiased">
20
20
  <div id="root"></div>
@@ -1,8 +1,9 @@
1
- import { chmodSync, existsSync, mkdirSync, readFileSync, } from "node:fs";
1
+ import { existsSync, readFileSync, } from "node:fs";
2
2
  import { Buffer } from "node:buffer";
3
3
  import { enrichActivityActorFieldsList } from "./activity-actor-fields.js";
4
4
  import { getOrgxPluginConfigDir, getOrgxPluginConfigPath } from "./paths.js";
5
5
  import { backupCorruptFileSync, writeJsonFileAtomicSync } from "./fs-utils.js";
6
+ import { ensureStoreDirSync, parseJsonSafe } from "./stores/json-store.js";
6
7
  const STORE_VERSION = 1;
7
8
  const STORE_FILENAME = "activity-store.json";
8
9
  const MAX_ITEMS = 50_000;
@@ -10,26 +11,11 @@ const RETENTION_DAYS = 45;
10
11
  const FLUSH_DEBOUNCE_MS = 1_250;
11
12
  let cached = null;
12
13
  function ensureDir() {
13
- const dir = getOrgxPluginConfigDir();
14
- mkdirSync(dir, { recursive: true, mode: 0o700 });
15
- try {
16
- chmodSync(dir, 0o700);
17
- }
18
- catch {
19
- // best effort
20
- }
14
+ ensureStoreDirSync(getOrgxPluginConfigDir());
21
15
  }
22
16
  function storePath() {
23
17
  return getOrgxPluginConfigPath(STORE_FILENAME);
24
18
  }
25
- function parseJson(value) {
26
- try {
27
- return JSON.parse(value);
28
- }
29
- catch {
30
- return null;
31
- }
32
- }
33
19
  function toEpoch(value) {
34
20
  if (!value)
35
21
  return 0;
@@ -75,7 +61,7 @@ function readPersistedStore() {
75
61
  }
76
62
  try {
77
63
  const raw = readFileSync(file, "utf8");
78
- const parsed = parseJson(raw);
64
+ const parsed = parseJsonSafe(raw);
79
65
  if (!parsed || parsed.version !== STORE_VERSION || !Array.isArray(parsed.items)) {
80
66
  backupCorruptFileSync(file);
81
67
  return { version: STORE_VERSION, updatedAt: new Date().toISOString(), items: [] };
@@ -1,6 +1,7 @@
1
- import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, } from "node:fs";
1
+ import { existsSync, readFileSync, } from "node:fs";
2
2
  import { getOrgxPluginConfigDir, getOrgxPluginConfigPath } from "./paths.js";
3
3
  import { backupCorruptFileSync, writeJsonFileAtomicSync } from "./fs-utils.js";
4
+ import { clearStoreFileSync, ensureStoreDirSync, parseJsonSafe, } from "./stores/json-store.js";
4
5
  const MAX_AGENTS = 120;
5
6
  const MAX_RUNS = 480;
6
7
  function contextDir() {
@@ -10,22 +11,7 @@ function contextFile() {
10
11
  return getOrgxPluginConfigPath("agent-contexts.json");
11
12
  }
12
13
  function ensureContextDir() {
13
- const dir = contextDir();
14
- mkdirSync(dir, { recursive: true, mode: 0o700 });
15
- try {
16
- chmodSync(dir, 0o700);
17
- }
18
- catch {
19
- // best effort
20
- }
21
- }
22
- function parseJson(value) {
23
- try {
24
- return JSON.parse(value);
25
- }
26
- catch {
27
- return null;
28
- }
14
+ ensureStoreDirSync(contextDir());
29
15
  }
30
16
  function normalizeContext(input) {
31
17
  return {
@@ -55,7 +41,7 @@ export function readAgentContexts() {
55
41
  return { updatedAt: new Date().toISOString(), agents: {}, runs: {} };
56
42
  }
57
43
  const raw = readFileSync(file, "utf8");
58
- const parsed = parseJson(raw);
44
+ const parsed = parseJsonSafe(raw);
59
45
  if (!parsed || typeof parsed !== "object") {
60
46
  backupCorruptFileSync(file);
61
47
  return { updatedAt: new Date().toISOString(), agents: {}, runs: {} };
@@ -157,11 +143,5 @@ export function upsertRunContext(input) {
157
143
  return next;
158
144
  }
159
145
  export function clearAgentContexts() {
160
- const file = contextFile();
161
- try {
162
- rmSync(file, { force: true });
163
- }
164
- catch {
165
- // best effort
166
- }
146
+ clearStoreFileSync(contextFile());
167
147
  }
@@ -1,6 +1,7 @@
1
- import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, } from "node:fs";
1
+ import { existsSync, readFileSync, } from "node:fs";
2
2
  import { getOrgxPluginConfigDir, getOrgxPluginConfigPath } from "./paths.js";
3
3
  import { backupCorruptFileSync, writeJsonFileAtomicSync } from "./fs-utils.js";
4
+ import { clearStoreFileSync, ensureStoreDirSync, parseJsonSafe, } from "./stores/json-store.js";
4
5
  const MAX_RUNS = 240;
5
6
  function runDir() {
6
7
  return getOrgxPluginConfigDir();
@@ -9,22 +10,7 @@ function runFile() {
9
10
  return getOrgxPluginConfigPath("agent-runs.json");
10
11
  }
11
12
  function ensureRunDir() {
12
- const dir = runDir();
13
- mkdirSync(dir, { recursive: true, mode: 0o700 });
14
- try {
15
- chmodSync(dir, 0o700);
16
- }
17
- catch {
18
- // best effort
19
- }
20
- }
21
- function parseJson(value) {
22
- try {
23
- return JSON.parse(value);
24
- }
25
- catch {
26
- return null;
27
- }
13
+ ensureStoreDirSync(runDir());
28
14
  }
29
15
  function normalizeNullableString(value) {
30
16
  if (typeof value !== "string")
@@ -56,7 +42,7 @@ export function readAgentRuns() {
56
42
  return { updatedAt: new Date().toISOString(), runs: {} };
57
43
  }
58
44
  const raw = readFileSync(file, "utf8");
59
- const parsed = parseJson(raw);
45
+ const parsed = parseJsonSafe(raw);
60
46
  if (!parsed || typeof parsed !== "object") {
61
47
  backupCorruptFileSync(file);
62
48
  return { updatedAt: new Date().toISOString(), runs: {} };
@@ -148,11 +134,5 @@ export function markAgentRunStopped(runId) {
148
134
  return updated ? normalizeRecord(updated) : null;
149
135
  }
150
136
  export function clearAgentRuns() {
151
- const file = runFile();
152
- try {
153
- rmSync(file, { force: true });
154
- }
155
- catch {
156
- // best effort
157
- }
137
+ clearStoreFileSync(runFile());
158
138
  }
@@ -3,6 +3,7 @@ import { existsSync, mkdirSync, readFileSync, statSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
4
  import { dirname, join } from "node:path";
5
5
  import { writeFileAtomicSync } from "./fs-utils.js";
6
+ import { parseJsonSafe } from "./json-utils.js";
6
7
  import { getOpenClawDir } from "./paths.js";
7
8
  export const ORGX_AGENT_SUITE_PACK_ID = "orgx-agent-suite";
8
9
  export const ORGX_AGENT_SUITE_AGENTS = [
@@ -29,14 +30,6 @@ const SUITE_FILES = [
29
30
  function isRecord(value) {
30
31
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
31
32
  }
32
- function parseJsonSafe(raw) {
33
- try {
34
- return JSON.parse(raw);
35
- }
36
- catch {
37
- return null;
38
- }
39
- }
40
33
  function isSafeAgentId(value) {
41
34
  const trimmed = value.trim();
42
35
  if (!trimmed)
@@ -0,0 +1,47 @@
1
+ import { type ResolvedConfig } from "../config/resolution.js";
2
+ import type { OnboardingState } from "../types.js";
3
+ type LoggerLike = {
4
+ info?: (msg: string, meta?: Record<string, unknown>) => void;
5
+ warn?: (msg: string, meta?: Record<string, unknown>) => void;
6
+ debug?: (msg: string, meta?: Record<string, unknown>) => void;
7
+ };
8
+ type RuntimeConfigState = Pick<ResolvedConfig, "apiKey" | "apiKeySource" | "userId" | "baseUrl" | "installationId">;
9
+ export declare function applyRuntimeApiKey(input: {
10
+ config: RuntimeConfigState;
11
+ apiKey: string;
12
+ source: "manual" | "browser_pairing";
13
+ workspaceName?: string | null;
14
+ keyPrefix?: string | null;
15
+ userId?: string | null;
16
+ currentWorkspaceName: string | null;
17
+ updateOnboardingState: (updates: Partial<OnboardingState>) => unknown;
18
+ setCredentials: (credentials: {
19
+ apiKey: string;
20
+ userId: string;
21
+ baseUrl: string;
22
+ }) => void;
23
+ logger?: LoggerLike;
24
+ }): void;
25
+ export declare function isAuthRequiredError(result: {
26
+ status: number;
27
+ error: string;
28
+ }): boolean;
29
+ export declare function buildManualKeyConnectUrl(baseApiUrl: string): string;
30
+ export declare function fetchOrgxJson<T>(input: {
31
+ baseApiUrl: string;
32
+ method: "GET" | "POST";
33
+ path: string;
34
+ body?: unknown;
35
+ options?: {
36
+ timeoutMs?: number;
37
+ };
38
+ toErrorMessage: (err: unknown) => string;
39
+ }): Promise<{
40
+ ok: true;
41
+ data: T;
42
+ } | {
43
+ ok: false;
44
+ status: number;
45
+ error: string;
46
+ }>;
47
+ export {};
@@ -0,0 +1,169 @@
1
+ import { saveAuthStore } from "../auth-store.js";
2
+ import { resolveRuntimeUserId, } from "../config/resolution.js";
3
+ import { autoConfigureDetectedMcpClients } from "../mcp-client-setup.js";
4
+ import { readOpenClawGatewayPort, readOpenClawSettingsSnapshot, } from "../openclaw-settings.js";
5
+ export function applyRuntimeApiKey(input) {
6
+ const nextApiKey = input.apiKey.trim();
7
+ input.config.apiKey = nextApiKey;
8
+ input.config.apiKeySource = "persisted";
9
+ input.config.userId = resolveRuntimeUserId(nextApiKey, [input.userId, input.config.userId]);
10
+ input.setCredentials({
11
+ apiKey: input.config.apiKey,
12
+ userId: input.config.userId,
13
+ baseUrl: input.config.baseUrl,
14
+ });
15
+ saveAuthStore({
16
+ installationId: input.config.installationId,
17
+ apiKey: nextApiKey,
18
+ userId: input.config.userId || null,
19
+ workspaceName: input.workspaceName ?? null,
20
+ keyPrefix: input.keyPrefix ?? null,
21
+ source: input.source,
22
+ });
23
+ input.updateOnboardingState({
24
+ hasApiKey: true,
25
+ keySource: "persisted",
26
+ installationId: input.config.installationId,
27
+ workspaceName: input.workspaceName ?? input.currentWorkspaceName,
28
+ });
29
+ if (input.source === "browser_pairing" &&
30
+ process.env.ORGX_DISABLE_MCP_CLIENT_AUTOCONFIG !== "1") {
31
+ try {
32
+ const snapshot = readOpenClawSettingsSnapshot();
33
+ const port = readOpenClawGatewayPort(snapshot.raw);
34
+ const localMcpUrl = `http://127.0.0.1:${port}/orgx/mcp`;
35
+ void autoConfigureDetectedMcpClients({
36
+ localMcpUrl,
37
+ logger: input.logger ?? {},
38
+ }).catch(() => {
39
+ // best effort
40
+ });
41
+ }
42
+ catch {
43
+ // best effort
44
+ }
45
+ }
46
+ }
47
+ export function isAuthRequiredError(result) {
48
+ if (result.status !== 401) {
49
+ return false;
50
+ }
51
+ return /auth|unauthorized|token/i.test(result.error);
52
+ }
53
+ export function buildManualKeyConnectUrl(baseApiUrl) {
54
+ try {
55
+ // Deep-link into the Security section where API keys live.
56
+ return new URL("/settings#security", baseApiUrl).toString();
57
+ }
58
+ catch {
59
+ return "https://www.useorgx.com/settings#security";
60
+ }
61
+ }
62
+ export async function fetchOrgxJson(input) {
63
+ try {
64
+ const controller = new AbortController();
65
+ const timeoutMs = typeof input.options?.timeoutMs === "number" &&
66
+ Number.isFinite(input.options.timeoutMs)
67
+ ? Math.max(1_000, Math.floor(input.options.timeoutMs))
68
+ : 12_000;
69
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
70
+ let response;
71
+ let rawText = "";
72
+ try {
73
+ response = await fetch(`${input.baseApiUrl}${input.path}`, {
74
+ method: input.method,
75
+ signal: controller.signal,
76
+ headers: {
77
+ Accept: "application/json",
78
+ "Content-Type": "application/json",
79
+ },
80
+ body: input.body ? JSON.stringify(input.body) : undefined,
81
+ });
82
+ rawText = await response.text().catch(() => "");
83
+ }
84
+ finally {
85
+ clearTimeout(timeout);
86
+ }
87
+ const payload = (() => {
88
+ if (!rawText)
89
+ return null;
90
+ try {
91
+ return JSON.parse(rawText);
92
+ }
93
+ catch {
94
+ return null;
95
+ }
96
+ })();
97
+ if (!response.ok) {
98
+ const rawError = payload?.error ?? payload?.message;
99
+ let errorMessage;
100
+ if (typeof rawError === "string") {
101
+ errorMessage = rawError;
102
+ }
103
+ else if (rawError &&
104
+ typeof rawError === "object" &&
105
+ "message" in rawError &&
106
+ typeof rawError.message === "string") {
107
+ errorMessage = rawError.message;
108
+ }
109
+ else if (rawText && rawText.trim().length > 0) {
110
+ // Avoid dumping HTML (Cloudflare / Next.js error pages) into UI; keep it short.
111
+ const sanitized = rawText
112
+ .replace(/\s+/g, " ")
113
+ .replace(/<[^>]+>/g, "")
114
+ .trim();
115
+ errorMessage =
116
+ sanitized.length > 0
117
+ ? sanitized.slice(0, 180)
118
+ : `OrgX request failed (${response.status})`;
119
+ }
120
+ else {
121
+ errorMessage = `OrgX request failed (${response.status})`;
122
+ }
123
+ const statusToken = `HTTP ${response.status}`;
124
+ if (response.status &&
125
+ !errorMessage.toLowerCase().includes(statusToken.toLowerCase()) &&
126
+ !errorMessage.includes(`(${response.status})`)) {
127
+ errorMessage = `${errorMessage} (HTTP ${response.status})`;
128
+ }
129
+ const debugParts = [];
130
+ const requestId = response.headers.get("x-request-id");
131
+ const vercelId = response.headers.get("x-vercel-id");
132
+ const cfRay = response.headers.get("cf-ray");
133
+ const clerkStatus = response.headers.get("x-clerk-auth-status");
134
+ const clerkReason = response.headers.get("x-clerk-auth-reason");
135
+ if (requestId)
136
+ debugParts.push(`req=${requestId}`);
137
+ if (vercelId && vercelId !== requestId)
138
+ debugParts.push(`vercel=${vercelId}`);
139
+ if (cfRay)
140
+ debugParts.push(`cf-ray=${cfRay}`);
141
+ if (clerkStatus)
142
+ debugParts.push(`clerk=${clerkStatus}`);
143
+ if (clerkReason)
144
+ debugParts.push(`clerk_reason=${clerkReason}`);
145
+ const debugSuffix = debugParts.length > 0 ? ` (${debugParts.join(", ")})` : "";
146
+ return {
147
+ ok: false,
148
+ status: response.status,
149
+ error: `${errorMessage}${debugSuffix}`,
150
+ };
151
+ }
152
+ if (payload?.data !== undefined) {
153
+ return { ok: true, data: payload.data };
154
+ }
155
+ if (payload !== null) {
156
+ return { ok: true, data: payload };
157
+ }
158
+ return { ok: true, data: rawText };
159
+ }
160
+ catch (err) {
161
+ const message = err &&
162
+ typeof err === "object" &&
163
+ "name" in err &&
164
+ err.name === "AbortError"
165
+ ? `OrgX request timed out (method=${input.method}, path=${input.path})`
166
+ : input.toErrorMessage(err);
167
+ return { ok: false, status: 0, error: message };
168
+ }
169
+ }
@@ -1,7 +1,8 @@
1
- import { mkdirSync, readFileSync, chmodSync, existsSync, rmSync } from 'node:fs';
1
+ import { existsSync, readFileSync } from "node:fs";
2
2
  import { randomUUID } from 'node:crypto';
3
3
  import { getOrgxPluginConfigDir, getOrgxPluginConfigPath } from './paths.js';
4
4
  import { backupCorruptFileSync, writeJsonFileAtomicSync } from './fs-utils.js';
5
+ import { clearStoreFileSync, ensureStoreDirSync, parseJsonSafe, } from "./stores/json-store.js";
5
6
  function authDir() {
6
7
  return getOrgxPluginConfigDir();
7
8
  }
@@ -18,22 +19,7 @@ function isUuid(value) {
18
19
  return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
19
20
  }
20
21
  function ensureAuthDir() {
21
- const dir = authDir();
22
- mkdirSync(dir, { recursive: true, mode: 0o700 });
23
- try {
24
- chmodSync(dir, 0o700);
25
- }
26
- catch {
27
- // best effort
28
- }
29
- }
30
- function parseJson(value) {
31
- try {
32
- return JSON.parse(value);
33
- }
34
- catch {
35
- return null;
36
- }
22
+ ensureStoreDirSync(authDir());
37
23
  }
38
24
  export function getAuthFilePath() {
39
25
  return authFile();
@@ -44,7 +30,7 @@ export function readPersistedAuth() {
44
30
  if (!existsSync(file))
45
31
  return null;
46
32
  const raw = readFileSync(file, 'utf8');
47
- const parsed = parseJson(raw);
33
+ const parsed = parseJsonSafe(raw);
48
34
  if (!parsed) {
49
35
  backupCorruptFileSync(file);
50
36
  return null;
@@ -83,13 +69,7 @@ export function writePersistedAuth(input) {
83
69
  return next;
84
70
  }
85
71
  export function clearPersistedAuth() {
86
- const file = authFile();
87
- try {
88
- rmSync(file, { force: true });
89
- }
90
- catch {
91
- // best effort
92
- }
72
+ clearStoreFileSync(authFile());
93
73
  }
94
74
  function readInstallationRecord() {
95
75
  const file = installationFile();
@@ -97,7 +77,7 @@ function readInstallationRecord() {
97
77
  if (!existsSync(file))
98
78
  return null;
99
79
  const raw = readFileSync(file, 'utf8');
100
- const parsed = parseJson(raw);
80
+ const parsed = parseJsonSafe(raw);
101
81
  if (!parsed) {
102
82
  backupCorruptFileSync(file);
103
83
  return null;
@@ -1,7 +1,8 @@
1
- import { chmodSync, existsSync, mkdirSync, readFileSync, statSync } from "node:fs";
1
+ import { existsSync, readFileSync, statSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { getOpenClawDir } from "./paths.js";
4
4
  import { backupCorruptFileSync, writeJsonFileAtomicSync } from "./fs-utils.js";
5
+ import { ensureStoreDirSync, parseJsonSafe, } from "./stores/json-store.js";
5
6
  const PROVIDER_PROFILE_MAP = {
6
7
  openaiApiKey: { profileId: "openai-codex", provider: "openai-codex" },
7
8
  anthropicApiKey: { profileId: "anthropic", provider: "anthropic" },
@@ -18,14 +19,6 @@ function isSafePathSegment(value) {
18
19
  return false;
19
20
  return true;
20
21
  }
21
- function parseJson(value) {
22
- try {
23
- return JSON.parse(value);
24
- }
25
- catch {
26
- return null;
27
- }
28
- }
29
22
  function readObject(value) {
30
23
  return value && typeof value === "object" && !Array.isArray(value)
31
24
  ? value
@@ -36,7 +29,7 @@ function resolveDefaultAgentId() {
36
29
  const configPath = join(getOpenClawDir(), "openclaw.json");
37
30
  if (!existsSync(configPath))
38
31
  return "main";
39
- const raw = parseJson(readFileSync(configPath, "utf8"));
32
+ const raw = parseJsonSafe(readFileSync(configPath, "utf8"));
40
33
  const agents = readObject(raw?.agents);
41
34
  const list = Array.isArray(agents.list) ? agents.list : [];
42
35
  for (const entry of list) {
@@ -70,14 +63,7 @@ function authProfilesFile() {
70
63
  return join(authProfilesDir(), "auth-profiles.json");
71
64
  }
72
65
  function ensureAuthProfilesDir() {
73
- const dir = authProfilesDir();
74
- mkdirSync(dir, { recursive: true, mode: 0o700 });
75
- try {
76
- chmodSync(dir, 0o700);
77
- }
78
- catch {
79
- // best effort
80
- }
66
+ ensureStoreDirSync(authProfilesDir());
81
67
  }
82
68
  function normalizeAuthProfileEntry(value) {
83
69
  if (!value || typeof value !== "object")
@@ -96,7 +82,7 @@ function readAuthProfiles() {
96
82
  if (!existsSync(file))
97
83
  return { file, parsed: null };
98
84
  const raw = readFileSync(file, "utf8");
99
- const parsed = parseJson(raw);
85
+ const parsed = parseJsonSafe(raw);
100
86
  if (!parsed || typeof parsed !== "object") {
101
87
  backupCorruptFileSync(file);
102
88
  return { file, parsed: null };