relay-opencode 0.0.0-stage → 0.2.0

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 (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -2
  3. package/dist/artificial-analysis.d.ts +50 -0
  4. package/dist/artificial-analysis.js +153 -0
  5. package/dist/chat-facts.d.ts +26 -0
  6. package/dist/chat-facts.js +96 -0
  7. package/dist/contract.d.ts +2727 -0
  8. package/dist/contract.js +111 -0
  9. package/dist/costs.d.ts +14 -0
  10. package/dist/costs.js +47 -0
  11. package/dist/decider.d.ts +73 -0
  12. package/dist/decider.js +199 -0
  13. package/dist/gui-experimental.cjs +92 -0
  14. package/dist/gui-styles.d.ts +5 -0
  15. package/dist/gui-styles.js +95 -0
  16. package/dist/index.d.ts +6 -0
  17. package/dist/index.js +62 -0
  18. package/dist/intelligence.d.ts +38 -0
  19. package/dist/intelligence.js +123 -0
  20. package/dist/inventory.d.ts +34 -0
  21. package/dist/inventory.js +28 -0
  22. package/dist/ranking.d.ts +31 -0
  23. package/dist/ranking.js +78 -0
  24. package/dist/relay-auto.d.ts +39 -0
  25. package/dist/relay-auto.js +96 -0
  26. package/dist/relay-command.d.ts +74 -0
  27. package/dist/relay-command.js +211 -0
  28. package/dist/relay-store.d.ts +124 -0
  29. package/dist/relay-store.js +196 -0
  30. package/dist/relay-view.d.ts +124 -0
  31. package/dist/relay-view.js +189 -0
  32. package/dist/review-helper.d.ts +8 -0
  33. package/dist/review-helper.js +68 -0
  34. package/dist/router.d.ts +122 -0
  35. package/dist/router.js +209 -0
  36. package/dist/rpc.d.ts +2725 -0
  37. package/dist/rpc.js +116 -0
  38. package/dist/settings.d.ts +16 -0
  39. package/dist/settings.js +22 -0
  40. package/dist/standings.d.ts +18 -0
  41. package/dist/standings.js +34 -0
  42. package/dist/tui.d.ts +3 -0
  43. package/dist/tui.js +26 -0
  44. package/dist/usage-log.d.ts +135 -0
  45. package/dist/usage-log.js +210 -0
  46. package/dist/usage-view.d.ts +70 -0
  47. package/dist/usage-view.js +104 -0
  48. package/package.json +46 -4
@@ -0,0 +1,92 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("solid-js/web"),n=require("solid-js"),Xe=require("@opencode/plugin/gui"),ir=require("@opencode/plugin/rpc"),_t={type:"object",properties:{providerID:{type:"string"},id:{type:"string"},variant:{anyOf:[{type:"string"},{type:"null"}]}},required:["providerID","id","variant"],additionalProperties:!1},x={anyOf:[{type:"string"},{type:"null"}]},ft={inputPerMillion:x,outputPerMillion:x,cacheReadPerMillion:x,cacheWritePerMillion:x},yt=["inputPerMillion","outputPerMillion","cacheReadPerMillion","cacheWritePerMillion"],Gt={type:"object",properties:{providerID:{type:"string"},id:{type:"string"},name:{type:"string"},enabled:{type:"boolean"},status:{type:"string"},variants:{type:"array",items:{type:"string"}},capabilities:{type:"object",properties:{input:{type:"array",items:{type:"string"}},output:{type:"array",items:{type:"string"}},tools:{type:"boolean"}},required:["input","output","tools"],additionalProperties:!1},limit:{type:"object",properties:{context:{type:"number"},output:{type:"number"}},required:["context","output"],additionalProperties:!1},cost:{type:"object",properties:{...ft,tiered:{type:"boolean"},steps:{type:"array",items:{type:"object",properties:{above:{type:"number"},...ft},required:["above",...yt],additionalProperties:!1}}},required:[...yt,"tiered","steps"],additionalProperties:!1}},required:["providerID","id","name","enabled","status","variants","capabilities","limit","cost"],additionalProperties:!1},Ye={anyOf:[{type:"number"},{type:"null"}]},St={anyOf:[{type:"string",enum:["plan","execute","review"]},{type:"null"}]},Jt={anyOf:[_t,{type:"null"}]},st={type:"object",properties:{..._t.properties,useFor:{type:"string"}},required:["providerID","id","variant","useFor"],additionalProperties:!1},at={type:"object",properties:{..._t.properties,useFor:{type:"string"}},required:["providerID","id","variant"],additionalProperties:!1},lr={type:"object",properties:{plan:{type:"array",items:st},execute:{type:"array",items:st},review:{type:"array",items:st}},required:["plan","execute","review"],additionalProperties:!1},sr={type:"object",properties:{plan:{type:"array",items:at},execute:{type:"array",items:at},review:{type:"array",items:at}},required:["plan","execute","review"],additionalProperties:!1},kt={anyOf:[{type:"string",enum:["opencode","artificial-analysis"]},{type:"null"}]},Yt={type:"object",properties:ft,required:[...yt],additionalProperties:!1},ar={type:"object",properties:{input:{type:"number"},output:{type:"number"},reasoning:{type:"number"},cacheRead:{type:"number"},cacheWrite:{type:"number"},costUsd:x},required:["input","output","reasoning","cacheRead","cacheWrite","costUsd"],additionalProperties:!1},or={type:"object",properties:{requests:{type:"number"},fresh:{type:"number"},cached:{type:"number"},costUsd:x,seconds:Ye,model:x,total:{anyOf:[ar,{type:"null"}]},prices:{anyOf:[Yt,{type:"null"}]},pricesFrom:kt},required:["requests","fresh","cached","costUsd","seconds","model","total","prices","pricesFrom"],additionalProperties:!1},Zt={type:"object",properties:{model:{type:"string"},messages:{type:"number"},requests:{type:"number"},input:{type:"number"},output:{type:"number"},reasoning:{type:"number"},cacheRead:{type:"number"},cacheWrite:{type:"number"},openCodeUsd:x,byPrice:{type:"object",properties:{input:x,output:x,cacheRead:x,cacheWrite:x},required:["input","output","cacheRead","cacheWrite"],additionalProperties:!1},prices:{anyOf:[Yt,{type:"null"}]},pricesFrom:kt},required:["model","messages","requests","input","output","reasoning","cacheRead","cacheWrite","openCodeUsd","byPrice","prices","pricesFrom"],additionalProperties:!1},vt={type:"object",properties:{at:{type:"string"},sessionID:{type:"string"},kind:{type:"string",enum:["chat","helper"]},mode:St,confidence:Ye,fit:Ye,model:x,ms:{type:"number"},costUsd:x,note:x,messageID:x,reply:{anyOf:[or,{type:"null"}]}},required:["at","sessionID","kind","mode","confidence","fit","model","ms","costUsd","note","messageID","reply"],additionalProperties:!1},Pt={type:"object",properties:{directory:{type:"string"},settings:{type:"object",properties:{revision:{type:"integer",minimum:0},modes:lr,decider:Jt},required:["revision","modes","decider"],additionalProperties:!1},decisions:{type:"array",items:vt},deciders:{type:"array",items:Gt},checks:{type:"object",properties:{active:{type:"boolean"},note:x},required:["active","note"],additionalProperties:!1},priceKey:{type:"boolean"}},required:["directory","settings","decisions","deciders","checks","priceKey"],additionalProperties:!1},Se={rejected:{type:"object",properties:{},additionalProperties:!1}},Ge={type:"object",properties:{},additionalProperties:!1},cr={type:"object",properties:{at:{type:"string"},sessionID:{type:"string"},messageID:{type:"string"},project:{type:"string"},kind:{type:"string",enum:["chat","helper","summary"]},agent:x,model:x,requests:{type:"number"},input:{type:"number"},output:{type:"number"},reasoning:{type:"number"},cacheRead:{type:"number"},cacheWrite:{type:"number"},costByPrice:x,openCodeUsd:x,pricesFrom:kt,relay:{anyOf:[{type:"object",properties:{mode:St,note:x},required:["mode","note"],additionalProperties:!1},{type:"null"}]}},required:["at","sessionID","messageID","project","kind","agent","model","requests","input","output","reasoning","cacheRead","cacheWrite","costByPrice","openCodeUsd","pricesFrom","relay"],additionalProperties:!1},dr={type:"object",properties:{model:{type:"string"},replies:{type:"number"},requests:{type:"number"},input:{type:"number"},output:{type:"number"},reasoning:{type:"number"},cacheRead:{type:"number"},cacheWrite:{type:"number"},cost:x,aaPriced:{type:"boolean"},unpriced:{type:"number"}},required:["model","replies","requests","input","output","reasoning","cacheRead","cacheWrite","cost","aaPriced","unpriced"],additionalProperties:!1},ur={type:"object",properties:{from:{type:"string"},to:{type:"string"},tzOffsetMinutes:{type:"integer",minimum:-840,maximum:840},timeZone:{anyOf:[{type:"string",maxLength:64},{type:"null"}]},search:{type:"string",maxLength:200},provider:x,effort:x,mode:x,relay:{type:"string",enum:["any","on","off"]},kind:{type:"string",enum:["any","chat","helper","summary"]},project:x,offset:{type:"integer",minimum:0},limit:{type:"integer",minimum:1,maximum:200}},required:["from","to","tzOffsetMinutes","search","provider","effort","mode","relay","kind","project","offset","limit"],additionalProperties:!1},Qe={type:"array",items:{type:"string"}},pr={type:"object",properties:{day:{type:"string"},models:{type:"array",items:{type:"object",properties:{model:{type:"string"},cost:x,tokens:{type:"number"},requests:{type:"number"}},required:["model","cost","tokens","requests"],additionalProperties:!1}}},required:["day","models"],additionalProperties:!1},hr={type:"object",properties:{directory:{type:"string"},days:{type:"array",items:pr},totals:{type:"array",items:dr},options:{type:"object",properties:{providers:Qe,efforts:Qe,modes:Qe,projects:Qe},required:["providers","efforts","modes","projects"],additionalProperties:!1},records:{type:"array",items:cr},matching:{type:"number"},first:x,before:{type:"object",properties:{since:x,rows:{type:"array",items:Zt}},required:["since","rows"],additionalProperties:!1},credit:x,removed:{type:"number"}},required:["directory","days","totals","options","records","matching","first","before","credit","removed"],additionalProperties:!1},ot={anyOf:[{type:"null"},{type:"object",properties:{kind:{type:"string",enum:["unranked"]},reason:{type:"string"}},required:["kind","reason"],additionalProperties:!1},{type:"object",properties:{kind:{type:"string",enum:["ranked"]},strongest:{type:"string"},cheapest:{type:"string"}},required:["kind","strongest","cheapest"],additionalProperties:!1}]},bt=ir.Rpc.define({id:"relay-opencode",events:{},methods:{getRelay:{errors:Se,input:Ge,output:Pt},saveRelay:{errors:Se,input:{type:"object",properties:{revision:{type:"integer",minimum:0},modes:sr,decider:Jt},required:["revision","modes","decider"],additionalProperties:!1},output:Pt},getRelayChat:{errors:Se,input:{type:"object",properties:{sessionID:{type:"string"}},required:["sessionID"],additionalProperties:!1},output:{type:"object",properties:{on:{type:"boolean"},last:{anyOf:[vt,{type:"null"}]},decider:{type:"boolean"}},required:["on","last","decider"],additionalProperties:!1}},getRelayDecisions:{errors:Se,input:Ge,output:{type:"object",properties:{directory:{type:"string"},decisions:{type:"array",items:vt}},required:["directory","decisions"],additionalProperties:!1}},setRelayChat:{errors:Se,input:{type:"object",properties:{sessionID:{type:"string"},on:{type:"boolean"}},required:["sessionID","on"],additionalProperties:!1},output:{type:"object",properties:{on:{type:"boolean"}},required:["on"],additionalProperties:!1}},testDecider:{errors:Se,input:{type:"object",properties:{text:{type:"string"}},required:["text"],additionalProperties:!1},output:{type:"object",properties:{directory:{type:"string"},mode:St,confidence:Ye,model:x,fit:Ye,ms:{type:"number"},costUsd:x,note:x},required:["directory","mode","confidence","model","fit","ms","costUsd","note"],additionalProperties:!1}},getRelayUsage:{errors:Se,input:Ge,output:{type:"object",properties:{directory:{type:"string"},since:x,rows:{type:"array",items:Zt},credit:x},required:["directory","since","rows","credit"],additionalProperties:!1}},getUsageLog:{errors:Se,input:ur,output:hr},getOwnChoice:{errors:Se,input:Ge,output:{type:"object",properties:{directory:{type:"string"},modes:{type:"object",properties:{plan:ot,execute:ot,review:ot},required:["plan","execute","review"],additionalProperties:!1}},required:["directory","modes"],additionalProperties:!1}},setPriceKey:{errors:Se,input:{type:"object",properties:{key:x},required:["key"],additionalProperties:!1},output:{type:"object",properties:{saved:{type:"boolean"},note:x},required:["saved","note"],additionalProperties:!1}},listModels:{errors:Se,input:Ge,output:{type:"object",properties:{directory:{type:"string"},models:{type:"array",items:Gt}},required:["directory","models"],additionalProperties:!1}},listIntelligence:{errors:Se,input:Ge,output:{type:"object",properties:{directory:{type:"string"},source:{type:"string"},fetchedAt:x,note:x,scores:{type:"array",items:{type:"object",properties:{providerID:{type:"string"},id:{type:"string"},index:{type:"number"},matched:{type:"string"}},required:["providerID","id","index","matched"],additionalProperties:!1}}},required:["directory","source","fetchedAt","note","scores"],additionalProperties:!1}}}});function ct(t,r){const l=t.find(s=>s.providerID===r.providerID&&s.id===r.id);return l&&l.enabled&&l.status!=="deprecated"&&(r.variant===null||l.variants.includes(r.variant))?l:void 0}const $t=1000000000000n;function Pe(t){if(!/^(?:0|[1-9]\d*)(?:\.\d{1,12})?$/.test(t))throw new Error("Invalid USD amount");const[r,l=""]=t.split(".");return BigInt(r)*$t+BigInt(l.padEnd(12,"0"))}function gr(t){if(typeof t!="string")return null;try{return Pe(t),t}catch{return null}}function mr(t,r){const l=gr(r);return l===null?null:BigInt(Math.max(0,Math.round(t)))*Pe(l)/1000000n}function lt(t){const r=t/$t,l=(t%$t).toString().padStart(12,"0").replace(/0+$/,"");return l?`${r}.${l}`:`${r}`}Promise.resolve();const fr=200,yr=t=>`${t.providerID}/${t.id}${t.variant===null?"":`#${t.variant}`}`;function Je(t,r){const l=typeof t=="string"?t:t&&typeof t=="object"&&typeof t.message=="string"?t.message:"";return l.trim()?l:r}const vr=["When you review work in this chat, follow these rules.","1. Report a blocking finding only when you have concrete evidence of a defect or of an unmet requirement. Everything else is an advisory note, and a note never calls for another round.",'2. End every review with a verdict: "approve" or "request changes". Approve when no blocking finding remains.',"3. When you check work again after a fix, look only at whether the earlier blocking findings are fixed and whether the fix broke something. Do not start a new full review.","4. One piece of work gets at most three checks. After the third, stop and list what is still open so the person can decide."].join(`
2
+ `),br={plan:"Plan",execute:"Execute",review:"Review"},Ue=t=>br[t],$r=4e3,xr=1500,wr=1500,_r=10,nt=t=>t===null?"not listed":`$${t}`;function Rt(t){const{inputPerMillion:r,outputPerMillion:l}=t;return r===null&&l===null?"price not listed":r==="0"&&l==="0"?"$0 or not listed":`${nt(r)} in / ${nt(l)} out per 1M tokens${t.tiered?" (base tier)":""}`}const Ve=t=>{if(t===null)return null;try{return Pe(t)}catch{return null}},Mt=(t,r)=>t===r?0:t===null?1:r===null||t<r?-1:1;function Sr(t,r){return Mt(Ve(t.cost.inputPerMillion),Ve(r.cost.inputPerMillion))||Mt(Ve(t.cost.outputPerMillion),Ve(r.cost.outputPerMillion))||t.name.localeCompare(r.name)}function kr(t){const{inputPerMillion:r,outputPerMillion:l}=t;return r===null&&l===null?"not listed":r==="0"&&l==="0"?"$0 or not listed":`${nt(r)} / ${nt(l)}${t.tiered?" (base tier)":""}`}function Cr(t){if(!(t>0))return"—";if(t<1e3)return String(t);const r=Math.round(t/1e3);return r<1e3?`${r}K`:`${+(t/1e6).toFixed(1)}M`}const Qt=t=>t==null?"—":String(Math.round(t*10)/10),Pr={provider:(t,r)=>t.providerID.localeCompare(r.providerID)||t.name.localeCompare(r.name),price:Sr,context:(t,r)=>r.limit.context-t.limit.context||t.name.localeCompare(r.name),index:(t,r)=>(r.index??-1)-(t.index??-1)||t.name.localeCompare(r.name)};function Rr(t,r){const l=r.query.toLowerCase().split(/\s+/).filter(Boolean);return t.filter(s=>(!r.provider||s.providerID===r.provider)&&l.every(d=>`${s.providerID} ${s.id} ${s.name}`.toLowerCase().includes(d))).sort(Pr[r.order])}function It(t,r){return[null,...r.variants].find(l=>!t.some(s=>s.providerID===r.providerID&&s.id===r.id&&s.variant===l))}const Dt=t=>`${Math.round(t*100)}%`,Vt=(t,r)=>[Ue(t.mode),r,...t.confidence===null?[]:[`${Dt(t.confidence)} sure`],...t.fit===null?[]:[`line fit ${Dt(t.fit)}`],`${Math.round(t.ms)} ms`].join(", "),it=(t,r)=>`${t}${r===null?"":` (${r})`}.`,er=t=>{const{mode:r,model:l}=t;return r!==null&&l!==null?Vt({...t,mode:r},l):t.kind==="helper"?"left as it was":"nothing switched"};function tr(t){return t?it(`Last choice${t.kind==="helper"?" (a helper)":""}: ${er(t)}`,t.note):"No /relay message yet."}const ge=t=>Math.round(t).toLocaleString("en-US"),At=t=>t===null||t==="0"?[]:[`$${t}`],Mr=t=>(t.inputPerMillion??"0")==="0"&&(t.outputPerMillion??"0")==="0"?" Price: $0 or not listed.":` Prices for a million tokens: ${[[t.inputPerMillion,"in"],[t.outputPerMillion,"out"],[t.cacheReadPerMillion,"cache read"],[t.cacheWritePerMillion,"cache write"]].flatMap(([r,l])=>r===null?[]:[`$${r} ${l}`]).join(", ")}.`,Ir=t=>{if(!t)return"";const{total:r,requests:l}=t;return`${r===null?` Requests in the reply: ${l}.`:` Reply${t.model===null?"":` from ${t.model}`}: ${[`${l} request${l===1?"":"s"}`,`${ge(r.input)} tokens in`,`${ge(r.output)} out`,...r.reasoning>0?[`${ge(r.reasoning)} reasoning`]:[],`${ge(r.cacheRead)} read from cache`,`${ge(r.cacheWrite)} written to cache`,...At(r.costUsd)].join(", ")}.`}${t.prices===null?"":Mr(t.prices)} First request: ${[`${ge(t.fresh)} tokens read new`,`${ge(t.cached)} from cache`,...At(t.costUsd),...t.seconds===null?[]:[`first word after ${t.seconds} s`]].join(", ")}.`},Dr=t=>`${it(`${t.kind==="helper"?"Helper":"Chat"}: ${er(t)}`,t.note)}${Ir(t.reply)}`,qt=[["input","in","inputPerMillion"],["output","out","outputPerMillion"],["cacheRead","cache read","cacheReadPerMillion"],["cacheWrite","cache write","cacheWritePerMillion"]];function Ar(t){const r=t.model.lastIndexOf("#"),l=qt.flatMap(([d])=>{const h=t.byPrice[d];return h===null?[]:[Pe(h)]}),s=l.length?qt.flatMap(([d,h,Z])=>{const B=d==="output"?`${ge(t.output)}${t.reasoning>0?` + ${ge(t.reasoning)} reasoning`:""}`:ge(t[d]),ee=t.byPrice[d],y=t.prices?.[Z]??null,W=d==="output"?t.output+t.reasoning:t[d];return ee!==null&&y!==null&&mr(W,y)===Pe(ee)?[`${h} ${B} x $${y} a million = $${ee}`]:ee!==null?[`${h} ${B}: $${ee} by each reply's own price${y===null?"":` (the last was $${y} a million)`}`]:W>0?[`${h} ${B}: no price listed`]:[]}):[];return{model:r<0?t.model:t.model.slice(0,r),effort:r<0?"-":t.model.slice(r+1),requests:ge(t.requests),input:ge(t.input),output:ge(t.output),cacheRead:ge(t.cacheRead),cacheWrite:ge(t.cacheWrite),cost:l.length?`$${lt(l.reduce((d,h)=>d+h,0n))}${t.pricesFrom==="artificial-analysis"?"*":""}`:"not listed",byPrice:[...s,...t.openCodeUsd!==null&&t.openCodeUsd!=="0"?[`OpenCode's own cost: $${t.openCodeUsd}`]:[]]}}function qr(t){const{mode:r}=t;return it(r===null?"No answer":`${Vt({...t,mode:r},t.model??"no model")}, cost ${t.costUsd===null?"not reported":`$${t.costUsd}`}`,t.note)}const jr="Several models: write a line for each and the decider follows your lines. Write none and Relay chooses by itself: the highest index for big, unclear or risky work, the cheapest for small, clear work. When it is not sure how big the work is, the highest index is used; when the decider gives no size, the first model in this list.";function Or(t,r){if(t?.kind!=="ranked")return null;const l=yr(r),s=t.strongest===l,d=t.cheapest===l;return s&&d?"Relay: all work (highest index and cheapest)":s?"Relay: big work (highest index)":d?"Relay: small work (cheapest)":null}const Tr=t=>t?.kind==="unranked"?`Relay can't rank this list: ${t.reason}. The first model is used.`:null,Lr=t=>`To choose, Relay sends to ${t??"the decider's provider"}: your message text (at most ${$r.toLocaleString("en-US")} characters), the end of the chat's last reply when it must choose between your models (at most ${xr.toLocaleString("en-US")} characters of its text, with your home folder as ~), the start of the chat's first message when Relay asks how big the work is (at most ${wr.toLocaleString("en-US")} characters, with your home folder as ~), the names and sizes of attached files (the first ${_r}), how many pictures are attached, whether the chat's agent can change files, and the lines you wrote above. Never the contents of files, pictures, the model's reasoning or tool output, other earlier messages, or model names, prices or scores. While a decider and a Review model are chosen, the task text of each helper that a model starts is sent the same way — written by the calling model, so it may itself quote code, files or earlier chat, and the person does not see it before it goes out.`;function Er(t){if(t.kind!=="chat"||t.model===null)return null;const r=t.model.indexOf("/");if(r<=0)return null;const l=t.model.slice(r+1),s=l.lastIndexOf("#"),d=s<0?l:l.slice(0,s),h=s<0?void 0:l.slice(s+1);return!d||h===""?null:{providerID:t.model.slice(0,r),modelID:d,...h===void 0?{}:{variant:h}}}const Fr="No decider chosen. Until you choose one below, /relay and Relay on send every message to the chat's current model without switching.";function Ur(t){const{on:r,last:l,decider:s}=t,d=l!==null&&l.model===null,h=r&&!s;return{label:r?s?"Relay on":"Relay on · no decider":"Relay off",...h?{icon:"circle-exclamation"}:{},tone:h?"warning":r?"success":void 0,rows:[{id:"toggle",label:r?"Turn Relay off for this chat":"Turn Relay on for this chat"},...s?[]:[{id:"decider",label:"No decider chosen, so Relay switches nothing. Open Relay to choose one.",tone:"warning"}],{id:"last",label:l===null?"No choice in this chat yet.":tr(l),...d?{tone:"warning"}:{}}]}}const Nr="To send every message in one chat through Relay, type /relay on in that chat or use the Relay pill above its chat box; /relay off turns it off. In the terminal app, /relay on and /relay off work the same way, without the pill.",Wr=t=>t.active?"Helpers that check work start on a Review model.":`Helpers that check work keep the chat's model: ${t.note??"not set up"}.`,jt=`
3
+ .rl{--rl-fg:var(--text-base,#2b2f36);--rl-strong:var(--text-strong,#14171c);--rl-weak:var(--text-weak,#6e7681);--rl-bg:var(--background-base,#fff);
4
+ --rl-card:var(--surface-raised-base,rgba(127,127,127,.07));--rl-inset:var(--surface-inset-base,rgba(127,127,127,.11));--rl-hover:var(--surface-base-hover,rgba(127,127,127,.15));
5
+ --rl-line:var(--border-weak-base,rgba(127,127,127,.22));--rl-line2:var(--border-base,rgba(127,127,127,.38));--rl-accent:var(--text-interactive-base,#4f7cff);
6
+ --rl-ok:var(--icon-success-base,#2ea36a);--rl-warn:var(--icon-warning-base,#d99a1c);--rl-bad:var(--icon-critical-base,#d9483b);--rl-wait:#8a7cf0;
7
+ display:flex;flex-direction:column;height:100%;min-height:0;color:var(--rl-fg);font-size:13px;line-height:1.4}
8
+ .rl *{box-sizing:border-box}
9
+ .rl h2,.rl h3,.rl p{margin:0}
10
+ .rl-top{display:grid;gap:10px;padding:14px 14px 0;flex:none}
11
+ .rl-brand{display:flex;align-items:center;gap:8px;min-width:0}
12
+ .rl-logo{flex:none;width:22px;height:22px;border-radius:7px;display:grid;place-items:center;color:#fff;font-size:12px;font-weight:700;background:linear-gradient(135deg,var(--rl-accent),#9b6bff)}
13
+ .rl-name{font-size:15px;font-weight:650;color:var(--rl-strong)}
14
+ .rl-tag{margin-left:auto;color:var(--rl-weak);font-size:11px;white-space:nowrap}
15
+ .rl-body{flex:1;min-height:0;overflow:auto;display:grid;grid-template-columns:minmax(0,1fr);grid-auto-rows:max-content;gap:12px;align-content:start;padding:12px 14px 18px}
16
+ .rl-card{display:grid;grid-template-columns:minmax(0,1fr);gap:10px;padding:12px;border:1px solid var(--rl-line);border-radius:12px;background:var(--rl-card)}
17
+ .rl-row{display:flex;align-items:center;justify-content:space-between;gap:8px;min-width:0}
18
+ .rl-inline{display:flex;align-items:center;gap:6px}
19
+ .rl-inline .rl-in{flex:1;min-width:0}
20
+ .rl-hint{margin:0;color:var(--rl-weak);font-size:11.5px;overflow-wrap:anywhere}
21
+ .rl-in{width:100%;min-width:0;padding:7px 9px;border:1px solid var(--rl-line);border-radius:8px;background:var(--rl-inset);color:var(--rl-strong);font:inherit;outline:none}
22
+ .rl-in:focus{border-color:var(--rl-accent);box-shadow:0 0 0 3px color-mix(in srgb,var(--rl-accent) 22%,transparent)}
23
+ .rl-in:disabled{opacity:.55}
24
+ .rl-btn{appearance:none;padding:6px 12px;border:1px solid var(--rl-line2);border-radius:8px;background:transparent;color:var(--rl-fg);font:inherit;font-weight:550;cursor:pointer;white-space:nowrap}
25
+ .rl-btn:hover:not(:disabled){background:var(--rl-hover)}
26
+ .rl-btn:disabled{opacity:.5;cursor:default}
27
+ .rl-btn.sm{padding:3px 9px;font-size:12px}
28
+ .rl button:focus-visible,.rl summary:focus-visible,.rl input:focus-visible,.rl select:focus-visible{outline:2px solid var(--rl-accent);outline-offset:2px}
29
+ .rl-note{--c:var(--rl-accent);display:grid;grid-template-columns:minmax(0,1fr);gap:2px;padding:8px 10px;border:1px solid color-mix(in srgb,var(--c) 32%,transparent);border-radius:10px;background:color-mix(in srgb,var(--c) 11%,transparent);font-size:12px;overflow-wrap:anywhere}
30
+ .rl-note.n-bad{--c:var(--rl-bad)}.rl-note.n-warn{--c:var(--rl-warn)}.rl-note.n-ok{--c:var(--rl-ok)}
31
+ .rl-pre{margin:6px 0 0;padding:8px;max-height:220px;overflow:auto;border-radius:8px;background:var(--rl-inset);font-size:11px;white-space:pre-wrap;overflow-wrap:anywhere}
32
+ .rl-acc{border:1px solid var(--rl-line);border-radius:12px;background:var(--rl-card)}
33
+ .rl-acc>summary{display:flex;align-items:center;gap:8px;padding:10px 12px;border-radius:11px;color:var(--rl-strong);font-weight:600;cursor:pointer;list-style:none}
34
+ .rl-acc>summary::-webkit-details-marker{display:none}
35
+ .rl-acc>summary::after{content:"\\203A";margin-left:auto;color:var(--rl-weak);transition:transform .15s}
36
+ .rl-acc[open]>summary::after{transform:rotate(90deg)}
37
+ .rl-acc[open]>summary{border-radius:11px 11px 0 0}
38
+ .rl-acc>summary:hover{background:var(--rl-hover)}
39
+ .rl-sub{margin-left:2px;color:var(--rl-weak);font-size:11px;font-weight:400;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
40
+ .rl-acc-body{display:grid;grid-template-columns:minmax(0,1fr);gap:10px;padding:4px 12px 12px}
41
+ .rl-pick{display:grid;grid-template-columns:minmax(0,1fr);gap:4px}
42
+ .rl-pick .rl-chip{justify-self:start}
43
+ .rl-chip{display:inline-flex;align-items:center;gap:6px;max-width:100%;padding:3px 4px 3px 10px;border:1px solid var(--rl-line);border-radius:99px;background:var(--rl-inset);font-size:12px}
44
+ .rl-chip.bad{border-color:color-mix(in srgb,var(--rl-bad) 50%,transparent)}
45
+ .rl-chip-t{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
46
+ .rl-chip small{color:var(--rl-bad)}
47
+ .rl-x{appearance:none;flex:none;width:18px;height:18px;padding:0;border:0;border-radius:50%;background:transparent;color:var(--rl-weak);font:inherit;line-height:1;cursor:pointer}
48
+ .rl-x:hover:not(:disabled){background:var(--rl-hover);color:var(--rl-strong)}
49
+ .rl-role{display:block;color:var(--rl-strong);font-weight:650}
50
+ .rl .rl-plain{margin:0;padding:0;list-style:none;display:grid;gap:6px}
51
+ .rl-add{justify-self:start}
52
+ .rl-inline .rl-effort{flex:none;width:auto;padding:3px 6px;font-size:12px}
53
+ .rl-picker{display:grid;grid-template-columns:minmax(0,1fr);gap:6px}
54
+ .rl-table-wrap{max-height:320px;overflow:auto;border:1px solid var(--rl-line);border-radius:8px;background:var(--rl-bg)}
55
+ .rl-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:fixed}
56
+ .rl-table th:nth-child(2){width:74px}.rl-table th:nth-child(3){width:46px;text-align:right;white-space:nowrap}.rl-table th:nth-child(4){width:42px;text-align:right;white-space:nowrap}.rl-table th:nth-child(5){width:46px}
57
+ .rl-table th{position:sticky;top:0;z-index:1;padding:5px 4px;border-bottom:1px solid var(--rl-line2);background:var(--rl-bg);color:var(--rl-weak);font-size:11px;font-weight:600;text-align:left;vertical-align:bottom}
58
+ .rl-table td{padding:5px 4px;border-top:1px solid var(--rl-line);vertical-align:middle;overflow-wrap:anywhere}
59
+ .rl-table tbody tr:first-child td{border-top:0}
60
+ .rl-table tbody tr:hover{background:var(--rl-hover)}
61
+ .rl-table td:nth-child(3),.rl-table td:nth-child(4){text-align:right;white-space:nowrap}
62
+ .rl-table td:last-child{text-align:right}
63
+ .rl-table small{display:block;color:var(--rl-weak);font-size:11px;font-weight:400}
64
+ .rl-t-name{color:var(--rl-strong);font-weight:550}
65
+ .rl-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
66
+ .rl-seg{display:flex;flex-wrap:wrap;gap:4px;align-items:center}
67
+ .rl-seg .rl-btn[aria-pressed=true]{background:var(--rl-inset);border-color:var(--rl-accent);color:var(--rl-strong)}
68
+ .rl-right{margin-left:auto}
69
+ .rl-filters{display:grid;grid-template-columns:repeat(auto-fill,minmax(118px,1fr));gap:6px}
70
+ .rl-chart{display:block;width:100%;height:110px}
71
+ .rl-chart g:hover rect[fill=transparent]{fill:var(--rl-hover)}
72
+ .rl-legend{display:flex;flex-wrap:wrap;gap:4px 10px;color:var(--rl-weak);font-size:11px}
73
+ .rl-dot{display:inline-block;width:8px;height:8px;border-radius:2px;margin-right:4px;vertical-align:baseline}
74
+ .rl-u-tiles{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
75
+ .rl-u-tile{display:grid;gap:1px;align-content:start;min-width:0;padding:10px 12px;border:1px solid var(--rl-line);border-radius:12px;background:var(--rl-card)}
76
+ .rl-u-big{color:var(--rl-strong);font-size:22px;font-weight:700;line-height:1.2;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}
77
+ .rl-u-plot{position:relative;padding-top:16px;border:1px solid var(--rl-line);border-radius:8px;background:var(--rl-bg);overflow:hidden}
78
+ .rl-u-scale{position:absolute;top:2px;left:6px;color:var(--rl-weak);font-size:10.5px;font-variant-numeric:tabular-nums}
79
+ .rl-u-empty{position:absolute;inset:0;display:grid;place-items:center;padding:0 12px;color:var(--rl-weak);font-size:11.5px;text-align:center}
80
+ .rl-u-days{display:grid;margin-top:3px;color:var(--rl-weak);font-size:10px;text-align:center;white-space:nowrap}
81
+ .rl .rl-u-list{margin:0;padding:0;list-style:none;border:1px solid var(--rl-line);border-radius:10px;background:var(--rl-bg);overflow:hidden}
82
+ .rl-u-list>li+li{border-top:1px solid var(--rl-line)}
83
+ .rl-u-item{display:grid;gap:1px;width:100%;min-width:0;padding:7px 10px;border:0;background:none;color:inherit;font:inherit;text-align:left}
84
+ button.rl-u-item{cursor:pointer}
85
+ button.rl-u-item:hover{background:var(--rl-hover)}
86
+ .rl-u-line{display:flex;align-items:baseline;gap:8px;min-width:0}
87
+ .rl-u-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--rl-strong);font-weight:550}
88
+ .rl-u-money{flex:none;margin-left:auto;color:var(--rl-strong);font-weight:650;font-variant-numeric:tabular-nums}
89
+ .rl-u-when{flex:none;color:var(--rl-weak);font-size:11.5px;font-variant-numeric:tabular-nums}
90
+ .rl-u-small{color:var(--rl-weak);font-size:11.5px;overflow-wrap:anywhere}
91
+ .rl-u-badge{padding:0 7px;border-radius:99px;background:var(--rl-inset);color:var(--rl-strong);font-size:11px;font-weight:600}
92
+ `,zr=[{id:"today",label:"Today"},{id:"7d",label:"7 days"},{id:"30d",label:"30 days"},{id:"90d",label:"90 days"}],Br={today:0,"7d":6,"30d":29,"90d":89};function Kr(t,r){return{from:new Date(r.getFullYear(),r.getMonth(),r.getDate()-Br[t]).toISOString(),to:r.toISOString(),tzOffsetMinutes:-r.getTimezoneOffset(),timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone}}const rr=50,Hr=200,Xr=t=>Math.min(Hr,Math.max(rr,t));function Gr(t){return t.costByPrice!==null?t.costByPrice:t.openCodeUsd!==null&&Pe(t.openCodeUsd)>0n?t.openCodeUsd:null}const Ot=t=>Math.round(t).toLocaleString("en-US"),xt=Pe("1"),Tt=xt/10n;function Ze(t){if(t===null)return"no price";const r=Pe(t);if(r===0n)return"$0";if(r<Tt){const s=Math.min(12,14-r.toString().length),d=10n**BigInt(12-s),h=(r+d/2n)/d;if(h*d<Tt)return`$0.${h.toString().padStart(s,"0").replace(/0+$/,"").padEnd(2,"0")}`}const l=(r+xt/200n)/(xt/100n);return`$${(l/100n).toLocaleString("en-US")}.${(l%100n).toString().padStart(2,"0")}`}const Jr=new Intl.NumberFormat("en-US",{notation:"compact",maximumFractionDigits:1}),je=t=>Jr.format(Math.round(t)),Yr=(t,r)=>t==="cost"?Ze(lt(BigInt(Math.round(r))*1000000n)):je(r),Zr=["Su","Mo","Tu","We","Th","Fr","Sa"],Qr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Vr(t){const r=s=>new Date(`${s}T12:00:00Z`);if(t.length<=10)return t.map(s=>`${Zr[r(s).getUTCDay()]} ${r(s).getUTCDate()}`);const l=new Set([0,Math.floor(t.length/2),t.length-1]);return t.map((s,d)=>l.has(d)?`${r(s).getUTCDate()} ${Qr[r(s).getUTCMonth()]}`:"")}const nr=t=>t.slice(t.indexOf("/")+1);function en(t){const r=t.model.indexOf("/"),l=r<0?"":t.model.slice(0,r),s=je(t.input+t.output+t.reasoning+t.cacheRead+t.cacheWrite);return{name:nr(t.model),provider:l,cost:`${Ze(t.cost)}${t.cost!==null&&t.aaPriced?"*":""}`,tokens:s,detail:[l,`${Ot(t.replies)} ${t.replies===1?"reply":"replies"}`,`${s} tokens`,t.cost!==null&&t.unpriced?`${Ot(t.unpriced)} without a price`:""].filter(Boolean).join(" · ")}}const dt=[{id:"cost",label:"Cost"},{id:"tokens",label:"Tokens"},{id:"requests",label:"Requests"}],Lt=["#4f7cff","#2ea36a","#d99a1c","#9b6bff","#e05a8a"],ut="#8b949e",tn=t=>t===null?0:Number(Pe(t)/1000000n),pt=(t,r)=>t==="cost"?tn(r.cost):t==="tokens"?r.tokens:r.requests,Et=(t,r)=>{if(t==="cost"){const l=r.flatMap(s=>s.cost===null?[]:[Pe(s.cost)]);return l.length?Ze(lt(l.reduce((s,d)=>s+d,0n))):"no price"}return t==="tokens"?`${je(r.reduce((l,s)=>l+s.tokens,0))} tokens`:`${je(r.reduce((l,s)=>l+s.requests,0))} requests`};function rn(t,r,l=5){const s=new Map;for(const y of t)for(const W of y.models)s.set(W.model,(s.get(W.model)??0)+pt(r,W));const d=[...s].sort((y,W)=>W[1]-y[1]||(y[0]<W[0]?-1:1)).map(([y])=>y),h=d.slice(0,l),Z=d.length>l,B=y=>h.includes(y)?Lt[h.indexOf(y)%Lt.length]:ut,ee=t.map(y=>{const W=h.flatMap(b=>{const _=y.models.find(C=>C.model===b);return _?[{model:b,value:pt(r,_),color:B(b)}]:[]}),se=y.models.filter(b=>!h.includes(b.model));se.length&&W.push({model:"other",value:se.reduce((b,_)=>b+pt(r,_),0),color:ut});const c=[...h.flatMap(b=>{const _=y.models.find(C=>C.model===b);return _?[`${b} ${Et(r,[_])}`]:[]}),...se.length?[`other ${Et(r,se)}`]:[]];return{day:y.day,total:W.reduce((b,_)=>b+_.value,0),title:`${y.day}: ${c.length?c.join(", "):"no use"}`,parts:W}});return{bars:ee,legend:[...h.map(y=>({model:y,color:B(y)})),...Z?[{model:"other",color:ut}]:[]],max:ee.reduce((y,W)=>Math.max(y,W.total),0)}}function nn(t){const r=Gr(t),l=t.project.split(/[\\/]/).filter(Boolean).at(-1)??t.project,s=t.model??"unknown model",d=s.includes("/")?s.slice(0,s.indexOf("/")):"",h=t.relay?.mode??t.agent??"",Z=t.relay?t.relay.note?`Relay: ${t.relay.note}`:"Relay on":"Relay off",B=`${je(t.input+t.cacheRead+t.cacheWrite)} in · ${je(t.output+t.reasoning)} out`;return{time:new Date(t.at).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),model:s,name:t.model?nr(t.model):s,cost:r===null?"no price":`${Ze(r)}${t.costByPrice!==null&&t.pricesFrom==="artificial-analysis"?"*":""}`,detail:[d,`${t.kind} ${t.sessionID.slice(-6)}`,h,B,l,Z].filter(Boolean).join(" · ")}}function ln(t,r){const l=d=>`${d.sessionID}/${d.messageID}`,s=new Set(t.map(l));return[...t,...r.filter(d=>!s.has(l(d)))]}var sn=e.template("<select class=rl-in><option value>"),wt=e.template("<option>"),an=e.template('<div class="rl-note n-warn"><div class=rl-row><span>Filtered</span><button type=button class="rl-btn sm">Clear'),on=e.template('<div class="rl-note n-bad"role=alert>'),cn=e.template('<section class=rl aria-label="Relay usage"><style></style><header class=rl-top><div class=rl-brand><span class=rl-logo aria-hidden=true>R</span><h2 class=rl-name>Relay usage</h2><button type=button class="rl-btn sm rl-right"></button></div></header><div class=rl-body><div class=rl-seg role=group aria-label="Time range">'),Ft=e.template('<button type=button class="rl-btn sm">'),Ut=e.template("<p class=rl-hint>"),dn=e.template("<span class=rl-hint> no price"),un=e.template("<div class=rl-u-tiles aria-live=polite><div class=rl-u-tile><span class=rl-hint>Spent</span><span class=rl-u-big></span><span class=rl-hint> · </span></div><div class=rl-u-tile><span class=rl-hint>Tokens</span><span class=rl-u-big></span><span class=rl-hint> in · <!> out"),pn=e.template("<span class=rl-u-scale>"),hn=e.template("<span class=rl-u-empty>No price in this range: see Tokens or Requests."),gn=e.template('<div class=rl-card><div class=rl-row><strong class=rl-role> by day</strong><div class=rl-seg role=group aria-label="Chart shows"></div></div><div><div class=rl-u-plot><svg class=rl-chart preserveAspectRatio=none role=img></svg></div><div class=rl-u-days></div></div><div class=rl-legend>'),mn=e.template("<div class=rl-row><strong class=rl-role>By model</strong><span class=rl-hint>most spent first · click to show one"),Nt=e.template("<ol class=rl-u-list>"),fn=e.template('<input class=rl-in type=search aria-label="Search models"placeholder="Search models, e.g. kimi or opencode-go">'),yn=e.template("<span class=rl-u-badge> on"),vn=e.template('<details class=rl-acc><summary>Filters<span class=rl-sub>provider, effort, mode, project, Relay, kind</span></summary><div class=rl-acc-body><div class=rl-filters><select class=rl-in aria-label="Relay on or off"></select><select class=rl-in aria-label=Kind>'),bn=e.template("<div class=rl-row><strong class=rl-role>Records</strong><span class=rl-hint>, newest first"),$n=e.template('<button type=button class="rl-btn sm">Show more'),xn=e.template("<div class=rl-inline><span class=rl-hint> of <!> shown."),wn=e.template("<p class=rl-hint>Every reply of every chat, Relay on or off. <!>In counts tokens read new, from a cache and into a cache; out counts reasoning too. Go is billed by allowance, so its cost is its list price."),_n=e.template("<ol class=rl-plain>"),Sn=e.template("<details class=rl-acc><summary>Before this history<span class=rl-sub>Relay's own messages since 19 Nov</span></summary><div class=rl-acc-body>"),kn=e.template("<svg><g><title></title><rect y=0 width=10 height=60 fill=transparent></svg>",!1,!0,!1),Cn=e.template("<svg><rect width=7></svg>",!1,!0,!1),Pn=e.template("<span>"),Rn=e.template("<span><i class=rl-dot>"),Mn=e.template("<p class=rl-hint>No replies in this range<!>. Relay counts every chat from the version that brought this tab on."),In=e.template("<li><button type=button class=rl-u-item><span class=rl-u-line><span class=rl-u-name></span><span class=rl-u-money></span></span><span class=rl-u-small>"),Dn=e.template("<li class=rl-u-item><span class=rl-u-line><span class=rl-u-when></span><span class=rl-u-name></span><span class=rl-u-money></span></span><span class=rl-u-small>"),An=e.template("<p class=rl-hint>Nothing counted before this history."),qn=e.template("<li class=rl-hint><strong></strong>: <!> request<!>, <br>in <!> · out <!> · cache read <!> · cache write ");const jn=3e4,ht=60,Wt=10,On=7,rt=t=>Math.round(t).toLocaleString("en-US"),Tn=[["any","All kinds"],["chat","Chats"],["helper","Helpers"],["summary","Summaries"]],Ln=[["any","Relay on or off"],["on","Relay on"],["off","Relay off"]],En=t=>t.split(/[\\/]/).filter(Boolean).at(-1)??t,et=(t,r,l)=>`${rt(t)} ${t===1?r:l}`,tt=t=>(()=>{var r=sn(),l=r.firstChild;return r.addEventListener("change",s=>t.set(s.currentTarget.value||null)),e.insert(l,()=>t.all),e.insert(r,e.createComponent(n.For,{get each(){return t.values},children:s=>(()=>{var d=wt();return d.value=s,e.setAttribute(d,"title",s),e.insert(d,(()=>{var h=e.memo(()=>!!t.name);return()=>h()?t.name(s):s})()),e.effect(()=>d.selected=t.value===s),d})()}),null),e.effect(s=>{var d=t.label,h=t.value===null;return d!==s.e&&e.setAttribute(r,"aria-label",s.e=d),h!==s.t&&(l.selected=s.t=h),s},{e:void 0,t:void 0}),r})();function Fn(t){const[r,l]=n.createSignal("7d"),[s,d]=n.createSignal(""),[h,Z]=n.createSignal(""),[B,ee]=n.createSignal(null),[y,W]=n.createSignal(null),[se,c]=n.createSignal(null),[b,_]=n.createSignal(null),[C,me]=n.createSignal("any"),[ve,te]=n.createSignal("any"),[re,Oe]=n.createSignal("cost"),[O,Re]=n.createSignal(),[Ne,We]=n.createSignal(""),[Me,Te]=n.createSignal(!1),ce=n.createMemo(()=>O()?.session===t.session?O():void 0),ze=async(f,E,pe=rr)=>{const S={...Kr(r(),new Date),search:h(),provider:B(),effort:y(),mode:se(),relay:C(),kind:ve(),project:b(),offset:E,limit:pe},D=await f.server.client.rpc(bt).getUsageLog(S,{location:{directory:f.directory}});if(D.directory!==f.directory)throw new Error("The usage came from a different project.");return D};let Le=0;const Ee=async(f=!1)=>{const E=t.session,pe=++Le,S=f&&ce()?ce().value.records.length+ce().more.length:0;Te(!0);try{const D=await ze(E,0,Xr(S));pe===Le&&(Re({session:E,value:D,more:[]}),We(""))}catch(D){pe===Le&&We(Je(D,"Could not load the usage."))}finally{pe===Le&&Te(!1)}},Be=async()=>{const f=ce();if(f)try{const E=await ze(f.session,f.value.records.length+f.more.length);O()===f&&Re({...f,more:ln([...f.value.records,...f.more],E.records).slice(f.value.records.length)})}catch(E){We(Je(E,"Could not load more records."))}};n.createEffect(n.on([r,h,B,y,se,C,ve,b,()=>t.session],()=>{Ee()})),n.createEffect(()=>{const f=s(),E=setTimeout(()=>Z(f.trim()),300);n.onCleanup(()=>clearTimeout(E))});const Ke=setInterval(()=>{!Me()&&!document.hidden&&Ee(!0)},jn);n.onCleanup(()=>clearInterval(Ke));const Ie=()=>[B(),y(),se(),b()].filter(f=>f!==null).length+(C()==="any"?0:1)+(ve()==="any"?0:1),He=()=>n.batch(()=>{d(""),Z(""),ee(null),W(null),c(null),_(null),me("any"),te("any")}),fe=n.createMemo(()=>{const f=ce();return f?rn(f.value.days,re()):void 0}),p=()=>Math.max(On,fe()?.bars.length??0),K=()=>Math.floor((p()-(fe()?.bars.length??0))/2),de=n.createMemo(()=>Vr(ce()?.value.days.map(f=>f.day)??[])),ue=()=>ce()?.value.totals??[],be=n.createMemo(()=>{const f=ce();return f?[...f.value.records,...f.more]:[]}),H=n.createMemo(()=>{const f=ce()?.value.totals??[],E=S=>f.reduce((D,ke)=>D+S(ke),0),pe=f.flatMap(S=>S.cost===null?[]:[Pe(S.cost)]);return{spent:pe.length||!f.length?Ze(lt(pe.reduce((S,D)=>S+D,0n))):"no price",aa:f.some(S=>S.cost!==null&&S.aaPriced),unpriced:E(S=>S.unpriced),replies:E(S=>S.replies),requests:E(S=>S.requests),in:E(S=>S.input+S.cacheRead+S.cacheWrite),out:E(S=>S.output+S.reasoning)}});return(()=>{var f=cn(),E=f.firstChild,pe=E.nextSibling,S=pe.firstChild,D=S.firstChild,ke=D.nextSibling,Q=ke.nextSibling,$e=pe.nextSibling,Ae=$e.firstChild;return e.insert(E,()=>t.css),Q.$$click=()=>{Ee(!0)},e.insert(Q,()=>Me()?"Loading…":"Refresh"),e.insert(Ae,e.createComponent(n.For,{each:zr,children:P=>(()=>{var g=Ft();return g.$$click=()=>l(P.id),e.insert(g,()=>P.label),e.effect(()=>e.setAttribute(g,"aria-pressed",r()===P.id)),g})()})),e.insert($e,e.createComponent(n.Show,{get when(){return h()||Ie()},get children(){var P=an(),g=P.firstChild,v=g.firstChild;v.firstChild;var k=v.nextSibling;return e.insert(v,(()=>{var R=e.memo(()=>!!h());return()=>R()?`: "${h()}"`:""})(),null),e.insert(v,(()=>{var R=e.memo(()=>!!Ie());return()=>R()?`${h()?" and":":"} ${et(Ie(),"filter","filters")}`:""})(),null),k.$$click=He,P}}),null),e.insert($e,e.createComponent(n.Show,{get when(){return Ne()},get children(){var P=on();return e.insert(P,Ne),P}}),null),e.insert($e,e.createComponent(n.Show,{get when(){return ce()},get fallback(){return(()=>{var P=Ut();return e.insert(P,()=>Me()?"Loading…":""),P})()},children:P=>[(()=>{var g=un(),v=g.firstChild,k=v.firstChild,R=k.nextSibling,z=R.nextSibling,A=z.firstChild,M=v.nextSibling,J=M.firstChild,T=J.nextSibling,V=T.nextSibling,$=V.firstChild,U=$.nextSibling;return U.nextSibling,e.insert(R,()=>H().spent,null),e.insert(R,()=>H().aa?"*":"",null),e.insert(z,()=>et(H().replies,"reply","replies"),A),e.insert(z,()=>et(H().requests,"request","requests"),null),e.insert(v,e.createComponent(n.Show,{get when(){return H().unpriced},get children(){var X=dn(),G=X.firstChild;return e.insert(X,()=>et(H().unpriced,"reply has","replies have"),G),X}}),null),e.insert(T,()=>je(H().in+H().out)),e.insert(V,()=>je(H().in),$),e.insert(V,()=>je(H().out),U),g})(),(()=>{var g=gn(),v=g.firstChild,k=v.firstChild,R=k.firstChild,z=k.nextSibling,A=v.nextSibling,M=A.firstChild,J=M.firstChild,T=M.nextSibling,V=A.nextSibling;return e.insert(k,()=>dt.find($=>$.id===re()).label,R),e.insert(z,e.createComponent(n.For,{each:dt,children:$=>(()=>{var U=Ft();return U.$$click=()=>Oe($.id),e.insert(U,()=>$.label),e.effect(()=>e.setAttribute(U,"aria-pressed",re()===$.id)),U})()})),e.insert(M,e.createComponent(n.Show,{get when(){return fe().max>0},get children(){var $=pn();return e.insert($,()=>Yr(re(),fe().max)),$}}),J),e.insert(M,e.createComponent(n.Show,{get when(){return e.memo(()=>re()==="cost"&&!fe().max)()&&P().value.matching},get children(){return hn()}}),J),e.insert(J,e.createComponent(n.For,{get each(){return fe().bars},children:($,U)=>{let X=ht;const G=(K()+U())*Wt;return(()=>{var xe=kn(),i=xe.firstChild,o=i.nextSibling;return e.insert(i,()=>$.title),e.setAttribute(o,"x",G),e.insert(xe,e.createComponent(n.For,{get each(){return $.parts},children:m=>{const N=fe().max?m.value/fe().max*(ht-2):0;return X-=N,(()=>{var a=Cn();return e.setAttribute(a,"x",G+1.5),e.setAttribute(a,"y",X),e.setAttribute(a,"height",N),e.effect(()=>e.setAttribute(a,"fill",m.color)),a})()}}),null),xe})()}})),e.insert(T,e.createComponent(n.For,{get each(){return de()},children:($,U)=>(()=>{var X=Pn();return e.insert(X,$),e.effect(G=>{var xe=`${K()+U()+1}`,i=de().length<=10?"center":U()===0?"start":U()===de().length-1?"end":"center";return xe!==G.e&&e.setStyleProperty(X,"grid-column",G.e=xe),i!==G.t&&e.setStyleProperty(X,"justify-self",G.t=i),G},{e:void 0,t:void 0}),X})()})),e.insert(V,e.createComponent(n.For,{get each(){return fe().legend},children:$=>(()=>{var U=Rn(),X=U.firstChild;return e.insert(U,()=>$.model,null),e.effect(G=>e.setStyleProperty(X,"background",$.color)),U})()})),e.effect($=>{var U=`0 0 ${p()*Wt} ${ht}`,X=`${dt.find(xe=>xe.id===re()).label} by day`,G=`repeat(${p()}, minmax(0, 1fr))`;return U!==$.e&&e.setAttribute(J,"viewBox",$.e=U),X!==$.t&&e.setAttribute(J,"aria-label",$.t=X),G!==$.a&&e.setStyleProperty(T,"grid-template-columns",$.a=G),$},{e:void 0,t:void 0,a:void 0}),g})(),e.createComponent(n.Show,{get when(){return P().value.matching},get fallback(){return(()=>{var g=Mn(),v=g.firstChild,k=v.nextSibling;return k.nextSibling,e.insert(g,()=>h()||Ie()?" with these filters":"",k),g})()},get children(){return[mn(),(()=>{var g=Nt();return e.insert(g,e.createComponent(n.For,{get each(){return ue()},children:v=>{const k=en(v);return(()=>{var R=In(),z=R.firstChild,A=z.firstChild,M=A.firstChild,J=M.nextSibling,T=A.nextSibling;return z.$$click=()=>d(v.model),e.insert(M,()=>k.name),e.insert(J,()=>k.cost),e.insert(T,()=>k.detail),e.effect(()=>e.setAttribute(z,"title",`${v.model}: show only this model`)),R})()}})),g})()]}}),(()=>{var g=fn();return g.$$input=v=>d(v.currentTarget.value),e.effect(()=>g.value=s()),g})(),(()=>{var g=vn(),v=g.firstChild,k=v.firstChild,R=k.nextSibling,z=v.nextSibling,A=z.firstChild,M=A.firstChild,J=M.nextSibling;return e.insert(v,e.createComponent(n.Show,{get when(){return Ie()},get children(){var T=yn(),V=T.firstChild;return e.insert(T,Ie,V),T}}),R),e.insert(A,e.createComponent(tt,{label:"Provider",all:"All providers",get values(){return P().value.options.providers},get value(){return B()},set:ee}),M),e.insert(A,e.createComponent(tt,{label:"Effort",all:"All efforts",get values(){return P().value.options.efforts},get value(){return y()},set:W}),M),e.insert(A,e.createComponent(tt,{label:"Mode or agent",all:"All modes",get values(){return P().value.options.modes},get value(){return se()},set:c}),M),e.insert(A,e.createComponent(tt,{label:"Project",all:"All projects",get values(){return P().value.options.projects},get value(){return b()},set:_,name:En}),M),M.addEventListener("change",T=>me(T.currentTarget.value)),e.insert(M,e.createComponent(n.For,{each:Ln,children:([T,V])=>(()=>{var $=wt();return $.value=T,e.insert($,V),e.effect(()=>$.selected=C()===T),$})()})),J.addEventListener("change",T=>te(T.currentTarget.value)),e.insert(J,e.createComponent(n.For,{each:Tn,children:([T,V])=>(()=>{var $=wt();return $.value=T,e.insert($,V),e.effect(()=>$.selected=ve()===T),$})()})),g})(),e.createComponent(n.Show,{get when(){return P().value.matching},get children(){return[(()=>{var g=bn(),v=g.firstChild,k=v.nextSibling,R=k.firstChild;return e.insert(k,()=>rt(P().value.matching),R),g})(),(()=>{var g=Nt();return e.insert(g,e.createComponent(n.For,{get each(){return be()},children:v=>{const k=nn(v);return(()=>{var R=Dn(),z=R.firstChild,A=z.firstChild,M=A.nextSibling,J=M.nextSibling,T=z.nextSibling;return e.insert(A,()=>k.time),e.insert(M,()=>k.name),e.insert(J,()=>k.cost),e.insert(T,()=>k.detail),e.effect(()=>e.setAttribute(R,"title",`${k.model} · chat ${v.sessionID}`)),R})()}})),g})(),(()=>{var g=xn(),v=g.firstChild,k=v.firstChild,R=k.nextSibling;return R.nextSibling,e.insert(v,()=>rt(be().length),k),e.insert(v,()=>rt(P().value.matching),R),e.insert(g,e.createComponent(n.Show,{get when(){return be().length<P().value.matching},get children(){var z=$n();return z.$$click=()=>{Be()},z}}),null),g})()]}}),(()=>{var g=wn(),v=g.firstChild,k=v.nextSibling;return k.nextSibling,e.insert(g,(()=>{var R=e.memo(()=>!!P().value.first);return()=>R()?`History since ${new Date(P().value.first).toLocaleDateString()}; records older than 90 days are removed. `:""})(),k),e.insert(g,()=>H().aa||P().value.records.some(R=>R.costByPrice!==null&&R.pricesFrom==="artificial-analysis")?"* at Artificial Analysis prices, all or in part. ":"",k),g})(),e.createComponent(n.Show,{get when(){return P().value.credit},children:g=>(()=>{var v=Ut();return e.insert(v,g),v})()}),(()=>{var g=Sn(),v=g.firstChild,k=v.nextSibling;return e.insert(k,e.createComponent(n.Show,{get when(){return P().value.before.rows.length},get fallback(){return An()},get children(){var R=_n();return e.insert(R,e.createComponent(n.For,{get each(){return P().value.before.rows},children:z=>{const A=Ar(z);return(()=>{var M=qn(),J=M.firstChild,T=J.nextSibling,V=T.nextSibling,$=V.nextSibling,U=$.nextSibling,X=U.nextSibling,G=X.nextSibling,xe=G.nextSibling,i=xe.nextSibling,o=i.nextSibling,m=o.nextSibling,N=m.nextSibling,a=N.nextSibling;return a.nextSibling,e.insert(J,()=>A.model),e.insert(M,(()=>{var q=e.memo(()=>A.effort==="-");return()=>q()?"":` · ${A.effort}`})(),T),e.insert(M,()=>A.requests,V),e.insert(M,()=>z.requests===1?"":"s",U),e.insert(M,()=>A.cost,G),e.insert(M,()=>A.input,i),e.insert(M,()=>A.output,m),e.insert(M,()=>A.cacheRead,a),e.insert(M,()=>A.cacheWrite,null),M})()}})),R}})),g})()]}),null),e.effect(()=>Q.disabled=Me()),f})()}e.delegateEvents(["click","input"]);var Un=e.template("<span class=rl-sub>"),Nn=e.template("<details class=rl-acc><summary></summary><div class=rl-acc-body>"),Wn=e.template('<div class=rl-picker role=group><div class=rl-inline><input class=rl-in type=search placeholder="Search, e.g. sonnet or ollama"aria-label="Search models"><button type=button class="rl-btn sm">Done</button></div><div class=rl-inline><select class=rl-in aria-label=Provider><option value>All providers (<!>)</option></select><select class=rl-in aria-label=Order><option value=provider>By provider</option><option value=price>Cheapest first</option><option value=context>Largest context</option><option value=index>Highest index</option></select></div><div class=rl-table-wrap><table class=rl-table><thead><tr><th scope=col>Model</th><th scope=col>Price per 1M<small>in / out</small></th><th scope=col>Context</th><th scope=col title="Artificial Analysis Intelligence Index">Index</th><th scope=col><span class=rl-sr></span></th></tr></thead><tbody></tbody></table></div><span class=rl-hint aria-live=polite></span><span class=rl-hint>'),zn=e.template("<option> (<!>)"),Bn=e.template('<tr><td><span class=rl-t-name></span><small></small></td><td></td><td></td><td></td><td><button type=button class="rl-btn sm">'),Kn=e.template('<div class="rl-note n-warn"role=status>'),Hn=e.template('<div class=rl-card><div><strong class=rl-role>Decider</strong><span class=rl-hint>A small decision model. It picks the mode, and the model inside the mode, for each /relay message.</span></div><span class=rl-hint></span><div class=rl-inline><input class=rl-in type=text aria-label="A sample message to try the decider with"placeholder="Try a message, e.g. fix the login test"><button type=button class="rl-btn sm"></button></div><span class=rl-hint aria-live=polite></span><span class=rl-hint></span><span class=rl-hint>'),Xn=e.template('<div class=rl-card><div><strong class=rl-role>Usage</strong><span class=rl-hint>Every reply of every chat, by day and model: cost, tokens and requests, with search and filters.</span></div><button type=button class="rl-btn sm">Open usage'),Gn=e.template("<span class=rl-hint>For a model OpenCode lists no price for, such as Claude through a subscription login, Relay can take its prices and its intelligence index from Artificial Analysis. Make a free key at artificialanalysis.ai and paste it here. It is kept in OpenCode's plugin storage on this machine, sent only to Artificial Analysis, and never shown again."),Jn=e.template('<div class=rl-inline><input class=rl-in type=password autocomplete=off aria-label="Artificial Analysis key"><button type=button class="rl-btn sm"></button><button type=button class="rl-btn sm">Remove'),Yn=e.template("<ol class=rl-plain>"),Zn=e.template("<pre class=rl-pre>"),Qn=e.template('<div class=rl-row><span class=rl-hint aria-live=polite></span><button type=button class="rl-btn sm">Refresh'),Vn=e.template('<div class="rl-note n-bad"role=alert>'),ei=e.template("<section class=rl aria-label=Relay><style></style><header class=rl-top><div class=rl-brand><span class=rl-logo aria-hidden=true>R</span><h2 class=rl-name>Relay</h2><span class=rl-tag>Plan · Execute · Review</span></div></header><div class=rl-body><p class=rl-hint>Type <strong>/relay</strong> and your message in the chat. Relay picks Plan, Execute or Review for it, switches the chat to a model you chose for that mode, and sends your message. These settings are the same in every project."),ti=e.template('<div class="rl-note n-bad"role=alert>Could not load the settings. Check the server connection and try again.'),ri=e.template("<span class=rl-hint>None chosen yet. /relay leaves the chat as it is for <!>."),gt=e.template("<span class=rl-hint>"),ni=e.template("<div class=rl-card><div><strong class=rl-role></strong><span class=rl-hint>"),zt=e.template("<small>unavailable"),ii=e.template('<div class=rl-pick><span><span class=rl-chip-t></span><button type=button class=rl-x>×</button></span><input class=rl-in type=text placeholder="Use it for… (your own words, optional)">'),li=e.template('<select class="rl-in rl-effort"><option value>default effort'),Bt=e.template("<div class=rl-inline><span class=rl-hint>"),Kt=e.template("<option> effort"),si=e.template('<button type=button class="rl-btn sm rl-add">+ Add a model'),ai=e.template("<span class=rl-hint>No decider chosen: /relay sends without switching."),oi=e.template("<div class=rl-pick><span><span class=rl-chip-t></span><button type=button class=rl-x>×"),ci=e.template('<select class="rl-in rl-effort"aria-label="Effort for the decider"><option value>default effort'),di=e.template('<button type=button class="rl-btn sm rl-add">'),Ht=e.template("<div role=status>"),ui=e.template("<p class=rl-hint>No /relay message yet."),pi=e.template("<li class=rl-hint><time></time> · ");const hi=[["plan","Thinks, explains and plans. Cannot change files."],["execute","Writes, changes, fixes and runs. Can change files."],["review","Checks existing work and reports. Cannot change files. Helpers that check work use these models too."]],mt=t=>{const[r,l]=n.createSignal(!1);return(()=>{var s=Nn(),d=s.firstChild,h=d.nextSibling;return s.addEventListener("toggle",Z=>{Z.currentTarget.open&&l(!0)}),e.insert(d,()=>t.title,null),e.insert(d,e.createComponent(n.Show,{get when(){return t.sub},get children(){var Z=Un();return e.insert(Z,()=>t.sub),Z}}),null),e.insert(h,e.createComponent(n.Show,{get when(){return r()},get children(){return t.children}})),s})()},Xt=t=>{const[r,l]=n.createSignal(""),[s,d]=n.createSignal(""),[h,Z]=n.createSignal("provider"),B=n.createMemo(()=>[...new Set(t.models.map(y=>y.providerID))].sort().map(y=>({id:y,count:t.models.filter(W=>W.providerID===y).length}))),ee=n.createMemo(()=>Rr(t.models,{query:r(),provider:s(),order:h()}));return(()=>{var y=Wn(),W=y.firstChild,se=W.firstChild,c=se.nextSibling,b=W.nextSibling,_=b.firstChild,C=_.firstChild,me=C.firstChild,ve=me.nextSibling;ve.nextSibling;var te=_.nextSibling,re=te.firstChild,Oe=re.nextSibling,O=Oe.nextSibling,Re=O.nextSibling,Ne=b.nextSibling,We=Ne.firstChild,Me=We.firstChild,Te=Me.firstChild,ce=Te.firstChild,ze=ce.nextSibling,Le=ze.nextSibling,Ee=Le.nextSibling,Be=Ee.nextSibling,Ke=Be.firstChild,Ie=Me.nextSibling,He=Ne.nextSibling,fe=He.nextSibling;return y.$$keydown=p=>{p.key==="Escape"&&(p.stopPropagation(),t.close())},se.$$input=p=>l(p.currentTarget.value),e.use(p=>setTimeout(()=>p.focus()),se),c.$$click=()=>t.close(),_.addEventListener("change",p=>d(p.currentTarget.value)),e.insert(C,()=>t.models.length,ve),e.insert(_,e.createComponent(n.For,{get each(){return B()},children:p=>(()=>{var K=zn(),de=K.firstChild,ue=de.nextSibling;return ue.nextSibling,e.insert(K,()=>p.id,de),e.insert(K,()=>p.count,ue),e.effect(()=>K.selected=s()===p.id),e.effect(()=>K.value=p.id),K})()}),null),te.addEventListener("change",p=>Z(p.currentTarget.value)),e.insert(Ke,()=>t.action),e.insert(Ie,e.createComponent(n.For,{get each(){return ee()},children:p=>(()=>{var K=Bn(),de=K.firstChild,ue=de.firstChild,be=ue.nextSibling,H=de.nextSibling,f=H.nextSibling,E=f.nextSibling,pe=E.nextSibling,S=pe.firstChild;return e.insert(ue,()=>p.name),e.insert(be,()=>p.providerID,null),e.insert(be,()=>t.mark(p),null),e.insert(H,()=>kr(p.cost)),e.insert(f,()=>Cr(p.limit.context)),e.insert(E,()=>Qt(p.index)),S.$$click=()=>t.pick(p),e.insert(S,()=>t.action),e.effect(D=>{var ke=p.limit.context>0?void 0:"Context size not listed",Q=p.matched?`Artificial Analysis, for ${p.matched} on OpenRouter${p.variants.length?", at its highest effort":""}`:"No index found for this model",$e=!t.can(p),Ae=t.tip?.(p),P=t.actionLabel(p);return ke!==D.e&&e.setAttribute(f,"title",D.e=ke),Q!==D.t&&e.setAttribute(E,"title",D.t=Q),$e!==D.a&&(S.disabled=D.a=$e),Ae!==D.o&&e.setAttribute(S,"title",D.o=Ae),P!==D.i&&e.setAttribute(S,"aria-label",D.i=P),D},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),K})()})),e.insert(He,(()=>{var p=e.memo(()=>!!ee().length);return()=>p()?`${ee().length} of ${t.models.length} models`:"No model matches. Try fewer words, or All providers."})()),e.insert(fe,()=>t.source),e.effect(p=>{var K=t.label,de=s()==="",ue=h()==="provider",be=h()==="price",H=h()==="context",f=h()==="index";return K!==p.e&&e.setAttribute(y,"aria-label",p.e=K),de!==p.t&&(C.selected=p.t=de),ue!==p.a&&(re.selected=p.a=ue),be!==p.o&&(Oe.selected=p.o=be),H!==p.i&&(O.selected=p.i=H),f!==p.n&&(Re.selected=p.n=f),p},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),e.effect(()=>se.value=r()),y})()},gi=Xe.Plugin.define({setup(t){const r={id:"models",title:"Relay",closable:"compact",fallback:!0};t.add(Xe.Command,()=>({id:"open",title:"Open Relay",keywords:"relay models modes plan execute review decider",enabled:!!t.sessions.current(),run:()=>{const c=t.sessions.current();c&&t.layout.toggle(`${t.id}:models`,c)}}));const l={id:"usage",title:"Relay usage",closable:"compact"};t.add(Xe.Command,()=>({id:"usage",title:"Open Relay usage",keywords:"relay usage cost tokens requests chart models",enabled:!!t.sessions.current(),run:()=>{const c=t.sessions.current();c&&t.layout.toggle(`${t.id}:usage`,c)}})),t.add(Xe.Panel,{id:"usage",region:"side",width:420,list:c=>c.open.includes("usage")?[l]:[],render:c=>e.createComponent(Fn,{get session(){return c.session},css:jt})}),t.add(Xe.Panel,{id:"models",region:"side",width:380,list:c=>c.open.includes("models")?[r]:[],render:c=>{const b=i=>({rpc:i.server.client.rpc(bt),options:{location:{directory:i.directory}}}),_=async(i,o)=>{const m=await o(b(i));if(m.directory!==i.directory)throw new Error("Wrong project");return m},[C,me]=n.createSignal(!1),[ve,te]=n.createSignal(""),[re,{refetch:Oe}]=n.createResource(()=>c.session,async i=>{const{rpc:o,options:m}=b(i),[N,a]=await Promise.all([o.listModels({},m),o.getRelay({},m)]);if(N.directory!==i.directory||a.directory!==i.directory)throw new Error("Data came from a different project");return{session:i,models:N.models,relay:a}}),O=n.createMemo(()=>re()?.session===c.session?re():void 0),Re=n.createMemo(()=>O()?.models),[Ne,{refetch:We}]=n.createResource(()=>c.session,async i=>{try{const o=await _(i,({rpc:m,options:N})=>m.listIntelligence({},N));return{session:i,source:o.source,note:o.note,byModel:new Map(o.scores.map(m=>[`${m.providerID}/${m.id}`,m]))}}catch(o){return{session:i,source:null,note:Je(o,"the index could not be loaded"),byModel:new Map}}}),Me=n.createMemo(()=>{const i=Ne();return i?.session===c.session?i:void 0}),Te=i=>{const o=Me()?.byModel.get(`${i.providerID}/${i.id}`);return{...i,index:o?.index??null,matched:o?.matched??null}},ce=i=>{const o=Te(i).index;return o===null?"":` · index ${Qt(o)}${i.variants.length?" at its highest effort":""}`},ze=()=>{const i=Me();return i?i.source?`Index: ${i.source}. For a model with efforts it is the highest effort's score; lower efforts score less.${i.note?` (${i.note})`:""}`:`Index: not shown (${i.note}).`:"Index: loading…"},[Le,{refetch:Ee}]=n.createResource(()=>c.session,async i=>{try{return{session:i,modes:(await _(i,({rpc:o,options:m})=>o.getOwnChoice({},m))).modes}}catch{return{session:i,modes:null}}}),Be=i=>{const o=Le();return o?.session===c.session&&o.modes?o.modes[i]:null},[Ke,Ie]=n.createSignal(),He=async()=>{const i=c.session;try{const o=await _(i,({rpc:m,options:N})=>m.getRelayDecisions({},N));c.session===i&&Ie({session:i,decisions:o.decisions})}catch{}},fe=setInterval(()=>{He()},5e3);n.onCleanup(()=>clearInterval(fe));const p=n.createMemo(()=>Ke()?.session===c.session?Ke().decisions:O()?.relay.decisions??[]),[K,de]=n.createSignal(""),[ue,be]=n.createSignal(!1),[H,f]=n.createSignal(),E=async i=>{const o=c.session;if(!ue()){be(!0);try{const{rpc:m,options:N}=b(o),a=await m.setPriceKey({key:i},N);de(""),f({session:o,bad:!!a.note,text:a.saved?a.note?`Key saved, but ${a.note}.`:"Key saved. Prices and the index now come from Artificial Analysis.":"Key removed."}),await Promise.all([Oe(),We(),Ee()])}catch(m){f({session:o,bad:!0,text:Je(m,"Could not save the key.")})}finally{be(!1)}}},pe=i=>new Date(i).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),[S,D]=n.createSignal(null),ke=(i,o)=>i.providerID===o.providerID&&i.id===o.id&&i.variant===o.variant,Q=i=>O()?.relay.settings.modes[i]??[],$e=async i=>{const o=O();if(!o||C())return;const{revision:m,modes:N,decider:a}=o.relay.settings;me(!0),te("");try{await _(o.session,({rpc:q,options:L})=>q.saveRelay({revision:m,modes:N,decider:a,...i},L))}catch(q){te(Je(q,"Could not save. The settings may have changed; refresh and try again."))}finally{try{c.session===o.session&&(await Oe(),Ee())}catch{te("Could not refresh the settings. Try Refresh.")}finally{me(!1)}}},Ae=(i,o)=>{const m=O();m&&$e({modes:{...m.relay.settings.modes,[i]:o}})},[P,g]=n.createSignal(""),[v,k]=n.createSignal(!1),[R,z]=n.createSignal(),A=async()=>{const i=c.session,o=P();if(!(v()||!o.trim())){k(!0);try{const m=await _(i,({rpc:N,options:a})=>N.testDecider({text:o},a));c.session===i&&z({session:i,text:qr(m),bad:m.mode===null})}catch(m){c.session===i&&z({session:i,text:Je(m,"Could not ask the decider."),bad:!0})}finally{k(!1)}}},M=i=>{const o=Re();return o!==void 0&&!ct(o,i)},J=n.createMemo(()=>(Re()??[]).filter(i=>i.enabled&&i.status!=="deprecated").map(Te)),T=n.createMemo(()=>(O()?.relay.deciders??[]).filter(i=>i.enabled&&i.status!=="deprecated").map(Te)),V=n.createMemo(()=>{const i=O()?.relay,o=i?.settings.decider;return i&&o?ct(i.deciders,o):void 0}),$=i=>{const o=O()?.relay.settings.decider;return!!o&&o.providerID===i.providerID&&o.id===i.id},U=(i,o)=>Q(i).some(m=>m.providerID===o.providerID&&m.id===o.id),X=(i,o)=>{const m=It(Q(i),o);m!==void 0&&Ae(i,[...Q(i),{providerID:o.providerID,id:o.id,variant:m,useFor:""}])},G=(i,o,m)=>Q(i).some(N=>ke(N,{...o,variant:m})),xe=(i,o,m)=>Ae(i,Q(i).map(N=>ke(N,o)?{...N,variant:m}:N));return(()=>{var i=ei(),o=i.firstChild,m=o.nextSibling,N=m.nextSibling;return N.firstChild,e.insert(o,jt),e.insert(N,e.createComponent(n.Show,{get when(){return!re.error},get fallback(){return ti()},get children(){return[e.createComponent(n.Show,{get when(){return e.memo(()=>!!O())()&&O().relay.settings.decider===null},get children(){var a=Kn();return e.insert(a,Fr),a}}),e.createComponent(n.For,{each:hi,children:([a,q])=>(()=>{var L=ni(),ye=L.firstChild,Y=ye.firstChild,Fe=Y.nextSibling;return e.insert(Y,()=>Ue(a)),e.insert(Fe,q),e.insert(L,e.createComponent(n.For,{get each(){return Q(a)},children:u=>(()=>{var he=ii(),qe=he.firstChild,w=qe.firstChild,we=w.nextSibling,Ce=qe.nextSibling;return e.insert(w,()=>u.id,null),e.insert(w,(()=>{var I=e.memo(()=>!!u.variant);return()=>I()?` · ${u.variant}`:""})(),null),e.insert(qe,e.createComponent(n.Show,{get when(){return M(u)},get children(){return zt()}}),we),we.$$click=()=>Ae(a,Q(a).filter(I=>!ke(I,u))),e.insert(he,e.createComponent(n.Show,{get when(){return e.memo(()=>!!Re())()&&ct(Re(),u)},children:I=>(()=>{var ne=Bt(),F=ne.firstChild;return e.insert(ne,e.createComponent(n.Show,{get when(){return I().variants.length},get children(){var ae=li(),_e=ae.firstChild;return ae.addEventListener("change",j=>xe(a,u,j.currentTarget.value||null)),e.insert(ae,e.createComponent(n.For,{get each(){return I().variants},children:j=>(()=>{var ie=Kt(),oe=ie.firstChild;return ie.value=j,e.insert(ie,j,oe),e.effect(le=>{var De=u.variant===j,Ct=u.variant!==j&&G(a,u,j);return De!==le.e&&(ie.selected=le.e=De),Ct!==le.t&&(ie.disabled=le.t=Ct),le},{e:void 0,t:void 0}),ie})()}),null),e.effect(j=>{var ie=`Effort for ${u.id} in ${Ue(a)}`,oe=C(),le=u.variant===null,De=u.variant!==null&&G(a,u,null);return ie!==j.e&&e.setAttribute(ae,"aria-label",j.e=ie),oe!==j.t&&(ae.disabled=j.t=oe),le!==j.a&&(_e.selected=j.a=le),De!==j.o&&(_e.disabled=j.o=De),j},{e:void 0,t:void 0,a:void 0,o:void 0}),ae}}),F),e.insert(F,()=>Rt(I().cost),null),e.insert(F,()=>ce(I()),null),ne})()}),Ce),e.insert(he,e.createComponent(n.Show,{get when(){return Or(Be(a),u)},children:I=>(()=>{var ne=gt();return e.insert(ne,I),ne})()}),Ce),Ce.addEventListener("change",I=>{const ne=I.currentTarget.value.replace(/\s+/g," ").trim();ne!==u.useFor&&Ae(a,Q(a).map(F=>ke(F,u)?{...F,useFor:ne}:F))}),e.setAttribute(Ce,"maxlength",fr),e.effect(I=>{var ne=`rl-chip ${M(u)?"bad":""}`,F=`${u.providerID} / ${u.id}`,ae=`Remove ${u.providerID} / ${u.id} / ${u.variant??"default"} from ${Ue(a)}`,_e=C(),j=`What ${u.id} is for in ${Ue(a)}`,ie=C();return ne!==I.e&&e.className(qe,I.e=ne),F!==I.t&&e.setAttribute(w,"title",I.t=F),ae!==I.a&&e.setAttribute(we,"aria-label",I.a=ae),_e!==I.o&&(we.disabled=I.o=_e),j!==I.i&&e.setAttribute(Ce,"aria-label",I.i=j),ie!==I.n&&(Ce.disabled=I.n=ie),I},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),e.effect(()=>Ce.value=u.useFor),he})()}),null),e.insert(L,e.createComponent(n.Show,{get when(){return!Q(a).length},get children(){var u=ri(),he=u.firstChild,qe=he.nextSibling;return qe.nextSibling,e.insert(u,()=>Ue(a),qe),u}}),null),e.insert(L,e.createComponent(n.Show,{get when(){return Q(a).length>1},get children(){var u=gt();return e.insert(u,jr),u}}),null),e.insert(L,e.createComponent(n.Show,{get when(){return Tr(Be(a))},children:u=>(()=>{var he=gt();return e.insert(he,u),he})()}),null),e.insert(L,e.createComponent(n.Show,{get when(){return S()===a},get fallback(){return(()=>{var u=si();return u.$$click=()=>D(a),e.effect(()=>u.disabled=C()||re.loading),u})()},get children(){return e.createComponent(Xt,{get label(){return`Add a model to ${Ue(a)}`},get models(){return J()},get source(){return ze()},action:"Add",actionLabel:u=>`Add ${u.name} from ${u.providerID} to ${Ue(a)}`,can:u=>!C()&&It(Q(a),u)!==void 0,mark:u=>`${u.capabilities.tools?"":" · no tools"}${U(a,u)?" · ✓ in the list":""}`,tip:u=>U(a,u)?"Adds it once more, with another effort":void 0,pick:u=>X(a,u),close:()=>D(null)})}}),null),L})()}),(()=>{var a=Hn(),q=a.firstChild,L=q.nextSibling,ye=L.nextSibling,Y=ye.firstChild,Fe=Y.nextSibling,u=ye.nextSibling,he=u.nextSibling,qe=he.nextSibling;return e.insert(a,e.createComponent(n.Show,{get when(){return O()?.relay.settings.decider},get fallback(){return ai()},children:w=>(()=>{var we=oi(),Ce=we.firstChild,I=Ce.firstChild,ne=I.nextSibling;return e.insert(I,()=>w().id,null),e.insert(I,(()=>{var F=e.memo(()=>!!w().variant);return()=>F()?` · ${w().variant}`:""})(),null),e.insert(Ce,e.createComponent(n.Show,{get when(){return e.memo(()=>!!O())()&&!V()},get children(){return zt()}}),ne),ne.$$click=()=>{$e({decider:null})},e.insert(we,e.createComponent(n.Show,{get when(){return V()},children:F=>(()=>{var ae=Bt(),_e=ae.firstChild;return e.insert(ae,e.createComponent(n.Show,{get when(){return F().variants.length},get children(){var j=ci(),ie=j.firstChild;return j.addEventListener("change",oe=>{$e({decider:{...w(),variant:oe.currentTarget.value||null}})}),e.insert(j,e.createComponent(n.For,{get each(){return F().variants},children:oe=>(()=>{var le=Kt(),De=le.firstChild;return le.value=oe,e.insert(le,oe,De),e.effect(()=>le.selected=w().variant===oe),le})()}),null),e.effect(oe=>{var le=C(),De=w().variant===null;return le!==oe.e&&(j.disabled=oe.e=le),De!==oe.t&&(ie.selected=oe.t=De),oe},{e:void 0,t:void 0}),j}}),_e),e.insert(_e,()=>Rt(F().cost),null),e.insert(_e,()=>ce(F()),null),ae})()}),null),e.effect(F=>{var ae=`rl-chip ${O()&&!V()?"bad":""}`,_e=`${w().providerID} / ${w().id}`,j=`Remove the decider ${w().providerID} / ${w().id}`,ie=C();return ae!==F.e&&e.className(Ce,F.e=ae),_e!==F.t&&e.setAttribute(I,"title",F.t=_e),j!==F.a&&e.setAttribute(ne,"aria-label",F.a=j),ie!==F.o&&(ne.disabled=F.o=ie),F},{e:void 0,t:void 0,a:void 0,o:void 0}),we})()}),L),e.insert(a,e.createComponent(n.Show,{get when(){return S()==="decider"},get fallback(){return(()=>{var w=di();return w.$$click=()=>D("decider"),e.insert(w,()=>O()?.relay.settings.decider?"Change the decider":"+ Choose a decider"),e.effect(()=>w.disabled=C()||re.loading),w})()},get children(){return e.createComponent(Xt,{label:"Choose a decider",get models(){return T()},get source(){return ze()},action:"Use",actionLabel:w=>`Use ${w.name} from ${w.providerID} as the decider`,can:w=>!C()&&!$(w),mark:w=>$(w)?" · ✓ in use":"",pick:w=>{D(null),$e({decider:{providerID:w.providerID,id:w.id,variant:null}})},close:()=>D(null)})}}),L),e.insert(L,()=>Lr(O()?.relay.settings.decider?.providerID??null)),Y.$$keydown=w=>{w.key==="Enter"&&A()},Y.$$input=w=>g(w.currentTarget.value),Fe.$$click=()=>{A()},e.insert(Fe,()=>v()?"Asking…":"Try"),e.insert(a,e.createComponent(n.Show,{get when(){return e.memo(()=>R()?.session===c.session)()?R():void 0},children:w=>(()=>{var we=Ht();return e.insert(we,()=>w().text),e.effect(()=>e.className(we,`rl-note ${w().bad?"n-bad":""}`)),we})()}),u),e.insert(u,()=>tr(p()[0])),e.insert(he,(()=>{var w=e.memo(()=>!!O());return()=>w()?Wr(O().relay.checks):""})()),e.insert(qe,Nr),e.effect(()=>Fe.disabled=v()||!P().trim()||!O()?.relay.settings.decider),e.effect(()=>Y.value=P()),a})(),(()=>{var a=Xn(),q=a.firstChild,L=q.nextSibling;return L.$$click=()=>t.layout.open(`${t.id}:usage`,c.session),a})(),e.createComponent(mt,{title:"Prices from Artificial Analysis",get sub(){return O()?.relay.priceKey?"key saved":"no key"},get children(){return[Gn(),(()=>{var a=Jn(),q=a.firstChild,L=q.nextSibling,ye=L.nextSibling;return q.$$keydown=Y=>{Y.key==="Enter"&&K().trim()&&E(K())},q.$$input=Y=>de(Y.currentTarget.value),L.$$click=()=>{E(K())},e.insert(L,()=>ue()?"Saving…":"Save"),ye.$$click=()=>{E(null)},e.effect(Y=>{var Fe=O()?.relay.priceKey?"A key is saved":"Paste a key",u=ue()||!K().trim(),he=ue()||!O()?.relay.priceKey;return Fe!==Y.e&&e.setAttribute(q,"placeholder",Y.e=Fe),u!==Y.t&&(L.disabled=Y.t=u),he!==Y.a&&(ye.disabled=Y.a=he),Y},{e:void 0,t:void 0,a:void 0}),e.effect(()=>q.value=K()),a})(),e.createComponent(n.Show,{get when(){return e.memo(()=>H()?.session===c.session)()?H():void 0},children:a=>(()=>{var q=Ht();return e.insert(q,()=>a().text),e.effect(()=>e.className(q,`rl-note ${a().bad?"n-bad":""}`)),q})()})]}}),e.createComponent(mt,{title:"Recent choices",sub:"the last 20, newest first",get children(){return e.createComponent(n.Show,{get when(){return p().length},get fallback(){return ui()},get children(){var a=Yn();return e.insert(a,e.createComponent(n.For,{get each(){return p()},children:q=>(()=>{var L=pi(),ye=L.firstChild;return ye.nextSibling,e.insert(ye,()=>pe(q.at)),e.insert(L,()=>Dr(q),null),e.effect(()=>e.setAttribute(ye,"datetime",q.at)),L})()})),a}})}}),e.createComponent(mt,{title:"Review rules",sub:"added to every review",get children(){var a=Zn();return e.insert(a,vr),a}}),(()=>{var a=Qn(),q=a.firstChild,L=q.nextSibling;return e.insert(q,(()=>{var ye=e.memo(()=>!!re.loading);return()=>ye()?"Loading…":`${Re()?.length??0} models available`})(),null),e.insert(q,()=>C()?" · saving…":"",null),L.$$click=()=>{Oe()},e.effect(()=>L.disabled=re.loading),a})(),e.createComponent(n.Show,{get when(){return ve()},get children(){var a=Vn();return e.insert(a,ve),a}})]}}),null),i})()}});const[s,d]=n.createSignal({}),h=new Map,Z=c=>({rpc:c.server.client.rpc(bt),options:{location:{directory:c.directory}}}),B=new Map,ee=(c,b)=>{const _=b?.at??"";if(!B.has(c.key)){B.set(c.key,_);return}if(!b||B.get(c.key)===_)return;const C=Er(b);if(!C){B.set(c.key,_);return}t.sessions.current()?.key===c.key&&t.screen.current()?.composer.setModel(C)&&B.set(c.key,_)},y=async c=>{try{const{rpc:b,options:_}=Z(c),C=await b.getRelayChat({sessionID:c.id},_);d(me=>({...me,[c.key]:C})),ee(c,C.last)}catch{}},W=async(c,b)=>{try{const{rpc:_,options:C}=Z(c);await _.setRelayChat({sessionID:c.id,on:b},C)}catch{}await y(c)},se=setInterval(()=>{const c=Date.now();for(const[b,_]of h)c-_.at>15e3?h.delete(b):y(_.session)},5e3);try{t.add(Xe.ComposerPill,{id:"relay",show:c=>{const b=c.session,_=!h.has(b.key);h.set(b.key,{session:b,at:Date.now()}),_&&y(b);const C=s()[b.key];if(!C)return;const me=Ur(C),ve=te=>te==="toggle"?()=>{W(b,!C.on)}:te==="decider"?()=>t.layout.open(`${t.id}:models`,b):void 0;return{label:me.label,icon:me.icon,tone:me.tone,title:"Relay",rows:me.rows.map(te=>({id:te.id,label:te.label,tone:te.tone,run:ve(te.id)}))}}})}catch{}return()=>clearInterval(se)}});e.delegateEvents(["keydown","input","click"]);exports.default=gi;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Styles for the Relay panel. Everything is scoped under `.rl` so nothing leaks into the host, and every colour comes from the host's own theme
3
+ * variables with a neutral fallback, so the panel follows light and dark themes. Plain CSS in a string because the GUI bundle has no CSS pipeline.
4
+ */
5
+ export declare const panelCss = "\n.rl{--rl-fg:var(--text-base,#2b2f36);--rl-strong:var(--text-strong,#14171c);--rl-weak:var(--text-weak,#6e7681);--rl-bg:var(--background-base,#fff);\n--rl-card:var(--surface-raised-base,rgba(127,127,127,.07));--rl-inset:var(--surface-inset-base,rgba(127,127,127,.11));--rl-hover:var(--surface-base-hover,rgba(127,127,127,.15));\n--rl-line:var(--border-weak-base,rgba(127,127,127,.22));--rl-line2:var(--border-base,rgba(127,127,127,.38));--rl-accent:var(--text-interactive-base,#4f7cff);\n--rl-ok:var(--icon-success-base,#2ea36a);--rl-warn:var(--icon-warning-base,#d99a1c);--rl-bad:var(--icon-critical-base,#d9483b);--rl-wait:#8a7cf0;\ndisplay:flex;flex-direction:column;height:100%;min-height:0;color:var(--rl-fg);font-size:13px;line-height:1.4}\n.rl *{box-sizing:border-box}\n.rl h2,.rl h3,.rl p{margin:0}\n.rl-top{display:grid;gap:10px;padding:14px 14px 0;flex:none}\n.rl-brand{display:flex;align-items:center;gap:8px;min-width:0}\n.rl-logo{flex:none;width:22px;height:22px;border-radius:7px;display:grid;place-items:center;color:#fff;font-size:12px;font-weight:700;background:linear-gradient(135deg,var(--rl-accent),#9b6bff)}\n.rl-name{font-size:15px;font-weight:650;color:var(--rl-strong)}\n.rl-tag{margin-left:auto;color:var(--rl-weak);font-size:11px;white-space:nowrap}\n.rl-body{flex:1;min-height:0;overflow:auto;display:grid;grid-template-columns:minmax(0,1fr);grid-auto-rows:max-content;gap:12px;align-content:start;padding:12px 14px 18px}\n.rl-card{display:grid;grid-template-columns:minmax(0,1fr);gap:10px;padding:12px;border:1px solid var(--rl-line);border-radius:12px;background:var(--rl-card)}\n.rl-row{display:flex;align-items:center;justify-content:space-between;gap:8px;min-width:0}\n.rl-inline{display:flex;align-items:center;gap:6px}\n.rl-inline .rl-in{flex:1;min-width:0}\n.rl-hint{margin:0;color:var(--rl-weak);font-size:11.5px;overflow-wrap:anywhere}\n.rl-in{width:100%;min-width:0;padding:7px 9px;border:1px solid var(--rl-line);border-radius:8px;background:var(--rl-inset);color:var(--rl-strong);font:inherit;outline:none}\n.rl-in:focus{border-color:var(--rl-accent);box-shadow:0 0 0 3px color-mix(in srgb,var(--rl-accent) 22%,transparent)}\n.rl-in:disabled{opacity:.55}\n.rl-btn{appearance:none;padding:6px 12px;border:1px solid var(--rl-line2);border-radius:8px;background:transparent;color:var(--rl-fg);font:inherit;font-weight:550;cursor:pointer;white-space:nowrap}\n.rl-btn:hover:not(:disabled){background:var(--rl-hover)}\n.rl-btn:disabled{opacity:.5;cursor:default}\n.rl-btn.sm{padding:3px 9px;font-size:12px}\n.rl button:focus-visible,.rl summary:focus-visible,.rl input:focus-visible,.rl select:focus-visible{outline:2px solid var(--rl-accent);outline-offset:2px}\n.rl-note{--c:var(--rl-accent);display:grid;grid-template-columns:minmax(0,1fr);gap:2px;padding:8px 10px;border:1px solid color-mix(in srgb,var(--c) 32%,transparent);border-radius:10px;background:color-mix(in srgb,var(--c) 11%,transparent);font-size:12px;overflow-wrap:anywhere}\n.rl-note.n-bad{--c:var(--rl-bad)}.rl-note.n-warn{--c:var(--rl-warn)}.rl-note.n-ok{--c:var(--rl-ok)}\n.rl-pre{margin:6px 0 0;padding:8px;max-height:220px;overflow:auto;border-radius:8px;background:var(--rl-inset);font-size:11px;white-space:pre-wrap;overflow-wrap:anywhere}\n.rl-acc{border:1px solid var(--rl-line);border-radius:12px;background:var(--rl-card)}\n.rl-acc>summary{display:flex;align-items:center;gap:8px;padding:10px 12px;border-radius:11px;color:var(--rl-strong);font-weight:600;cursor:pointer;list-style:none}\n.rl-acc>summary::-webkit-details-marker{display:none}\n.rl-acc>summary::after{content:\"\\203A\";margin-left:auto;color:var(--rl-weak);transition:transform .15s}\n.rl-acc[open]>summary::after{transform:rotate(90deg)}\n.rl-acc[open]>summary{border-radius:11px 11px 0 0}\n.rl-acc>summary:hover{background:var(--rl-hover)}\n.rl-sub{margin-left:2px;color:var(--rl-weak);font-size:11px;font-weight:400;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n.rl-acc-body{display:grid;grid-template-columns:minmax(0,1fr);gap:10px;padding:4px 12px 12px}\n.rl-pick{display:grid;grid-template-columns:minmax(0,1fr);gap:4px}\n.rl-pick .rl-chip{justify-self:start}\n.rl-chip{display:inline-flex;align-items:center;gap:6px;max-width:100%;padding:3px 4px 3px 10px;border:1px solid var(--rl-line);border-radius:99px;background:var(--rl-inset);font-size:12px}\n.rl-chip.bad{border-color:color-mix(in srgb,var(--rl-bad) 50%,transparent)}\n.rl-chip-t{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n.rl-chip small{color:var(--rl-bad)}\n.rl-x{appearance:none;flex:none;width:18px;height:18px;padding:0;border:0;border-radius:50%;background:transparent;color:var(--rl-weak);font:inherit;line-height:1;cursor:pointer}\n.rl-x:hover:not(:disabled){background:var(--rl-hover);color:var(--rl-strong)}\n.rl-role{display:block;color:var(--rl-strong);font-weight:650}\n.rl .rl-plain{margin:0;padding:0;list-style:none;display:grid;gap:6px}\n.rl-add{justify-self:start}\n.rl-inline .rl-effort{flex:none;width:auto;padding:3px 6px;font-size:12px}\n.rl-picker{display:grid;grid-template-columns:minmax(0,1fr);gap:6px}\n.rl-table-wrap{max-height:320px;overflow:auto;border:1px solid var(--rl-line);border-radius:8px;background:var(--rl-bg)}\n.rl-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:fixed}\n.rl-table th:nth-child(2){width:74px}.rl-table th:nth-child(3){width:46px;text-align:right;white-space:nowrap}.rl-table th:nth-child(4){width:42px;text-align:right;white-space:nowrap}.rl-table th:nth-child(5){width:46px}\n.rl-table th{position:sticky;top:0;z-index:1;padding:5px 4px;border-bottom:1px solid var(--rl-line2);background:var(--rl-bg);color:var(--rl-weak);font-size:11px;font-weight:600;text-align:left;vertical-align:bottom}\n.rl-table td{padding:5px 4px;border-top:1px solid var(--rl-line);vertical-align:middle;overflow-wrap:anywhere}\n.rl-table tbody tr:first-child td{border-top:0}\n.rl-table tbody tr:hover{background:var(--rl-hover)}\n.rl-table td:nth-child(3),.rl-table td:nth-child(4){text-align:right;white-space:nowrap}\n.rl-table td:last-child{text-align:right}\n.rl-table small{display:block;color:var(--rl-weak);font-size:11px;font-weight:400}\n.rl-t-name{color:var(--rl-strong);font-weight:550}\n.rl-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}\n.rl-seg{display:flex;flex-wrap:wrap;gap:4px;align-items:center}\n.rl-seg .rl-btn[aria-pressed=true]{background:var(--rl-inset);border-color:var(--rl-accent);color:var(--rl-strong)}\n.rl-right{margin-left:auto}\n.rl-filters{display:grid;grid-template-columns:repeat(auto-fill,minmax(118px,1fr));gap:6px}\n.rl-chart{display:block;width:100%;height:110px}\n.rl-chart g:hover rect[fill=transparent]{fill:var(--rl-hover)}\n.rl-legend{display:flex;flex-wrap:wrap;gap:4px 10px;color:var(--rl-weak);font-size:11px}\n.rl-dot{display:inline-block;width:8px;height:8px;border-radius:2px;margin-right:4px;vertical-align:baseline}\n.rl-u-tiles{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}\n.rl-u-tile{display:grid;gap:1px;align-content:start;min-width:0;padding:10px 12px;border:1px solid var(--rl-line);border-radius:12px;background:var(--rl-card)}\n.rl-u-big{color:var(--rl-strong);font-size:22px;font-weight:700;line-height:1.2;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}\n.rl-u-plot{position:relative;padding-top:16px;border:1px solid var(--rl-line);border-radius:8px;background:var(--rl-bg);overflow:hidden}\n.rl-u-scale{position:absolute;top:2px;left:6px;color:var(--rl-weak);font-size:10.5px;font-variant-numeric:tabular-nums}\n.rl-u-empty{position:absolute;inset:0;display:grid;place-items:center;padding:0 12px;color:var(--rl-weak);font-size:11.5px;text-align:center}\n.rl-u-days{display:grid;margin-top:3px;color:var(--rl-weak);font-size:10px;text-align:center;white-space:nowrap}\n.rl .rl-u-list{margin:0;padding:0;list-style:none;border:1px solid var(--rl-line);border-radius:10px;background:var(--rl-bg);overflow:hidden}\n.rl-u-list>li+li{border-top:1px solid var(--rl-line)}\n.rl-u-item{display:grid;gap:1px;width:100%;min-width:0;padding:7px 10px;border:0;background:none;color:inherit;font:inherit;text-align:left}\nbutton.rl-u-item{cursor:pointer}\nbutton.rl-u-item:hover{background:var(--rl-hover)}\n.rl-u-line{display:flex;align-items:baseline;gap:8px;min-width:0}\n.rl-u-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--rl-strong);font-weight:550}\n.rl-u-money{flex:none;margin-left:auto;color:var(--rl-strong);font-weight:650;font-variant-numeric:tabular-nums}\n.rl-u-when{flex:none;color:var(--rl-weak);font-size:11.5px;font-variant-numeric:tabular-nums}\n.rl-u-small{color:var(--rl-weak);font-size:11.5px;overflow-wrap:anywhere}\n.rl-u-badge{padding:0 7px;border-radius:99px;background:var(--rl-inset);color:var(--rl-strong);font-size:11px;font-weight:600}\n";
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Styles for the Relay panel. Everything is scoped under `.rl` so nothing leaks into the host, and every colour comes from the host's own theme
3
+ * variables with a neutral fallback, so the panel follows light and dark themes. Plain CSS in a string because the GUI bundle has no CSS pipeline.
4
+ */
5
+ export const panelCss = `
6
+ .rl{--rl-fg:var(--text-base,#2b2f36);--rl-strong:var(--text-strong,#14171c);--rl-weak:var(--text-weak,#6e7681);--rl-bg:var(--background-base,#fff);
7
+ --rl-card:var(--surface-raised-base,rgba(127,127,127,.07));--rl-inset:var(--surface-inset-base,rgba(127,127,127,.11));--rl-hover:var(--surface-base-hover,rgba(127,127,127,.15));
8
+ --rl-line:var(--border-weak-base,rgba(127,127,127,.22));--rl-line2:var(--border-base,rgba(127,127,127,.38));--rl-accent:var(--text-interactive-base,#4f7cff);
9
+ --rl-ok:var(--icon-success-base,#2ea36a);--rl-warn:var(--icon-warning-base,#d99a1c);--rl-bad:var(--icon-critical-base,#d9483b);--rl-wait:#8a7cf0;
10
+ display:flex;flex-direction:column;height:100%;min-height:0;color:var(--rl-fg);font-size:13px;line-height:1.4}
11
+ .rl *{box-sizing:border-box}
12
+ .rl h2,.rl h3,.rl p{margin:0}
13
+ .rl-top{display:grid;gap:10px;padding:14px 14px 0;flex:none}
14
+ .rl-brand{display:flex;align-items:center;gap:8px;min-width:0}
15
+ .rl-logo{flex:none;width:22px;height:22px;border-radius:7px;display:grid;place-items:center;color:#fff;font-size:12px;font-weight:700;background:linear-gradient(135deg,var(--rl-accent),#9b6bff)}
16
+ .rl-name{font-size:15px;font-weight:650;color:var(--rl-strong)}
17
+ .rl-tag{margin-left:auto;color:var(--rl-weak);font-size:11px;white-space:nowrap}
18
+ .rl-body{flex:1;min-height:0;overflow:auto;display:grid;grid-template-columns:minmax(0,1fr);grid-auto-rows:max-content;gap:12px;align-content:start;padding:12px 14px 18px}
19
+ .rl-card{display:grid;grid-template-columns:minmax(0,1fr);gap:10px;padding:12px;border:1px solid var(--rl-line);border-radius:12px;background:var(--rl-card)}
20
+ .rl-row{display:flex;align-items:center;justify-content:space-between;gap:8px;min-width:0}
21
+ .rl-inline{display:flex;align-items:center;gap:6px}
22
+ .rl-inline .rl-in{flex:1;min-width:0}
23
+ .rl-hint{margin:0;color:var(--rl-weak);font-size:11.5px;overflow-wrap:anywhere}
24
+ .rl-in{width:100%;min-width:0;padding:7px 9px;border:1px solid var(--rl-line);border-radius:8px;background:var(--rl-inset);color:var(--rl-strong);font:inherit;outline:none}
25
+ .rl-in:focus{border-color:var(--rl-accent);box-shadow:0 0 0 3px color-mix(in srgb,var(--rl-accent) 22%,transparent)}
26
+ .rl-in:disabled{opacity:.55}
27
+ .rl-btn{appearance:none;padding:6px 12px;border:1px solid var(--rl-line2);border-radius:8px;background:transparent;color:var(--rl-fg);font:inherit;font-weight:550;cursor:pointer;white-space:nowrap}
28
+ .rl-btn:hover:not(:disabled){background:var(--rl-hover)}
29
+ .rl-btn:disabled{opacity:.5;cursor:default}
30
+ .rl-btn.sm{padding:3px 9px;font-size:12px}
31
+ .rl button:focus-visible,.rl summary:focus-visible,.rl input:focus-visible,.rl select:focus-visible{outline:2px solid var(--rl-accent);outline-offset:2px}
32
+ .rl-note{--c:var(--rl-accent);display:grid;grid-template-columns:minmax(0,1fr);gap:2px;padding:8px 10px;border:1px solid color-mix(in srgb,var(--c) 32%,transparent);border-radius:10px;background:color-mix(in srgb,var(--c) 11%,transparent);font-size:12px;overflow-wrap:anywhere}
33
+ .rl-note.n-bad{--c:var(--rl-bad)}.rl-note.n-warn{--c:var(--rl-warn)}.rl-note.n-ok{--c:var(--rl-ok)}
34
+ .rl-pre{margin:6px 0 0;padding:8px;max-height:220px;overflow:auto;border-radius:8px;background:var(--rl-inset);font-size:11px;white-space:pre-wrap;overflow-wrap:anywhere}
35
+ .rl-acc{border:1px solid var(--rl-line);border-radius:12px;background:var(--rl-card)}
36
+ .rl-acc>summary{display:flex;align-items:center;gap:8px;padding:10px 12px;border-radius:11px;color:var(--rl-strong);font-weight:600;cursor:pointer;list-style:none}
37
+ .rl-acc>summary::-webkit-details-marker{display:none}
38
+ .rl-acc>summary::after{content:"\\203A";margin-left:auto;color:var(--rl-weak);transition:transform .15s}
39
+ .rl-acc[open]>summary::after{transform:rotate(90deg)}
40
+ .rl-acc[open]>summary{border-radius:11px 11px 0 0}
41
+ .rl-acc>summary:hover{background:var(--rl-hover)}
42
+ .rl-sub{margin-left:2px;color:var(--rl-weak);font-size:11px;font-weight:400;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
43
+ .rl-acc-body{display:grid;grid-template-columns:minmax(0,1fr);gap:10px;padding:4px 12px 12px}
44
+ .rl-pick{display:grid;grid-template-columns:minmax(0,1fr);gap:4px}
45
+ .rl-pick .rl-chip{justify-self:start}
46
+ .rl-chip{display:inline-flex;align-items:center;gap:6px;max-width:100%;padding:3px 4px 3px 10px;border:1px solid var(--rl-line);border-radius:99px;background:var(--rl-inset);font-size:12px}
47
+ .rl-chip.bad{border-color:color-mix(in srgb,var(--rl-bad) 50%,transparent)}
48
+ .rl-chip-t{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
49
+ .rl-chip small{color:var(--rl-bad)}
50
+ .rl-x{appearance:none;flex:none;width:18px;height:18px;padding:0;border:0;border-radius:50%;background:transparent;color:var(--rl-weak);font:inherit;line-height:1;cursor:pointer}
51
+ .rl-x:hover:not(:disabled){background:var(--rl-hover);color:var(--rl-strong)}
52
+ .rl-role{display:block;color:var(--rl-strong);font-weight:650}
53
+ .rl .rl-plain{margin:0;padding:0;list-style:none;display:grid;gap:6px}
54
+ .rl-add{justify-self:start}
55
+ .rl-inline .rl-effort{flex:none;width:auto;padding:3px 6px;font-size:12px}
56
+ .rl-picker{display:grid;grid-template-columns:minmax(0,1fr);gap:6px}
57
+ .rl-table-wrap{max-height:320px;overflow:auto;border:1px solid var(--rl-line);border-radius:8px;background:var(--rl-bg)}
58
+ .rl-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:fixed}
59
+ .rl-table th:nth-child(2){width:74px}.rl-table th:nth-child(3){width:46px;text-align:right;white-space:nowrap}.rl-table th:nth-child(4){width:42px;text-align:right;white-space:nowrap}.rl-table th:nth-child(5){width:46px}
60
+ .rl-table th{position:sticky;top:0;z-index:1;padding:5px 4px;border-bottom:1px solid var(--rl-line2);background:var(--rl-bg);color:var(--rl-weak);font-size:11px;font-weight:600;text-align:left;vertical-align:bottom}
61
+ .rl-table td{padding:5px 4px;border-top:1px solid var(--rl-line);vertical-align:middle;overflow-wrap:anywhere}
62
+ .rl-table tbody tr:first-child td{border-top:0}
63
+ .rl-table tbody tr:hover{background:var(--rl-hover)}
64
+ .rl-table td:nth-child(3),.rl-table td:nth-child(4){text-align:right;white-space:nowrap}
65
+ .rl-table td:last-child{text-align:right}
66
+ .rl-table small{display:block;color:var(--rl-weak);font-size:11px;font-weight:400}
67
+ .rl-t-name{color:var(--rl-strong);font-weight:550}
68
+ .rl-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
69
+ .rl-seg{display:flex;flex-wrap:wrap;gap:4px;align-items:center}
70
+ .rl-seg .rl-btn[aria-pressed=true]{background:var(--rl-inset);border-color:var(--rl-accent);color:var(--rl-strong)}
71
+ .rl-right{margin-left:auto}
72
+ .rl-filters{display:grid;grid-template-columns:repeat(auto-fill,minmax(118px,1fr));gap:6px}
73
+ .rl-chart{display:block;width:100%;height:110px}
74
+ .rl-chart g:hover rect[fill=transparent]{fill:var(--rl-hover)}
75
+ .rl-legend{display:flex;flex-wrap:wrap;gap:4px 10px;color:var(--rl-weak);font-size:11px}
76
+ .rl-dot{display:inline-block;width:8px;height:8px;border-radius:2px;margin-right:4px;vertical-align:baseline}
77
+ .rl-u-tiles{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
78
+ .rl-u-tile{display:grid;gap:1px;align-content:start;min-width:0;padding:10px 12px;border:1px solid var(--rl-line);border-radius:12px;background:var(--rl-card)}
79
+ .rl-u-big{color:var(--rl-strong);font-size:22px;font-weight:700;line-height:1.2;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}
80
+ .rl-u-plot{position:relative;padding-top:16px;border:1px solid var(--rl-line);border-radius:8px;background:var(--rl-bg);overflow:hidden}
81
+ .rl-u-scale{position:absolute;top:2px;left:6px;color:var(--rl-weak);font-size:10.5px;font-variant-numeric:tabular-nums}
82
+ .rl-u-empty{position:absolute;inset:0;display:grid;place-items:center;padding:0 12px;color:var(--rl-weak);font-size:11.5px;text-align:center}
83
+ .rl-u-days{display:grid;margin-top:3px;color:var(--rl-weak);font-size:10px;text-align:center;white-space:nowrap}
84
+ .rl .rl-u-list{margin:0;padding:0;list-style:none;border:1px solid var(--rl-line);border-radius:10px;background:var(--rl-bg);overflow:hidden}
85
+ .rl-u-list>li+li{border-top:1px solid var(--rl-line)}
86
+ .rl-u-item{display:grid;gap:1px;width:100%;min-width:0;padding:7px 10px;border:0;background:none;color:inherit;font:inherit;text-align:left}
87
+ button.rl-u-item{cursor:pointer}
88
+ button.rl-u-item:hover{background:var(--rl-hover)}
89
+ .rl-u-line{display:flex;align-items:baseline;gap:8px;min-width:0}
90
+ .rl-u-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--rl-strong);font-weight:550}
91
+ .rl-u-money{flex:none;margin-left:auto;color:var(--rl-strong);font-weight:650;font-variant-numeric:tabular-nums}
92
+ .rl-u-when{flex:none;color:var(--rl-weak);font-size:11.5px;font-variant-numeric:tabular-nums}
93
+ .rl-u-small{color:var(--rl-weak);font-size:11.5px;overflow-wrap:anywhere}
94
+ .rl-u-badge{padding:0 7px;border-radius:99px;background:var(--rl-inset);color:var(--rl-strong);font-size:11px;font-weight:600}
95
+ `;
@@ -0,0 +1,6 @@
1
+ import { Plugin } from '@opencode/plugin';
2
+ export declare function createRuntime(context: Plugin.Context): Promise<{
3
+ dispose: () => Promise<void>;
4
+ }>;
5
+ declare const _default: Plugin.Plugin;
6
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ import { Plugin } from '@opencode/plugin';
2
+ import { registerRpc } from './rpc.js';
3
+ import { listProjectModels } from './inventory.js';
4
+ import { relayCommand, fileSize } from './relay-command.js';
5
+ import { reviewHelperHook } from './review-helper.js';
6
+ import { relayAutoHook, relayCompactionHook, relayReplyHook } from './relay-auto.js';
7
+ import { decide } from './decider.js';
8
+ import { storedAaModels } from './artificial-analysis.js';
9
+ export async function createRuntime(context) {
10
+ const disposers = [];
11
+ const dispose = async () => {
12
+ let failure;
13
+ for (const undo of disposers.reverse()) {
14
+ try {
15
+ await undo();
16
+ }
17
+ catch (error) {
18
+ failure ??= error;
19
+ }
20
+ }
21
+ if (failure)
22
+ throw failure;
23
+ };
24
+ try {
25
+ const relayDeps = {
26
+ session: context.session, store: context.storage, chatModels: () => listProjectModels(context), fileSize,
27
+ decide: (decider, input) => decide({ decisions: request => context.experimental.generate.decisions(request) }, decider, input),
28
+ };
29
+ // `/relay` in a chat. The host runs the callback again whenever it rebuilds its commands, so the command (and its per-chat queue) is made once.
30
+ const relay = relayCommand(relayDeps);
31
+ const command = await context.command.transform(editor => editor.add(relay));
32
+ disposers.push(() => command.dispose());
33
+ // A helper whose task is a check of work starts on a Review model. The hook sees every tool call and leaves all others alone.
34
+ const helper = await context.tool.hook('execute.before', reviewHelperHook(relayDeps));
35
+ disposers.push(() => helper.dispose());
36
+ // The switch: in a chat where `/relay on` turned it on, every message is placed before it goes out. The hook sees every message and never throws.
37
+ const auto = await context.session.hook('prompt', relayAutoHook(relayDeps));
38
+ disposers.push(() => auto.dispose());
39
+ // When any chat has finished its work, what the reply to a placed message took is kept with its record, and every chat's newest messages
40
+ // get their usage records (numbers only). No model is asked.
41
+ const usage = { ...relayDeps, borrowedPrices: () => storedAaModels(context.storage), log: context.storage, project: context.location.directory };
42
+ const replies = await context.session.hook('experimental.idle', relayReplyHook(usage));
43
+ disposers.push(() => replies.dispose());
44
+ // Just before a long chat is summarized, the usage records so far are kept, since the chat is listed from the summary on afterwards.
45
+ const compaction = await context.session.hook('compaction', relayCompactionHook(usage));
46
+ disposers.push(() => compaction.dispose());
47
+ const rpc = await registerRpc(context);
48
+ disposers.push(() => rpc.dispose());
49
+ }
50
+ catch (error) {
51
+ await dispose().catch(() => undefined);
52
+ throw error;
53
+ }
54
+ return { dispose };
55
+ }
56
+ export default Plugin.define({
57
+ id: 'relay-opencode',
58
+ async setup(context) {
59
+ const runtime = await createRuntime(context);
60
+ return () => runtime.dispose();
61
+ },
62
+ });
@@ -0,0 +1,38 @@
1
+ export declare const INDEX_SOURCE = "Artificial Analysis Intelligence Index, from OpenRouter's public model list";
2
+ export type IndexTable = Map<string, {
3
+ id: string;
4
+ index: number;
5
+ }>;
6
+ /** One form for a model's id or name: no vendor, lower case, no variant suffix, and dashes for dots, colons, underscores and spaces. */
7
+ export declare function modelKey(text: string): string;
8
+ /** The models in OpenRouter's reply that carry an index, by key. A key that two different models would share is left out. */
9
+ export declare function indexTable(reply: unknown): IndexTable;
10
+ /** A model's index: by its id or its name, then by the one listed model whose key ends in its key. Null when none fits clearly. */
11
+ export declare function indexFor(model: {
12
+ id: string;
13
+ name: string;
14
+ }, table: IndexTable): {
15
+ index: number;
16
+ matched: string;
17
+ } | null;
18
+ /** Fetches OpenRouter's public model list (one GET, no key, nothing about the person) and keeps the models that carry an index. */
19
+ export declare function fetchIndexTable(fetcher?: typeof fetch, ms?: number): Promise<IndexTable>;
20
+ type Cache = {
21
+ fetchedAt: string;
22
+ rows: [string, string, number][];
23
+ };
24
+ type CacheStore = {
25
+ get(key: string): Promise<unknown>;
26
+ set(key: string, value: Cache): Promise<void>;
27
+ };
28
+ /** The stored table at any age, from storage alone and never the network, for Relay's own choice while a message is placed. Empty when there is no readable copy. */
29
+ export declare function storedIndexTable(store: {
30
+ get(key: string): Promise<unknown>;
31
+ }): Promise<IndexTable>;
32
+ /** The index table: the stored copy while it is under a day old, else a fresh fetch, stored; when that fails, the older copy with a note. */
33
+ export declare function loadIndexTable(store: CacheStore, fetcher: typeof fetch, now: number): Promise<{
34
+ table: IndexTable;
35
+ fetchedAt: string | null;
36
+ note: string | null;
37
+ }>;
38
+ export {};