relay-opencode 0.0.0-stage → 0.1.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.
@@ -0,0 +1,57 @@
1
+ import { Rpc } from '@opencode/plugin/rpc';
2
+ const choice = { type: 'object', properties: { providerID: { type: 'string' }, id: { type: 'string' }, variant: { anyOf: [{ type: 'string' }, { type: 'null' }] } }, required: ['providerID', 'id', 'variant'], additionalProperties: false };
3
+ const nullableString = { anyOf: [{ type: 'string' }, { type: 'null' }] };
4
+ const prices = { inputPerMillion: nullableString, outputPerMillion: nullableString, cacheReadPerMillion: nullableString, cacheWritePerMillion: nullableString };
5
+ const priceNames = ['inputPerMillion', 'outputPerMillion', 'cacheReadPerMillion', 'cacheWritePerMillion'];
6
+ /** One model as the panel sees it: display fields only, never the host's record. Prices are USD for one million tokens; null is unknown. `steps` are the prices for chats over a size. */
7
+ const modelItem = {
8
+ type: 'object', properties: {
9
+ providerID: { type: 'string' }, id: { type: 'string' }, name: { type: 'string' }, enabled: { type: 'boolean' }, status: { type: 'string' },
10
+ variants: { type: 'array', items: { type: 'string' } },
11
+ capabilities: { type: 'object', properties: { input: { type: 'array', items: { type: 'string' } }, output: { type: 'array', items: { type: 'string' } }, tools: { type: 'boolean' } }, required: ['input', 'output', 'tools'], additionalProperties: false },
12
+ limit: { type: 'object', properties: { context: { type: 'number' }, output: { type: 'number' } }, required: ['context', 'output'], additionalProperties: false },
13
+ cost: { type: 'object', properties: { ...prices, tiered: { type: 'boolean' }, steps: { type: 'array', items: { type: 'object', properties: { above: { type: 'number' }, ...prices }, required: ['above', ...priceNames], additionalProperties: false } } }, required: [...priceNames, 'tiered', 'steps'], additionalProperties: false },
14
+ }, required: ['providerID', 'id', 'name', 'enabled', 'status', 'variants', 'capabilities', 'limit', 'cost'], additionalProperties: false,
15
+ };
16
+ // One set of settings for every project (the host shares plugin storage), the last decisions, and the panel's test box.
17
+ const nullableNumber = { anyOf: [{ type: 'number' }, { type: 'null' }] };
18
+ const nullableMode = { anyOf: [{ type: 'string', enum: ['plan', 'execute', 'review'] }, { type: 'null' }] };
19
+ const nullableChoice = { anyOf: [choice, { type: 'null' }] };
20
+ /** A model chosen for a mode, with the person's "use it for" line. The line is optional in what the panel sends and always present in what comes back. */
21
+ const modeChoice = { type: 'object', properties: { ...choice.properties, useFor: { type: 'string' } }, required: ['providerID', 'id', 'variant', 'useFor'], additionalProperties: false };
22
+ const modeChoiceInput = { type: 'object', properties: { ...choice.properties, useFor: { type: 'string' } }, required: ['providerID', 'id', 'variant'], additionalProperties: false };
23
+ const modeLists = { type: 'object', properties: { plan: { type: 'array', items: modeChoice }, execute: { type: 'array', items: modeChoice }, review: { type: 'array', items: modeChoice } }, required: ['plan', 'execute', 'review'], additionalProperties: false };
24
+ const modeListsInput = { type: 'object', properties: { plan: { type: 'array', items: modeChoiceInput }, execute: { type: 'array', items: modeChoiceInput }, review: { type: 'array', items: modeChoiceInput } }, required: ['plan', 'execute', 'review'], additionalProperties: false };
25
+ /** What the reply to a placed message took; null until the chat has answered it. */
26
+ const reply = { type: 'object', properties: { requests: { type: 'number' }, fresh: { type: 'number' }, cached: { type: 'number' }, costUsd: nullableString, seconds: nullableNumber }, required: ['requests', 'fresh', 'cached', 'costUsd', 'seconds'], additionalProperties: false };
27
+ const decision = { type: 'object', properties: { at: { type: 'string' }, sessionID: { type: 'string' }, kind: { type: 'string', enum: ['chat', 'helper'] }, mode: nullableMode, confidence: nullableNumber, fit: nullableNumber, model: nullableString, ms: { type: 'number' }, costUsd: nullableString, note: nullableString, messageID: nullableString, reply: { anyOf: [reply, { type: 'null' }] } }, required: ['at', 'sessionID', 'kind', 'mode', 'confidence', 'fit', 'model', 'ms', 'costUsd', 'note', 'messageID', 'reply'], additionalProperties: false };
28
+ const relayOutput = { type: 'object', properties: {
29
+ directory: { type: 'string' },
30
+ settings: { type: 'object', properties: { revision: { type: 'integer', minimum: 0 }, modes: modeLists, decider: nullableChoice }, required: ['revision', 'modes', 'decider'], additionalProperties: false },
31
+ decisions: { type: 'array', items: decision }, deciders: { type: 'array', items: modelItem },
32
+ checks: { type: 'object', properties: { active: { type: 'boolean' }, note: nullableString }, required: ['active', 'note'], additionalProperties: false },
33
+ }, required: ['directory', 'settings', 'decisions', 'deciders', 'checks'], additionalProperties: false };
34
+ /** The host reports any exception thrown by a handler as an opaque "RPC call failed", so a refusal the panel must show is returned as this declared error instead. */
35
+ const errors = { rejected: { type: 'object', properties: {}, additionalProperties: false } };
36
+ const nothing = { type: 'object', properties: {}, additionalProperties: false };
37
+ export const RelayRpc = Rpc.define({
38
+ id: 'relay-opencode',
39
+ events: {},
40
+ methods: {
41
+ getRelay: { errors, input: nothing, output: relayOutput },
42
+ saveRelay: { errors, input: { type: 'object', properties: { revision: { type: 'integer', minimum: 0 }, modes: modeListsInput, decider: nullableChoice }, required: ['revision', 'modes', 'decider'], additionalProperties: false }, output: relayOutput },
43
+ /** The pill: one chat's switch, that chat's newest record, and whether a decider is chosen at all. */
44
+ getRelayChat: { errors, input: { type: 'object', properties: { sessionID: { type: 'string' } }, required: ['sessionID'], additionalProperties: false }, output: { type: 'object', properties: { on: { type: 'boolean' }, last: { anyOf: [decision, { type: 'null' }] }, decider: { type: 'boolean' } }, required: ['on', 'last', 'decider'], additionalProperties: false } },
45
+ /** The panel's Recent choices, newest first. Storage only, so the panel can ask every few seconds. */
46
+ getRelayDecisions: { errors, input: nothing, output: { type: 'object', properties: { directory: { type: 'string' }, decisions: { type: 'array', items: decision } }, required: ['directory', 'decisions'], additionalProperties: false } },
47
+ setRelayChat: { errors, input: { type: 'object', properties: { sessionID: { type: 'string' }, on: { type: 'boolean' } }, required: ['sessionID', 'on'], additionalProperties: false }, output: { type: 'object', properties: { on: { type: 'boolean' } }, required: ['on'], additionalProperties: false } },
48
+ /** What Relay would do with a sample message: the mode after the 0.6 rule, the model it would pick, and the note. Nothing is switched, sent or recorded. */
49
+ testDecider: { errors, input: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'], additionalProperties: false }, output: { type: 'object', properties: { directory: { type: 'string' }, mode: nullableMode, confidence: nullableNumber, model: nullableString, fit: nullableNumber, ms: { type: 'number' }, costUsd: nullableString, note: nullableString }, required: ['directory', 'mode', 'confidence', 'model', 'fit', 'ms', 'costUsd', 'note'], additionalProperties: false } },
50
+ listModels: { errors, input: nothing, output: { type: 'object', properties: { directory: { type: 'string' }, models: { type: 'array', items: modelItem } }, required: ['directory', 'models'], additionalProperties: false } },
51
+ /** The intelligence index of each listed model that could be matched, with where it came from, when it was fetched, and why it may be old or missing. */
52
+ listIntelligence: { errors, input: nothing, output: { type: 'object', properties: {
53
+ directory: { type: 'string' }, source: { type: 'string' }, fetchedAt: nullableString, note: nullableString,
54
+ 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: false } },
55
+ }, required: ['directory', 'source', 'fetchedAt', 'note', 'scores'], additionalProperties: false } },
56
+ },
57
+ });
@@ -0,0 +1,7 @@
1
+ /** A price as the host reports it (a number of USD) becomes a USD string. Anything that is not a plain amount, or is too small to show in six decimals, is unknown. */
2
+ export declare function usdString(value: unknown): string | null;
3
+ /** A USD string as a whole number of trillionths of a dollar, so that prices compare exactly. Money is never a float. */
4
+ export declare function parseUsd(value: string): bigint;
5
+ export declare function formatUsd(value: bigint): string;
6
+ /** An amount for a sentence: rounded to the cent, and "under $0.01" when that leaves nothing. */
7
+ export declare function aboutUsd(value: bigint): string;
package/dist/costs.js ADDED
@@ -0,0 +1,25 @@
1
+ const SCALE = 1000000000000n;
2
+ /** A price as the host reports it (a number of USD) becomes a USD string. Anything that is not a plain amount, or is too small to show in six decimals, is unknown. */
3
+ export function usdString(value) {
4
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value >= 1e21)
5
+ return null;
6
+ const text = value.toFixed(6).replace(/\.?0+$/, '');
7
+ return text === '0' && value !== 0 ? null : text;
8
+ }
9
+ /** A USD string as a whole number of trillionths of a dollar, so that prices compare exactly. Money is never a float. */
10
+ export function parseUsd(value) {
11
+ if (!/^(?:0|[1-9]\d*)(?:\.\d{1,12})?$/.test(value))
12
+ throw new Error('Invalid USD amount');
13
+ const [whole, fraction = ''] = value.split('.');
14
+ return BigInt(whole) * SCALE + BigInt(fraction.padEnd(12, '0'));
15
+ }
16
+ export function formatUsd(value) {
17
+ const whole = value / SCALE;
18
+ const fraction = (value % SCALE).toString().padStart(12, '0').replace(/0+$/, '');
19
+ return fraction ? `${whole}.${fraction}` : `${whole}`;
20
+ }
21
+ /** An amount for a sentence: rounded to the cent, and "under $0.01" when that leaves nothing. */
22
+ export function aboutUsd(value) {
23
+ const cents = (value + SCALE / 200n) / (SCALE / 100n);
24
+ return cents === 0n ? 'under $0.01' : `about $${cents / 100n}.${(cents % 100n).toString().padStart(2, '0')}`;
25
+ }
@@ -0,0 +1,49 @@
1
+ import { type Mode } from './relay-store.js';
2
+ import { type DeciderAnswer } from './router.js';
3
+ import type { ModelChoice } from './settings.js';
4
+ export declare const MAX_CHARS = 4000;
5
+ export declare const TIMEOUT_MS = 5000;
6
+ export declare const MAX_FILE_NAMES = 10;
7
+ export type FileFact = {
8
+ name: string;
9
+ bytes: number | null;
10
+ };
11
+ export type DecideInput = {
12
+ kind: 'chat' | 'helper';
13
+ text: string;
14
+ agent: string | null;
15
+ files: readonly FileFact[];
16
+ images: number;
17
+ lines: Partial<Record<Mode, readonly string[]>>;
18
+ };
19
+ export type DecisionsRequest = {
20
+ model: {
21
+ providerID: string;
22
+ id: string;
23
+ variant?: string;
24
+ };
25
+ input: {
26
+ type: 'text';
27
+ text: string;
28
+ }[];
29
+ questions: {
30
+ type: 'choice';
31
+ name: string;
32
+ instructions: string;
33
+ choices: {
34
+ value: string;
35
+ description: string;
36
+ }[];
37
+ }[];
38
+ };
39
+ export type DecisionsHost = {
40
+ decisions(request: DecisionsRequest): Promise<unknown>;
41
+ };
42
+ /** Text over the limit keeps its first and last half, and is never cut inside a two-unit character. */
43
+ export declare function capText(text: string): string;
44
+ export declare function buildDecisionRequest(decider: ModelChoice, input: DecideInput): DecisionsRequest;
45
+ export declare const LATE: unique symbol;
46
+ /** What the work gives, or LATE when it takes longer than `ms`. Work that is given up on cannot be stopped; the race keeps a handler on it, so its late failure is not an unhandled rejection. */
47
+ export declare function within<T>(work: () => T | Promise<T>, ms: number): Promise<T | typeof LATE>;
48
+ /** Asks the decider once and never throws. A late answer and a late failure are both dropped. */
49
+ export declare function decide(host: DecisionsHost, decider: ModelChoice | null, input: DecideInput, timeoutMs?: number): Promise<DeciderAnswer>;
@@ -0,0 +1,109 @@
1
+ import { usdString } from './costs.js';
2
+ import { modes } from './relay-store.js';
3
+ import { brief, safeHead, MAX_LINES } from './router.js';
4
+ // One request to a decision model: which mode fits the text, and, for each mode that has a choice to make, which "use it for" line fits it.
5
+ // The decider is given the text, the names and sizes of attached files and the lines. Never file contents, pictures, earlier messages, model names or prices.
6
+ // Its requests are not reserved in the budget ledger (the owner, 2026-11-14); what is sent is capped instead. Nothing here may import from `node:`.
7
+ export const MAX_CHARS = 4000;
8
+ export const TIMEOUT_MS = 5000;
9
+ export const MAX_FILE_NAMES = 10;
10
+ const MAX_NAME = 80;
11
+ /** Text over the limit keeps its first and last half, and is never cut inside a two-unit character. */
12
+ export function capText(text) {
13
+ if (text.length <= MAX_CHARS)
14
+ return text;
15
+ const head = safeHead(text, MAX_CHARS / 2);
16
+ let tail = text.slice(-MAX_CHARS / 2);
17
+ if (/^[\uDC00-\uDFFF]/.test(tail))
18
+ tail = tail.slice(1);
19
+ return `${head}\n[...]\n${tail}`;
20
+ }
21
+ const flat = (text, max) => safeHead(text.replace(/[\s\x00-\x1f\x7f]+/g, ' ').trim(), max);
22
+ /** Only the last part of a path is sent, so the name of a home folder never leaves the machine. */
23
+ const fileName = (name) => flat(name.split(/[\\/]/).pop() ?? '', MAX_NAME) || 'file';
24
+ const size = (bytes) => bytes === null ? 'size unknown' : bytes < 1000 ? `${bytes} B` : bytes < 1_000_000 ? `${Math.round(bytes / 1000)} kB` : `${Math.round(bytes / 1_000_000)} MB`;
25
+ /** What the chat's agent can do, so that "ok, do it" after a plan reads as a go-ahead. Never its name: "plan" is also an answer, and told
26
+ * "The chat is on the agent: plan" a real decider hedged on clear fix requests (16 Nov). Other agents are unknown here, so nothing is said. */
27
+ const agentLine = (agent) => agent === 'plan' ? 'Before this message the chat was on a read-only agent, which explains and plans and cannot change files. '
28
+ : agent === 'build' ? 'Before this message the chat was on an agent that can change files. ' : '';
29
+ function describe(input) {
30
+ const text = capText(input.text);
31
+ if (input.kind === 'helper')
32
+ return `A task that a model is handing to a helper: "${text}"`;
33
+ const shown = input.files.slice(0, MAX_FILE_NAMES).map(file => `${fileName(file.name)} (${size(file.bytes)})`).join(', '), more = input.files.length - MAX_FILE_NAMES;
34
+ const files = input.files.length ? `${shown}${more > 0 ? ` and ${more} more` : ''}` : 'none';
35
+ return `The person's message: "${text}"\n${agentLine(input.agent)}Attached files: ${files}. Attached pictures: ${input.images}.`;
36
+ }
37
+ const modeQuestion = {
38
+ type: 'choice', name: 'mode',
39
+ instructions: 'Which mode fits the text? Choose execute only when it clearly asks to change, create, fix or run something now. Choose review when it asks to check existing work and report, with nothing to change. Otherwise choose plan.',
40
+ choices: [
41
+ { value: 'plan', description: 'Think, explain, investigate, design or plan. Nothing is changed.' },
42
+ { value: 'execute', description: 'Write, change, create, fix or run something now.' },
43
+ { value: 'review', description: 'Check existing work for mistakes and risks, and report them.' },
44
+ ],
45
+ };
46
+ const lineQuestion = (mode, lines) => ({
47
+ type: 'choice', name: `${mode}_line`,
48
+ instructions: 'Which description of work fits the text best? Choose none when no description fits clearly.',
49
+ choices: [...lines.slice(0, MAX_LINES).map((line, index) => ({ value: String(index + 1), description: line })), { value: 'none', description: 'None of these fits clearly.' }],
50
+ });
51
+ export function buildDecisionRequest(decider, input) {
52
+ return {
53
+ model: { providerID: decider.providerID, id: decider.id, ...(decider.variant === null ? {} : { variant: decider.variant }) },
54
+ input: [{ type: 'text', text: describe(input) }],
55
+ questions: [{ ...modeQuestion, choices: [...modeQuestion.choices] }, ...modes.flatMap(mode => input.lines[mode]?.length ? [lineQuestion(mode, input.lines[mode])] : [])],
56
+ };
57
+ }
58
+ const sure = (value) => typeof value === 'number' && value >= 0 && value <= 1;
59
+ /** The mode answer must be exactly right, or there is no answer. A line answer that cannot be used is left out, and the router then falls back by its rule. */
60
+ function read(result, input, ms) {
61
+ const unreadable = { kind: 'none', reason: "the decider's answer could not be read", ms };
62
+ const answers = result?.answers;
63
+ if (!Array.isArray(answers))
64
+ return unreadable;
65
+ const named = (name) => answers.find(item => item !== null && typeof item === 'object' && item.name === name);
66
+ const mode = named('mode');
67
+ if (mode?.type === 'error')
68
+ return { kind: 'none', reason: `the decider gave no answer: ${brief(typeof mode.reason === 'string' && mode.reason.trim() ? mode.reason : mode.message)}`, ms };
69
+ const found = modes.find(item => item === mode?.choice);
70
+ if (mode?.type !== 'choice' || !found || !sure(mode.confidence))
71
+ return unreadable;
72
+ const lines = {};
73
+ for (const item of modes) {
74
+ const sent = Math.min(input.lines[item]?.length ?? 0, MAX_LINES), line = named(`${item}_line`);
75
+ if (!sent || line?.type !== 'choice' || !sure(line.confidence))
76
+ continue;
77
+ if (line.choice === 'none')
78
+ lines[item] = { index: null, confidence: line.confidence };
79
+ else if (typeof line.choice === 'string' && /^[1-8]$/.test(line.choice) && Number(line.choice) <= sent)
80
+ lines[item] = { index: Number(line.choice) - 1, confidence: line.confidence };
81
+ }
82
+ return { kind: 'answer', mode: found, confidence: mode.confidence, lines, ms, costUsd: usdString(result.cost) };
83
+ }
84
+ export const LATE = Symbol('late');
85
+ /** What the work gives, or LATE when it takes longer than `ms`. Work that is given up on cannot be stopped; the race keeps a handler on it, so its late failure is not an unhandled rejection. */
86
+ export async function within(work, ms) {
87
+ let timer;
88
+ try {
89
+ return await Promise.race([Promise.resolve().then(work), new Promise(done => { timer = setTimeout(() => done(LATE), ms); })]);
90
+ }
91
+ finally {
92
+ clearTimeout(timer);
93
+ }
94
+ }
95
+ /** Asks the decider once and never throws. A late answer and a late failure are both dropped. */
96
+ export async function decide(host, decider, input, timeoutMs = TIMEOUT_MS) {
97
+ if (!decider)
98
+ return { kind: 'none', reason: 'no decider chosen', ms: 0 };
99
+ const started = Date.now();
100
+ try {
101
+ const result = await within(() => host.decisions(buildDecisionRequest(decider, input)), timeoutMs);
102
+ if (result === LATE)
103
+ return { kind: 'none', reason: `the decider took longer than ${timeoutMs / 1000} seconds`, ms: Date.now() - started };
104
+ return read(result, input, Date.now() - started);
105
+ }
106
+ catch (error) {
107
+ return { kind: 'none', reason: `the decider gave no answer: ${brief(error)}`, ms: Date.now() - started };
108
+ }
109
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("solid-js/web"),o=require("solid-js"),_e=require("@opencode/plugin/gui"),ut=require("@opencode/plugin/rpc"),Ne={type:"object",properties:{providerID:{type:"string"},id:{type:"string"},variant:{anyOf:[{type:"string"},{type:"null"}]}},required:["providerID","id","variant"],additionalProperties:!1},M={anyOf:[{type:"string"},{type:"null"}]},We={inputPerMillion:M,outputPerMillion:M,cacheReadPerMillion:M,cacheWritePerMillion:M},He=["inputPerMillion","outputPerMillion","cacheReadPerMillion","cacheWritePerMillion"],nt={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:{...We,tiered:{type:"boolean"},steps:{type:"array",items:{type:"object",properties:{above:{type:"number"},...We},required:["above",...He],additionalProperties:!1}}},required:[...He,"tiered","steps"],additionalProperties:!1}},required:["providerID","id","name","enabled","status","variants","capabilities","limit","cost"],additionalProperties:!1},me={anyOf:[{type:"number"},{type:"null"}]},it={anyOf:[{type:"string",enum:["plan","execute","review"]},{type:"null"}]},lt={anyOf:[Ne,{type:"null"}]},Le={type:"object",properties:{...Ne.properties,useFor:{type:"string"}},required:["providerID","id","variant","useFor"],additionalProperties:!1},Ee={type:"object",properties:{...Ne.properties,useFor:{type:"string"}},required:["providerID","id","variant"],additionalProperties:!1},ht={type:"object",properties:{plan:{type:"array",items:Le},execute:{type:"array",items:Le},review:{type:"array",items:Le}},required:["plan","execute","review"],additionalProperties:!1},ft={type:"object",properties:{plan:{type:"array",items:Ee},execute:{type:"array",items:Ee},review:{type:"array",items:Ee}},required:["plan","execute","review"],additionalProperties:!1},vt={type:"object",properties:{requests:{type:"number"},fresh:{type:"number"},cached:{type:"number"},costUsd:M,seconds:me},required:["requests","fresh","cached","costUsd","seconds"],additionalProperties:!1},Ue={type:"object",properties:{at:{type:"string"},sessionID:{type:"string"},kind:{type:"string",enum:["chat","helper"]},mode:it,confidence:me,fit:me,model:M,ms:{type:"number"},costUsd:M,note:M,messageID:M,reply:{anyOf:[vt,{type:"null"}]}},required:["at","sessionID","kind","mode","confidence","fit","model","ms","costUsd","note","messageID","reply"],additionalProperties:!1},Be={type:"object",properties:{directory:{type:"string"},settings:{type:"object",properties:{revision:{type:"integer",minimum:0},modes:ht,decider:lt},required:["revision","modes","decider"],additionalProperties:!1},decisions:{type:"array",items:Ue},deciders:{type:"array",items:nt},checks:{type:"object",properties:{active:{type:"boolean"},note:M},required:["active","note"],additionalProperties:!1}},required:["directory","settings","decisions","deciders","checks"],additionalProperties:!1},Z={rejected:{type:"object",properties:{},additionalProperties:!1}},Ce={type:"object",properties:{},additionalProperties:!1},Xe=ut.Rpc.define({id:"relay-opencode",events:{},methods:{getRelay:{errors:Z,input:Ce,output:Be},saveRelay:{errors:Z,input:{type:"object",properties:{revision:{type:"integer",minimum:0},modes:ft,decider:lt},required:["revision","modes","decider"],additionalProperties:!1},output:Be},getRelayChat:{errors:Z,input:{type:"object",properties:{sessionID:{type:"string"}},required:["sessionID"],additionalProperties:!1},output:{type:"object",properties:{on:{type:"boolean"},last:{anyOf:[Ue,{type:"null"}]},decider:{type:"boolean"}},required:["on","last","decider"],additionalProperties:!1}},getRelayDecisions:{errors:Z,input:Ce,output:{type:"object",properties:{directory:{type:"string"},decisions:{type:"array",items:Ue}},required:["directory","decisions"],additionalProperties:!1}},setRelayChat:{errors:Z,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:Z,input:{type:"object",properties:{text:{type:"string"}},required:["text"],additionalProperties:!1},output:{type:"object",properties:{directory:{type:"string"},mode:it,confidence:me,model:M,fit:me,ms:{type:"number"},costUsd:M,note:M},required:["directory","mode","confidence","model","fit","ms","costUsd","note"],additionalProperties:!1}},listModels:{errors:Z,input:Ce,output:{type:"object",properties:{directory:{type:"string"},models:{type:"array",items:nt}},required:["directory","models"],additionalProperties:!1}},listIntelligence:{errors:Z,input:Ce,output:{type:"object",properties:{directory:{type:"string"},source:{type:"string"},fetchedAt:M,note:M,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 Te(t,n){const c=t.find(h=>h.providerID===n.providerID&&h.id===n.id);return c&&c.enabled&&c.status!=="deprecated"&&(n.variant===null||c.variants.includes(n.variant))?c:void 0}Promise.resolve();const gt=200,mt=1000000000000n;function yt(t){if(!/^(?:0|[1-9]\d*)(?:\.\d{1,12})?$/.test(t))throw new Error("Invalid USD amount");const[n,c=""]=t.split(".");return BigInt(n)*mt+BigInt(c.padEnd(12,"0"))}function Fe(t,n){const c=typeof t=="string"?t:t&&typeof t=="object"&&typeof t.message=="string"?t.message:"";return c.trim()?c:n}const bt=["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
+ `),xt={plan:"Plan",execute:"Execute",review:"Review"},ee=t=>xt[t],wt=4e3,$t=10,Ie=t=>t===null?"not listed":`$${t}`;function Je(t){const{inputPerMillion:n,outputPerMillion:c}=t;return n===null&&c===null?"price not listed":n==="0"&&c==="0"?"$0 or not listed":`${Ie(n)} in / ${Ie(c)} out per 1M tokens${t.tiered?" (base tier)":""}`}const Se=t=>{if(t===null)return null;try{return yt(t)}catch{return null}},Ke=(t,n)=>t===n?0:t===null?1:n===null||t<n?-1:1;function kt(t,n){return Ke(Se(t.cost.inputPerMillion),Se(n.cost.inputPerMillion))||Ke(Se(t.cost.outputPerMillion),Se(n.cost.outputPerMillion))||t.name.localeCompare(n.name)}function _t(t){const{inputPerMillion:n,outputPerMillion:c}=t;return n===null&&c===null?"not listed":n==="0"&&c==="0"?"$0 or not listed":`${Ie(n)} / ${Ie(c)}${t.tiered?" (base tier)":""}`}function Ct(t){if(!(t>0))return"—";if(t<1e3)return String(t);const n=Math.round(t/1e3);return n<1e3?`${n}K`:`${+(t/1e6).toFixed(1)}M`}const at=t=>t==null?"—":String(Math.round(t*10)/10),St={provider:(t,n)=>t.providerID.localeCompare(n.providerID)||t.name.localeCompare(n.name),price:kt,context:(t,n)=>n.limit.context-t.limit.context||t.name.localeCompare(n.name),index:(t,n)=>(n.index??-1)-(t.index??-1)||t.name.localeCompare(n.name)};function It(t,n){const c=n.query.toLowerCase().split(/\s+/).filter(Boolean);return t.filter(h=>(!n.provider||h.providerID===n.provider)&&c.every(k=>`${h.providerID} ${h.id} ${h.name}`.toLowerCase().includes(k))).sort(St[n.order])}function Qe(t,n){return[null,...n.variants].find(c=>!t.some(h=>h.providerID===n.providerID&&h.id===n.id&&h.variant===c))}const Ve=t=>`${Math.round(t*100)}%`,ot=(t,n)=>[ee(t.mode),n,...t.confidence===null?[]:[`${Ve(t.confidence)} sure`],...t.fit===null?[]:[`line fit ${Ve(t.fit)}`],`${Math.round(t.ms)} ms`].join(", "),De=(t,n)=>`${t}${n===null?"":` (${n})`}.`,st=t=>{const{mode:n,model:c}=t;return n!==null&&c!==null?ot({...t,mode:n},c):t.kind==="helper"?"left as it was":"nothing switched"};function dt(t){return t?De(`Last choice${t.kind==="helper"?" (a helper)":""}: ${st(t)}`,t.note):"No /relay message yet."}const Ge=t=>Math.round(t).toLocaleString("en-US"),Dt=t=>t?` First request of the reply: ${[`${Ge(t.fresh)} tokens read new`,`${Ge(t.cached)} from cache`,...t.costUsd===null||t.costUsd==="0"?[]:[`$${t.costUsd}`],...t.seconds===null?[]:[`first word after ${t.seconds} s`]].join(", ")}. Requests in the reply: ${t.requests}.`:"",Pt=t=>`${De(`${t.kind==="helper"?"Helper":"Chat"}: ${st(t)}`,t.note)}${Dt(t.reply)}`;function Rt(t){const{mode:n}=t;return De(n===null?"No answer":`${ot({...t,mode:n},t.model??"no model")}, cost ${t.costUsd===null?"not reported":`$${t.costUsd}`}`,t.note)}const Mt=t=>`To choose, Relay sends to ${t??"the decider's provider"}: your message text (at most ${wt.toLocaleString("en-US")} characters), the names and sizes of attached files (the first ${$t}), 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 or earlier messages. 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 qt(t){if(t.kind!=="chat"||t.model===null)return null;const n=t.model.indexOf("/");if(n<=0)return null;const c=t.model.slice(n+1),h=c.lastIndexOf("#"),k=h<0?c:c.slice(0,h),_=h<0?void 0:c.slice(h+1);return!k||_===""?null:{providerID:t.model.slice(0,n),modelID:k,..._===void 0?{}:{variant:_}}}const jt="No decider chosen. Until you choose one below, /relay and Relay on send every message to the chat's current model without switching.";function At(t){const{on:n,last:c,decider:h}=t,k=c!==null&&c.model===null,_=n&&!h;return{label:n?h?"Relay on":"Relay on · no decider":"Relay off",..._?{icon:"circle-exclamation"}:{},tone:_?"warning":n?"success":void 0,rows:[{id:"toggle",label:n?"Turn Relay off for this chat":"Turn Relay on for this chat"},...h?[]:[{id:"decider",label:"No decider chosen, so Relay switches nothing. Open Relay to choose one.",tone:"warning"}],{id:"last",label:c===null?"No choice in this chat yet.":dt(c),...k?{tone:"warning"}:{}}]}}const Lt="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.",Et=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"}.`,Tt=`
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);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}.rl-table th:nth-child(4){width:42px}.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 th:nth-child(3),.rl-table td:nth-child(3),.rl-table th:nth-child(4),.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
+ `;var Ft=e.template("<span class=rl-sub>"),Ut=e.template("<details class=rl-acc><summary></summary><div class=rl-acc-body>"),Nt=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>'),Ot=e.template("<option> (<!>)"),zt=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">'),Wt=e.template('<div class="rl-note n-warn"role=status>'),Ht=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>'),Bt=e.template("<ol class=rl-plain>"),Xt=e.template("<pre class=rl-pre>"),Jt=e.template('<div class=rl-row><span class=rl-hint aria-live=polite></span><button type=button class="rl-btn sm">Refresh'),Kt=e.template('<div class="rl-note n-bad"role=alert>'),Qt=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."),Vt=e.template('<div class="rl-note n-bad"role=alert>Could not load the settings. Check the server connection and try again.'),Gt=e.template("<span class=rl-hint>None chosen yet. /relay leaves the chat as it is for <!>."),Yt=e.template("<span class=rl-hint>Several models: the decider picks the one whose line fits your message. When no line fits clearly, the chat keeps its model if it is in this list; otherwise the first is used. With no lines written, the first is always used."),Zt=e.template("<div class=rl-card><div><strong class=rl-role></strong><span class=rl-hint>"),Ye=e.template("<small>unavailable"),er=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)">'),tr=e.template('<select class="rl-in rl-effort"><option value>default effort'),Ze=e.template("<div class=rl-inline><span class=rl-hint>"),et=e.template("<option> effort"),rr=e.template('<button type=button class="rl-btn sm rl-add">+ Add a model'),nr=e.template("<span class=rl-hint>No decider chosen: /relay sends without switching."),ir=e.template("<div class=rl-pick><span><span class=rl-chip-t></span><button type=button class=rl-x>×"),lr=e.template('<select class="rl-in rl-effort"aria-label="Effort for the decider"><option value>default effort'),ar=e.template('<button type=button class="rl-btn sm rl-add">'),or=e.template("<div role=status>"),sr=e.template("<p class=rl-hint>No /relay message yet."),dr=e.template("<li class=rl-hint><time></time> · ");const cr=[["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."]],tt=t=>{const[n,c]=o.createSignal(!1);return(()=>{var h=Ut(),k=h.firstChild,_=k.nextSibling;return h.addEventListener("toggle",T=>{T.currentTarget.open&&c(!0)}),e.insert(k,()=>t.title,null),e.insert(k,e.createComponent(o.Show,{get when(){return t.sub},get children(){var T=Ft();return e.insert(T,()=>t.sub),T}}),null),e.insert(_,e.createComponent(o.Show,{get when(){return n()},get children(){return t.children}})),h})()},rt=t=>{const[n,c]=o.createSignal(""),[h,k]=o.createSignal(""),[_,T]=o.createSignal("provider"),Pe=o.createMemo(()=>[...new Set(t.models.map(O=>O.providerID))].sort().map(O=>({id:O,count:t.models.filter(ie=>ie.providerID===O).length}))),te=o.createMemo(()=>It(t.models,{query:n(),provider:h(),order:_()}));return(()=>{var O=Nt(),ie=O.firstChild,d=ie.firstChild,y=d.nextSibling,b=ie.nextSibling,g=b.firstChild,L=g.firstChild,le=L.firstChild,q=le.nextSibling;q.nextSibling;var z=g.nextSibling,de=z.firstChild,x=de.nextSibling,Q=x.nextSibling,Re=Q.nextSibling,ce=b.nextSibling,pe=ce.firstChild,ue=pe.firstChild,ye=ue.firstChild,be=ye.firstChild,Me=be.nextSibling,qe=Me.nextSibling,je=qe.nextSibling,he=je.nextSibling,Ae=he.firstChild,xe=ue.nextSibling,V=ce.nextSibling,ae=V.nextSibling;return O.$$keydown=i=>{i.key==="Escape"&&(i.stopPropagation(),t.close())},d.$$input=i=>c(i.currentTarget.value),e.use(i=>setTimeout(()=>i.focus()),d),y.$$click=()=>t.close(),g.addEventListener("change",i=>k(i.currentTarget.value)),e.insert(L,()=>t.models.length,q),e.insert(g,e.createComponent(o.For,{get each(){return Pe()},children:i=>(()=>{var C=Ot(),E=C.firstChild,F=E.nextSibling;return F.nextSibling,e.insert(C,()=>i.id,E),e.insert(C,()=>i.count,F),e.effect(()=>C.selected=h()===i.id),e.effect(()=>C.value=i.id),C})()}),null),z.addEventListener("change",i=>T(i.currentTarget.value)),e.insert(Ae,()=>t.action),e.insert(xe,e.createComponent(o.For,{get each(){return te()},children:i=>(()=>{var C=zt(),E=C.firstChild,F=E.firstChild,re=F.nextSibling,X=E.nextSibling,J=X.nextSibling,oe=J.nextSibling,we=oe.nextSibling,G=we.firstChild;return e.insert(F,()=>i.name),e.insert(re,()=>i.providerID,null),e.insert(re,()=>t.mark(i),null),e.insert(X,()=>_t(i.cost)),e.insert(J,()=>Ct(i.limit.context)),e.insert(oe,()=>at(i.index)),G.$$click=()=>t.pick(i),e.insert(G,()=>t.action),e.effect(j=>{var $e=i.limit.context>0?void 0:"Context size not listed",ke=i.matched?`Artificial Analysis, for ${i.matched} on OpenRouter${i.variants.length?", at its highest effort":""}`:"No index found for this model",se=!t.can(i),fe=t.tip?.(i),ve=t.actionLabel(i);return $e!==j.e&&e.setAttribute(J,"title",j.e=$e),ke!==j.t&&e.setAttribute(oe,"title",j.t=ke),se!==j.a&&(G.disabled=j.a=se),fe!==j.o&&e.setAttribute(G,"title",j.o=fe),ve!==j.i&&e.setAttribute(G,"aria-label",j.i=ve),j},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),C})()})),e.insert(V,(()=>{var i=e.memo(()=>!!te().length);return()=>i()?`${te().length} of ${t.models.length} models`:"No model matches. Try fewer words, or All providers."})()),e.insert(ae,()=>t.source),e.effect(i=>{var C=t.label,E=h()==="",F=_()==="provider",re=_()==="price",X=_()==="context",J=_()==="index";return C!==i.e&&e.setAttribute(O,"aria-label",i.e=C),E!==i.t&&(L.selected=i.t=E),F!==i.a&&(de.selected=i.a=F),re!==i.o&&(x.selected=i.o=re),X!==i.i&&(Q.selected=i.i=X),J!==i.n&&(Re.selected=i.n=J),i},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),e.effect(()=>d.value=n()),O})()},pr=_e.Plugin.define({setup(t){const n={id:"models",title:"Relay",closable:"compact",fallback:!0};t.add(_e.Command,()=>({id:"open",title:"Open Relay",keywords:"relay models modes plan execute review decider",enabled:!!t.sessions.current(),run:()=>{const d=t.sessions.current();d&&t.layout.toggle(`${t.id}:models`,d)}})),t.add(_e.Panel,{id:"models",region:"side",width:380,list:d=>d.open.includes("models")?[n]:[],render:d=>{const y=r=>({rpc:r.server.client.rpc(Xe),options:{location:{directory:r.directory}}}),b=async(r,l)=>{const u=await l(y(r));if(u.directory!==r.directory)throw new Error("Wrong project");return u},[g,L]=o.createSignal(!1),[le,q]=o.createSignal(""),[z,{refetch:de}]=o.createResource(()=>d.session,async r=>{const{rpc:l,options:u}=y(r),[$,a]=await Promise.all([l.listModels({},u),l.getRelay({},u)]);if($.directory!==r.directory||a.directory!==r.directory)throw new Error("Data came from a different project");return{session:r,models:$.models,relay:a}}),x=o.createMemo(()=>z()?.session===d.session?z():void 0),Q=o.createMemo(()=>x()?.models),[Re]=o.createResource(()=>d.session,async r=>{try{const l=await b(r,({rpc:u,options:$})=>u.listIntelligence({},$));return{session:r,source:l.source,note:l.note,byModel:new Map(l.scores.map(u=>[`${u.providerID}/${u.id}`,u]))}}catch(l){return{session:r,source:null,note:Fe(l,"the index could not be loaded"),byModel:new Map}}}),ce=o.createMemo(()=>{const r=Re();return r?.session===d.session?r:void 0}),pe=r=>{const l=ce()?.byModel.get(`${r.providerID}/${r.id}`);return{...r,index:l?.index??null,matched:l?.matched??null}},ue=r=>{const l=pe(r).index;return l===null?"":` · index ${at(l)}${r.variants.length?" at its highest effort":""}`},ye=()=>{const r=ce();return r?r.source?`Index: ${r.source}. For a model with efforts it is the highest effort's score; lower efforts score less.${r.note?` (${r.note})`:""}`:`Index: not shown (${r.note}).`:"Index: loading…"},[be,Me]=o.createSignal(),qe=async()=>{const r=d.session;try{const l=await b(r,({rpc:u,options:$})=>u.getRelayDecisions({},$));d.session===r&&Me({session:r,decisions:l.decisions})}catch{}},je=setInterval(()=>{qe()},5e3);o.onCleanup(()=>clearInterval(je));const he=o.createMemo(()=>be()?.session===d.session?be().decisions:x()?.relay.decisions??[]),Ae=r=>new Date(r).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),[xe,V]=o.createSignal(null),ae=(r,l)=>r.providerID===l.providerID&&r.id===l.id&&r.variant===l.variant,i=r=>x()?.relay.settings.modes[r]??[],C=async r=>{const l=x();if(!l||g())return;const{revision:u,modes:$,decider:a}=l.relay.settings;L(!0),q("");try{await b(l.session,({rpc:R,options:w})=>R.saveRelay({revision:u,modes:$,decider:a,...r},w))}catch(R){q(Fe(R,"Could not save. The settings may have changed; refresh and try again."))}finally{try{d.session===l.session&&await de()}catch{q("Could not refresh the settings. Try Refresh.")}finally{L(!1)}}},E=(r,l)=>{const u=x();u&&C({modes:{...u.relay.settings.modes,[r]:l}})},[F,re]=o.createSignal(""),[X,J]=o.createSignal(!1),[oe,we]=o.createSignal(),G=async()=>{const r=d.session,l=F();if(!(X()||!l.trim())){J(!0);try{const u=await b(r,({rpc:$,options:a})=>$.testDecider({text:l},a));d.session===r&&we({session:r,text:Rt(u),bad:u.mode===null})}catch(u){d.session===r&&we({session:r,text:Fe(u,"Could not ask the decider."),bad:!0})}finally{J(!1)}}},j=r=>{const l=Q();return l!==void 0&&!Te(l,r)},$e=o.createMemo(()=>(Q()??[]).filter(r=>r.enabled&&r.status!=="deprecated").map(pe)),ke=o.createMemo(()=>(x()?.relay.deciders??[]).filter(r=>r.enabled&&r.status!=="deprecated").map(pe)),se=o.createMemo(()=>{const r=x()?.relay,l=r?.settings.decider;return r&&l?Te(r.deciders,l):void 0}),fe=r=>{const l=x()?.relay.settings.decider;return!!l&&l.providerID===r.providerID&&l.id===r.id},ve=(r,l)=>i(r).some(u=>u.providerID===l.providerID&&u.id===l.id),ct=(r,l)=>{const u=Qe(i(r),l);u!==void 0&&E(r,[...i(r),{providerID:l.providerID,id:l.id,variant:u,useFor:""}])},Oe=(r,l,u)=>i(r).some($=>ae($,{...l,variant:u})),pt=(r,l,u)=>E(r,i(r).map($=>ae($,l)?{...$,variant:u}:$));return(()=>{var r=Qt(),l=r.firstChild,u=l.nextSibling,$=u.nextSibling;return $.firstChild,e.insert(l,Tt),e.insert($,e.createComponent(o.Show,{get when(){return!z.error},get fallback(){return Vt()},get children(){return[e.createComponent(o.Show,{get when(){return e.memo(()=>!!x())()&&x().relay.settings.decider===null},get children(){var a=Wt();return e.insert(a,jt),a}}),e.createComponent(o.For,{each:cr,children:([a,R])=>(()=>{var w=Zt(),W=w.firstChild,ne=W.firstChild,ge=ne.nextSibling;return e.insert(ne,()=>ee(a)),e.insert(ge,R),e.insert(w,e.createComponent(o.For,{get each(){return i(a)},children:s=>(()=>{var Y=er(),K=Y.firstChild,p=K.firstChild,U=p.nextSibling,H=K.nextSibling;return e.insert(p,()=>s.id,null),e.insert(p,(()=>{var f=e.memo(()=>!!s.variant);return()=>f()?` · ${s.variant}`:""})(),null),e.insert(K,e.createComponent(o.Show,{get when(){return j(s)},get children(){return Ye()}}),U),U.$$click=()=>E(a,i(a).filter(f=>!ae(f,s))),e.insert(Y,e.createComponent(o.Show,{get when(){return e.memo(()=>!!Q())()&&Te(Q(),s)},children:f=>(()=>{var A=Ze(),m=A.firstChild;return e.insert(A,e.createComponent(o.Show,{get when(){return f().variants.length},get children(){var D=tr(),N=D.firstChild;return D.addEventListener("change",v=>pt(a,s,v.currentTarget.value||null)),e.insert(D,e.createComponent(o.For,{get each(){return f().variants},children:v=>(()=>{var S=et(),P=S.firstChild;return S.value=v,e.insert(S,v,P),e.effect(I=>{var B=s.variant===v,ze=s.variant!==v&&Oe(a,s,v);return B!==I.e&&(S.selected=I.e=B),ze!==I.t&&(S.disabled=I.t=ze),I},{e:void 0,t:void 0}),S})()}),null),e.effect(v=>{var S=`Effort for ${s.id} in ${ee(a)}`,P=g(),I=s.variant===null,B=s.variant!==null&&Oe(a,s,null);return S!==v.e&&e.setAttribute(D,"aria-label",v.e=S),P!==v.t&&(D.disabled=v.t=P),I!==v.a&&(N.selected=v.a=I),B!==v.o&&(N.disabled=v.o=B),v},{e:void 0,t:void 0,a:void 0,o:void 0}),D}}),m),e.insert(m,()=>Je(f().cost),null),e.insert(m,()=>ue(f()),null),A})()}),H),H.addEventListener("change",f=>{const A=f.currentTarget.value.replace(/\s+/g," ").trim();A!==s.useFor&&E(a,i(a).map(m=>ae(m,s)?{...m,useFor:A}:m))}),e.setAttribute(H,"maxlength",gt),e.effect(f=>{var A=`rl-chip ${j(s)?"bad":""}`,m=`${s.providerID} / ${s.id}`,D=`Remove ${s.providerID} / ${s.id} / ${s.variant??"default"} from ${ee(a)}`,N=g(),v=`What ${s.id} is for in ${ee(a)}`,S=g();return A!==f.e&&e.className(K,f.e=A),m!==f.t&&e.setAttribute(p,"title",f.t=m),D!==f.a&&e.setAttribute(U,"aria-label",f.a=D),N!==f.o&&(U.disabled=f.o=N),v!==f.i&&e.setAttribute(H,"aria-label",f.i=v),S!==f.n&&(H.disabled=f.n=S),f},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),e.effect(()=>H.value=s.useFor),Y})()}),null),e.insert(w,e.createComponent(o.Show,{get when(){return!i(a).length},get children(){var s=Gt(),Y=s.firstChild,K=Y.nextSibling;return K.nextSibling,e.insert(s,()=>ee(a),K),s}}),null),e.insert(w,e.createComponent(o.Show,{get when(){return i(a).length>1},get children(){return Yt()}}),null),e.insert(w,e.createComponent(o.Show,{get when(){return xe()===a},get fallback(){return(()=>{var s=rr();return s.$$click=()=>V(a),e.effect(()=>s.disabled=g()||z.loading),s})()},get children(){return e.createComponent(rt,{get label(){return`Add a model to ${ee(a)}`},get models(){return $e()},get source(){return ye()},action:"Add",actionLabel:s=>`Add ${s.name} from ${s.providerID} to ${ee(a)}`,can:s=>!g()&&Qe(i(a),s)!==void 0,mark:s=>`${s.capabilities.tools?"":" · no tools"}${ve(a,s)?" · ✓ in the list":""}`,tip:s=>ve(a,s)?"Adds it once more, with another effort":void 0,pick:s=>ct(a,s),close:()=>V(null)})}}),null),w})()}),(()=>{var a=Ht(),R=a.firstChild,w=R.nextSibling,W=w.nextSibling,ne=W.firstChild,ge=ne.nextSibling,s=W.nextSibling,Y=s.nextSibling,K=Y.nextSibling;return e.insert(a,e.createComponent(o.Show,{get when(){return x()?.relay.settings.decider},get fallback(){return nr()},children:p=>(()=>{var U=ir(),H=U.firstChild,f=H.firstChild,A=f.nextSibling;return e.insert(f,()=>p().id,null),e.insert(f,(()=>{var m=e.memo(()=>!!p().variant);return()=>m()?` · ${p().variant}`:""})(),null),e.insert(H,e.createComponent(o.Show,{get when(){return e.memo(()=>!!x())()&&!se()},get children(){return Ye()}}),A),A.$$click=()=>{C({decider:null})},e.insert(U,e.createComponent(o.Show,{get when(){return se()},children:m=>(()=>{var D=Ze(),N=D.firstChild;return e.insert(D,e.createComponent(o.Show,{get when(){return m().variants.length},get children(){var v=lr(),S=v.firstChild;return v.addEventListener("change",P=>{C({decider:{...p(),variant:P.currentTarget.value||null}})}),e.insert(v,e.createComponent(o.For,{get each(){return m().variants},children:P=>(()=>{var I=et(),B=I.firstChild;return I.value=P,e.insert(I,P,B),e.effect(()=>I.selected=p().variant===P),I})()}),null),e.effect(P=>{var I=g(),B=p().variant===null;return I!==P.e&&(v.disabled=P.e=I),B!==P.t&&(S.selected=P.t=B),P},{e:void 0,t:void 0}),v}}),N),e.insert(N,()=>Je(m().cost),null),e.insert(N,()=>ue(m()),null),D})()}),null),e.effect(m=>{var D=`rl-chip ${x()&&!se()?"bad":""}`,N=`${p().providerID} / ${p().id}`,v=`Remove the decider ${p().providerID} / ${p().id}`,S=g();return D!==m.e&&e.className(H,m.e=D),N!==m.t&&e.setAttribute(f,"title",m.t=N),v!==m.a&&e.setAttribute(A,"aria-label",m.a=v),S!==m.o&&(A.disabled=m.o=S),m},{e:void 0,t:void 0,a:void 0,o:void 0}),U})()}),w),e.insert(a,e.createComponent(o.Show,{get when(){return xe()==="decider"},get fallback(){return(()=>{var p=ar();return p.$$click=()=>V("decider"),e.insert(p,()=>x()?.relay.settings.decider?"Change the decider":"+ Choose a decider"),e.effect(()=>p.disabled=g()||z.loading),p})()},get children(){return e.createComponent(rt,{label:"Choose a decider",get models(){return ke()},get source(){return ye()},action:"Use",actionLabel:p=>`Use ${p.name} from ${p.providerID} as the decider`,can:p=>!g()&&!fe(p),mark:p=>fe(p)?" · ✓ in use":"",pick:p=>{V(null),C({decider:{providerID:p.providerID,id:p.id,variant:null}})},close:()=>V(null)})}}),w),e.insert(w,()=>Mt(x()?.relay.settings.decider?.providerID??null)),ne.$$keydown=p=>{p.key==="Enter"&&G()},ne.$$input=p=>re(p.currentTarget.value),ge.$$click=()=>{G()},e.insert(ge,()=>X()?"Asking…":"Try"),e.insert(a,e.createComponent(o.Show,{get when(){return e.memo(()=>oe()?.session===d.session)()?oe():void 0},children:p=>(()=>{var U=or();return e.insert(U,()=>p().text),e.effect(()=>e.className(U,`rl-note ${p().bad?"n-bad":""}`)),U})()}),s),e.insert(s,()=>dt(he()[0])),e.insert(Y,(()=>{var p=e.memo(()=>!!x());return()=>p()?Et(x().relay.checks):""})()),e.insert(K,Lt),e.effect(()=>ge.disabled=X()||!F().trim()||!x()?.relay.settings.decider),e.effect(()=>ne.value=F()),a})(),e.createComponent(tt,{title:"Recent choices",sub:"the last 20, newest first",get children(){return e.createComponent(o.Show,{get when(){return he().length},get fallback(){return sr()},get children(){var a=Bt();return e.insert(a,e.createComponent(o.For,{get each(){return he()},children:R=>(()=>{var w=dr(),W=w.firstChild;return W.nextSibling,e.insert(W,()=>Ae(R.at)),e.insert(w,()=>Pt(R),null),e.effect(()=>e.setAttribute(W,"datetime",R.at)),w})()})),a}})}}),e.createComponent(tt,{title:"Review rules",sub:"added to every review",get children(){var a=Xt();return e.insert(a,bt),a}}),(()=>{var a=Jt(),R=a.firstChild,w=R.nextSibling;return e.insert(R,(()=>{var W=e.memo(()=>!!z.loading);return()=>W()?"Loading…":`${Q()?.length??0} models available`})(),null),e.insert(R,()=>g()?" · saving…":"",null),w.$$click=()=>{de()},e.effect(()=>w.disabled=z.loading),a})(),e.createComponent(o.Show,{get when(){return le()},get children(){var a=Kt();return e.insert(a,le),a}})]}}),null),r})()}});const[c,h]=o.createSignal({}),k=new Map,_=d=>({rpc:d.server.client.rpc(Xe),options:{location:{directory:d.directory}}}),T=new Map,Pe=(d,y)=>{const b=y?.at??"";if(!T.has(d.key)){T.set(d.key,b);return}if(!y||T.get(d.key)===b)return;const g=qt(y);if(!g){T.set(d.key,b);return}t.sessions.current()?.key===d.key&&t.screen.current()?.composer.setModel(g)&&T.set(d.key,b)},te=async d=>{try{const{rpc:y,options:b}=_(d),g=await y.getRelayChat({sessionID:d.id},b);h(L=>({...L,[d.key]:g})),Pe(d,g.last)}catch{}},O=async(d,y)=>{try{const{rpc:b,options:g}=_(d);await b.setRelayChat({sessionID:d.id,on:y},g)}catch{}await te(d)},ie=setInterval(()=>{const d=Date.now();for(const[y,b]of k)d-b.at>15e3?k.delete(y):te(b.session)},5e3);try{t.add(_e.ComposerPill,{id:"relay",show:d=>{const y=d.session,b=!k.has(y.key);k.set(y.key,{session:y,at:Date.now()}),b&&te(y);const g=c()[y.key];if(!g)return;const L=At(g),le=q=>q==="toggle"?()=>{O(y,!g.on)}:q==="decider"?()=>t.layout.open(`${t.id}:models`,y):void 0;return{label:L.label,icon:L.icon,tone:L.tone,title:"Relay",rows:L.rows.map(q=>({id:q.id,label:q.label,tone:q.tone,run:le(q.id)}))}}})}catch{}return()=>clearInterval(ie)}});e.delegateEvents(["keydown","input","click"]);exports.default=pr;
@@ -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);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}.rl-table th:nth-child(4){width:42px}.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 th:nth-child(3),.rl-table td:nth-child(3),.rl-table th:nth-child(4),.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";
@@ -0,0 +1,69 @@
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);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}.rl-table th:nth-child(4){width:42px}.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 th:nth-child(3),.rl-table td:nth-child(3),.rl-table th:nth-child(4),.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
+ `;
@@ -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,56 @@
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, relayReplyHook } from './relay-auto.js';
7
+ import { decide } from './decider.js';
8
+ export async function createRuntime(context) {
9
+ const disposers = [];
10
+ const dispose = async () => {
11
+ let failure;
12
+ for (const undo of disposers.reverse()) {
13
+ try {
14
+ await undo();
15
+ }
16
+ catch (error) {
17
+ failure ??= error;
18
+ }
19
+ }
20
+ if (failure)
21
+ throw failure;
22
+ };
23
+ try {
24
+ const relayDeps = {
25
+ session: context.session, store: context.storage, chatModels: () => listProjectModels(context), fileSize,
26
+ decide: (decider, input) => decide({ decisions: request => context.experimental.generate.decisions(request) }, decider, input),
27
+ };
28
+ // `/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.
29
+ const relay = relayCommand(relayDeps);
30
+ const command = await context.command.transform(editor => editor.add(relay));
31
+ disposers.push(() => command.dispose());
32
+ // 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.
33
+ const helper = await context.tool.hook('execute.before', reviewHelperHook(relayDeps));
34
+ disposers.push(() => helper.dispose());
35
+ // 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.
36
+ const auto = await context.session.hook('prompt', relayAutoHook(relayDeps));
37
+ disposers.push(() => auto.dispose());
38
+ // When a chat has finished its work, what the reply to a placed message took is read from the chat and kept with its record. No model is asked.
39
+ const replies = await context.session.hook('experimental.idle', relayReplyHook(relayDeps));
40
+ disposers.push(() => replies.dispose());
41
+ const rpc = await registerRpc(context);
42
+ disposers.push(() => rpc.dispose());
43
+ }
44
+ catch (error) {
45
+ await dispose().catch(() => undefined);
46
+ throw error;
47
+ }
48
+ return { dispose };
49
+ }
50
+ export default Plugin.define({
51
+ id: 'relay-opencode',
52
+ async setup(context) {
53
+ const runtime = await createRuntime(context);
54
+ return () => runtime.dispose();
55
+ },
56
+ });
@@ -0,0 +1,34 @@
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 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. */
29
+ export declare function loadIndexTable(store: CacheStore, fetcher: typeof fetch, now: number): Promise<{
30
+ table: IndexTable;
31
+ fetchedAt: string | null;
32
+ note: string | null;
33
+ }>;
34
+ export {};