@miadi/connector 0.1.26 → 0.1.28
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/README.md +18 -9
- package/STEERING.md +87 -0
- package/dist/approve.d.ts +29 -3
- package/dist/approve.js +352 -18
- package/dist/bin.js +5 -0
- package/dist/captions.d.ts +7 -0
- package/dist/captions.js +2 -2
- package/dist/decisions.d.ts +4 -1
- package/dist/decisions.js +10 -1
- package/dist/mission-status.d.ts +5 -0
- package/dist/mission-status.js +7 -1
- package/dist/provider-policy.d.ts +9 -1
- package/dist/provider-policy.js +14 -4
- package/dist/providers.d.ts +1 -1
- package/dist/providers.js +12 -1
- package/dist/records.d.ts +1 -1
- package/dist/records.js +1 -0
- package/dist/request-state.d.ts +1 -1
- package/dist/request-state.js +3 -1
- package/dist/runtime-steer.d.ts +23 -9
- package/dist/runtime-steer.js +272 -35
- package/dist/server.d.ts +3 -1
- package/dist/server.js +18 -2
- package/dist/steer.d.ts +8 -1
- package/dist/steer.js +60 -32
- package/dist/steering-adapters.d.ts +78 -0
- package/dist/steering-adapters.js +214 -0
- package/dist/tools.d.ts +7 -16
- package/dist/tools.js +122 -20
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -2
package/dist/decisions.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ export declare class DecisionTokens {
|
|
|
14
14
|
private readonly secret;
|
|
15
15
|
constructor(stateDir: string, ttl?: number);
|
|
16
16
|
private sign;
|
|
17
|
+
/** The key in a consent link: it opens one request, and only for the person that request names (jgwill/Miadi#925). */
|
|
18
|
+
consentKey(recordId: string): string;
|
|
19
|
+
consentKeyOk(recordId: string, key: string): boolean;
|
|
17
20
|
/** A token for one card: one request, at the version the card shows, for one person in one client. */
|
|
18
21
|
issue(recordId: string, personId: string, clientId: string, now?: number, version?: number): string;
|
|
19
22
|
/** `stale`: the token is genuine but was minted for a version the request no longer holds. */
|
|
@@ -25,4 +28,4 @@ export declare class DecisionTokens {
|
|
|
25
28
|
* and calls `decide_request` through the host. In a host without that bridge it
|
|
26
29
|
* shows each request's approval page instead.
|
|
27
30
|
*/
|
|
28
|
-
export declare const DECISIONS_CARD_HTML = "<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<style>\n:root{color-scheme:light dark;--fg:#1d1b18;--muted:#5b5650;--line:#d9d4cc;--accent:#7a4a00;--ok:#1d6b3a;--err:#b00020;--chip:#f1ede6}\n@media (prefers-color-scheme:dark){:root{--fg:#ece8e1;--muted:#b3ada4;--line:#3a3631;--accent:#ffd700;--ok:#7fd49b;--err:#ff8a80;--chip:#24211d}}\n*{box-sizing:border-box}\nbody{margin:0;color:var(--fg);font:15px/1.45 system-ui,sans-serif;background:transparent}\nmain{padding:12px;display:grid;gap:12px}\n.empty,.note{color:var(--muted)}\narticle{border:1px solid var(--line);border-radius:10px;padding:12px}\nh2{font-size:15px;margin:0 0 4px}\n.kind{display:inline-block;font-size:12px;padding:1px 8px;border-radius:999px;background:var(--chip);color:var(--muted);margin-bottom:6px}\n.meta{font-size:13px;color:var(--muted);margin:0 0 6px}\n.does{margin:6px 0;font-weight:600}\ndetails{margin:6px 0}\nsummary{cursor:pointer;color:var(--muted);font-size:13px}\npre{white-space:pre-wrap;overflow-wrap:anywhere;font-size:12px;margin:6px 0 0;max-height:240px;overflow:auto}\ntextarea{width:100%;min-height:64px;padding:8px;border:1px solid var(--line);border-radius:8px;background:transparent;color:var(--fg);font:inherit;margin-top:8px}\n.row{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px}\nbutton{padding:8px 12px;border-radius:8px;border:1px solid var(--line);background:transparent;color:var(--fg);font:inherit;cursor:pointer;min-height:40px}\nbutton.primary{border-color:var(--accent);outline:1px solid var(--accent)}\nbutton:focus-visible,a:focus-visible,textarea:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\nbutton[disabled]{opacity:.55;cursor:default}\na{color:inherit}\n.done{color:var(--ok);font-weight:600}\n.std{border-top:1px solid var(--line);margin:8px 0;padding-top:8px;display:grid;gap:8px}\nh3{font-size:14px;margin:0;font-weight:600}\n.aspects{list-style:none;margin:4px 0;padding:0;display:grid;gap:14px}\n.asp{display:grid;grid-template-columns:16px 1fr;gap:6px;font-size:14px;overflow-wrap:anywhere}\n.asp .gl{margin-top:3px;color:var(--muted);display:block}\n.asp p{margin:1px 0}\n.asp .nm{color:var(--muted)}\n.asp .ask{font-weight:600}\n.asp details{margin:0}\n.asp details[open]{border-left:2px solid var(--accent);padding-left:8px;margin-top:2px}\n.asp summary{padding:8px 0}\n.who{display:flex;gap:8px;align-items:center}\n.who .settler{flex:1}\n.yours .settler{color:var(--fg);font-weight:600}\n.yours .gl{color:var(--accent)}\n.iconbtn{min-height:34px;width:34px;padding:0;display:inline-grid;place-items:center;flex:none;border-color:var(--accent);color:var(--accent)}\n.openL{display:none}\ndetails[open]>summary .openL{display:inline}\ndetails[open]>summary .closedL{display:none}\n.fact{margin:0;font-size:14px;overflow-wrap:anywhere}\n.code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px}\n.small{font-size:13px;color:var(--muted);margin:0;overflow-wrap:anywhere}\nblockquote{margin:4px 0 0;padding-left:8px;border-left:2px solid var(--line);font-size:14px;overflow-wrap:anywhere}\nsummary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\n</style></head><body><main id=\"root\" aria-live=\"polite\"><p class=\"note\">Loading requests\u2026</p></main>\n<script>\n(function(){\n var root=document.getElementById(\"root\");\n var decided={};\n // A redraw while a decision is being recorded must not offer the buttons again.\n var pending={};\n var errors={};\n // A decision still running is followed to its outcome (jgwill/Miadi#924): one read every POLL_MS, at most POLL_MAX.\n var POLL_MS=3000,POLL_MAX=100,polls={};\n // An error that leaves the request open offers its approval page under it.\n var relink={};\n function el(tag,attrs,text){var e=document.createElement(tag);if(attrs)for(var k in attrs){if(k===\"class\")e.className=attrs[k];else e.setAttribute(k,attrs[k]);}if(text!=null)e.textContent=text;return e;}\n function host(){return window.openai||null;}\n function data(){var h=host();return h&&h.toolOutput?h.toolOutput:null;}\n function tokens(){var h=host();var m=h&&h.toolResponseMetadata;return (m&&m[\"miadi/decisionTokens\"])||{};}\n function render(){\n var d=data();root.textContent=\"\";\n if(!d){root.appendChild(el(\"p\",{class:\"note\"},\"Waiting for the request list.\"));return;}\n var list=d.decisions||[];\n if(!list.length){root.appendChild(el(\"p\",{class:\"empty\"},d.message||\"No request is waiting for a decision.\"));return;}\n if(!d.can_decide_here&&d.reason){root.appendChild(el(\"p\",{class:\"note\"},d.reason));}\n var t=tokens();\n list.forEach(function(r){root.appendChild(card(r,t[r.id]));});\n }\n // Where a request stands, as the connector projected it: the label, its lines, and the review it produced.\n function decidedBlock(d){\n var box=el(\"div\",{role:\"status\",class:d.cls});\n if(d.note)box.appendChild(el(\"p\",{class:\"line\"},d.note));\n box.appendChild(el(\"p\",{class:\"label\"},d.label));\n (d.lines||[]).forEach(function(l){box.appendChild(el(\"p\",{class:\"line\"},l));});\n if(d.url){var p=el(\"p\",{class:\"line\"});p.appendChild(el(\"a\",{href:d.url,target:\"_blank\",rel:\"noopener\"},d.url));box.appendChild(p);}\n return box;\n }\n function toolResult(res){\n var out=(res&&(res.structuredContent||res.structured_content))||null;\n if(!out&&res&&res.content&&res.content[0]&&res.content[0].text){try{out=JSON.parse(res.content[0].text);}catch(e){out={message:res.content[0].text};}}\n return out;\n }\n function projectionView(p,note){return {cls:p.stage===\"failed\"?\"fail\":[\"recording\",\"dispatching\"].indexOf(p.stage)!==-1?\"note\":\"done\",stage:p.stage,label:p.label,lines:p.lines||[],url:p.receipt_url||null,note:note||null};}\n // Read where a request stands. Still running: read again later. Never decided (the call was lost on the way): offer the decision again.\n function follow(r,lost){\n if(!host()||!host().callTool)return;\n polls[r.id]=(polls[r.id]||0)+1;\n host().callTool(\"get_run_result\",{record_id:r.id}).then(function(res){\n var out=toolResult(res);var p=out&&(out.projection||(out.data&&out.data.projection));\n if(!p){if(lost){delete decided[r.id];errors[r.id]=lost;}render();return;}\n if(p.stage===\"awaiting_decision\"){delete decided[r.id];if(lost)errors[r.id]=lost+\" Nothing was decided; decide again.\";render();return;}\n var note=decided[r.id]&&decided[r.id].note;\n decided[r.id]=projectionView(p,note);delete errors[r.id];render();\n if(p.stage===\"recording\"&&polls[r.id]<POLL_MAX)setTimeout(function(){follow(r);},POLL_MS);\n },function(err){\n if(lost){decided[r.id]={cls:\"note\",stage:\"recording\",label:\"Your decision may be recorded. Checking again\u2026\",lines:[],url:null,note:null};render();}\n if(polls[r.id]<POLL_MAX)setTimeout(function(){follow(r,lost);},POLL_MS);\n });\n }\n var SETTLED={drafter:\"The drafting agent can answer this.\",person:\"Only you can answer this. Write it under Instructions.\",bystander:\"Only the person deciding can answer this, in their instructions.\",local_agent:\"A local agent can settle this from the running system.\"};\n var ARROW='<svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.9\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M12 17V3\"/><path d=\"m6 11 6 6 6-6\"/><path d=\"M19 21H5\"/></svg>';\n var DASHED='<path d=\"M10.1 2.182a10 10 0 0 1 3.8 0\"/><path d=\"M13.9 21.818a10 10 0 0 1-3.8 0\"/><path d=\"M17.609 3.721a10 10 0 0 1 2.69 2.7\"/><path d=\"M2.182 13.9a10 10 0 0 1 0-3.8\"/><path d=\"M20.279 17.609a10 10 0 0 1-2.7 2.69\"/><path d=\"M21.818 10.1a10 10 0 0 1 0 3.8\"/><path d=\"M3.721 6.391a10 10 0 0 1 2.7-2.69\"/><path d=\"M6.391 20.279a10 10 0 0 1-2.69-2.7\"/>';var EYE='<path d=\"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/>';\n function glyph(label,paths){return '<svg role=\"img\" aria-label=\"'+label+'\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.9\" stroke-linecap=\"round\" stroke-linejoin=\"round\">'+paths+'</svg>';}\n // A redraw rebuilds the card: what the person typed and which reasons they opened stay.\n var typed={};var whyOpen={};var boxes={};\n function stateLine(label,paths,build){var row=el(\"div\",{class:\"asp state\"});var g=el(\"span\",{class:\"gl\"});g.innerHTML=glyph(label,paths);row.appendChild(g);var t=el(\"p\",{class:\"small\"});build(t);row.appendChild(t);return row;}\n // The mission standard's open aspects, for the person deciding: what only they can answer first, and no verdict (jgwill/Miadi#939).\n function standardBlock(r,token){\n var rv=r.draft_review;\n var canAnswer=Boolean(token&&host()&&host().callTool);\n var s=el(\"section\",{class:\"std\",\"aria-label\":\"The mission standard\"});\n var list=rv?(rv.needs_revision||[]).slice().sort(function(a,b){var p=(b.settled_by===\"person\"?1:0)-(a.settled_by===\"person\"?1:0);return p||String(a.aspect).localeCompare(String(b.aspect));}):[];\n var version=rv&&rv.standard?\" v\"+rv.standard.version:\"\";\n s.appendChild(el(\"h3\",null,list.length?list.length+\" open on the mission standard\"+version:\"The mission standard\"+version));\n if(r.delivery){\n var place=el(\"p\",{class:\"fact\"});place.appendChild(el(\"span\",{class:\"small\"},\"The result lands at: \"));var disputed=list.some(function(f){return f.aspect===\"S1\";});\n place.appendChild(el(\"span\",disputed?{class:\"small\"}:null,r.delivery));\n if(disputed)place.appendChild(el(\"span\",{class:\"small\"},\" (S1 below asks about this)\"));\n s.appendChild(place);\n }\n if(r.person_words){var w=el(\"div\");w.appendChild(el(\"p\",{class:\"small\"},\"The person's words, as the drafting agent quoted them:\"));w.appendChild(el(\"blockquote\",null,r.person_words));s.appendChild(w);}\n if(!rv){s.appendChild(stateLine(\"Read it yourself\",EYE,function(t){t.textContent=\"No check ran on this version of the mission. Read it yourself.\";}));return s;}\n if(!list.length)s.appendChild(stateLine(\"Nothing flagged\",DASHED,function(t){t.textContent=\"Nothing flagged on the aspects checked.\";}));\n else{\n var ul=el(\"ul\",{class:\"aspects\"});\n list.forEach(function(f){\n var mine=f.settled_by===\"person\"&&canAnswer;\n var row=el(\"li\",{class:\"asp\"+(mine?\" yours\":\"\")});\n var g=el(\"span\",{class:\"gl\"});g.innerHTML=glyph(\"Open aspect\",DASHED);row.appendChild(g);\n var t=el(\"div\");\n var name=el(\"p\",{class:\"nm\"});name.appendChild(el(\"span\",{class:\"code\"},f.aspect));name.appendChild(el(\"span\",null,\" \"+f.name));t.appendChild(name);\n t.appendChild(el(\"p\",{class:\"ask\"},f.ask));\n if(f.span&&f.span!==r.delivery)t.appendChild(el(\"p\",{class:\"small\"},\"The mission says: \"+f.span));\n if(f.note)t.appendChild(el(\"p\",{class:\"small\"},f.note));\n var who=el(\"div\",{class:\"who\"});\n who.appendChild(el(\"p\",{class:\"small settler\"},(f.settled_by===\"person\"&&!canAnswer?SETTLED.bystander:SETTLED[f.settled_by])||f.settled_by));\n if(mine){\n var go=el(\"button\",{type:\"button\",class:\"iconbtn\",\"aria-label\":\"Go to Instructions\",title:\"Go to Instructions\"});go.innerHTML=ARROW;\n go.addEventListener(\"click\",function(){var box=boxes[r.id];if(box){if(box.scrollIntoView)box.scrollIntoView({block:\"center\"});box.focus();}});\n who.appendChild(go);\n }\n t.appendChild(who);\n var key=r.id+\"/\"+f.aspect;\n var why=el(\"details\");if(whyOpen[key])why.setAttribute(\"open\",\"\");\n why.addEventListener(\"toggle\",function(){whyOpen[key]=why.open;});\n var sum=el(\"summary\");sum.appendChild(el(\"span\",{class:\"closedL\"},\"Why\"));sum.appendChild(el(\"span\",{class:\"openL\"},\"Hide why\"));why.appendChild(sum);\n why.appendChild(el(\"p\",{class:\"small\"},f.why));\n var by=String(f.checked_by||\"\").split(\" \")[0]===\"jev\"?\"Jev\":f.checked_by===\"code\"?\"a check in code\":\"the \"+f.checked_by;\n why.appendChild(el(\"p\",{class:\"small\"},\"Flagged by \"+by+\".\"));\n t.appendChild(why);\n row.appendChild(t);ul.appendChild(row);\n });\n s.appendChild(ul);\n }\n var open={};list.forEach(function(f){open[f.aspect]=true;});\n var unseen=(rv.not_checked||[]).filter(function(n){return !open[n.aspect];});\n var rest=unseen.filter(function(n){return !n.in_part;});\n unseen.filter(function(n){return n.in_part;}).forEach(function(n){\n s.appendChild(stateLine(\"Checked in part\",EYE,function(t){t.appendChild(el(\"span\",null,\"Checked in part: \"));t.appendChild(el(\"span\",{class:\"code\"},n.aspect));t.appendChild(el(\"span\",null,\" \"+n.name+\" (\"+n.in_part+\")\"));}));\n });\n if(rest.length)s.appendChild(stateLine(\"Read it yourself\",EYE,function(t){\n t.appendChild(el(\"span\",null,\"No check covers these, so read the mission for them: \"));\n rest.forEach(function(n,i){if(i)t.appendChild(el(\"span\",null,\" \u00B7 \"));t.appendChild(el(\"span\",{class:\"code\"},n.aspect));t.appendChild(el(\"span\",null,\" \"+n.name));});\n }));\n if(canAnswer&&list.some(function(f){return f.settled_by===\"drafter\";}))s.appendChild(el(\"p\",{class:\"small\"},\"To put the drafting agent's questions to it, say what to revise under Instructions and send it back.\"));\n var refused=r.provider_authorization&&r.provider_authorization.authorized===false;\n if(canAnswer&&list.length&&!refused)s.appendChild(el(\"p\",{class:\"small\"},\"Approving as it stands starts the session, and the worker reads these questions with the task.\"));\n return s;\n }\n function card(r,token){\n var a=el(\"article\",{\"aria-label\":r.title});\n a.appendChild(el(\"span\",{class:\"kind\"},r.kind_label||r.kind));\n a.appendChild(el(\"h2\",null,r.title));\n a.appendChild(el(\"p\",{class:\"meta\"},\"Asked by \"+r.by+(r.via?\" through \"+r.via:\"\")+\" \u00B7 \"+new Date(r.created_at).toLocaleString()+(r.circle?\" \u00B7 \"+r.circle+\" circle\":\"\")));\n a.appendChild(el(\"p\",{class:\"does\"},r.consequence));\n if(r.intention)a.appendChild(el(\"p\",null,r.intention));\n if(!decided[r.id]&&!pending[r.id]&&r.projection&&r.projection.stage===\"awaiting_decision\"&&(r.kind===\"run_request\"||r.kind===\"work_proposal\"||r.draft_review||r.delivery||r.person_words))a.appendChild(standardBlock(r,token));\n var det=el(\"details\");det.appendChild(el(\"summary\",null,\"What exactly is asked\"));det.appendChild(el(\"pre\",null,r.detail||\"\"));a.appendChild(det);\n var status=el(\"p\",{role:\"status\"});\n if(r.projection&&r.projection.stage!==\"awaiting_decision\"&&(!decided[r.id]||[\"recording\",\"dispatching\"].indexOf(r.projection.stage)===-1)){decided[r.id]=projectionView(r.projection);}\n if(decided[r.id]){\n var shown=decided[r.id];a.appendChild(decidedBlock(shown));\n if(shown.stage===\"recording\"&&polls[r.id]===undefined&&host()&&host().callTool){polls[r.id]=0;setTimeout(function(){follow(r);},POLL_MS);}\n if([\"recording\",\"dispatching\"].indexOf(shown.stage)!==-1&&host()&&host().callTool){\n var refresh=el(\"button\",{type:\"button\"},\"Refresh status\");\n refresh.addEventListener(\"click\",function(){\n refresh.disabled=true;\n host().callTool(\"get_run_result\",{record_id:r.id}).then(function(res){\n var out=toolResult(res);var p=out&&(out.projection||(out.data&&out.data.projection));\n if(p){decided[r.id]=projectionView(p);delete errors[r.id];}\n else{errors[r.id]=(out&&out.message)||\"Status could not be refreshed.\";}\n render();\n },function(err){errors[r.id]=\"Status could not be refreshed: \"+String(err&&err.message||err);render();});\n });\n a.appendChild(refresh);\n }\n if(errors[r.id])a.appendChild(el(\"p\",{class:\"fail\",role:\"status\"},errors[r.id]));\n return a;\n }\n function approvalLink(){var p=el(\"p\",{class:\"note\"});p.appendChild(document.createTextNode(\"Decide on its approval page: \"));p.appendChild(el(\"a\",{href:r.approval_url,target:\"_blank\",rel:\"noopener\"},\"open the approval page\"));return p;}\n if(pending[r.id]){status.className=\"note\";status.textContent=\"Recording your decision\u2026\";a.appendChild(status);return a;}\n if(!token||!host()||!host().callTool){a.appendChild(approvalLink());return a;}\n var ta=el(\"textarea\",{\"aria-label\":\"Instructions or changes (needed to approve with changes or send back)\",placeholder:\"Instructions or changes (needed to approve with changes or send back)\"});\n ta.value=typed[r.id]||\"\";boxes[r.id]=ta;\n ta.addEventListener(\"input\",function(){typed[r.id]=ta.value;});\n a.appendChild(ta);\n var row=el(\"div\",{class:\"row\"});\n // The ring on a mission would move with its report and read as a verdict, so a mission's buttons carry none (jgwill/Miadi#939).\n var mission=r.kind===\"run_request\"||r.kind===\"work_proposal\";\n var buttons=[[\"approve\",\"Approve\",mission?\"\":\"primary\"],[\"approve_with_changes\",\"Approve with my changes\",\"\"],[\"request_revision\",\"Send back for revision\",\"\"],[\"decline\",\"Decline\",\"\"]];\n var btns=[];\n buttons.forEach(function(b){var x=el(\"button\",{type:\"button\",class:b[2]},b[1]);x.addEventListener(\"click\",function(){go(b[0]);});btns.push(x);row.appendChild(x);});\n a.appendChild(row);a.appendChild(status);\n if(errors[r.id]){status.className=\"fail\";status.textContent=errors[r.id];if(relink[r.id])a.appendChild(approvalLink());}\n function go(choice){\n var text=ta.value.trim();\n if((choice===\"approve_with_changes\"||choice===\"request_revision\")&&!text){status.className=\"fail\";status.textContent=choice===\"request_revision\"?\"Say what to revise.\":\"Write the changes to apply.\";ta.focus();return;}\n btns.forEach(function(x){x.disabled=true;});status.className=\"note\";status.textContent=\"Recording your decision\u2026\";pending[r.id]=true;delete errors[r.id];\n host().callTool(\"decide_request\",{record_id:r.id,decision:choice,instructions:text||undefined,decision_token:token}).then(function(res){\n var out=toolResult(res);\n // The connector answers with the request's projection, also when a click finds it decided already.\n var proj=out&&(out.projection||(out.detail&&out.detail.projection));\n var code=out&&out.error;\n delete pending[r.id];\n // The token expired or the request was revised, and it still awaits a decision: say so and keep it open.\n if(code&&(!proj||proj.stage===\"awaiting_decision\")){errors[r.id]=(out&&out.message)||\"Not recorded.\";relink[r.id]=true;render();return;}\n var note=out&&out.replayed?\"This decision was already recorded. Nothing ran again.\":code===\"decision_conflict\"?\"A different decision was recorded first. Here is where it stands.\":code===\"already_decided\"?\"This request was already decided. Here is where it stands.\":null;\n if(proj){decided[r.id]=projectionView(proj,note);}\n else{decided[r.id]={cls:code?\"fail\":\"done\",label:code?((out&&out.message)||\"Not recorded.\"):((out&&out.summary)||\"Recorded.\"),lines:[],url:null,note:null};}\n render();\n },function(err){\n // The host gave up waiting; the connector may still have recorded it. Read before offering the buttons again (#924).\n delete pending[r.id];\n decided[r.id]={cls:\"note\",stage:\"recording\",label:\"Checking whether your decision was recorded\u2026\",lines:[],url:null,note:null};\n polls[r.id]=0;render();\n follow(r,\"Not recorded: \"+(err&&err.message?err.message:String(err))+\".\");\n });\n }\n return a;\n }\n window.addEventListener(\"openai:set_globals\",render);\n render();\n})();\n</script></body></html>";
|
|
31
|
+
export declare const DECISIONS_CARD_HTML = "<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<style>\n:root{color-scheme:light dark;--fg:#1d1b18;--muted:#5b5650;--line:#d9d4cc;--accent:#7a4a00;--ok:#1d6b3a;--err:#b00020;--chip:#f1ede6}\n@media (prefers-color-scheme:dark){:root{--fg:#ece8e1;--muted:#b3ada4;--line:#3a3631;--accent:#ffd700;--ok:#7fd49b;--err:#ff8a80;--chip:#24211d}}\n*{box-sizing:border-box}\nbody{margin:0;color:var(--fg);font:15px/1.45 system-ui,sans-serif;background:transparent}\nmain{padding:12px;display:grid;gap:12px}\n.empty,.note{color:var(--muted)}\narticle{border:1px solid var(--line);border-radius:10px;padding:12px}\nh2{font-size:15px;margin:0 0 4px}\n.kind{display:inline-block;font-size:12px;padding:1px 8px;border-radius:999px;background:var(--chip);color:var(--muted);margin-bottom:6px}\n.meta{font-size:13px;color:var(--muted);margin:0 0 6px}\n.does{margin:6px 0;font-weight:600}\ndetails{margin:6px 0}\nsummary{cursor:pointer;color:var(--muted);font-size:13px}\npre{white-space:pre-wrap;overflow-wrap:anywhere;font-size:12px;margin:6px 0 0;max-height:240px;overflow:auto}\ntextarea{width:100%;min-height:64px;padding:8px;border:1px solid var(--line);border-radius:8px;background:transparent;color:var(--fg);font:inherit;margin-top:8px}\n.row{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px}\nbutton{padding:8px 12px;border-radius:8px;border:1px solid var(--line);background:transparent;color:var(--fg);font:inherit;cursor:pointer;min-height:40px}\nbutton.primary{border-color:var(--accent);outline:1px solid var(--accent)}\nbutton:focus-visible,a:focus-visible,textarea:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\nbutton[disabled]{opacity:.55;cursor:default}\na{color:inherit}\n.done{color:var(--ok);font-weight:600}\n.std{border-top:1px solid var(--line);margin:8px 0;padding-top:8px;display:grid;gap:8px}\nh3{font-size:14px;margin:0;font-weight:600}\n.aspects{list-style:none;margin:4px 0;padding:0;display:grid;gap:14px}\n.asp{display:grid;grid-template-columns:16px 1fr;gap:6px;font-size:14px;overflow-wrap:anywhere}\n.asp .gl{margin-top:3px;color:var(--muted);display:block}\n.asp p{margin:1px 0}\n.asp .nm{color:var(--muted)}\n.asp .ask{font-weight:600}\n.asp details{margin:0}\n.asp details[open]{border-left:2px solid var(--accent);padding-left:8px;margin-top:2px}\n.asp summary{padding:8px 0}\n.who{display:flex;gap:8px;align-items:center}\n.who .settler{flex:1}\n.yours .settler{color:var(--fg);font-weight:600}\n.yours .gl{color:var(--accent)}\n.iconbtn{min-height:34px;width:34px;padding:0;display:inline-grid;place-items:center;flex:none;border-color:var(--accent);color:var(--accent)}\n.openL{display:none}\ndetails[open]>summary .openL{display:inline}\ndetails[open]>summary .closedL{display:none}\n.fact{margin:0;font-size:14px;overflow-wrap:anywhere}\n.code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px}\n.small{font-size:13px;color:var(--muted);margin:0;overflow-wrap:anywhere}\nblockquote{margin:4px 0 0;padding-left:8px;border-left:2px solid var(--line);font-size:14px;overflow-wrap:anywhere}\nsummary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\n</style></head><body><main id=\"root\" aria-live=\"polite\"><p class=\"note\">Loading requests\u2026</p></main>\n<script>\n(function(){\n var root=document.getElementById(\"root\");\n var decided={};\n // A redraw while a decision is being recorded must not offer the buttons again.\n var pending={};\n var errors={};\n // A decision still running is followed to its outcome (jgwill/Miadi#924): one read every POLL_MS, at most POLL_MAX.\n var POLL_MS=3000,POLL_MAX=100,polls={};\n // An error that leaves the request open offers its approval page under it.\n var relink={};\n function el(tag,attrs,text){var e=document.createElement(tag);if(attrs)for(var k in attrs){if(k===\"class\")e.className=attrs[k];else e.setAttribute(k,attrs[k]);}if(text!=null)e.textContent=text;return e;}\n function host(){return window.openai||null;}\n function data(){var h=host();return h&&h.toolOutput?h.toolOutput:null;}\n function tokens(){var h=host();var m=h&&h.toolResponseMetadata;return (m&&m[\"miadi/decisionTokens\"])||{};}\n function render(){\n var d=data();root.textContent=\"\";\n if(!d){root.appendChild(el(\"p\",{class:\"note\"},\"Waiting for the request list.\"));return;}\n var list=d.decisions||[];\n if(!list.length){root.appendChild(el(\"p\",{class:\"empty\"},d.message||\"No request is waiting for a decision.\"));return;}\n if(!d.can_decide_here&&d.reason){root.appendChild(el(\"p\",{class:\"note\"},d.reason));}\n var t=tokens();\n list.forEach(function(r){root.appendChild(card(r,t[r.id]));});\n }\n // Where a request stands, as the connector projected it: the label, its lines, and the review it produced.\n function decidedBlock(d){\n var box=el(\"div\",{role:\"status\",class:d.cls});\n if(d.note)box.appendChild(el(\"p\",{class:\"line\"},d.note));\n box.appendChild(el(\"p\",{class:\"label\"},d.label));\n (d.lines||[]).forEach(function(l){box.appendChild(el(\"p\",{class:\"line\"},l));});\n if(d.url){var p=el(\"p\",{class:\"line\"});p.appendChild(el(\"a\",{href:d.url,target:\"_blank\",rel:\"noopener\"},d.url));box.appendChild(p);}\n return box;\n }\n function toolResult(res){\n var out=(res&&(res.structuredContent||res.structured_content))||null;\n if(!out&&res&&res.content&&res.content[0]&&res.content[0].text){try{out=JSON.parse(res.content[0].text);}catch(e){out={message:res.content[0].text};}}\n return out;\n }\n function projectionView(p,note){return {cls:p.stage===\"failed\"?\"fail\":[\"recording\",\"dispatching\"].indexOf(p.stage)!==-1?\"note\":\"done\",stage:p.stage,label:p.label,lines:p.lines||[],url:p.receipt_url||null,note:note||null};}\n // Read where a request stands. Still running: read again later. Never decided (the call was lost on the way): offer the decision again.\n function follow(r,lost){\n if(!host()||!host().callTool)return;\n polls[r.id]=(polls[r.id]||0)+1;\n host().callTool(\"get_run_result\",{record_id:r.id}).then(function(res){\n var out=toolResult(res);var p=out&&(out.projection||(out.data&&out.data.projection));\n if(!p){if(lost){delete decided[r.id];errors[r.id]=lost;}render();return;}\n if(p.stage===\"awaiting_decision\"){delete decided[r.id];if(lost)errors[r.id]=lost+\" Nothing was decided; decide again.\";render();return;}\n var note=decided[r.id]&&decided[r.id].note;\n decided[r.id]=projectionView(p,note);delete errors[r.id];render();\n if(p.stage===\"recording\"&&polls[r.id]<POLL_MAX)setTimeout(function(){follow(r);},POLL_MS);\n },function(err){\n if(lost){decided[r.id]={cls:\"note\",stage:\"recording\",label:\"Your decision may be recorded. Checking again\u2026\",lines:[],url:null,note:null};render();}\n if(polls[r.id]<POLL_MAX)setTimeout(function(){follow(r,lost);},POLL_MS);\n });\n }\n var SETTLED={drafter:\"The drafting agent can answer this.\",person:\"Only you can answer this. Write it under Instructions.\",bystander:\"Only the person deciding can answer this, in their instructions.\",local_agent:\"A local agent can settle this from the running system.\"};\n var ARROW='<svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.9\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M12 17V3\"/><path d=\"m6 11 6 6 6-6\"/><path d=\"M19 21H5\"/></svg>';\n var DASHED='<path d=\"M10.1 2.182a10 10 0 0 1 3.8 0\"/><path d=\"M13.9 21.818a10 10 0 0 1-3.8 0\"/><path d=\"M17.609 3.721a10 10 0 0 1 2.69 2.7\"/><path d=\"M2.182 13.9a10 10 0 0 1 0-3.8\"/><path d=\"M20.279 17.609a10 10 0 0 1-2.7 2.69\"/><path d=\"M21.818 10.1a10 10 0 0 1 0 3.8\"/><path d=\"M3.721 6.391a10 10 0 0 1 2.7-2.69\"/><path d=\"M6.391 20.279a10 10 0 0 1-2.69-2.7\"/>';var EYE='<path d=\"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/>';\n function glyph(label,paths){return '<svg role=\"img\" aria-label=\"'+label+'\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.9\" stroke-linecap=\"round\" stroke-linejoin=\"round\">'+paths+'</svg>';}\n // A redraw rebuilds the card: what the person typed and which reasons they opened stay.\n var typed={};var whyOpen={};var boxes={};\n function stateLine(label,paths,build){var row=el(\"div\",{class:\"asp state\"});var g=el(\"span\",{class:\"gl\"});g.innerHTML=glyph(label,paths);row.appendChild(g);var t=el(\"p\",{class:\"small\"});build(t);row.appendChild(t);return row;}\n // The mission standard's open aspects, for the person deciding: what only they can answer first, and no verdict (jgwill/Miadi#939).\n function standardBlock(r,token){\n var rv=r.draft_review;\n var canAnswer=Boolean(token&&host()&&host().callTool);\n var s=el(\"section\",{class:\"std\",\"aria-label\":\"The mission standard\"});\n var list=rv?(rv.needs_revision||[]).slice().sort(function(a,b){var p=(b.settled_by===\"person\"?1:0)-(a.settled_by===\"person\"?1:0);return p||String(a.aspect).localeCompare(String(b.aspect));}):[];\n var version=rv&&rv.standard?\" v\"+rv.standard.version:\"\";\n s.appendChild(el(\"h3\",null,list.length?list.length+\" open on the mission standard\"+version:\"The mission standard\"+version));\n if(r.delivery){\n var place=el(\"p\",{class:\"fact\"});place.appendChild(el(\"span\",{class:\"small\"},\"The result lands at: \"));var disputed=list.some(function(f){return f.aspect===\"S1\";});\n place.appendChild(el(\"span\",disputed?{class:\"small\"}:null,r.delivery));\n if(disputed)place.appendChild(el(\"span\",{class:\"small\"},\" (S1 below asks about this)\"));\n s.appendChild(place);\n }\n if(r.person_words){var w=el(\"div\");w.appendChild(el(\"p\",{class:\"small\"},\"The person's words, as the drafting agent quoted them:\"));w.appendChild(el(\"blockquote\",null,r.person_words));s.appendChild(w);}\n if(!rv){s.appendChild(stateLine(\"Read it yourself\",EYE,function(t){t.textContent=\"No check ran on this version of the mission. Read it yourself.\";}));return s;}\n if(!list.length)s.appendChild(stateLine(\"Nothing flagged\",DASHED,function(t){t.textContent=\"Nothing flagged on the aspects checked.\";}));\n else{\n var ul=el(\"ul\",{class:\"aspects\"});\n list.forEach(function(f){\n var mine=f.settled_by===\"person\"&&canAnswer;\n var row=el(\"li\",{class:\"asp\"+(mine?\" yours\":\"\")});\n var g=el(\"span\",{class:\"gl\"});g.innerHTML=glyph(\"Open aspect\",DASHED);row.appendChild(g);\n var t=el(\"div\");\n var name=el(\"p\",{class:\"nm\"});name.appendChild(el(\"span\",{class:\"code\"},f.aspect));name.appendChild(el(\"span\",null,\" \"+f.name));t.appendChild(name);\n t.appendChild(el(\"p\",{class:\"ask\"},f.ask));\n if(f.span&&f.span!==r.delivery)t.appendChild(el(\"p\",{class:\"small\"},\"The mission says: \"+f.span));\n if(f.note)t.appendChild(el(\"p\",{class:\"small\"},f.note));\n var who=el(\"div\",{class:\"who\"});\n who.appendChild(el(\"p\",{class:\"small settler\"},(f.settled_by===\"person\"&&!canAnswer?SETTLED.bystander:SETTLED[f.settled_by])||f.settled_by));\n if(mine){\n var go=el(\"button\",{type:\"button\",class:\"iconbtn\",\"aria-label\":\"Go to Instructions\",title:\"Go to Instructions\"});go.innerHTML=ARROW;\n go.addEventListener(\"click\",function(){var box=boxes[r.id];if(box){if(box.scrollIntoView)box.scrollIntoView({block:\"center\"});box.focus();}});\n who.appendChild(go);\n }\n t.appendChild(who);\n var key=r.id+\"/\"+f.aspect;\n var why=el(\"details\");if(whyOpen[key])why.setAttribute(\"open\",\"\");\n why.addEventListener(\"toggle\",function(){whyOpen[key]=why.open;});\n var sum=el(\"summary\");sum.appendChild(el(\"span\",{class:\"closedL\"},\"Why\"));sum.appendChild(el(\"span\",{class:\"openL\"},\"Hide why\"));why.appendChild(sum);\n why.appendChild(el(\"p\",{class:\"small\"},f.why));\n var by=String(f.checked_by||\"\").split(\" \")[0]===\"jev\"?\"Jev\":f.checked_by===\"code\"?\"a check in code\":\"the \"+f.checked_by;\n why.appendChild(el(\"p\",{class:\"small\"},\"Flagged by \"+by+\".\"));\n t.appendChild(why);\n row.appendChild(t);ul.appendChild(row);\n });\n s.appendChild(ul);\n }\n var open={};list.forEach(function(f){open[f.aspect]=true;});\n var unseen=(rv.not_checked||[]).filter(function(n){return !open[n.aspect];});\n var rest=unseen.filter(function(n){return !n.in_part;});\n unseen.filter(function(n){return n.in_part;}).forEach(function(n){\n s.appendChild(stateLine(\"Checked in part\",EYE,function(t){t.appendChild(el(\"span\",null,\"Checked in part: \"));t.appendChild(el(\"span\",{class:\"code\"},n.aspect));t.appendChild(el(\"span\",null,\" \"+n.name+\" (\"+n.in_part+\")\"));}));\n });\n if(rest.length)s.appendChild(stateLine(\"Read it yourself\",EYE,function(t){\n t.appendChild(el(\"span\",null,\"No check covers these, so read the mission for them: \"));\n rest.forEach(function(n,i){if(i)t.appendChild(el(\"span\",null,\" \u00B7 \"));t.appendChild(el(\"span\",{class:\"code\"},n.aspect));t.appendChild(el(\"span\",null,\" \"+n.name));});\n }));\n if(canAnswer&&list.some(function(f){return f.settled_by===\"drafter\";}))s.appendChild(el(\"p\",{class:\"small\"},\"To put the drafting agent's questions to it, say what to revise under Instructions and send it back.\"));\n var refused=r.provider_authorization&&r.provider_authorization.authorized===false;\n if(canAnswer&&list.length&&!refused)s.appendChild(el(\"p\",{class:\"small\"},\"Approving as it stands starts the session, and the worker reads these questions with the task.\"));\n return s;\n }\n function card(r,token){\n var a=el(\"article\",{\"aria-label\":r.title});\n a.appendChild(el(\"span\",{class:\"kind\"},r.kind_label||r.kind));\n a.appendChild(el(\"h2\",null,r.title));\n a.appendChild(el(\"p\",{class:\"meta\"},\"Asked by \"+r.by+(r.via?\" through \"+r.via:\"\")+\" \u00B7 \"+new Date(r.created_at).toLocaleString()+(r.circle?\" \u00B7 \"+r.circle+\" circle\":\"\")));\n a.appendChild(el(\"p\",{class:\"does\"},r.consequence));\n if(r.intention)a.appendChild(el(\"p\",null,r.intention));\n if(!decided[r.id]&&!pending[r.id]&&r.projection&&r.projection.stage===\"awaiting_decision\"&&(r.kind===\"run_request\"||r.kind===\"work_proposal\"||r.draft_review||r.delivery||r.person_words))a.appendChild(standardBlock(r,token));\n var det=el(\"details\");det.appendChild(el(\"summary\",null,\"What exactly is asked\"));det.appendChild(el(\"pre\",null,r.detail||\"\"));a.appendChild(det);\n var status=el(\"p\",{role:\"status\"});\n if(r.projection&&r.projection.stage!==\"awaiting_decision\"&&(!decided[r.id]||[\"recording\",\"dispatching\"].indexOf(r.projection.stage)===-1)){decided[r.id]=projectionView(r.projection);}\n if(decided[r.id]){\n var shown=decided[r.id];a.appendChild(decidedBlock(shown));\n if(shown.stage===\"recording\"&&polls[r.id]===undefined&&host()&&host().callTool){polls[r.id]=0;setTimeout(function(){follow(r);},POLL_MS);}\n if([\"recording\",\"dispatching\"].indexOf(shown.stage)!==-1&&host()&&host().callTool){\n var refresh=el(\"button\",{type:\"button\"},\"Refresh status\");\n refresh.addEventListener(\"click\",function(){\n refresh.disabled=true;\n host().callTool(\"get_run_result\",{record_id:r.id}).then(function(res){\n var out=toolResult(res);var p=out&&(out.projection||(out.data&&out.data.projection));\n if(p){decided[r.id]=projectionView(p);delete errors[r.id];}\n else{errors[r.id]=(out&&out.message)||\"Status could not be refreshed.\";}\n render();\n },function(err){errors[r.id]=\"Status could not be refreshed: \"+String(err&&err.message||err);render();});\n });\n a.appendChild(refresh);\n }\n if(errors[r.id])a.appendChild(el(\"p\",{class:\"fail\",role:\"status\"},errors[r.id]));\n return a;\n }\n function approvalLink(){var p=el(\"p\",{class:\"note\"});p.appendChild(document.createTextNode(r.kind===\"participant_consent_request\"?\"Only the person it asks decides this. Its page: \":\"Decide on its approval page: \"));p.appendChild(el(\"a\",{href:r.approval_url,target:\"_blank\",rel:\"noopener\"},\"open the approval page\"));return p;}\n if(pending[r.id]){status.className=\"note\";status.textContent=\"Recording your decision\u2026\";a.appendChild(status);return a;}\n if(!token||!host()||!host().callTool){a.appendChild(approvalLink());return a;}\n var ta=el(\"textarea\",{\"aria-label\":\"Instructions or changes (needed to approve with changes or send back)\",placeholder:\"Instructions or changes (needed to approve with changes or send back)\"});\n ta.value=typed[r.id]||\"\";boxes[r.id]=ta;\n ta.addEventListener(\"input\",function(){typed[r.id]=ta.value;});\n a.appendChild(ta);\n var row=el(\"div\",{class:\"row\"});\n // The ring on a mission would move with its report and read as a verdict, so a mission's buttons carry none (jgwill/Miadi#939).\n var mission=r.kind===\"run_request\"||r.kind===\"work_proposal\";\n var buttons=[[\"approve\",\"Approve\",mission?\"\":\"primary\"],[\"approve_with_changes\",\"Approve with my changes\",\"\"],[\"request_revision\",\"Send back for revision\",\"\"],[\"decline\",\"Decline\",\"\"]];\n var btns=[];\n buttons.forEach(function(b){var x=el(\"button\",{type:\"button\",class:b[2]},b[1]);x.addEventListener(\"click\",function(){go(b[0]);});btns.push(x);row.appendChild(x);});\n a.appendChild(row);a.appendChild(status);\n if(errors[r.id]){status.className=\"fail\";status.textContent=errors[r.id];if(relink[r.id])a.appendChild(approvalLink());}\n function go(choice){\n var text=ta.value.trim();\n if((choice===\"approve_with_changes\"||choice===\"request_revision\")&&!text){status.className=\"fail\";status.textContent=choice===\"request_revision\"?\"Say what to revise.\":\"Write the changes to apply.\";ta.focus();return;}\n btns.forEach(function(x){x.disabled=true;});status.className=\"note\";status.textContent=\"Recording your decision\u2026\";pending[r.id]=true;delete errors[r.id];\n host().callTool(\"decide_request\",{record_id:r.id,decision:choice,instructions:text||undefined,decision_token:token}).then(function(res){\n var out=toolResult(res);\n // The connector answers with the request's projection, also when a click finds it decided already.\n var proj=out&&(out.projection||(out.detail&&out.detail.projection));\n var code=out&&out.error;\n delete pending[r.id];\n // The token expired or the request was revised, and it still awaits a decision: say so and keep it open.\n if(code&&(!proj||proj.stage===\"awaiting_decision\")){errors[r.id]=(out&&out.message)||\"Not recorded.\";relink[r.id]=true;render();return;}\n var note=out&&out.replayed?\"This decision was already recorded. Nothing ran again.\":code===\"decision_conflict\"?\"A different decision was recorded first. Here is where it stands.\":code===\"already_decided\"?\"This request was already decided. Here is where it stands.\":null;\n if(proj){decided[r.id]=projectionView(proj,note);}\n else{decided[r.id]={cls:code?\"fail\":\"done\",label:code?((out&&out.message)||\"Not recorded.\"):((out&&out.summary)||\"Recorded.\"),lines:[],url:null,note:null};}\n render();\n },function(err){\n // The host gave up waiting; the connector may still have recorded it. Read before offering the buttons again (#924).\n delete pending[r.id];\n decided[r.id]={cls:\"note\",stage:\"recording\",label:\"Checking whether your decision was recorded\u2026\",lines:[],url:null,note:null};\n polls[r.id]=0;render();\n follow(r,\"Not recorded: \"+(err&&err.message?err.message:String(err))+\".\");\n });\n }\n return a;\n }\n window.addEventListener(\"openai:set_globals\",render);\n render();\n})();\n</script></body></html>";
|
package/dist/decisions.js
CHANGED
|
@@ -50,6 +50,15 @@ export class DecisionTokens {
|
|
|
50
50
|
const v = version === undefined ? "" : `\nv${version}`;
|
|
51
51
|
return createHmac("sha256", this.secret).update(`${recordId}\n${personId}\n${clientId}\n${exp}${v}`).digest("base64url");
|
|
52
52
|
}
|
|
53
|
+
/** The key in a consent link: it opens one request, and only for the person that request names (jgwill/Miadi#925). */
|
|
54
|
+
consentKey(recordId) {
|
|
55
|
+
return createHmac("sha256", this.secret).update(`consent\n${recordId}`).digest("base64url");
|
|
56
|
+
}
|
|
57
|
+
consentKeyOk(recordId, key) {
|
|
58
|
+
const expected = Buffer.from(this.consentKey(recordId));
|
|
59
|
+
const given = Buffer.from(String(key ?? ""));
|
|
60
|
+
return expected.length === given.length && timingSafeEqual(expected, given);
|
|
61
|
+
}
|
|
53
62
|
/** A token for one card: one request, at the version the card shows, for one person in one client. */
|
|
54
63
|
issue(recordId, personId, clientId, now = Math.floor(Date.now() / 1000), version = 1) {
|
|
55
64
|
const exp = now + this.ttl;
|
|
@@ -284,7 +293,7 @@ summary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
|
|
|
284
293
|
if(errors[r.id])a.appendChild(el("p",{class:"fail",role:"status"},errors[r.id]));
|
|
285
294
|
return a;
|
|
286
295
|
}
|
|
287
|
-
function approvalLink(){var p=el("p",{class:"note"});p.appendChild(document.createTextNode("Decide on its approval page: "));p.appendChild(el("a",{href:r.approval_url,target:"_blank",rel:"noopener"},"open the approval page"));return p;}
|
|
296
|
+
function approvalLink(){var p=el("p",{class:"note"});p.appendChild(document.createTextNode(r.kind==="participant_consent_request"?"Only the person it asks decides this. Its page: ":"Decide on its approval page: "));p.appendChild(el("a",{href:r.approval_url,target:"_blank",rel:"noopener"},"open the approval page"));return p;}
|
|
288
297
|
if(pending[r.id]){status.className="note";status.textContent="Recording your decision…";a.appendChild(status);return a;}
|
|
289
298
|
if(!token||!host()||!host().callTool){a.appendChild(approvalLink());return a;}
|
|
290
299
|
var ta=el("textarea",{"aria-label":"Instructions or changes (needed to approve with changes or send back)",placeholder:"Instructions or changes (needed to approve with changes or send back)"});
|
package/dist/mission-status.d.ts
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import type { ConnectorRecord } from "./records.js";
|
|
23
23
|
import type { RequestProjection } from "./request-state.js";
|
|
24
24
|
import type { SteerDelivery } from "./runtime-steer.js";
|
|
25
|
+
import type { SteeringSupport } from "./steering-adapters.js";
|
|
25
26
|
import type { FactoryReceipt } from "./factory-receipt.js";
|
|
26
27
|
import { type GithubGet, type MissionResult } from "./mission-result.js";
|
|
27
28
|
export interface MissionSession {
|
|
@@ -197,6 +198,8 @@ export interface MissionStatus {
|
|
|
197
198
|
route: string;
|
|
198
199
|
delivery: SteerDelivery;
|
|
199
200
|
}[];
|
|
201
|
+
/** What a session of this mission's provider can promise on this host, and how that is known. */
|
|
202
|
+
support?: SteeringSupport;
|
|
200
203
|
};
|
|
201
204
|
stage_truth?: MissionStageTruth;
|
|
202
205
|
/**
|
|
@@ -228,6 +231,8 @@ export interface MissionStatusDeps {
|
|
|
228
231
|
paneBusy?: (session: string, paneId?: string) => "busy" | "idle" | "unknown";
|
|
229
232
|
/** Where one steer stands, read from the runtime's inbox and the session's transcript (write tier only). */
|
|
230
233
|
steerDeliveryOf?: (steer: ConnectorRecord) => SteerDelivery | null;
|
|
234
|
+
/** The steering support of a provider on this host (write tier only). */
|
|
235
|
+
steeringSupportOf?: (provider: string) => SteeringSupport;
|
|
231
236
|
/** Whether the tmux session still holds the pane id (write tier only); undefined when it cannot be listed. */
|
|
232
237
|
panePresent?: (session: string, paneId: string) => boolean | undefined;
|
|
233
238
|
/** The factory runner's delivery receipts for one record, newest first (write tier only). */
|
package/dist/mission-status.js
CHANGED
|
@@ -470,7 +470,13 @@ export async function missionStatus(ref, records, deps) {
|
|
|
470
470
|
...(queue ? { queue } : {}),
|
|
471
471
|
sessions,
|
|
472
472
|
issues,
|
|
473
|
-
steering: {
|
|
473
|
+
steering: {
|
|
474
|
+
grant: grantState,
|
|
475
|
+
attempts_used: attempts,
|
|
476
|
+
...(grant?.max_attempts !== undefined ? { max_attempts: grant.max_attempts } : {}),
|
|
477
|
+
...(steers.length ? { steers } : {}),
|
|
478
|
+
...(deps.steeringSupportOf && (provider?.actual ?? provider?.resolved) ? { support: deps.steeringSupportOf(String(provider.actual ?? provider.resolved)) } : {}),
|
|
479
|
+
},
|
|
474
480
|
...(provider ? { provider } : {}),
|
|
475
481
|
stage_truth: stageTruth,
|
|
476
482
|
mission_stage: missionStage(standing ?? null, stageTruth),
|
|
@@ -31,15 +31,23 @@ export declare const CHOICE_TTL_MS: number;
|
|
|
31
31
|
export declare function needsPersonChoice(provider: string | null | undefined): boolean;
|
|
32
32
|
/** Whether a person id may make a choice or set a policy: a person, never a service token. */
|
|
33
33
|
export declare function isPersonId(personId: string | undefined): boolean;
|
|
34
|
+
/** What may stand in for naming a provider. Codex never does: it runs only on a choice for one mission or an explicit policy (jgwill/Miadi#926). */
|
|
35
|
+
export declare const DEFAULT_PROVIDERS: readonly string[];
|
|
36
|
+
/** The value a person picks on /providers to mean no default of their own, whatever the operator set. */
|
|
37
|
+
export declare const HOST_ORDER = "host_order";
|
|
34
38
|
export interface ProviderPolicy {
|
|
35
39
|
person_id: string;
|
|
36
40
|
codex: CodexPolicy;
|
|
37
41
|
source: "default" | "person";
|
|
38
42
|
record?: string;
|
|
39
43
|
set_at?: string;
|
|
44
|
+
/** The provider a request of theirs runs on when it names none (jgwill/Miadi#942). Absent: the host's order. */
|
|
45
|
+
default_provider?: string;
|
|
46
|
+
/** Who said so: the person on /providers, or the operator's factory.json for this person. */
|
|
47
|
+
default_provider_source?: "person" | "host_config";
|
|
40
48
|
}
|
|
41
49
|
/** A person's provider policy: the latest one they set themself, else the default. */
|
|
42
|
-
export declare function providerPolicyOf(records: ConnectorRecord[], personId: string): ProviderPolicy;
|
|
50
|
+
export declare function providerPolicyOf(records: ConnectorRecord[], personId: string, hostDefaults?: Record<string, string> | null): ProviderPolicy;
|
|
43
51
|
export interface ProviderChoiceView {
|
|
44
52
|
record: string;
|
|
45
53
|
provider: string;
|
package/dist/provider-policy.js
CHANGED
|
@@ -12,19 +12,29 @@ export function needsPersonChoice(provider) {
|
|
|
12
12
|
export function isPersonId(personId) {
|
|
13
13
|
return typeof personId === "string" && personId.length > 0 && !personId.startsWith("system:");
|
|
14
14
|
}
|
|
15
|
+
/** What may stand in for naming a provider. Codex never does: it runs only on a choice for one mission or an explicit policy (jgwill/Miadi#926). */
|
|
16
|
+
export const DEFAULT_PROVIDERS = ["claude", "pi", "copilot"];
|
|
17
|
+
/** The value a person picks on /providers to mean no default of their own, whatever the operator set. */
|
|
18
|
+
export const HOST_ORDER = "host_order";
|
|
15
19
|
/** A person's provider policy: the latest one they set themself, else the default. */
|
|
16
|
-
export function providerPolicyOf(records, personId) {
|
|
20
|
+
export function providerPolicyOf(records, personId, hostDefaults) {
|
|
17
21
|
let latest;
|
|
22
|
+
let chosenDefault;
|
|
18
23
|
for (const r of records) {
|
|
19
24
|
if (r.kind !== "provider_policy" || r.actor.person_id !== personId || !isPersonId(r.actor.person_id))
|
|
20
25
|
continue;
|
|
21
|
-
|
|
26
|
+
const body = r.body;
|
|
27
|
+
if (!CODEX_POLICIES.includes(String(body.codex)))
|
|
22
28
|
continue;
|
|
23
29
|
latest = r;
|
|
30
|
+
chosenDefault = typeof body.default_provider === "string" && body.default_provider ? body.default_provider : chosenDefault;
|
|
24
31
|
}
|
|
32
|
+
const hostDefault = hostDefaults?.[personId];
|
|
33
|
+
const default_provider = chosenDefault === HOST_ORDER ? undefined : (chosenDefault ?? hostDefault);
|
|
34
|
+
const defaults = default_provider && DEFAULT_PROVIDERS.includes(default_provider) ? { default_provider, default_provider_source: (chosenDefault ? "person" : "host_config") } : {};
|
|
25
35
|
if (!latest)
|
|
26
|
-
return { person_id: personId, codex: DEFAULT_CODEX_POLICY, source: "default" };
|
|
27
|
-
return { person_id: personId, codex: latest.body.codex, source: "person", record: latest.id, set_at: latest.created_at };
|
|
36
|
+
return { person_id: personId, codex: DEFAULT_CODEX_POLICY, source: "default", ...defaults };
|
|
37
|
+
return { person_id: personId, codex: latest.body.codex, source: "person", record: latest.id, set_at: latest.created_at, ...defaults };
|
|
28
38
|
}
|
|
29
39
|
function str(v) {
|
|
30
40
|
return typeof v === "string" && v ? v : null;
|
package/dist/providers.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export type ProviderResolution = {
|
|
|
45
45
|
* preference order that may be selected by default wins. Codex and Claude Code
|
|
46
46
|
* only ever by name; whether a named Codex may run is provider-policy.ts's answer.
|
|
47
47
|
*/
|
|
48
|
-
export declare function resolveProvider(requested: string | undefined, found: ProviderAvailability[]): ProviderResolution;
|
|
48
|
+
export declare function resolveProvider(requested: string | undefined, found: ProviderAvailability[], personDefault?: string): ProviderResolution;
|
|
49
49
|
/**
|
|
50
50
|
* Where Jev is reached from this host (jgwill/Miadi#913 C1), by the names
|
|
51
51
|
* smcraft's lane-check decider uses (examples/decision-gate/lane-check,
|
package/dist/providers.js
CHANGED
|
@@ -68,8 +68,19 @@ export function discoverProviders(probe = {}, specs = PROVIDERS) {
|
|
|
68
68
|
* preference order that may be selected by default wins. Codex and Claude Code
|
|
69
69
|
* only ever by name; whether a named Codex may run is provider-policy.ts's answer.
|
|
70
70
|
*/
|
|
71
|
-
export function resolveProvider(requested, found) {
|
|
71
|
+
export function resolveProvider(requested, found, personDefault) {
|
|
72
72
|
const installed = found.filter((p) => p.installed);
|
|
73
|
+
// A person's own default stands in for naming it, and never silently becomes another provider (jgwill/Miadi#942).
|
|
74
|
+
if (!requested && personDefault) {
|
|
75
|
+
const avail = found.find((p) => p.id === personDefault);
|
|
76
|
+
if (avail?.installed)
|
|
77
|
+
return { state: "ok", provider: avail, explicit: false };
|
|
78
|
+
return {
|
|
79
|
+
state: "provider_unavailable",
|
|
80
|
+
message: `Your default provider, ${personDefault}, is not installed on the connector host. The mission is left unstarted; name an available provider.`,
|
|
81
|
+
available: installed,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
73
84
|
if (requested) {
|
|
74
85
|
const spec = PROVIDERS.find((p) => p.id === requested || p.cli === requested);
|
|
75
86
|
if (!spec) {
|
package/dist/records.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export declare const DOMAINS: readonly ["creative", "ceremonial", "engineering"]
|
|
|
36
36
|
/** #815 "claim category": what kind of statement a record makes. */
|
|
37
37
|
export declare const CLAIM_CATEGORIES: readonly ["observed", "hypothesis", "desired_future", "fiction", "verified_implementation"];
|
|
38
38
|
export type ClaimCategory = (typeof CLAIM_CATEGORIES)[number];
|
|
39
|
-
export declare const RECORD_KINDS: readonly ["observation", "inquiry", "link", "work_proposal", "run_request", "handoff", "source_intent", "review_operation_request", "deep_diver_request", "review_episode_link_request", "calendar_event_draft", "session_completion_proposal", "research_artifact", "inquiry_episode_request", "session_steer_request", "steering_revocation", "provider_choice", "provider_policy"];
|
|
39
|
+
export declare const RECORD_KINDS: readonly ["observation", "inquiry", "link", "work_proposal", "run_request", "handoff", "source_intent", "review_operation_request", "participant_consent_request", "deep_diver_request", "review_episode_link_request", "calendar_event_draft", "session_completion_proposal", "research_artifact", "inquiry_episode_request", "session_steer_request", "steering_revocation", "provider_choice", "provider_policy"];
|
|
40
40
|
export type RecordKind = (typeof RECORD_KINDS)[number];
|
|
41
41
|
/** #816 handoff states. */
|
|
42
42
|
export declare const HANDOFF_STATES: readonly ["pending", "blocked", "ready", "in_progress", "completed", "withdrawn"];
|
package/dist/records.js
CHANGED
package/dist/request-state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ConnectorRecord } from "./records.js";
|
|
2
|
-
export declare const APPROVABLE_KINDS: readonly ["run_request", "review_operation_request", "deep_diver_request", "review_episode_link_request", "work_proposal", "session_completion_proposal", "inquiry_episode_request", "session_steer_request"];
|
|
2
|
+
export declare const APPROVABLE_KINDS: readonly ["run_request", "review_operation_request", "participant_consent_request", "deep_diver_request", "review_episode_link_request", "work_proposal", "session_completion_proposal", "inquiry_episode_request", "session_steer_request"];
|
|
3
3
|
export declare const APPROVABLE: ReadonlySet<string>;
|
|
4
4
|
/** `recording`: a decision was taken a moment ago and its run is still going (in memory, or written ahead as outcome `running`). */
|
|
5
5
|
export type RequestStage = "awaiting_decision" | "recording" | "declined" | "sent_back" | "dispatching" | "completed" | "failed";
|
package/dist/request-state.js
CHANGED
|
@@ -22,6 +22,7 @@ import { transcriptLines } from "./captions.js";
|
|
|
22
22
|
export const APPROVABLE_KINDS = [
|
|
23
23
|
"run_request",
|
|
24
24
|
"review_operation_request",
|
|
25
|
+
"participant_consent_request",
|
|
25
26
|
"deep_diver_request",
|
|
26
27
|
"review_episode_link_request",
|
|
27
28
|
"work_proposal",
|
|
@@ -49,6 +50,7 @@ const OUTCOME_WORDS = {
|
|
|
49
50
|
minted_and_woven: "a new episode minted with it",
|
|
50
51
|
marked_ready: "marked ready for Deep Diver",
|
|
51
52
|
decided: "recorded",
|
|
53
|
+
released: "the source is released",
|
|
52
54
|
nothing_to_run: "nothing to run",
|
|
53
55
|
accepted: "typed into an idle session, which turned busy; its delivery says whether the model read it",
|
|
54
56
|
queued_at_runtime: "handed to the session's inbox, on its way to the model",
|
|
@@ -126,7 +128,7 @@ function projectCore(record, ctx = {}) {
|
|
|
126
128
|
}
|
|
127
129
|
if (record.approval_state === "awaiting_approval") {
|
|
128
130
|
return finish({ ...base, stage: "awaiting_decision", standing: "waiting", label: "Awaiting a decision" }, [
|
|
129
|
-
"Waiting for a person with Miadi's write tier to decide.",
|
|
131
|
+
record.kind === "participant_consent_request" ? `Waiting for ${text(record.body.decider_name)} to decide.` : "Waiting for a person with Miadi's write tier to decide.",
|
|
130
132
|
]);
|
|
131
133
|
}
|
|
132
134
|
if (record.approval_state === "declined") {
|
package/dist/runtime-steer.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { type InboxRoute, type SteerableProvider } from "./steering-adapters.js";
|
|
1
2
|
export declare const STEER_PROTOCOL = 1;
|
|
2
3
|
/** A correction no continuation consumed in a day is stale: the work has moved on. A grant's own expiry comes sooner when it has one. */
|
|
3
4
|
export declare const ENVELOPE_TTL_MS: number;
|
|
4
5
|
export declare const CLAUDE_ADAPTER = "miadi-session-observability 0.1.34 or later";
|
|
6
|
+
export { STEERING_CONTRACT_ID } from "./steering-adapters.js";
|
|
5
7
|
export declare const DELIVERY_STATES: readonly ["authorized", "forwarded_to_runtime", "queued_at_runtime", "delivered_to_agent_context", "acknowledged", "behavior_adjusted", "unsupported", "expired", "blocked", "unknown"];
|
|
6
8
|
export type DeliveryState = (typeof DELIVERY_STATES)[number];
|
|
7
9
|
export interface RuntimeDeps {
|
|
@@ -23,24 +25,28 @@ export interface ClaudeSessionRecord {
|
|
|
23
25
|
/** Claude Code's own record of a running session, `<claudeDir>/sessions/<pid>.json`, if its process lives. */
|
|
24
26
|
export declare function readClaudeSession(deps: RuntimeDeps, sessionId: string): ClaudeSessionRecord | null;
|
|
25
27
|
export type RuntimeRoute = {
|
|
26
|
-
route:
|
|
28
|
+
route: InboxRoute;
|
|
29
|
+
provider: SteerableProvider;
|
|
27
30
|
session_id: string;
|
|
28
31
|
seat: string;
|
|
32
|
+
self_wakes: boolean;
|
|
29
33
|
transcript_path?: string;
|
|
34
|
+
adapter_version?: string;
|
|
30
35
|
} | {
|
|
31
36
|
route: "none";
|
|
32
37
|
code: "unsupported" | "wrong_pane" | "stale_binding";
|
|
33
38
|
reason: string;
|
|
34
39
|
};
|
|
35
40
|
/**
|
|
36
|
-
* Mission → session → runtime, from what each one signed: the runner's receipt names the session
|
|
37
|
-
*
|
|
38
|
-
*
|
|
41
|
+
* Mission → session → runtime, from what each one signed: the runner's receipt names the session and
|
|
42
|
+
* pane, the agent's own record says it runs there, and the adapter's file says this session loaded
|
|
43
|
+
* its adapter. The inbox belongs to this Unix account alone or it is not used.
|
|
39
44
|
*/
|
|
40
45
|
export declare function resolveRuntime(deps: RuntimeDeps, binding: {
|
|
41
46
|
session_id?: string;
|
|
42
47
|
pane_id?: string;
|
|
43
48
|
provider?: string;
|
|
49
|
+
socket?: string | null;
|
|
44
50
|
}): RuntimeRoute;
|
|
45
51
|
export interface SteerEnvelope {
|
|
46
52
|
protocol: number;
|
|
@@ -60,6 +66,8 @@ export interface SteerEnvelope {
|
|
|
60
66
|
transcript_offset?: number;
|
|
61
67
|
/** A person decided this exact steer: the grant it cites no longer speaks for it. */
|
|
62
68
|
decided?: boolean;
|
|
69
|
+
/** The provider whose adapter this was addressed to. */
|
|
70
|
+
provider?: string;
|
|
63
71
|
}
|
|
64
72
|
/** The steer already on its way with these same words under this grant: one correction, one delivery. */
|
|
65
73
|
export declare function sameInstructionInFlight(deps: RuntimeDeps, sessionId: string, grant: string, instruction: string): string | null;
|
|
@@ -76,6 +84,7 @@ export declare function enqueueSteer(deps: RuntimeDeps, args: {
|
|
|
76
84
|
grant_expires_at?: string;
|
|
77
85
|
decided?: boolean;
|
|
78
86
|
transcript_path?: string;
|
|
87
|
+
provider?: string;
|
|
79
88
|
now?: Date;
|
|
80
89
|
}): {
|
|
81
90
|
already: boolean;
|
|
@@ -95,22 +104,26 @@ export declare function revokeInInbox(deps: RuntimeDeps, sessionId: string, targ
|
|
|
95
104
|
already_consumed: string[];
|
|
96
105
|
};
|
|
97
106
|
export interface DeliveryReceipt {
|
|
98
|
-
state: DeliveryState | "runtime_hook_emitted" | "seat_was_idle" | "seat_woken";
|
|
107
|
+
state: DeliveryState | "runtime_hook_emitted" | "in_model_request" | "seat_was_idle" | "seat_woken" | "emit_failed" | "wake_not_submitted" | "left_provider_queue";
|
|
99
108
|
at?: string;
|
|
100
|
-
source: "connector" | "runtime_inbox" | "runtime_hook" | "claude_transcript" | "connector_clock" | "factory_runner";
|
|
109
|
+
source: "connector" | "runtime_inbox" | "runtime_hook" | "claude_transcript" | "pi_session" | "copilot_events" | "codex_rollout" | "connector_clock" | "factory_runner";
|
|
101
110
|
detail?: Record<string, unknown>;
|
|
102
111
|
}
|
|
103
112
|
export interface SteerDelivery {
|
|
104
113
|
state: DeliveryState;
|
|
105
114
|
route: string;
|
|
115
|
+
provider?: string;
|
|
106
116
|
session_id?: string;
|
|
107
117
|
receipts: DeliveryReceipt[];
|
|
108
118
|
/**
|
|
109
119
|
* While it waits, what will carry it: `next_tool_or_turn_end` for a working seat;
|
|
110
120
|
* `runner_wakes_idle_seat` for a seat already idle, which the factory runner's next pass prompts;
|
|
111
|
-
* `session_not_running` until a person resumes it, or it expires
|
|
121
|
+
* `session_not_running` until a person resumes it, or it expires;
|
|
122
|
+
* `provider_queue` once it sits in the provider's own queue, which drains at its next continuation.
|
|
112
123
|
*/
|
|
113
|
-
continuation?: "next_tool_or_turn_end" | "runner_wakes_idle_seat" | "session_not_running";
|
|
124
|
+
continuation?: "next_tool_or_turn_end" | "runner_wakes_idle_seat" | "session_not_running" | "provider_queue";
|
|
125
|
+
/** It has waited longer than this route should take, or its door refused it: still on its way, and not on time. */
|
|
126
|
+
overdue?: boolean;
|
|
114
127
|
/** What the agent did after it received it, from its transcript. Whether that follows the correction is a person's judgment unless the steer named what to look for. */
|
|
115
128
|
next_actions?: {
|
|
116
129
|
at?: string;
|
|
@@ -145,6 +158,8 @@ interface TranscriptEvidence {
|
|
|
145
158
|
* results and the agent's quotes of the id do not count as delivery.
|
|
146
159
|
*/
|
|
147
160
|
export declare function readTranscriptEvidence(path: string, offset: number, steer: string): TranscriptEvidence;
|
|
161
|
+
/** What a provider other than Claude Code recorded about this steer, by the same rule as readTranscriptEvidence. */
|
|
162
|
+
export declare function readAgentEvidence(provider: SteerableProvider, path: string, offset: number, steer: string): TranscriptEvidence;
|
|
148
163
|
/** Whether a prompt typed into the bound pane reached the session: Claude Code's own user or queued-prompt record. A pane echo proves nothing. */
|
|
149
164
|
export declare function typedLineInTranscript(path: string, offset: number, instruction: string): {
|
|
150
165
|
at?: string;
|
|
@@ -179,4 +194,3 @@ export declare function settlementOf(deps: RuntimeDeps, record: {
|
|
|
179
194
|
message: string;
|
|
180
195
|
at?: string;
|
|
181
196
|
} | null;
|
|
182
|
-
export {};
|