gui: a routing group's rule reads as one line, its conditions added from its + menu
The rules editor drew every condition of every rule as an empty box to fill (tokens, images, effort, agents, intent, compact, folders, hours), then "send to" and the model, with Move up / Remove as words and two paragraphs of help below. Three intent rules took ~600px and the intent itself was cut at 24ch. The owner: "现在这个页面太复杂了,用户要输入、 填写这么多东西,太恐怖了。" Now each rule is one line, read as a sentence: 1 asks for <intent…> + → [model] ⋯ - Only the conditions a rule has are drawn, in the rule's own order; each has a × (shown on hover or focus, always on touch) that clears it back to "not set". The rule's + opens the app menu (openProtoMenu, never a native select) with the conditions it doesn't have yet; a pause is offered only the conditions a pause can hold by. - "→ model" sits in its own grid column (subgrid), so it lines up across rules whatever the conditions' widths; under 640px it wraps under the conditions. - The intent is a one-row textarea that grows with its words (a hidden copy sizes it), so the whole intent shows and wraps; Enter and pasted newlines stay one line, as saved before. - Folder boxes size to their text (canvas-measured with the box's own font, +8px so the caret never scrolls the text inside). - Sending is the default and goes unsaid; a pause says "pause" before its model. The ⋯ menu holds Move up, Move down, Send to / Pause the model instead, and Remove rule. - "Add a rule" starts a rule with the intent box ready. The two help paragraphs became an ⓘ beside it, and beside Effort and the intent model. - Saved data is unchanged: an unchanged editor saves the same rules field for field (routing-rules-line round-trips the old assets too). Docs: intent.html and start.html (en, zh, ja) say where Add a rule's intent box and the ⋯ menu's pause now are. The /img/intent-rules-*.png screenshots still show the old editor; not regenerated here. Run: - New routing-rules-line.test.cjs: every condition drawn in order, none empty, + menu (app menu, not select), × removes, ⋯ moves, no overflow or sideways scroll; Chromium and WebKit, en/zh/zh-TW/ja/de, 1100 and 390px. Broken by hand, it went red. - Updated routing-intent-entry, routing-compact, routing-pause, routing-pause-folder, routing-time; with routing-folder, routing-manual, routing-levels, own-requests, i18n-keys, click-scroll and every *menu* test: all pass in both engines but removed-groups-menu-scroll, red 1-2 of 8 per run on a4d580fa2's assets too. - The full routing-*/group-*/images-* GUI set (1261 tests, both engines, concurrency 6): reds outside the editor (routing-days-fit, -agent-gone, -agent-hue-not-red, -burst-speed, -failed-open, -keys-fold, -model-rest, -side-calls, -wb-restricted, group-found-off) fail the same on a4d580fa2's assets run alone here. Of the editor's own reds in that run, two were the tests' clicks (now wheeled to, both ways). The third was real: in WebKit routing-pause-folder's ⋯ menu shut at once, because the folder box's text had scrolled inside it. The box now has room for the caret; the next commit fixes the menu itself. - go test ./internal/gui: ok. - Shots: zh 1000px before/after, en 390 WebKit, zh 390 Chromium, dark. Not tried: the real Wails window, the Windows box, a WebKitGTK without subgrid (falls back to unaligned columns), the docs images.
This commit is contained in:
@@ -3260,9 +3260,16 @@ const I18N = {
|
||||
"Couldn't save the group: {error}": "分组没能保存:{error}",
|
||||
"Rules": "规则",
|
||||
"Add a rule": "添加规则",
|
||||
"Route by what it asks for": "按意图分流",
|
||||
"Add a condition": "添加条件",
|
||||
"Conversation length": "对话长度",
|
||||
"Reasoning level": "推理强度",
|
||||
"Hours and days": "时段",
|
||||
"Remove condition": "移除条件",
|
||||
"Actions for rule {n}": "规则 {n} 的操作",
|
||||
"Pause the model instead": "改为暂停该模型",
|
||||
"Send to the model instead": "改为先发给该模型",
|
||||
"Remove rule": "删除规则",
|
||||
"It can pick the model too: add a rule with an intent": "它也能挑模型:添加一条带意图的规则",
|
||||
"When": "当",
|
||||
"has an image": "带图片",
|
||||
"compacting": "压缩上下文时",
|
||||
"in {folders}": "在 {folders} 中",
|
||||
@@ -4481,7 +4488,15 @@ const I18N = {
|
||||
"No prompts read yet": "還沒有讀到提示詞",
|
||||
"Requests your agents send through magpie show here.": "你的 agent 經 magpie 送出的請求會顯示在這裡。",
|
||||
"No sessions in this range": "這個時間範圍內沒有會話",
|
||||
"Route by what it asks for": "按意圖分流",
|
||||
"Add a condition": "新增條件",
|
||||
"Conversation length": "對話長度",
|
||||
"Reasoning level": "推理強度",
|
||||
"Hours and days": "時段",
|
||||
"Remove condition": "移除條件",
|
||||
"Actions for rule {n}": "規則 {n} 的操作",
|
||||
"Pause the model instead": "改為暫停該模型",
|
||||
"Send to the model instead": "改為先發給該模型",
|
||||
"Remove rule": "刪除規則",
|
||||
"It can pick the model too: add a rule with an intent": "它也能挑模型:新增一條帶意圖的規則",
|
||||
"No installed fonts found": "未找到已安裝字型",
|
||||
"Interface font": "介面字型",
|
||||
@@ -7446,7 +7461,6 @@ const I18N = {
|
||||
"Couldn't save the group: {error}": "分組沒能儲存:{error}",
|
||||
"Rules": "規則",
|
||||
"Add a rule": "新增規則",
|
||||
"When": "當",
|
||||
"has an image": "帶圖片",
|
||||
"compacting": "壓縮上下文時",
|
||||
"in {folders}": "在 {folders} 中",
|
||||
@@ -11644,9 +11658,16 @@ const I18N = {
|
||||
"Couldn't save the group: {error}": "グループを保存できませんでした:{error}",
|
||||
"Rules": "ルール",
|
||||
"Add a rule": "ルールを追加",
|
||||
"Route by what it asks for": "インテントで振り分け",
|
||||
"Add a condition": "条件を追加",
|
||||
"Conversation length": "会話の長さ",
|
||||
"Reasoning level": "推論レベル",
|
||||
"Hours and days": "時間帯",
|
||||
"Remove condition": "条件を削除",
|
||||
"Actions for rule {n}": "ルール {n} の操作",
|
||||
"Pause the model instead": "代わりにモデルを一時停止",
|
||||
"Send to the model instead": "代わりにモデルへ送信",
|
||||
"Remove rule": "ルールを削除",
|
||||
"It can pick the model too: add a rule with an intent": "モデルも選べます:インテント付きのルールを追加",
|
||||
"When": "条件",
|
||||
"has an image": "画像あり",
|
||||
"compacting": "コンパクト化中",
|
||||
"in {folders}": "{folders} 内",
|
||||
@@ -15851,9 +15872,16 @@ const I18N = {
|
||||
"Couldn't save the group: {error}": "Gruppe konnte nicht gespeichert werden: {error}",
|
||||
"Rules": "Regeln",
|
||||
"Add a rule": "Regel hinzufügen",
|
||||
"Route by what it asks for": "Nach Absicht leiten",
|
||||
"Add a condition": "Bedingung hinzufügen",
|
||||
"Conversation length": "Gesprächslänge",
|
||||
"Reasoning level": "Reasoning-Stufe",
|
||||
"Hours and days": "Uhrzeit und Tage",
|
||||
"Remove condition": "Bedingung entfernen",
|
||||
"Actions for rule {n}": "Aktionen für Regel {n}",
|
||||
"Pause the model instead": "Stattdessen Modell pausieren",
|
||||
"Send to the model instead": "Stattdessen an das Modell senden",
|
||||
"Remove rule": "Regel entfernen",
|
||||
"It can pick the model too: add a rule with an intent": "Es kann auch das Modell wählen: Regel mit Absicht hinzufügen",
|
||||
"When": "Wenn",
|
||||
"has an image": "enthält ein Bild",
|
||||
"compacting": "beim Kompaktieren",
|
||||
"in {folders}": "in {folders}",
|
||||
|
||||
@@ -538,15 +538,62 @@ button.rt-session { cursor: pointer; }
|
||||
/* Add a rule, and beside it a rule by what the message asks for */
|
||||
.rt-gadds { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.rt-gadds > [hidden] { display: none; }
|
||||
/* a group's rules: when, and the model it sends that turn to first */
|
||||
.rt-rules .fbl { gap: 6px; }
|
||||
.rt-rule { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; align-items: center; gap: 4px 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
|
||||
.rt-rule:first-child { border-top: 0; padding-top: 0; }
|
||||
.rt-rule > .i { color: var(--muted); font-variant-numeric: tabular-nums; }
|
||||
.rt-rule .when, .rt-rule .rt-use { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; min-width: 0; }
|
||||
.rt-rule .rt-use { grid-column: 2; }
|
||||
.rt-rule .ctl { grid-column: 3; grid-row: 1; display: flex; }
|
||||
.rt-rule .w { color: var(--muted); font-size: 12px; }
|
||||
/* a group's rules, each one line read as a sentence: the conditions it
|
||||
has, → and the model it sends that turn to first; its acts under ⋯ */
|
||||
.rt-rules .fbl:empty { display: none; }
|
||||
.rt-rules .fbl:not(:empty) + .rt-gadds { margin-top: 2px; }
|
||||
/* the rules share their columns (each rule a subgrid of the list), so
|
||||
every rule's → and model start at one x: the number, the conditions
|
||||
(as wide as the widest rule's, to at most half the width before they wrap), what
|
||||
it does, the ⋯. Where subgrid isn't, each rule keeps the same columns
|
||||
on its own */
|
||||
.rt-rules .fbl { display: grid; grid-template-columns: 16px fit-content(50%) minmax(0, 1fr) auto; gap: 0; }
|
||||
.rt-rule { grid-column: 1 / -1; display: grid; grid-template-columns: 16px fit-content(50%) minmax(0, 1fr) auto; align-items: start; column-gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
|
||||
@supports (grid-template-columns: subgrid) { .rt-rule { grid-template-columns: subgrid; } }
|
||||
.rt-rule:first-child { border-top: 0; padding-top: 2px; }
|
||||
.rt-rule > .i { line-height: 26px; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; text-align: right; }
|
||||
.rt-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
|
||||
/* on a narrow page what it does goes under the conditions */
|
||||
@media (max-width: 640px) {
|
||||
.rt-rules .fbl { display: flex; flex-direction: column; }
|
||||
.rt-rule { grid-template-columns: 16px minmax(0, 1fr) auto; row-gap: 6px; }
|
||||
.rt-rule > .rt-then { grid-column: 2; grid-row: 2; }
|
||||
.rt-rule > .rt-rmore { grid-column: 3; grid-row: 1; }
|
||||
}
|
||||
.rt-arrow { color: var(--muted); font-size: 12px; padding: 0 1px; }
|
||||
/* a set condition, and the × on its corner that takes it off: shown on
|
||||
hover or focus, always where nothing hovers */
|
||||
.rt-c { position: relative; display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
|
||||
.rt-cx {
|
||||
position: absolute; top: -5px; right: -5px; z-index: 1; display: grid; place-items: center;
|
||||
width: 16px; height: 16px; padding: 0; border-radius: 50%; border: 1px solid var(--line);
|
||||
background: var(--card); color: var(--muted); cursor: pointer;
|
||||
opacity: 0; pointer-events: none; transition: opacity .12s, color .12s;
|
||||
}
|
||||
.rt-cx:hover { color: var(--fg); border-color: var(--muted); }
|
||||
.rt-c:hover > .rt-cx, .rt-c:focus-within > .rt-cx { opacity: 1; pointer-events: auto; }
|
||||
@media (hover: none) { .rt-cx { opacity: 1; pointer-events: auto; } }
|
||||
/* the quiet + that adds a condition; in words while the rule has none */
|
||||
.rt-addc {
|
||||
display: inline-grid; grid-auto-flow: column; place-items: center; gap: 5px;
|
||||
width: 24px; height: 24px; padding: 0; border-radius: 999px; border: 1px solid transparent;
|
||||
background: transparent; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer;
|
||||
transition: color .15s, border-color .15s, background .15s;
|
||||
}
|
||||
.rt-addc.wide { width: auto; height: 26px; padding: 0 10px 0 8px; border: 1px dashed var(--line); }
|
||||
.rt-addc:hover, .rt-addc.open, .rt-addc:focus-visible { color: var(--fg); background: var(--card-2); }
|
||||
.rt-addc.wide:hover, .rt-addc.wide.open { border-color: var(--muted); }
|
||||
/* the rule's ⋯: on hover, as the usage rows' */
|
||||
.rt-rule > .rt-rmore { align-self: start; opacity: 0; transition: opacity .12s, background .12s, color .12s; }
|
||||
.rt-rule:hover > .rt-rmore, .rt-rule > .rt-rmore:focus-visible, .rt-rule > .rt-rmore.open { opacity: 1; }
|
||||
@media (hover: none) { .rt-rule > .rt-rmore { opacity: 1; } }
|
||||
/* how a part works, under an ⓘ beside it */
|
||||
.rt-info { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: var(--muted); cursor: help; outline: none; }
|
||||
.rt-info:hover, .rt-info:focus-visible { color: var(--fg); }
|
||||
.rt-info:focus-visible { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent); }
|
||||
.rt-info[hidden] { display: none; }
|
||||
.rt-gadds { align-items: center; }
|
||||
.rt-pickrow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
||||
.rt-cond {
|
||||
display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px; border-radius: 999px;
|
||||
border: 1px dashed var(--line); background: transparent; color: var(--muted);
|
||||
@@ -562,11 +609,36 @@ button.rt-session { cursor: pointer; }
|
||||
.rt-cond > .ic-stack { overflow: visible; }
|
||||
.rt-cond.tk { cursor: text; }
|
||||
.rt-cond.in { cursor: text; }
|
||||
.rt-cond.in input, .editor .rt-cond.in input[type="text"] { width: 24ch; }
|
||||
.rt-cond.fd { cursor: text; }
|
||||
.rt-cond.fd input, .editor .rt-cond.fd input[type="text"] { width: 24ch; }
|
||||
.rt-cond.xf { cursor: text; }
|
||||
.rt-cond.xf input, .editor .rt-cond.xf input[type="text"] { width: 24ch; }
|
||||
/* a narrow line squeezes what was typed (it scrolls in its box), never
|
||||
the word that says what the box is */
|
||||
.rt-cond.in > span:not(.rt-grow), .rt-cond.fd > span, .rt-cond.xf > span { flex: none; }
|
||||
.rt-cond.fd > input, .rt-cond.xf > input { min-width: 0; flex: 0 1 auto; }
|
||||
/* the intent, a sentence, shown whole: its box as wide as the words and
|
||||
onto more lines where the line ends. A hidden copy of the words, in the
|
||||
same cell and font, gives the box its size; the pill rounds less once
|
||||
it is more than one line */
|
||||
.rt-cond.in { height: auto; min-height: 26px; padding-top: 2px; padding-bottom: 2px; border-radius: 13px; white-space: normal; }
|
||||
.rt-cond.in > span:first-child { align-self: flex-start; line-height: 20px; }
|
||||
.rt-cond > .rt-grow { align-self: flex-start; display: inline-grid; flex: 0 1 auto; min-width: min(6ch, 100%); max-width: 100%; overflow: visible; }
|
||||
.rt-grow::after, .rt-grow > textarea, .editor .rt-grow > textarea {
|
||||
grid-area: 1 / 1; box-sizing: border-box; margin: 0; padding: 0 2px; border: 0; min-width: 0;
|
||||
font: inherit; line-height: 20px; white-space: pre-wrap; overflow-wrap: anywhere;
|
||||
}
|
||||
.rt-grow::after { content: attr(data-v) " "; visibility: hidden; }
|
||||
.rt-grow > textarea, .editor .rt-grow > textarea {
|
||||
width: 100%; height: 100%; min-height: 20px; resize: none; overflow: hidden;
|
||||
background: transparent; color: inherit; outline: none; box-shadow: none; border-radius: 0;
|
||||
}
|
||||
@media (max-width: 760px), (pointer: coarse) and (max-width: 1024px) {
|
||||
/* a phone's page sets its boxes at 16px (no zoom on focus): the copy too */
|
||||
body.web .rt-grow { font-size: 16px; }
|
||||
body.web .rt-cond.in { padding-top: 11px; padding-bottom: 11px; } /* the first line in the middle of the 44px pill */
|
||||
body.web .rt-grow > textarea { min-height: 0; }
|
||||
}
|
||||
/* a rule's hours: two times in the pill, typed; one that isn't a time is marked */
|
||||
.rt-cond.tm { cursor: text; }
|
||||
.rt-cond.tm input.clock, .editor .rt-cond.tm input.clock[type="text"] { width: 5.5ch; text-align: center; }
|
||||
@@ -583,10 +655,10 @@ button.rt-session { cursor: pointer; }
|
||||
.rt-levels { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 6px; }
|
||||
.rt-levels[hidden] { display: none; }
|
||||
/* the field is the pill: the editor's boxed input (its border and focus ring) stays off it */
|
||||
.rt-cond input, .editor .rt-cond input[type="text"], .editor .rt-cond input:focus { box-shadow: none; border-radius: 0; }
|
||||
.rt-cond input, .editor .rt-cond input[type="text"], .editor .rt-cond input[type="number"], .editor .rt-cond input:focus { box-shadow: none; border-radius: 0; }
|
||||
.editor .rt-cond input:focus-visible { box-shadow: none; border-radius: 0; }
|
||||
.rt-cond:focus-within { border-style: solid; border-color: var(--accent); color: var(--fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
|
||||
.rt-cond input, .editor .rt-cond input[type="text"] { width: 7ch; height: 20px; padding: 0 2px; border: 0; background: transparent; color: inherit; font: inherit; font-variant-numeric: tabular-nums; outline: none; -moz-appearance: textfield; }
|
||||
.rt-cond input, .editor .rt-cond input[type="text"], .editor .rt-cond input[type="number"] { width: 7ch; height: 20px; padding: 0 2px; border: 0; background: transparent; color: inherit; font: inherit; font-variant-numeric: tabular-nums; outline: none; -moz-appearance: textfield; }
|
||||
.rt-cond input::-webkit-outer-spin-button, .rt-cond input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
|
||||
.rt-rwarn { color: var(--amber, var(--muted)); font-size: 11.5px; }
|
||||
.rt-rwarn:empty { display: none; }
|
||||
|
||||
+339
-157
@@ -4540,149 +4540,301 @@
|
||||
aw.append(segs(AFF_OPTS.map(([id, n]) => [id, t(n)]), d.affinity, (v) => { d.affinity = v; aHint.textContent = t(AFF_HINT[v] || AFF_HINT[""]); }), aHint);
|
||||
ed.append(el("label", "", t("Stays")), aw);
|
||||
|
||||
// rules: which member a turn goes to first, by what the request shows
|
||||
// rules: which member a turn goes to first, by what the request shows.
|
||||
// A rule reads as one line, a sentence: the conditions it has, then →
|
||||
// and the model. A condition that isn't set isn't drawn at all; the
|
||||
// quiet + beside them adds one from the app's menu, and a set one is
|
||||
// taken off with its ×. A new rule starts as an intent, the common case
|
||||
// (the owner, 10-14: every rule showed all ten conditions, empty —
|
||||
// "用户要输入、填写这么多东西,太恐怖了"; CherryL1quor on X took Jev for
|
||||
// the effort alone while the intent sat among the others).
|
||||
const RULE_PAUSE = "M6 4.5v7M10 4.5v7", RULE_SEND = "M3 8h9M8.5 4.5 12 8l-3.5 3.5";
|
||||
// how a part works, said under an ⓘ beside it rather than in a
|
||||
// paragraph under it: on hover, and read out with focus
|
||||
const infoTip = (text) => {
|
||||
const s = el("span", "rt-info");
|
||||
s.tabIndex = 0;
|
||||
s.setAttribute("role", "img");
|
||||
const set = (v) => { s.title = v; s.setAttribute("aria-label", v); };
|
||||
set(text);
|
||||
s.set = set;
|
||||
s.append(svg(INFO_I, 14, 1.5));
|
||||
return s;
|
||||
};
|
||||
const rbox = el("div", "fallback rt-rules");
|
||||
const rlist = el("div", "fbl");
|
||||
const rAdd = el("button", "rt-gadd");
|
||||
rAdd.append(svg(PLUS, 11, 1.8), el("span", "", t("Add a rule")));
|
||||
// a rule by what the message asks for, offered beside it: told only as
|
||||
// one of a rule's conditions, an intent went unseen (CherryL1quor on X
|
||||
// took Jev for effort alone)
|
||||
const rIntent = el("button", "rt-gadd");
|
||||
rIntent.append(svg(PLUS, 11, 1.8), el("span", "", t("Route by what it asks for")));
|
||||
const RULES_TIP = "Checked top first when you send a message: the first that matches sends that turn to its model first; the rest stay behind it if it fails. A turn under way is never moved.";
|
||||
const rTip = infoTip(t(RULES_TIP));
|
||||
const rAdds = el("div", "rt-gadds");
|
||||
rAdds.append(rAdd, rIntent);
|
||||
// the rule just added by intent, its intent not yet typed: the
|
||||
// classifier shows for it all the same, so it is seen to be needed
|
||||
let asking = null;
|
||||
rAdds.append(rAdd, rTip);
|
||||
const rHint2 = el("div", "hint");
|
||||
// the conditions opened on each rule while the editor is open: one just
|
||||
// added, or emptied while typing, stays in its place until it is taken
|
||||
// off, rather than vanishing under the cursor
|
||||
const opened = new WeakMap();
|
||||
const openedOf = (r) => { let s = opened.get(r); if (!s) opened.set(r, s = new Set()); return s; };
|
||||
// the condition to open once the rules are drawn: {r, k}
|
||||
let focusCond = null;
|
||||
// what a rule can hold, in the order a rule reads: [kind, its name in
|
||||
// the menu, whether a pause takes it]. A pause holds by hours, days,
|
||||
// agents and folders only: the others are about a request, and a pause
|
||||
// keeps the model out of every one.
|
||||
const COND_KINDS = [
|
||||
["intent", "asks for", false],
|
||||
["tokens", "Conversation length", false],
|
||||
["images", "has an image", false],
|
||||
["effort", "Reasoning level", false],
|
||||
["compact", "compacting", false],
|
||||
["agents", "Agents", true],
|
||||
["folders", "in folder", true],
|
||||
["exceptFolders", "not in folder", true],
|
||||
["time", "Hours and days", true],
|
||||
];
|
||||
const condSet = (r, k) => k === "time" ? !!(r.time && (r.time.from || r.time.to || r.time.days?.length))
|
||||
: Array.isArray(r[k]) ? r[k].length > 0 : !!r[k];
|
||||
// a condition taken off is the value saved for none, as before
|
||||
const condNone = { intent: "", tokens: 0, images: false, effort: "", compact: false, agents: [], folders: [], exceptFolders: [], time: null };
|
||||
const addCond = (r, k) => {
|
||||
openedOf(r).add(k);
|
||||
if (k === "images" || k === "compact") r[k] = true;
|
||||
if (k === "intent" && !d.classifier && deciders.length) d.classifier = deciders[0].id;
|
||||
focusCond = { r, k };
|
||||
drawRules();
|
||||
};
|
||||
const dropCond = (r, k) => {
|
||||
openedOf(r).delete(k);
|
||||
r[k] = Array.isArray(condNone[k]) ? [] : condNone[k];
|
||||
focusCond = { r, k: "+" };
|
||||
drawRules();
|
||||
};
|
||||
// a text box as wide as what is in it (or its placeholder), measured
|
||||
// in the box's own font (a phone's page sets inputs at 16px), between
|
||||
// 6 and 44 columns; a box not yet on the page is measured once it is
|
||||
const fitCanvas = document.createElement("canvas").getContext("2d");
|
||||
const fitBox = (b) => {
|
||||
const s = b.value || b.placeholder || "";
|
||||
const cs = getComputedStyle(b.isConnected ? b : document.body);
|
||||
fitCanvas.font = `${b.isConnected ? cs.fontSize : "12px"} ${cs.fontFamily}`;
|
||||
const w = Math.ceil(fitCanvas.measureText(s).width) + 8; // its 2px sides, and room for the caret so the text never scrolls in its box
|
||||
b.style.width = `clamp(6ch, ${w}px, 44ch)`;
|
||||
if (!b.isConnected) requestAnimationFrame(() => { if (b.isConnected) fitBox(b); });
|
||||
};
|
||||
const drawRules = () => {
|
||||
drawCtx(); // the members' windows changed with them
|
||||
rlist.replaceChildren();
|
||||
rAdd.hidden = rIntent.hidden = d.members.length < 2;
|
||||
rHint2.textContent = t(d.members.length < 2 ? "With two models or more, a rule can send some turns to one of them first."
|
||||
: d.routing === "manual" ? "The rules wait while you pick the model by hand."
|
||||
: "Checked top first when you send a message: the first that matches sends that turn to its model first; the rest stay behind it if it fails. A turn under way is never moved.");
|
||||
rAdd.hidden = rTip.hidden = d.members.length < 2;
|
||||
// only what holds the rules back is said in a line: how they work is
|
||||
// under the ⓘ beside Add a rule
|
||||
rHint2.textContent = d.members.length < 2 ? t("With two models or more, a rule can send some turns to one of them first.")
|
||||
: d.routing === "manual" ? t("The rules wait while you pick the model by hand.") : "";
|
||||
rHint2.hidden = !rHint2.textContent;
|
||||
let focus = null;
|
||||
d.rules.forEach((r, i) => {
|
||||
const row = el("div", "rt-rule");
|
||||
const when = el("div", "when");
|
||||
when.append(el("span", "w", t("When")));
|
||||
// tokens: at least this long
|
||||
const tk = el("span", "rt-cond tk" + (r.tokens ? " on" : ""));
|
||||
tk.onclick = () => ti.focus();
|
||||
const ti = input(r.tokens ? String(r.tokens) : "", "", "number");
|
||||
ti.min = "0"; ti.step = "1000";
|
||||
ti.oninput = () => { r.tokens = Math.max(0, parseInt(ti.value, 10) || 0); tk.classList.toggle("on", !!r.tokens); warn(); };
|
||||
ti.onkeydown = (e) => e.stopPropagation();
|
||||
tk.append(el("span", "", "≥"), ti, el("span", "", t("tokens")));
|
||||
// images
|
||||
const im = el("button", "rt-cond" + (r.images ? " on" : ""), t("has an image"));
|
||||
im.onclick = () => { r.images = !r.images; im.classList.toggle("on", r.images); warn(); };
|
||||
// reasoning
|
||||
const effortName = (v) => v === "on" ? t("reasoning on") : v ? t("reasoning ≥ {level}", { level: v }) : t("any reasoning");
|
||||
const ef = el("button", "rt-cond" + (r.effort ? " on" : ""), effortName(r.effort));
|
||||
ef.onclick = (ev) => pickFrom("reasoning", ef, ev, [
|
||||
{ value: "", label: t("any reasoning"), note: t("not a condition") },
|
||||
{ value: "on", label: t("reasoning on"), note: t("thinking or any effort level") },
|
||||
...EFFORTS.map((v) => ({ value: v, label: t("reasoning ≥ {level}", { level: v }) })),
|
||||
], (v) => { r.effort = v; ef.textContent = effortName(v); ef.classList.toggle("on", !!v); });
|
||||
// agents
|
||||
const clients = state.clients || state.agents || [];
|
||||
const agentsName = () => r.agents.length ? r.agents.map((id) => clients.find((a) => a.id === id)?.name || id).join(", ") : t("any agent");
|
||||
const ag = el("button", "rt-cond" + (r.agents.length ? " on" : ""), agentsName());
|
||||
ag.onclick = (ev) => pickFrom("agent", ag, ev, [
|
||||
{ value: "", label: t("any agent"), note: t("not a condition") },
|
||||
...clients.map((a) => ({ value: a.id, label: a.name, icon: a.icon, note: r.agents.includes(a.id) ? "✓" : "" })),
|
||||
], (v) => {
|
||||
r.agents = !v ? [] : r.agents.includes(v) ? r.agents.filter((x) => x !== v) : [...r.agents, v];
|
||||
ag.textContent = agentsName(); ag.classList.toggle("on", r.agents.length > 0);
|
||||
});
|
||||
// intent: what the message asks for, as the classifier judges it
|
||||
const it = el("span", "rt-cond in" + (r.intent ? " on" : ""));
|
||||
it.onclick = () => ii.focus();
|
||||
const ii = input(r.intent || "", t("what it asks for, e.g. writing tests"));
|
||||
ii.maxLength = 200;
|
||||
ii.oninput = () => {
|
||||
r.intent = ii.value; it.classList.toggle("on", !!r.intent.trim());
|
||||
// Jev, when there is one, as the effort picked per turn takes it
|
||||
if (r.intent.trim() && !d.classifier && deciders.length) d.classifier = deciders[0].id;
|
||||
drawClassifier();
|
||||
const row = el("div", "rt-rule" + (r.pause ? " pause" : ""));
|
||||
const line = el("div", "rt-line when");
|
||||
const shown = (k, pauses) => (pauses || !r.pause) && (condSet(r, k) || openedOf(r).has(k));
|
||||
const kinds = COND_KINDS.filter(([k, , p]) => shown(k, p)).map(([k]) => k);
|
||||
const mine = focusCond?.r === r ? focusCond.k : null;
|
||||
// a set condition in its pill, and the × that takes it off
|
||||
const wrap = (k, ...els) => {
|
||||
openedOf(r).add(k); // emptied, it stays until its × takes it off
|
||||
const w = el("span", "rt-c");
|
||||
w.dataset.k = k;
|
||||
const x = el("button", "rt-cx");
|
||||
x.type = "button";
|
||||
x.title = t("Remove condition");
|
||||
x.setAttribute("aria-label", x.title);
|
||||
x.append(svg(CROSS, 8, 2));
|
||||
x.onclick = (e) => { e.stopPropagation(); dropCond(r, k); };
|
||||
w.append(...els, x);
|
||||
line.append(w);
|
||||
};
|
||||
if (r === asking) focusIntent = ii;
|
||||
ii.onkeydown = (e) => e.stopPropagation();
|
||||
it.append(el("span", "", t("asks for")), ii);
|
||||
// intent: what the message asks for, as the classifier judges it.
|
||||
// Told in a sentence, so it is shown whole: the box is as wide as
|
||||
// what is in it and wraps onto more lines where the line ends
|
||||
// (a hidden copy of the text sizes it), never cut off
|
||||
if (kinds.includes("intent")) {
|
||||
const it = el("span", "rt-cond in" + (r.intent ? " on" : ""));
|
||||
it.onclick = (e) => { if (e.target === it || e.target.tagName === "SPAN") ii.focus(); };
|
||||
const grow = el("span", "rt-grow");
|
||||
const ii = el("textarea");
|
||||
ii.rows = 1; ii.cols = 1; // sized by the copy of its words, not by columns
|
||||
ii.value = r.intent || "";
|
||||
ii.placeholder = t("what it asks for, e.g. writing tests");
|
||||
ii.spellcheck = false;
|
||||
ii.autocomplete = "off";
|
||||
ii.maxLength = 200;
|
||||
const size = () => { grow.dataset.v = ii.value || ii.placeholder; };
|
||||
ii.oninput = () => {
|
||||
// one line of words: a pasted line break is a space
|
||||
if (/[\r\n]/.test(ii.value)) { const at = ii.selectionStart; ii.value = ii.value.replace(/\r?\n|\r/g, " "); ii.setSelectionRange(at, at); }
|
||||
r.intent = ii.value; it.classList.toggle("on", !!r.intent.trim());
|
||||
size();
|
||||
// Jev, when there is one, as the effort picked per turn takes it
|
||||
if (r.intent.trim() && !d.classifier && deciders.length) d.classifier = deciders[0].id;
|
||||
drawClassifier();
|
||||
};
|
||||
ii.onkeydown = (e) => {
|
||||
e.stopPropagation();
|
||||
if (e.key === "Enter") e.preventDefault(); // nothing to break the line for
|
||||
};
|
||||
size();
|
||||
grow.append(ii);
|
||||
it.append(el("span", "", t("asks for")), grow);
|
||||
wrap("intent", it);
|
||||
if (mine === "intent") focus = () => ii.focus({ preventScroll: true });
|
||||
}
|
||||
// tokens: at least this long
|
||||
if (kinds.includes("tokens")) {
|
||||
const tk = el("span", "rt-cond tk" + (r.tokens ? " on" : ""));
|
||||
tk.onclick = (e) => { if (e.target === tk || e.target.tagName === "SPAN") ti.focus(); };
|
||||
const ti = input(r.tokens ? String(r.tokens) : "", "", "number");
|
||||
ti.min = "0"; ti.step = "1000";
|
||||
ti.oninput = () => { r.tokens = Math.max(0, parseInt(ti.value, 10) || 0); tk.classList.toggle("on", !!r.tokens); warn(); };
|
||||
ti.onkeydown = (e) => e.stopPropagation();
|
||||
tk.append(el("span", "", "≥"), ti, el("span", "", t("tokens")));
|
||||
wrap("tokens", tk);
|
||||
if (mine === "tokens") focus = () => ti.focus({ preventScroll: true });
|
||||
}
|
||||
// images
|
||||
if (kinds.includes("images")) {
|
||||
const im = el("button", "rt-cond" + (r.images ? " on" : ""), t("has an image"));
|
||||
im.onclick = () => { r.images = !r.images; im.classList.toggle("on", r.images); warn(); };
|
||||
wrap("images", im);
|
||||
if (mine === "images") focus = () => im.focus({ preventScroll: true });
|
||||
}
|
||||
// reasoning
|
||||
if (kinds.includes("effort")) {
|
||||
const effortName = (v) => v === "on" ? t("reasoning on") : v ? t("reasoning ≥ {level}", { level: v }) : t("any reasoning");
|
||||
const ef = el("button", "rt-cond" + (r.effort ? " on" : ""), effortName(r.effort));
|
||||
ef.onclick = (ev) => pickFrom("reasoning", ef, ev, [
|
||||
{ value: "", label: t("any reasoning"), note: t("not a condition") },
|
||||
{ value: "on", label: t("reasoning on"), note: t("thinking or any effort level") },
|
||||
...EFFORTS.map((v) => ({ value: v, label: t("reasoning ≥ {level}", { level: v }) })),
|
||||
], (v) => { r.effort = v; ef.textContent = effortName(v); ef.classList.toggle("on", !!v); });
|
||||
wrap("effort", ef);
|
||||
if (mine === "effort") focus = () => { ef.focus({ preventScroll: true }); ef.onclick({ stopPropagation() {} }); };
|
||||
}
|
||||
// compacting: the agent summarizing its conversation (/compact),
|
||||
// which a cheaper, faster model can do
|
||||
const cp = el("button", "rt-cond" + (r.compact ? " on" : ""), t("compacting"));
|
||||
cp.title = t("The agent summarizes the conversation to go on in less room (Claude Code's /compact, Codex, OpenCode…): a cheaper, faster model can do it");
|
||||
cp.onclick = () => { r.compact = !r.compact; cp.classList.toggle("on", r.compact); warn(); };
|
||||
// hours of the day, on this computer's clock (a vendor's peak
|
||||
// hours, say): typed as 09:00 and 18:00, past midnight when the
|
||||
// second comes first; the days are picked like the agents
|
||||
const tm = el("span", "rt-cond tm");
|
||||
const tw = () => r.time || (r.time = { from: "", to: "", days: [] });
|
||||
const tFrom = input(r.time?.from || "", "09:00"), tTo = input(r.time?.to || "", "18:00");
|
||||
tm.title = t("The turn begins within these hours, on this computer's clock — a provider's peak-price hours sent to another, say");
|
||||
tm.onclick = (e) => { if (e.target === tm || e.target.tagName === "SPAN") (tFrom.value ? tTo : tFrom).focus({ preventScroll: true }); };
|
||||
const dayBtn = el("button", "rt-cond");
|
||||
const drawTime = () => {
|
||||
const w = r.time, from = clockOf(w?.from), to = clockOf(w?.to);
|
||||
const typed = !!(w && (w.from || w.to));
|
||||
tm.classList.toggle("on", !!(from && to));
|
||||
// a time typed that isn't one, once its field is left
|
||||
tm.classList.toggle("bad", [[tFrom, w?.from], [tTo, w?.to]].some(([b, v]) => v && !clockOf(v) && document.activeElement !== b));
|
||||
dayBtn.hidden = !typed && !w?.days?.length;
|
||||
dayBtn.textContent = daysText(w?.days) || t("every day");
|
||||
dayBtn.classList.toggle("on", !!daysText(w?.days));
|
||||
};
|
||||
for (const [box, key] of [[tFrom, "from"], [tTo, "to"]]) {
|
||||
box.className = "clock";
|
||||
box.maxLength = 5;
|
||||
box.inputMode = "numeric";
|
||||
box.oninput = () => { tw()[key] = box.value.trim(); drawTime(); warn(); };
|
||||
box.onblur = () => { const v = clockOf(box.value); if (v) { box.value = v; tw()[key] = v; } drawTime(); warn(); };
|
||||
box.onkeydown = (e) => e.stopPropagation();
|
||||
if (kinds.includes("compact")) {
|
||||
const cp = el("button", "rt-cond" + (r.compact ? " on" : ""), t("compacting"));
|
||||
cp.title = t("The agent summarizes the conversation to go on in less room (Claude Code's /compact, Codex, OpenCode…): a cheaper, faster model can do it");
|
||||
cp.onclick = () => { r.compact = !r.compact; cp.classList.toggle("on", r.compact); warn(); };
|
||||
wrap("compact", cp);
|
||||
if (mine === "compact") focus = () => cp.focus({ preventScroll: true });
|
||||
}
|
||||
// agents
|
||||
if (kinds.includes("agents")) {
|
||||
const clients = state.clients || state.agents || [];
|
||||
const agentsName = () => r.agents.length ? r.agents.map((id) => clients.find((a) => a.id === id)?.name || id).join(", ") : t("any agent");
|
||||
const ag = el("button", "rt-cond" + (r.agents.length ? " on" : ""), agentsName());
|
||||
ag.onclick = (ev) => pickFrom("agent", ag, ev, [
|
||||
{ value: "", label: t("any agent"), note: t("not a condition") },
|
||||
...clients.map((a) => ({ value: a.id, label: a.name, icon: a.icon, note: r.agents.includes(a.id) ? "✓" : "" })),
|
||||
], (v) => {
|
||||
r.agents = !v ? [] : r.agents.includes(v) ? r.agents.filter((x) => x !== v) : [...r.agents, v];
|
||||
ag.textContent = agentsName(); ag.classList.toggle("on", r.agents.length > 0);
|
||||
});
|
||||
wrap("agents", ag);
|
||||
if (mine === "agents") focus = () => { ag.focus({ preventScroll: true }); ag.onclick({ stopPropagation() {} }); };
|
||||
}
|
||||
tm.append(el("span", "", t("from")), tFrom, el("span", "", t("to")), tTo);
|
||||
const presets = [["", "every day", []], ["weekdays", "weekdays", WEEK.slice(0, 5)], ["weekends", "weekends", WEEK.slice(5)]];
|
||||
dayBtn.onclick = (ev) => pickFrom("days", dayBtn, ev, [
|
||||
...presets.map(([v, label, ds]) => ({ value: "=" + v, label: t(label), note: ds.length ? daysText(ds) : t("not a condition") })),
|
||||
...WEEK.map((d) => ({ value: d, label: t(DAY_NAMES[d]), note: r.time?.days?.includes(d) ? "✓" : "" })),
|
||||
], (v) => {
|
||||
const w = tw();
|
||||
if (v.startsWith("=")) w.days = [...presets.find(([id]) => "=" + id === v)[2]];
|
||||
else w.days = w.days.includes(v) ? w.days.filter((x) => x !== v) : WEEK.filter((x) => x === v || w.days.includes(x));
|
||||
if (w.days.length === 7) w.days = [];
|
||||
drawTime(); warn();
|
||||
});
|
||||
drawTime();
|
||||
// folders: the project the agent works in, as it tells its model
|
||||
// (Cario0x on X), typed comma separated; a folder inside one counts
|
||||
const fd = el("span", "rt-cond fd" + (r.folders?.length ? " on" : ""));
|
||||
fd.onclick = () => fi.focus();
|
||||
const fi = input((r.folders || []).join(", "), "~/work/acme, ~/oss");
|
||||
fd.title = t("The agent works in one of these folders or a folder inside one, as it tells the model (Claude Code, Codex, OpenCode, Pi); an agent that doesn't say isn't matched");
|
||||
fi.oninput = () => { r.folders = fi.value.split(",").map((x) => x.trim()).filter(Boolean); fd.classList.toggle("on", r.folders.length > 0); };
|
||||
fi.onkeydown = (e) => e.stopPropagation();
|
||||
fd.append(el("span", "", t("in folder")), fi);
|
||||
if (kinds.includes("folders")) {
|
||||
const fd = el("span", "rt-cond fd" + (r.folders?.length ? " on" : ""));
|
||||
fd.onclick = (e) => { if (e.target === fd || e.target.tagName === "SPAN") fi.focus(); };
|
||||
const fi = input((r.folders || []).join(", "), "~/work/acme, ~/oss");
|
||||
fd.title = t("The agent works in one of these folders or a folder inside one, as it tells the model (Claude Code, Codex, OpenCode, Pi); an agent that doesn't say isn't matched");
|
||||
fi.oninput = () => { r.folders = fi.value.split(",").map((x) => x.trim()).filter(Boolean); fd.classList.toggle("on", r.folders.length > 0); fitBox(fi); };
|
||||
fi.onkeydown = (e) => e.stopPropagation();
|
||||
fitBox(fi);
|
||||
fd.append(el("span", "", t("in folder")), fi);
|
||||
wrap("folders", fd);
|
||||
if (mine === "folders") focus = () => fi.focus({ preventScroll: true });
|
||||
}
|
||||
// outside folders (#1606, Ti800): a model kept for the task in one
|
||||
// folder is paused for every other; an agent that doesn't say its
|
||||
// folder isn't known to be in one, so it counts as outside
|
||||
const xf = el("span", "rt-cond xf" + (r.exceptFolders?.length ? " on" : ""));
|
||||
xf.onclick = () => xi.focus();
|
||||
const xi = input((r.exceptFolders || []).join(", "), "~/big-task");
|
||||
xf.title = t("The agent works in none of these folders, nor a folder inside one, as it tells the model; an agent that doesn't say counts as outside them");
|
||||
xi.oninput = () => { r.exceptFolders = xi.value.split(",").map((x) => x.trim()).filter(Boolean); xf.classList.toggle("on", r.exceptFolders.length > 0); };
|
||||
xi.onkeydown = (e) => e.stopPropagation();
|
||||
xf.append(el("span", "", t("not in folder")), xi);
|
||||
// a pause holds by hours, days, agents and folders only: the others
|
||||
// are about a request, and a pause keeps the model out of every one
|
||||
const byRequest = [tk, im, ef, it, cp];
|
||||
for (const c of byRequest) c.hidden = !!r.pause;
|
||||
when.append(tk, im, ef, ag, it, cp, fd, xf, tm, dayBtn);
|
||||
if (kinds.includes("exceptFolders")) {
|
||||
const xf = el("span", "rt-cond xf" + (r.exceptFolders?.length ? " on" : ""));
|
||||
xf.onclick = (e) => { if (e.target === xf || e.target.tagName === "SPAN") xi.focus(); };
|
||||
const xi = input((r.exceptFolders || []).join(", "), "~/big-task");
|
||||
xf.title = t("The agent works in none of these folders, nor a folder inside one, as it tells the model; an agent that doesn't say counts as outside them");
|
||||
xi.oninput = () => { r.exceptFolders = xi.value.split(",").map((x) => x.trim()).filter(Boolean); xf.classList.toggle("on", r.exceptFolders.length > 0); fitBox(xi); };
|
||||
xi.onkeydown = (e) => e.stopPropagation();
|
||||
fitBox(xi);
|
||||
xf.append(el("span", "", t("not in folder")), xi);
|
||||
wrap("exceptFolders", xf);
|
||||
if (mine === "exceptFolders") focus = () => xi.focus({ preventScroll: true });
|
||||
}
|
||||
// hours of the day, on this computer's clock (a vendor's peak
|
||||
// hours, say): typed as 09:00 and 18:00, past midnight when the
|
||||
// second comes first; the days are picked like the agents, and
|
||||
// days alone are all day
|
||||
if (kinds.includes("time")) {
|
||||
const tm = el("span", "rt-cond tm");
|
||||
const tw = () => r.time || (r.time = { from: "", to: "", days: [] });
|
||||
const tFrom = input(r.time?.from || "", "09:00"), tTo = input(r.time?.to || "", "18:00");
|
||||
tm.title = t("The turn begins within these hours, on this computer's clock — a provider's peak-price hours sent to another, say");
|
||||
tm.onclick = (e) => { if (e.target === tm || e.target.tagName === "SPAN") (tFrom.value ? tTo : tFrom).focus({ preventScroll: true }); };
|
||||
const dayBtn = el("button", "rt-cond");
|
||||
const drawTime = () => {
|
||||
const w = r.time, from = clockOf(w?.from), to = clockOf(w?.to);
|
||||
tm.classList.toggle("on", !!(from && to));
|
||||
// a time typed that isn't one, once its field is left
|
||||
tm.classList.toggle("bad", [[tFrom, w?.from], [tTo, w?.to]].some(([b, v]) => v && !clockOf(v) && document.activeElement !== b));
|
||||
dayBtn.textContent = daysText(w?.days) || t("every day");
|
||||
dayBtn.classList.toggle("on", !!daysText(w?.days));
|
||||
};
|
||||
for (const [box, key] of [[tFrom, "from"], [tTo, "to"]]) {
|
||||
box.className = "clock";
|
||||
box.maxLength = 5;
|
||||
box.inputMode = "numeric";
|
||||
box.oninput = () => { tw()[key] = box.value.trim(); drawTime(); warn(); };
|
||||
box.onblur = () => { const v = clockOf(box.value); if (v) { box.value = v; tw()[key] = v; } drawTime(); warn(); };
|
||||
box.onkeydown = (e) => e.stopPropagation();
|
||||
}
|
||||
tm.append(el("span", "", t("from")), tFrom, el("span", "", t("to")), tTo);
|
||||
const presets = [["", "every day", []], ["weekdays", "weekdays", WEEK.slice(0, 5)], ["weekends", "weekends", WEEK.slice(5)]];
|
||||
dayBtn.onclick = (ev) => pickFrom("days", dayBtn, ev, [
|
||||
...presets.map(([v, label, ds]) => ({ value: "=" + v, label: t(label), note: ds.length ? daysText(ds) : t("not a condition") })),
|
||||
...WEEK.map((d) => ({ value: d, label: t(DAY_NAMES[d]), note: r.time?.days?.includes(d) ? "✓" : "" })),
|
||||
], (v) => {
|
||||
const w = tw();
|
||||
if (v.startsWith("=")) w.days = [...presets.find(([id]) => "=" + id === v)[2]];
|
||||
else w.days = w.days.includes(v) ? w.days.filter((x) => x !== v) : WEEK.filter((x) => x === v || w.days.includes(x));
|
||||
if (w.days.length === 7) w.days = [];
|
||||
drawTime(); warn();
|
||||
});
|
||||
drawTime();
|
||||
wrap("time", tm, dayBtn);
|
||||
if (mine === "time") focus = () => tFrom.focus({ preventScroll: true });
|
||||
}
|
||||
// the quiet + that adds a condition: what the rule doesn't show yet,
|
||||
// in the app's menu; said in words while the rule has none
|
||||
const free = COND_KINDS.filter(([k, , p]) => (p || !r.pause) && !kinds.includes(k));
|
||||
if (free.length) {
|
||||
const add = el("button", "rt-addc" + (kinds.length ? "" : " wide"));
|
||||
add.type = "button";
|
||||
add.setAttribute("aria-haspopup", "menu");
|
||||
add.setAttribute("aria-label", t("Add a condition"));
|
||||
add.title = t("Add a condition");
|
||||
add.append(svg(PLUS, 11, 1.8));
|
||||
if (!kinds.length) add.append(el("span", "", t("Add a condition")));
|
||||
add.onclick = () => openProtoMenu(add, free.map(([k, name]) => ({ v: k, name, note: "" })), null, (k) => addCond(r, k), "Add a condition");
|
||||
line.append(add);
|
||||
if (mine === "+") focus = () => add.focus({ preventScroll: true });
|
||||
}
|
||||
// what it does, in a column of its own so every rule's → and model
|
||||
// line up down the list
|
||||
const then = el("div", "rt-line rt-then");
|
||||
then.append(el("span", "rt-arrow", "→"));
|
||||
then.lastChild.setAttribute("aria-hidden", "true");
|
||||
// the member it sends to
|
||||
const use = el("div", "rt-use");
|
||||
const ub = el("button", "rt-cond on");
|
||||
const ub = el("button", "rt-cond on rt-model");
|
||||
const drawUse = () => { const note = memberNote(r.use); ub.replaceChildren(memberIcon(r.use), el("span", "", note ? `${memberName(r.use)} · ${note}` : r.use)); };
|
||||
drawUse();
|
||||
ub.onclick = (ev) => pickFrom("member", ub, ev, d.members.map((id) => { const s = subOf(id); return { value: id, label: memberName(id), note: memberNote(id), icon: s ? undefined : modelOf(id)?.icon, icons: s ? groupIcons(s) : undefined }; }),
|
||||
@@ -4702,40 +4854,66 @@
|
||||
warn();
|
||||
// what it does: send the turn there first, or keep the model out
|
||||
// of the group while the rule holds (John on Discord: a model
|
||||
// paused in its vendor's peak hours)
|
||||
const act = el("button", "rt-cond rt-act" + (r.pause ? " on" : ""), t(r.pause ? "pause" : "send to"));
|
||||
act.onclick = (ev) => pickFrom("action", act, ev, [
|
||||
{ value: "send", label: t("send to"), note: t("goes first; the others stay behind it") },
|
||||
{ value: "pause", label: t("pause"), note: t("left out of the group: not tried, not a fallback") },
|
||||
], (v) => {
|
||||
// paused in its vendor's peak hours). Sending is the plain case and
|
||||
// goes unsaid; a pause says so before the model, and turns back
|
||||
// from there or from the rule's menu.
|
||||
const setAct = (v) => {
|
||||
r.pause = v === "pause";
|
||||
// what a pause doesn't take is cleared, not kept out of sight
|
||||
if (r.pause) Object.assign(r, { tokens: 0, images: false, effort: "", intent: "", compact: false });
|
||||
if (r.pause) {
|
||||
Object.assign(r, { tokens: 0, images: false, effort: "", intent: "", compact: false });
|
||||
for (const [k, , p] of COND_KINDS) if (!p) openedOf(r).delete(k);
|
||||
}
|
||||
drawRules();
|
||||
}, r.pause ? "pause" : "send");
|
||||
use.append(act, ub, hint);
|
||||
const ctl = el("span", "ctl");
|
||||
if (i) { const up = el("button", "text", t("Up")); up.onclick = () => { d.rules.splice(i - 1, 0, d.rules.splice(i, 1)[0]); drawRules(); }; ctl.append(up); }
|
||||
const rm = el("button", "text", t("Remove"));
|
||||
rm.onclick = () => { d.rules.splice(i, 1); drawRules(); };
|
||||
ctl.append(rm);
|
||||
row.append(el("span", "i", String(i + 1)), when, use, ctl);
|
||||
};
|
||||
if (r.pause) {
|
||||
const act = el("button", "rt-cond rt-act on", t("pause"));
|
||||
act.onclick = (ev) => pickFrom("action", act, ev, [
|
||||
{ value: "send", label: t("send to"), note: t("goes first; the others stay behind it") },
|
||||
{ value: "pause", label: t("pause"), note: t("left out of the group: not tried, not a fallback") },
|
||||
], setAct, "pause");
|
||||
then.append(act);
|
||||
}
|
||||
then.append(ub, hint);
|
||||
// the rule's own acts, under ⋯ as on the groups' cards: its place
|
||||
// in the order, sending or pausing, and taking it out
|
||||
const more = el("button", "icon rt-rmore");
|
||||
more.type = "button";
|
||||
more.setAttribute("aria-haspopup", "menu");
|
||||
more.setAttribute("aria-label", t("Actions for rule {n}", { n: i + 1 }));
|
||||
more.title = t("Actions for rule {n}", { n: i + 1 });
|
||||
more.append(svg(DOTS, 14, 2.2));
|
||||
const move = (to) => { d.rules.splice(to, 0, d.rules.splice(i, 1)[0]); drawRules(); rlist.querySelectorAll(".rt-rmore")[to]?.focus({ preventScroll: true }); };
|
||||
more.onclick = () => {
|
||||
const again = agentMenu?.anchor === more;
|
||||
closeAgentMenu();
|
||||
if (again) return;
|
||||
openRowMenu(more, [
|
||||
{ name: "Move up", icon: MOVE_UP, off: i === 0, run: () => move(i - 1) },
|
||||
{ name: "Move down", icon: MOVE_DOWN, off: i === d.rules.length - 1, run: () => move(i + 1) },
|
||||
r.pause
|
||||
? { name: "Send to the model instead", icon: RULE_SEND, sep: true, run: () => setAct("send") }
|
||||
: { name: "Pause the model instead", icon: RULE_PAUSE, sep: true, run: () => setAct("pause") },
|
||||
{ name: "Remove rule", icon: CROSS, sep: true, run: () => { d.rules.splice(i, 1); drawRules(); } },
|
||||
]);
|
||||
};
|
||||
row.append(el("span", "i", String(i + 1)), line, then, more);
|
||||
rlist.append(row);
|
||||
});
|
||||
drawClassifier();
|
||||
focusIntent?.focus({ preventScroll: true });
|
||||
focusIntent = null;
|
||||
focusCond = null;
|
||||
focus?.();
|
||||
};
|
||||
let focusIntent = null;
|
||||
const newRule = () => ({ use: d.members[d.members.length - 1], pause: false, tokens: 0, images: false, effort: "", agents: [], intent: "", compact: false, folders: [], exceptFolders: [], time: null });
|
||||
rAdd.onclick = () => { d.rules.push(newRule()); drawRules(); };
|
||||
// a new rule asks for an intent first, its box focused and the
|
||||
// classifier shown (Jev picked when there is one); any other condition
|
||||
// is a + away, and the intent an × away
|
||||
const addIntentRule = () => {
|
||||
asking = newRule();
|
||||
d.rules.push(asking);
|
||||
if (!d.classifier && deciders.length) d.classifier = deciders[0].id;
|
||||
drawRules();
|
||||
const r = newRule();
|
||||
d.rules.push(r);
|
||||
addCond(r, "intent");
|
||||
};
|
||||
rIntent.onclick = addIntentRule;
|
||||
rAdd.onclick = addIntentRule;
|
||||
// the classifier, once a rule has an intent or the effort is picked
|
||||
// per turn: the model asked which intent a turn's message is and how
|
||||
// hard it is. Jev (a decision provider's model) answers both in one
|
||||
@@ -4761,7 +4939,7 @@
|
||||
};
|
||||
const drawClassifier = () => {
|
||||
const auto = d.effort === "auto";
|
||||
const intents = d.rules.some((r) => r.intent?.trim() || (r === asking && d.rules.includes(r)));
|
||||
const intents = d.rules.some((r) => r.intent?.trim() || (!r.pause && opened.get(r)?.has("intent")));
|
||||
const on = auto || intents;
|
||||
cls.hidden = cw.hidden = clabel.hidden = !on;
|
||||
if (!on) return;
|
||||
@@ -4779,9 +4957,10 @@
|
||||
.map((x) => ({ value: "group/" + x.id, label: x.name, note: "group/" + x.id, icons: groupIcons(x), group: ROUTING_GROUPS, ref: "group/" + x.id }));
|
||||
cb.onclick = (ev) => openPicker({ id: "", name: "", fields: [] }, { key: "classifier", label: "model", value: d.classifier, options: [...deciders.map(opt), ...subs, ...groups.models.map(opt)],
|
||||
onPick: (id) => { if (id) d.classifier = id; drawClassifier(); } }, cb, ev);
|
||||
cls.replaceChildren(cb,
|
||||
...(sg ? [el("div", "hint", t("A routing group classifies as any request to it goes: if its first model fails, the next is asked."))] : []),
|
||||
el("div", "hint", t(isJev(d.classifier) && !intents
|
||||
// how it is asked goes under the ⓘ beside it: a paragraph under the
|
||||
// pick was most of the editor's words
|
||||
const how = [...(sg ? [t("A routing group classifies as any request to it goes: if its first model fails, the next is asked.")] : []),
|
||||
t(isJev(d.classifier) && !intents
|
||||
? "Jev is asked once as each turn begins, with the message and what it said of the turn before. Its calls show in the usage as magpie’s own."
|
||||
: isJev(d.classifier)
|
||||
? "As a turn begins, Jev is asked once which of the intents the message is, and how hard the turn is when it picks the effort. An intent it isn't sure of matches no rule. Its calls show in the usage as magpie’s own."
|
||||
@@ -4789,7 +4968,10 @@
|
||||
? "As a turn begins, this model is asked how hard the turn is — once; a small, fast one without reasoning is best. If it fails or can't say, the turn reasons as the agent asked. Its calls show in the usage as magpie’s own."
|
||||
: auto
|
||||
? "As a turn begins, this model is asked which of the intents the message is and how hard the turn is, each once; a small, fast one without reasoning is best. If it can't say, no intent matches and the turn reasons as the agent asked. Its calls show in the usage as magpie’s own."
|
||||
: "As a turn begins, this model is asked which of the intents the message is — once; a small, fast one without reasoning is best. If it fails or can't say, no intent matches. Its calls show in the usage as magpie’s own.")));
|
||||
: "As a turn begins, this model is asked which of the intents the message is — once; a small, fast one without reasoning is best. If it fails or can't say, no intent matches. Its calls show in the usage as magpie’s own.")];
|
||||
const pickRow = el("div", "rt-pickrow");
|
||||
pickRow.append(cb, infoTip(how.join(" ")));
|
||||
cls.replaceChildren(pickRow);
|
||||
// a subscription asked as every turn begins spends its allowance
|
||||
// on it, beside the agent's own requests (#1839): said beside the
|
||||
// pick, once for a model, for a group when the one it asks first is
|
||||
@@ -4809,15 +4991,15 @@
|
||||
};
|
||||
rbox.append(rlist, rAdds);
|
||||
const rw2 = el("div");
|
||||
rw2.append(rbox, rHint2);
|
||||
rw2.append(rHint2, rbox);
|
||||
ed.append(el("label", "", t("Rules")), rw2);
|
||||
// the effort: the agent's, or the classifier's pick for each turn
|
||||
const eHint = el("div", "hint");
|
||||
const ew = el("div");
|
||||
const eHint = infoTip("");
|
||||
const ew = el("div", "rt-pickrow");
|
||||
const drawEffort = () => {
|
||||
eHint.textContent = t(d.effort === "auto"
|
||||
eHint.set(t(d.effort === "auto"
|
||||
? "As a turn begins, the classifier rates how hard it is and the turn's requests ask their model for low, medium, high or xhigh reasoning — the level each model has nearest. Only where the agent asked for reasoning: a request without any (a session title) stays without."
|
||||
: "Each request reasons as much as the agent asked.");
|
||||
: "Each request reasons as much as the agent asked."));
|
||||
};
|
||||
ew.append(segs([["", t("Agent's")], ["auto", t("Picked per turn")]], d.effort, (v) => {
|
||||
d.effort = v;
|
||||
|
||||
@@ -111,8 +111,17 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
}
|
||||
const ab = await add.boundingBox();
|
||||
await page.mouse.click(ab.x + ab.width / 2, ab.y + ab.height / 2);
|
||||
// a new rule asks for an intent: taken off with its ×, and
|
||||
// compacting added from the rule's + menu instead
|
||||
await rows.nth(1).locator('.rt-c[data-k="intent"]').hover();
|
||||
await rows.nth(1).locator('.rt-c[data-k="intent"] .rt-cx').click();
|
||||
await rows.nth(1).locator(".rt-addc").click();
|
||||
await page.locator(".proto-menu .pm-item", { hasText: w.cond }).click();
|
||||
const second = rows.nth(1).locator("button.rt-cond", { hasText: w.cond });
|
||||
await second.waitFor();
|
||||
assert.equal(await second.getAttribute("class"), "rt-cond on", "added as set");
|
||||
await second.click();
|
||||
assert.equal(await second.getAttribute("class"), "rt-cond");
|
||||
const at = () => page.evaluate(() => [...document.querySelectorAll("*")].filter((e) => e.scrollTop).map((e) => [e.id || e.className, e.scrollTop]).join(";") + "|" + Math.round(document.querySelector(".rt-gedit").getBoundingClientRect().top));
|
||||
await second.scrollIntoViewIfNeeded(); // by the test, as the reader would
|
||||
await page.waitForTimeout(200);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A routing group's rule by intent has an entry of its own (CherryL1quor on
|
||||
// A routing group's rule by intent is what Add a rule makes (CherryL1quor on
|
||||
// X took Jev for picking the effort only: the intent was one of a rule's
|
||||
// seven conditions). Beside "Add a rule", "Route by what it asks for" adds a
|
||||
// rule with its intent box focused and Jev picked as the classifier when
|
||||
// there is one, the button kept under the pointer as the rule comes in
|
||||
// above it; it saves as {use, intent} with the classifier. A group whose effort Jev picks offers, under the classifier,
|
||||
// to add a rule with an intent. At a narrow window both buttons stay inside
|
||||
// seven conditions; the owner, 10-14, found the editor too much to fill
|
||||
// in). Add a rule adds a rule with its intent box focused and Jev picked as
|
||||
// the classifier when there is one, the button kept under the pointer as
|
||||
// the rule comes in above it; it saves as {use, intent} with the
|
||||
// classifier. A group whose effort Jev picks offers, under the classifier,
|
||||
// to add a rule with an intent. At a narrow window the button stays inside
|
||||
// the editor. In English and Chinese.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
@@ -30,8 +31,8 @@ const groups = () => ({
|
||||
});
|
||||
|
||||
const words = {
|
||||
en: { edit: "Edit", add: "Add a rule", intent: "Route by what it asks for", more: "It can pick the model too: add a rule with an intent", told: "Intent told by", save: "Save" },
|
||||
zh: { edit: "编辑", add: "添加规则", intent: "按意图分流", more: "它也能挑模型:添加一条带意图的规则", told: "意图判断模型", save: "保存" },
|
||||
en: { edit: "Edit", add: "Add a rule", more: "It can pick the model too: add a rule with an intent", told: "Intent told by", save: "Save" },
|
||||
zh: { edit: "编辑", add: "添加规则", more: "它也能挑模型:添加一条带意图的规则", told: "意图判断模型", save: "保存" },
|
||||
};
|
||||
|
||||
function serve(lang, posts) {
|
||||
@@ -76,7 +77,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
for (const lang of ["en", "zh"]) {
|
||||
const w = words[lang];
|
||||
for (const width of [1100, 440]) {
|
||||
test(`${engine} ${lang} ${width}: a rule by intent has its own entry`, async (t) => {
|
||||
test(`${engine} ${lang} ${width}: Add a rule makes a rule by intent`, async (t) => {
|
||||
const height = 1400;
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
@@ -91,13 +92,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
|
||||
await press(page, group.locator("button", { hasText: w.edit }), height);
|
||||
const ed = page.locator(".rt-gedit");
|
||||
const add = ed.locator(".rt-gadds button", { hasText: w.add });
|
||||
const byIntent = ed.locator(".rt-gadds button", { hasText: w.intent });
|
||||
const byIntent = ed.locator(".rt-gadds button", { hasText: w.add });
|
||||
await byIntent.waitFor();
|
||||
assert(await add.isVisible(), "Add a rule is there too");
|
||||
// both inside the editor, however narrow
|
||||
assert.equal(await ed.locator(".rt-gadds button").count(), 1, "one way to add a rule");
|
||||
// inside the editor, however narrow
|
||||
const eb = await ed.boundingBox();
|
||||
for (const b of [await add.boundingBox(), await byIntent.boundingBox()]) assert(b.x >= eb.x - 0.5 && b.x + b.width <= eb.x + eb.width + 0.5, `${JSON.stringify(b)} in ${JSON.stringify(eb)}`);
|
||||
for (const b of [await byIntent.boundingBox()]) assert(b.x >= eb.x - 0.5 && b.x + b.width <= eb.x + eb.width + 0.5, `${JSON.stringify(b)} in ${JSON.stringify(eb)}`);
|
||||
// no classifier yet: no rule has an intent
|
||||
assert.equal(await ed.locator(".rt-classifier").isVisible(), false);
|
||||
|
||||
@@ -118,7 +118,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert(Math.abs(after.y - bb.y) < 1, `the button moved from ${bb.y} to ${after.y}`);
|
||||
const rb = await rule.boundingBox();
|
||||
assert(rb.y >= 0 && rb.y + rb.height <= height, `the rule in view: ${JSON.stringify(rb)}`);
|
||||
const box = rule.locator(".rt-cond.in input");
|
||||
const box = rule.locator(".rt-cond.in textarea");
|
||||
assert(await box.evaluate((b) => b === document.activeElement), "the intent box has the focus");
|
||||
const cls = ed.locator(".rt-classifier");
|
||||
assert(await cls.isVisible(), "the classifier shows for the rule");
|
||||
@@ -143,7 +143,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert(mb.x + mb.width <= eb2.x + eb2.width + 0.5, "the offer wraps inside the editor");
|
||||
await press(page, more, height);
|
||||
await ed.locator(".rt-rule").first().waitFor();
|
||||
assert(await ed.locator(".rt-rule .rt-cond.in input").first().evaluate((b) => b === document.activeElement), "its intent box has the focus");
|
||||
assert(await ed.locator(".rt-rule .rt-cond.in textarea").first().evaluate((b) => b === document.activeElement), "its intent box has the focus");
|
||||
assert.equal(await more.count(), 0, "offered no more once a rule has an intent");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
@@ -34,6 +34,14 @@ const routeFrom = (folder) => ({
|
||||
tries: [{ id: "b", model: "opus", start: new Date(now - 2000).toISOString(), done: true, ms: 800, status: 200 }],
|
||||
});
|
||||
|
||||
// the rule's ⋯ menu: turned to send-to, and back to a pause
|
||||
const TURN = {
|
||||
en: ["Send to the model instead", "Pause the model instead"],
|
||||
zh: ["改为先发给该模型", "改为暂停该模型"],
|
||||
"zh-TW": ["改為先發給該模型", "改為暫停該模型"],
|
||||
ja: ["代わりにモデルへ送信", "代わりにモデルを一時停止"],
|
||||
de: ["Stattdessen an das Modell senden", "Stattdessen Modell pausieren"],
|
||||
};
|
||||
const words = {
|
||||
en: { cond: "not in ~/big-task", dir: "The agent works in /Users/me/scratch.", none: "The agent didn't say which folder it works in.", label: "not in folder", in: "in folder",
|
||||
aside: "a/opus is paused by rule 1 (not in ~/big-task), so it is left out until that ends. The agent works in /Users/me/scratch.",
|
||||
@@ -91,12 +99,14 @@ async function open(t, engine, lang, width, folder) {
|
||||
return { page, group, errors, posts };
|
||||
}
|
||||
|
||||
// the view wheeled down to a button, as the reader would (the page keeps
|
||||
// the view wheeled to a button, as the reader would (the page keeps
|
||||
// still for any other scroll), and the button clicked where it is
|
||||
async function press(page, b) {
|
||||
await page.mouse.move(Math.min(550, page.viewportSize().width / 2), 600);
|
||||
for (let i = 0; i < 10 && (await b.boundingBox()).y > 1400 - 160; i++) {
|
||||
await page.mouse.wheel(0, 300);
|
||||
for (let i = 0; i < 20; i++) {
|
||||
const y = (await b.boundingBox()).y;
|
||||
if (y > 80 && y < 1400 - 160) break;
|
||||
await page.mouse.wheel(0, y < 80 ? -300 : 300);
|
||||
await page.waitForTimeout(150);
|
||||
}
|
||||
const bb = await b.boundingBox();
|
||||
@@ -119,7 +129,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const title = await group.evaluate((g) => [...g.querySelectorAll("[title]")].map((e) => e.title).join("\n"));
|
||||
assert(title.includes(`1. ${w.cond} → ${w.pause}`), `the rule reads by its folders: ${title}`);
|
||||
|
||||
// the editor: a pause shows both folder conditions, the request's are hidden
|
||||
// the editor: a pause shows the folder condition it has; in folder
|
||||
// is offered for it, the request's conditions aren't
|
||||
await group.locator("button", { hasText: w.edit }).click();
|
||||
const ed = page.locator(".rt-gedit");
|
||||
const row = ed.locator(".rt-rule").first();
|
||||
@@ -127,9 +138,13 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await xf.waitFor();
|
||||
assert.equal(await xf.getAttribute("class"), "rt-cond xf on");
|
||||
assert.equal(await xf.locator("span").first().textContent(), w.label);
|
||||
assert.equal(await row.locator(".rt-cond.fd").isVisible(), true, "in folder on a pause");
|
||||
assert.equal(await row.locator(".rt-cond.fd span").first().textContent(), w.in);
|
||||
assert.equal(await row.locator(".rt-cond.tk").isVisible(), false, "no tokens on a pause");
|
||||
assert.equal(await row.locator(".rt-cond.fd").count(), 0, "in folder isn't set, so not drawn");
|
||||
assert.equal(await row.locator(".rt-cond.tk").count(), 0, "no tokens on a pause");
|
||||
await press(page, row.locator(".rt-addc"));
|
||||
const offered = await page.locator(".proto-menu .pm-item .pm-name").allTextContents();
|
||||
assert(offered.includes(w.in), `in folder offered on a pause: ${offered}`);
|
||||
assert(!offered.includes(w.label), `not in folder is set already: ${offered}`);
|
||||
await page.keyboard.press("Escape");
|
||||
const box = xf.locator("input");
|
||||
assert.equal(await box.inputValue(), "~/big-task");
|
||||
|
||||
@@ -149,12 +164,15 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
|
||||
// turned to send-to and back to a pause, the folders typed are kept
|
||||
await box.fill("~/big-task , ~/My Task/,");
|
||||
await press(page, row.locator(".rt-act"));
|
||||
await press(page, row.locator(".rt-rmore"));
|
||||
assert.equal(await page.locator("select").count(), 0, "the app menu, not a native select");
|
||||
await page.locator("#list li").filter({ hasText: w.send }).first().click();
|
||||
assert.equal(await ed.locator(".rt-rule").first().locator(".rt-cond.tk").isVisible(), true, "a send-to rule's tokens");
|
||||
await press(page, ed.locator(".rt-rule").first().locator(".rt-act"));
|
||||
await page.locator("#list li").filter({ hasText: w.pause }).first().click();
|
||||
await page.locator(".row-menu .rm-item", { hasText: TURN[lang][0] }).click();
|
||||
assert.equal(await ed.locator(".rt-rule").first().locator(".rt-act").count(), 0, "a send-to rule says no action");
|
||||
await press(page, ed.locator(".rt-rule").first().locator(".rt-addc"));
|
||||
assert(await page.locator(".proto-menu .pm-item").count() > 4, "a send-to rule is offered the request's conditions too");
|
||||
await page.keyboard.press("Escape");
|
||||
await press(page, ed.locator(".rt-rule").first().locator(".rt-rmore"));
|
||||
await page.locator(".row-menu .rm-item", { hasText: TURN[lang][1] }).click();
|
||||
const xf2 = ed.locator(".rt-rule").first().locator(".rt-cond.xf");
|
||||
assert.equal(await xf2.getAttribute("class"), "rt-cond xf on");
|
||||
assert.equal(await xf2.locator("input").inputValue(), "~/big-task, ~/My Task/");
|
||||
@@ -175,7 +193,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const xf = row.locator(".rt-cond.xf");
|
||||
await xf.waitFor();
|
||||
const r = await row.boundingBox();
|
||||
for (const c of [xf, row.locator(".rt-cond.fd")]) {
|
||||
for (const c of [xf, row.locator(".rt-addc"), row.locator(".rt-model")]) {
|
||||
const b = await c.boundingBox();
|
||||
assert(b.x >= r.x - 1 && b.x + b.width <= r.x + r.width + 1, `the folders' condition stays in its rule: ${JSON.stringify([b, r])}`);
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ const route = {
|
||||
};
|
||||
|
||||
const words = {
|
||||
en: { aside: "a/glm is paused by rule 1 (14:00–18:00 Mon–Fri), so it is left out until that ends.", title: "1. 14:00–18:00 Mon–Fri → pause A · glm", pause: "pause", send: "send to", edit: "Edit", add: "Add a rule", save: "Save", bare: "Rule 2: a pause needs hours, days, agents or folders", warn: "left out of the group then: not tried, not a fallback" },
|
||||
zh: { aside: "a/glm 被规则 1(周一–周五 14:00–18:00)暂停,在此之前不会被调用。", title: "1. 周一–周五 14:00–18:00 → 暂停 A · glm", pause: "暂停", send: "先发给", edit: "编辑", add: "添加规则", save: "保存", bare: "第 2 条规则:暂停需要设时段、星期、Agent 或文件夹", warn: "这段时间移出分组:不会被调用,也不做备用" },
|
||||
en: { aside: "a/glm is paused by rule 1 (14:00–18:00 Mon–Fri), so it is left out until that ends.", title: "1. 14:00–18:00 Mon–Fri → pause A · glm", pause: "pause", send: "send to", edit: "Edit", add: "Add a rule", save: "Save", bare: "Rule 2: a pause needs hours, days, agents or folders", warn: "left out of the group then: not tried, not a fallback", length: "Conversation length", hours: "Hours and days", toPause: "Pause the model instead" },
|
||||
zh: { aside: "a/glm 被规则 1(周一–周五 14:00–18:00)暂停,在此之前不会被调用。", title: "1. 周一–周五 14:00–18:00 → 暂停 A · glm", pause: "暂停", send: "先发给", edit: "编辑", add: "添加规则", save: "保存", bare: "第 2 条规则:暂停需要设时段、星期、Agent 或文件夹", warn: "这段时间移出分组:不会被调用,也不做备用", length: "对话长度", hours: "时段", toPause: "改为暂停该模型" },
|
||||
"zh-TW": { pause: "暫停", send: "先發給", edit: "編輯", add: "新增規則", save: "儲存" },
|
||||
ja: { pause: "一時停止", send: "送信先" },
|
||||
de: { pause: "pausieren", send: "senden an" },
|
||||
@@ -136,21 +136,28 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(await rows.first().locator(".rt-cond.tm").getAttribute("class"), "rt-cond tm on");
|
||||
assert.equal(await rows.first().locator(".rt-rwarn").textContent(), w.warn);
|
||||
|
||||
// a second rule: a send-to rule turned into a pause from the app menu
|
||||
// a second rule: a send-to rule (sending goes unsaid) turned into a
|
||||
// pause from its ⋯ menu
|
||||
const addBtn = ed.locator("button", { hasText: w.add });
|
||||
await press(page, addBtn);
|
||||
const row2 = rows.nth(1);
|
||||
const act2 = row2.locator(".rt-act");
|
||||
assert.equal(await act2.textContent(), w.send);
|
||||
assert.equal(await row2.locator(".rt-act").count(), 0, "sending is the plain case");
|
||||
// a condition set before it turns to a pause is cleared, not kept out of sight
|
||||
await row2.locator(".rt-addc").click();
|
||||
assert.equal(await page.locator("select").count(), 0, "the app menu, not a native select");
|
||||
await page.locator(".proto-menu .pm-item", { hasText: w.length }).click();
|
||||
await row2.locator(".rt-cond.tk input").fill("50000");
|
||||
assert.equal(await row2.locator(".rt-cond.tk").isVisible(), true);
|
||||
await press(page, act2);
|
||||
assert.equal(await page.locator("select").count(), 0, "the app menu, not a native select");
|
||||
await page.locator("#list li").filter({ hasText: w.pause }).first().click();
|
||||
await press(page, row2.locator(".rt-rmore"));
|
||||
await page.locator(".row-menu .rm-item", { hasText: w.toPause }).click();
|
||||
const row2b = rows.nth(1);
|
||||
assert.equal(await row2b.locator(".rt-act").textContent(), w.pause);
|
||||
assert.equal(await row2b.locator(".rt-cond.tk").isVisible(), false);
|
||||
assert.equal(await row2b.locator(".rt-cond.tk").count(), 0);
|
||||
assert.equal(await row2b.locator(".rt-cond.in").count(), 0, "nor the intent it was added with");
|
||||
// what a pause can't hold isn't offered for it
|
||||
await row2b.locator(".rt-addc").click();
|
||||
assert.equal(await page.locator(".proto-menu .pm-item", { hasText: w.length }).count(), 0);
|
||||
await page.locator(".proto-menu .pm-item", { hasText: w.hours }).click();
|
||||
assert.equal(await row2b.locator(".rt-cond.tm").isVisible(), true);
|
||||
|
||||
// not saved without hours, days or agents
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A routing group's rule reads as one line (the owner, 10-14: every rule
|
||||
// showed all ten conditions, empty, "用户要输入、填写这么多东西,太恐怖了"):
|
||||
// the conditions it has, → and the model. A rule with only an intent shows
|
||||
// that intent and nothing empty; a rule with every condition shows each,
|
||||
// in the rule's order; a condition is added from the rule's + in the app's
|
||||
// menu (never a native select) and taken off with its ×; the ⋯ moves a rule.
|
||||
// Saved untouched, the rules are what was loaded, field for field (run with
|
||||
// ASSETS set to the assets before this change to see the old editor save
|
||||
// the same). In every language, at a wide and a phone's width, nothing past
|
||||
// the editor's side.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(process.env.ASSETS || path.join(__dirname, "../assets"));
|
||||
const models = [
|
||||
{ id: "a/opus", name: "opus", providerName: "A", icon: "generic", context: 1000000, ready: true },
|
||||
{ id: "b/flash", name: "flash", providerName: "B", icon: "generic", context: 1000000, ready: true },
|
||||
];
|
||||
const member = (id) => ({ id, ready: true, context: 1000000, images: true });
|
||||
const WEEKDAYS = ["mon", "tue", "wed", "thu", "fri"];
|
||||
const rule = (use, more) => ({ use, pause: false, tokens: 0, images: false, effort: "", agents: [], intent: "", compact: false, folders: [], exceptFolders: [], time: null, ...more });
|
||||
// as the group's rules are loaded, and so as they are saved untouched
|
||||
const RULES = [
|
||||
rule("b/flash", { intent: "a quick question" }),
|
||||
rule("a/opus", { tokens: 50000, images: true, effort: "high", agents: ["claude"], intent: "code review", compact: true, folders: ["~/work/acme", "~/oss"], exceptFolders: ["~/big-task"], time: { from: "09:00", to: "18:00", days: WEEKDAYS } }),
|
||||
rule("a/opus", { pause: true, time: { from: "14:00", to: "18:00", days: [] } }),
|
||||
];
|
||||
const groups = () => ({
|
||||
models,
|
||||
deciders: [{ id: "typesafe/jev-latest", name: "Jev", providerName: "TypeSafe", icon: "generic" }],
|
||||
groups: [{ id: "main", name: "Main", members: ["a/opus", "b/flash"], routing: "order", ready: true, classifier: "typesafe/jev-latest",
|
||||
rules: structuredClone(RULES), memberInfo: [member("a/opus"), member("b/flash")] }],
|
||||
pools: [],
|
||||
});
|
||||
// the order a rule reads, as the editor draws its conditions
|
||||
const ORDER = ["intent", "tokens", "images", "effort", "compact", "agents", "folders", "exceptFolders", "time"];
|
||||
|
||||
const words = {
|
||||
en: { edit: "Edit", save: "Save", image: "has an image", down: "Move down" },
|
||||
zh: { edit: "编辑", save: "保存", image: "带图片", down: "下移" },
|
||||
"zh-TW": { edit: "編輯", save: "儲存", image: "帶圖片", down: "下移" },
|
||||
ja: { edit: "編集", save: "保存", image: "画像あり", down: "下へ移動" },
|
||||
de: { edit: "Bearbeiten", save: "Speichern", image: "enthält ein Bild", down: "Nach unten" },
|
||||
};
|
||||
|
||||
function serve(lang, posts) {
|
||||
const state = { agents: [{ id: "claude", name: "Claude Code", path: "/test/claude", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
|
||||
return async (r) => {
|
||||
const url = new URL(r.request().url());
|
||||
const json = (data) => r.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json(state);
|
||||
if (url.pathname === "/api/gateway/trace") {
|
||||
if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes
|
||||
return json({ mine: true, now: new Date().toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
||||
}
|
||||
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
||||
if (url.pathname === "/api/groups") return json(groups());
|
||||
if (url.pathname.startsWith("/api/groups/")) {
|
||||
posts.push({ path: url.pathname, body: JSON.parse(r.request().postData() || "{}") });
|
||||
return json(groups());
|
||||
}
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
try { await r.fulfill({ body: await fs.readFile(file), contentType }); } catch { await r.fulfill({ status: 404 }); }
|
||||
};
|
||||
}
|
||||
|
||||
// wheel to a control, as the reader would (the page keeps still for any
|
||||
// other scroll), and return where it is
|
||||
async function reach(page, loc) {
|
||||
const height = page.viewportSize().height;
|
||||
await page.mouse.move(Math.min(550, (page.viewportSize().width / 2) | 0), 300);
|
||||
for (let i = 0; i < 30; i++) {
|
||||
const y = (await loc.boundingBox()).y;
|
||||
if (y > 80 && y < height - 160) break;
|
||||
await page.mouse.wheel(0, y < 80 ? -300 : 300);
|
||||
await page.waitForTimeout(150);
|
||||
}
|
||||
return loc.boundingBox();
|
||||
}
|
||||
|
||||
// reached, then clicked with the mouse
|
||||
async function press(page, loc) {
|
||||
const b = await reach(page, loc);
|
||||
await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2);
|
||||
}
|
||||
|
||||
async function openEditor(page, w) {
|
||||
const group = page.locator(".rt-group").first();
|
||||
await group.waitFor();
|
||||
await press(page, group.locator("button", { hasText: w.edit }));
|
||||
const ed = page.locator(".rt-gedit");
|
||||
await ed.locator(".rt-rule").first().waitFor();
|
||||
return ed;
|
||||
}
|
||||
|
||||
async function saved(page, ed, w, posts) {
|
||||
const n = posts.length;
|
||||
await press(page, ed.locator("button.primary", { hasText: w.save }));
|
||||
await page.waitForFunction(() => !document.querySelector(".rt-gedit"));
|
||||
const save = posts.slice(n).find((p) => p.path === "/api/groups/save");
|
||||
assert(save, `saved: ${JSON.stringify(posts)}`);
|
||||
return save.body;
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of Object.keys(words)) {
|
||||
const w = words[lang];
|
||||
for (const width of [1100, 390]) {
|
||||
test(`${engine} ${lang} ${width}: a rule reads as one line, its conditions added from a menu`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 1400 } })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [], posts = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, posts));
|
||||
await page.goto("http://magpie.test/?view=routing");
|
||||
|
||||
// saved untouched: the rules as loaded, field for field
|
||||
let ed = await openEditor(page, w);
|
||||
const body = await saved(page, ed, w, posts);
|
||||
assert.deepEqual(body.rules, RULES);
|
||||
assert.equal(body.classifier, "typesafe/jev-latest");
|
||||
if (process.env.ASSETS) return; // the old editor: only the round trip is asked of it
|
||||
|
||||
ed = await openEditor(page, w);
|
||||
const rows = ed.locator(".rt-rule");
|
||||
const kinds = (row) => row.locator(".rt-c").evaluateAll((xs) => xs.map((x) => x.dataset.k));
|
||||
// an intent alone: the intent, the model, nothing empty
|
||||
const r1 = rows.nth(0);
|
||||
assert.deepEqual(await kinds(r1), ["intent"]);
|
||||
assert.equal(await r1.locator(".rt-cond.in textarea").inputValue(), "a quick question");
|
||||
const chips1 = await r1.locator(".rt-cond").evaluateAll((xs) => xs.map((x) => x.className));
|
||||
assert.deepEqual(chips1, ["rt-cond in on", "rt-cond on rt-model"], "no empty chip beside the intent");
|
||||
assert.equal(await r1.locator(".rt-act").count(), 0, "sending goes unsaid");
|
||||
// every condition, each set, in the rule's order; nothing left to add
|
||||
const r2 = rows.nth(1);
|
||||
assert.deepEqual(await kinds(r2), ORDER);
|
||||
assert.equal(await r2.locator(".rt-addc").count(), 0);
|
||||
for (const c of [".tk", ".in", ".fd", ".xf", ".tm"]) assert.match(await r2.locator(".rt-cond" + c).getAttribute("class"), /\bon\b/, c);
|
||||
// a pause: its hours, and says it pauses
|
||||
const r3 = rows.nth(2);
|
||||
assert.deepEqual(await kinds(r3), ["time"]);
|
||||
assert.equal(await r3.locator(".rt-act").count(), 1);
|
||||
|
||||
// nothing past the editor's side, nor a sideways scroll
|
||||
const over = await page.evaluate(() => {
|
||||
const e = document.querySelector(".rt-gedit").getBoundingClientRect();
|
||||
return [...document.querySelectorAll(".rt-rule, .rt-rule *")].filter((x) => x.offsetParent && x.getBoundingClientRect().right > e.right + 1).map((x) => x.className || x.tagName);
|
||||
});
|
||||
assert.deepEqual(over, []);
|
||||
assert(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth), "no sideways scroll");
|
||||
|
||||
// a condition added from the rule's + menu: the app's, the ones
|
||||
// the rule hasn't, and the pick shows set
|
||||
await press(page, r1.locator(".rt-addc"));
|
||||
assert.equal(await page.locator("select").count(), 0, "the app menu, not a native select");
|
||||
const items = page.locator(".proto-menu .pm-item");
|
||||
assert.equal(await items.count(), ORDER.length - 1, "all but the intent it has");
|
||||
await items.filter({ hasText: w.image }).click();
|
||||
assert.deepEqual(await kinds(r1), ["intent", "images"]);
|
||||
assert.equal(await r1.locator('.rt-c[data-k="images"] .rt-cond').getAttribute("class"), "rt-cond on");
|
||||
// and one taken off with its ×
|
||||
const c = await reach(page, r2.locator('.rt-c[data-k="agents"]'));
|
||||
await page.mouse.move(c.x + c.width / 2, c.y + c.height / 2);
|
||||
await press(page, r2.locator('.rt-c[data-k="agents"] .rt-cx'));
|
||||
assert.equal(await r2.locator('.rt-c[data-k="agents"]').count(), 0);
|
||||
// the ⋯ moves a rule
|
||||
await press(page, r1.locator(".rt-rmore"));
|
||||
await page.locator(".row-menu .rm-item", { hasText: w.down }).click();
|
||||
assert.deepEqual(await kinds(rows.nth(1)), ["intent", "images"]);
|
||||
|
||||
const body2 = await saved(page, ed, w, posts);
|
||||
assert.deepEqual(body2.rules, [{ ...RULES[1], agents: [] }, { ...RULES[0], images: true }, RULES[2]]);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,8 @@ const route = {
|
||||
};
|
||||
|
||||
const words = {
|
||||
en: { cond: "22:00–08:00 Mon–Fri", story: "rule 1 matches — 22:00–08:00 Mon–Fri —", night: "runs past midnight, into the next day", every: "every day", weekdays: "weekdays", sat: "Sat", monSat: "Mon–Sat", edit: "Edit", add: "Add a rule", save: "Save" },
|
||||
zh: { cond: "周一–周五 22:00–08:00", story: "规则 1", night: "跨过午夜,到第二天", every: "每天", weekdays: "工作日", sat: "周六", monSat: "周一–周六", edit: "编辑", add: "添加规则", save: "保存" },
|
||||
en: { cond: "22:00–08:00 Mon–Fri", story: "rule 1 matches — 22:00–08:00 Mon–Fri —", night: "runs past midnight, into the next day", every: "every day", weekdays: "weekdays", sat: "Sat", monSat: "Mon–Sat", edit: "Edit", add: "Add a rule", save: "Save", hours: "Hours and days" },
|
||||
zh: { cond: "周一–周五 22:00–08:00", story: "规则 1", night: "跨过午夜,到第二天", every: "每天", weekdays: "工作日", sat: "周六", monSat: "周一–周六", edit: "编辑", add: "添加规则", save: "保存", hours: "时段" },
|
||||
};
|
||||
|
||||
function serve(lang, posts) {
|
||||
@@ -119,10 +119,17 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await wheelTo(addBtn);
|
||||
await addBtn.click();
|
||||
const row2 = rows.nth(1);
|
||||
// a new rule asks for an intent; the hours take its place, added
|
||||
// from the rule's + menu
|
||||
assert.equal(await row2.locator(".rt-cond.tm").count(), 0, "no hours until they are added");
|
||||
await row2.locator('.rt-c[data-k="intent"]').hover();
|
||||
await row2.locator('.rt-c[data-k="intent"] .rt-cx').click();
|
||||
await row2.locator(".rt-addc").click();
|
||||
await page.locator(".proto-menu .pm-item", { hasText: w.hours }).click();
|
||||
const tm2 = row2.locator(".rt-cond.tm");
|
||||
await tm2.waitFor();
|
||||
const dayBtn2 = row2.locator("button.rt-cond", { hasText: w.every });
|
||||
assert.equal(await dayBtn2.isVisible(), false, "no days until hours are typed");
|
||||
assert.equal(await dayBtn2.isVisible(), true, "the days beside the hours, every day until picked");
|
||||
const at = () => page.evaluate(() => [...document.querySelectorAll("*")].filter((e) => e.scrollTop).map((e) => [e.id || e.className, e.scrollTop]).join(";") + "|" + Math.round(document.querySelector(".rt-gedit").getBoundingClientRect().top));
|
||||
await tm2.scrollIntoViewIfNeeded(); // by the test, as the reader would
|
||||
await page.waitForTimeout(200);
|
||||
@@ -148,7 +155,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await dayBtn2.click();
|
||||
assert.equal(await at(), before, "the click moved nothing");
|
||||
await page.locator("#list li").filter({ hasText: w.weekdays }).first().click();
|
||||
const days2 = row2.locator(".when > button.rt-cond").last();
|
||||
const days2 = row2.locator('.rt-c[data-k="time"] > button.rt-cond').last();
|
||||
assert.equal(await days2.textContent(), lang === "en" ? "Mon–Fri" : "周一–周五");
|
||||
await days2.click();
|
||||
await page.locator("#list li").filter({ hasText: w.sat }).last().click(); // the day's own, after weekends
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
<p>You need a <a href="/docs/start#routing">routing group</a> with at least two models, and one more model to classify with. The classifier can be any model magpie has, in the group or not.</p>
|
||||
<ol class="steps">
|
||||
<li><b>Open the group</b>Go to <span class="ui">Routing</span>, find the group under <em>Routing groups</em> and click <span class="ui">Edit</span>.</li>
|
||||
<li><b>Add a rule with an intent</b>Click <span class="ui">Route by what it asks for</span> (or <span class="ui">Add a rule</span>), choose the model under <span class="ui">send to</span>, click <span class="ui">asks for</span> and type what the message asks for, such as <em>writing or fixing tests</em>. Other conditions on the same rule must hold too.</li>
|
||||
<li><b>Add a rule with an intent</b>Click <span class="ui">Add a rule</span>. The new rule reads <span class="ui">asks for</span> → a model, with the intent box ready: type what the message asks for, such as <em>writing or fixing tests</em>, then pick the model after →. More conditions come from the rule’s <span class="ui">+</span>, and must hold too.</li>
|
||||
<li><b>Pick the classifier</b><span class="ui">Intent told by</span> appears once a rule has an intent, set to Jev when you have a TypeSafe provider. Otherwise choose a small, fast model without reasoning. A group whose effort Jev already picks offers the same under its classifier: <span class="ui">It can pick the model too</span>. A group can’t be saved with an intent and no classifier.</li>
|
||||
<li><b>Save, and send a message</b>Changes apply from the next turn, with no restart. The <span class="ui">Routing</span> tab shows what the classifier said and where the turn went.</li>
|
||||
</ol>
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
<p>モデルが 2 つ以上ある<a href="/docs/ja/start#routing">ルーティンググループ</a>と、判定用のモデルがもう 1 つ必要です。判定モデルは magpie にあるモデルならどれでもよく、グループに入っているかどうかは問いません。</p>
|
||||
<ol class="steps">
|
||||
<li><b>グループを開く</b><span class="ui">Routing</span> を開き、<em>Routing groups</em> からグループを探して <span class="ui">Edit</span> をクリックします。</li>
|
||||
<li><b>インテント付きのルールを追加する</b><span class="ui">Route by what it asks for</span>(または <span class="ui">Add a rule</span>)をクリックし、<span class="ui">send to</span> でモデルを選び、<span class="ui">asks for</span> をクリックして、メッセージが求めていることを書きます(例:<em>writing or fixing tests</em>)。同じルールのほかの条件も満たされている必要があります。</li>
|
||||
<li><b>インテント付きのルールを追加する</b><span class="ui">ルールを追加</span> をクリックします。新しいルールは <span class="ui">インテント</span> → モデル の 1 行で、インテント欄にカーソルがあります。メッセージが求めていることを書き(例:<em>writing or fixing tests</em>)、→ の後でモデルを選びます。ほかの条件はルールの <span class="ui">+</span> から追加し、それらも満たされている必要があります。</li>
|
||||
<li><b>判定モデルを選ぶ</b>ルールにインテントが付くと <span class="ui">Intent told by</span> が表示されます。TypeSafe プロバイダーがあれば Jev が選ばれ、なければ推理なしの、小さく速いモデルを選んでください。推論の強さをすでに Jev が選んでいるグループでは、判定モデルの下に同じ入口(<span class="ui">It can pick the model too</span>)があります。インテントがあって判定モデルがないグループは保存できません。</li>
|
||||
<li><b>保存して、メッセージを送る</b>変更は次のターンから反映され、再起動は不要です。<span class="ui">Routing</span> タブに、判定モデルの答えとターンの行き先が表示されます。</li>
|
||||
</ol>
|
||||
|
||||
@@ -194,7 +194,7 @@
|
||||
<li>サブエージェントはそれ自体が独立した会話なので、親のエージェントはそのままに、ルールでサブエージェントだけを別の送り先に送れます。</li>
|
||||
<li>インテントは、ユーザーが求めていることを数語で表したものです(「テストを書く・直す」「ちょっとした質問」など)。ターンの開始時に、グループの分類モデル(magpie にある任意のモデル。小さく高速で推論なしのものが最適です)に、一致しうるインテントのうちユーザーのメッセージがどれに当たるかを一度だけ尋ねます。送られるのはそのメッセージだけで、会話全体ではありません。分類モデルが失敗した、遅すぎた(8 秒)、または判断できなかった場合は、どのインテントも一致せず、そのターンは他のルールに従います。インテントのないルールでいずれにせよ決まる場合は問い合わせず、同じメッセージについて二度尋ねることもありません。その呼び出しは使用量に magpie 自身の呼び出しとして表示されます。何を尋ねるのか、回答がどう使われるのか、失敗したらどうなるのかの詳細は<a href="/docs/ja/intent">インテントルーティング</a>を参照してください。</li>
|
||||
<li><span class="ui">compacting</span> は、エージェントが会話を圧縮するとき(Claude Code の <code>/compact</code> と自動圧縮、Codex、OpenCode、Pi、Gemini CLI、Qwen Code、Kimi Code)に一致します。これにより、会話は元のモデルのまま、要約だけをより安く速いモデルに書かせられます。圧縮は単独で判断されます。圧縮が起きたターンとそのキャッシュは元の送り先に留まります。会話がルールのモデルが受け付けられる長さを超えている場合は、次に一致するルール、またはグループの順序で決まります。</li>
|
||||
<li><b>時間帯と曜日。</b>ルールは、このコンピューターの時計で、特定の時間帯や曜日だけ有効にできます(ベンダーのピーク時間など)。その間のターンを別のモデルに送るルールでは、ベンダーのモデルはフォールバックとして後ろに残ります。完全に外すには、ルールの <span class="ui">送信先</span> を <span class="ui">一時停止</span> に変えます。ルールが有効な間(時間帯、曜日、エージェント)、そのモデルはグループから外れ、先頭にもフォールバックにもならず、会話の継続でも使われません。時間帯が終われば戻ります。一時停止は時間帯、曜日、エージェントだけで判断し、グループのモデルがすべて一時停止中ならエージェントにそう伝えます。</li>
|
||||
<li><b>時間帯と曜日。</b>ルールは、このコンピューターの時計で、特定の時間帯や曜日だけ有効にできます(ベンダーのピーク時間など)。その間のターンを別のモデルに送るルールでは、ベンダーのモデルはフォールバックとして後ろに残ります。完全に外すには、ルールの <span class="ui">⋯</span> メニューから <span class="ui">代わりにモデルを一時停止</span> を選びます。ルールが有効な間(時間帯、曜日、エージェント)、そのモデルはグループから外れ、先頭にもフォールバックにもならず、会話の継続でも使われません。時間帯が終われば戻ります。一時停止は時間帯、曜日、エージェントだけで判断し、グループのモデルがすべて一時停止中ならエージェントにそう伝えます。</li>
|
||||
<li><b>フォルダ。</b><span class="ui">フォルダ</span> は、エージェントの作業フォルダが指定したフォルダのどれか、またはその中にあるときに一致します。<code>~/work/acme</code> は <code>~/work/acme/web</code> を含み、<code>~/work/acme-old</code> は含みません。フォルダはエージェントがリクエストでモデルに伝えるもの(Claude Code、Codex、OpenCode、Pi が伝えます)なので、伝えないエージェントはフォルダのルールに一致しません。<code>~</code> はホームフォルダ、<code>C:\work</code> は WSL の <code>/mnt/c/work</code> と同じで、macOS と Windows では大文字小文字を区別しません。</li>
|
||||
<li>ルーティングタブには、各ターンをどのルールがどこへ送ったか、分類モデルが何と答えたか、エージェントが伝えた作業フォルダが表示されます。</li>
|
||||
</ul>
|
||||
|
||||
@@ -194,7 +194,7 @@
|
||||
<li>A subagent is a conversation of its own, so a rule can send it elsewhere while its agent keeps where it is.</li>
|
||||
<li>An intent is a few words for what the user asks for — “writing or fixing tests”, “a quick question”. As a turn begins, the group’s classifier — any model magpie has; a small, fast one without reasoning is best — is asked once which of the intents that could match the user’s message is. Only the message is sent, not the conversation. If it fails, is slow (8 s) or can’t say, no intent matches and the turn goes by the other rules. It isn’t asked when a rule without an intent would decide anyway, and the same message isn’t asked about twice. Its calls show in Usage as magpie’s own. Exactly what it is asked, how its answer is used and what happens when it fails: <a href="/docs/intent">Intent routing</a>.</li>
|
||||
<li><span class="ui">compacting</span> matches an agent compacting its conversation — Claude Code’s <code>/compact</code> and auto-compact, Codex, OpenCode, Pi, Gemini CLI, Qwen Code, Kimi Code — so a cheaper, faster model writes the summary while the conversation stays on its own. A compaction is decided on its own: the turn it happens in, and its cache, stay where they were. When the conversation is longer than the rule’s model takes, the next rule that matches, or the group’s order, decides instead.</li>
|
||||
<li><b>Hours and days.</b> A rule can hold only at some hours, on some days, by this computer’s clock — a vendor’s peak hours, say. A rule that sends those turns elsewhere still leaves the vendor’s model behind it for failover. To keep a model out entirely, turn the rule’s <span class="ui">send to</span> into <span class="ui">pause</span>: while it holds (its hours and days, its agents), that model is left out of the group — never first, never a fallback, not kept for the conversation it was in — and it is back once they end. A pause holds by hours, days and agents only; if every model of the group is paused, the agent is told so.</li>
|
||||
<li><b>Hours and days.</b> A rule can hold only at some hours, on some days, by this computer’s clock — a vendor’s peak hours, say. A rule that sends those turns elsewhere still leaves the vendor’s model behind it for failover. To keep a model out entirely, choose <span class="ui">Pause the model instead</span> from the rule’s <span class="ui">⋯</span> menu: while it holds (its hours and days, its agents), that model is left out of the group — never first, never a fallback, not kept for the conversation it was in — and it is back once they end. A pause holds by hours, days and agents only; if every model of the group is paused, the agent is told so.</li>
|
||||
<li><b>Folders.</b> <span class="ui">in folder</span> matches a turn from an agent working in one of the folders you list, or a folder inside one: <code>~/work/acme</code> takes <code>~/work/acme/web</code>, not <code>~/work/acme-old</code>. The folder is the one the agent tells its model in the request — Claude Code, Codex, OpenCode and Pi say it — so an agent that doesn’t say its folder matches no folder rule. <code>~</code> is your home folder, <code>C:\work</code> is also WSL’s <code>/mnt/c/work</code>, and on macOS and Windows case doesn’t count.</li>
|
||||
<li>The Routing tab says which rule sent each turn where, what the classifier said, and the folder the agent said it was in.</li>
|
||||
</ul>
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
<p>你需要一个至少有两个模型的<a href="/docs/zh/start#routing">路由组</a>,再加一个用来判断意图的模型。这个模型可以是 magpie 里的任意模型,在不在组里都行。</p>
|
||||
<ol class="steps">
|
||||
<li><b>打开分组</b>进入<span class="ui">路由</span>页,在「路由组」里找到分组,点<span class="ui">编辑</span>。</li>
|
||||
<li><b>添加带意图的规则</b>点<span class="ui">按意图分流</span>(或<span class="ui">添加规则</span>),在<span class="ui">先发给</span>里选模型,点<span class="ui">意图是</span>,写下这类消息想做什么,例如 <em>writing or fixing tests</em> 或「写测试或修测试」。同一条规则上的其他条件也必须同时满足。</li>
|
||||
<li><b>添加带意图的规则</b>点<span class="ui">添加规则</span>。新规则读作<span class="ui">意图是</span> → 模型,光标已在意图框里:写下这类消息想做什么,例如 <em>writing or fixing tests</em> 或「写测试或修测试」,再在 → 后选模型。其他条件从规则的 <span class="ui">+</span> 添加,也必须同时满足。</li>
|
||||
<li><b>选择意图判断模型</b>有规则带意图后,下方会出现<span class="ui">意图判断模型</span>;有 TypeSafe provider 时默认就是 Jev,否则建议选小而快、不带推理的模型。已经让 Jev 选推理强度的分组,判断模型下方也有同一个入口:<span class="ui">它也能挑模型</span>。有意图却没有判断模型时,分组无法保存。</li>
|
||||
<li><b>保存,然后发条消息</b>从下一轮起生效,不用重启。<span class="ui">路由</span>页会显示判断模型说了什么、这一轮去了哪里。</li>
|
||||
</ol>
|
||||
|
||||
@@ -194,7 +194,7 @@
|
||||
<li>子代理是单独的会话,规则可以把它发到别处,主代理仍留在原处。</li>
|
||||
<li>意图是用几个词描述用户想做什么,例如“写或修测试”“一个简单问题”。每一轮开始时,magpie 会问一次组里指定的意图判断模型:用户这条消息属于哪个可能命中的意图。这个模型可以是 magpie 里的任意模型,建议选小而快、不带推理的。发过去的只有这条消息,不包括整段对话。它出错、超时(8 秒)或给不出答案时,意图条件都不命中,这一轮按其他规则走。如果前面有不带意图的规则已经能决定,就不会去问;同一条消息也不会问两次。它的调用在用量里显示为 magpie 自己的调用。它具体被问了什么、回答怎么用、失败时怎么办,详见<a href="/docs/zh/intent">意图路由</a>。</li>
|
||||
<li><span class="ui">压缩上下文时</span>:Agent 压缩对话上下文时命中——Claude Code 的 <code>/compact</code> 和自动压缩、Codex、OpenCode、Pi、Gemini CLI、Qwen Code、Kimi Code——让更便宜、更快的模型来写总结,对话本身仍留在原来的模型上。压缩请求单独决定:它所在的这一轮和缓存都留在原处。对话比规则里的模型能装下的还长时,改由下一条命中的规则或组本来的顺序决定。</li>
|
||||
<li><b>时段和星期。</b>规则可以只在某些时段、某几天生效,按这台电脑的时钟——比如厂商的高峰期。把这段时间的对话“先发给”别的模型,厂商那个模型仍排在后面做故障转移。要把它完全拿掉,把规则里的 <span class="ui">先发给</span> 改成 <span class="ui">暂停</span>:规则生效期间(它的时段、星期和 Agent),这个模型移出分组——不排第一、不做备用、也不会因为会话粘性被留住——时段过了自动回来。暂停只按时段、星期和 Agent 判断;组里所有模型都被暂停时,会告诉 Agent。</li>
|
||||
<li><b>时段和星期。</b>规则可以只在某些时段、某几天生效,按这台电脑的时钟——比如厂商的高峰期。把这段时间的对话“先发给”别的模型,厂商那个模型仍排在后面做故障转移。要把它完全拿掉,在规则的 <span class="ui">⋯</span> 菜单里选 <span class="ui">改为暂停该模型</span>:规则生效期间(它的时段、星期和 Agent),这个模型移出分组——不排第一、不做备用、也不会因为会话粘性被留住——时段过了自动回来。暂停只按时段、星期和 Agent 判断;组里所有模型都被暂停时,会告诉 Agent。</li>
|
||||
<li><b>文件夹。</b><span class="ui">项目文件夹</span>:Agent 的工作目录是你列出的文件夹之一或其子文件夹时命中:<code>~/work/acme</code> 包括 <code>~/work/acme/web</code>,不包括 <code>~/work/acme-old</code>。文件夹以 Agent 在请求里告诉模型的为准——Claude Code、Codex、OpenCode 和 Pi 都会说——不说明工作目录的 Agent 不会命中任何按文件夹的规则。<code>~</code> 是你的主目录,<code>C:\work</code> 也就是 WSL 里的 <code>/mnt/c/work</code>,macOS 和 Windows 上不区分大小写。</li>
|
||||
<li>路由标签页会显示每一轮是被哪条规则送到哪里的、意图判断模型给出的答案,以及 Agent 说的工作目录。</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user