AnyBot/.claude/skills/verify-approval-routing/model/statechart-view.ts

34 lines
2.0 KiB
TypeScript

// /pstack:statechart 讀 ApprovalRouting 的結果時用的白話標籤(照 pstack 0.15.43 的 view 格式寫;
// /pstack:statechart 現在的說明不一樣時,照它的說明改這個檔)。
type Pair = { 1: number; 2: number };
type Msg = { from: string; ans: string; key: number; seen: number };
type V = { bot: string; card: number; page: Pair; screen: Pair; banner: Pair; inflight: Msg[]; allowed: Pair[]; rules: Pair[] };
export const title = "等你允許的卡片:回答落在哪一張";
export const state = (v: V) => {
const wrong = v.allowed.some((p) => p[1] !== p[2]);
const brain = wrong ? "讓沒看到的卡通過了" : v.card !== 0 ? "有一張卡在等" : v.bot === "sent" ? "新的請求在路上" : "沒有卡在等";
const drawn = [v.page, v.banner, v.screen].filter((p) => p[1] !== 0);
const away = drawn.length === 0 ? "沒有卡" : drawn.some((p) => p[1] !== v.card) ? "有舊的卡" : "是現在這張";
const sent = v.inflight.length === 0 ? "沒有" : v.inflight.some((m) => m.seen !== v.card) ? "給舊卡的回答" : "給現在這張的回答";
return { 大腦: brain, 手機和螢幕電腦上: away, 路上的回答: sent };
};
export const step = (action: string, from: V, to: V) => {
switch (action) {
case "BotAsks": return "Bot 要做下一件要問的事";
case "CardShows": return "大腦把卡放上來";
case "TurnStops": return "卡沒被回答就不見了(停止、逾時)";
case "YouAnswerOnDesk": return "你在電腦上回答";
case "PageRefreshes": return "手機重新拿到畫面";
case "YouTapOnPage": return "你在手機的卡上按";
case "YouTapBanner": return "你在手機通知上按";
case "ScreenRefreshes": return "螢幕電腦同步";
case "YouAnswerOnScreen": return "你在螢幕電腦上回答";
case "BrainTakesAnswer": return to.card !== from.card ? "大腦收到回答,交給現在的卡" : "大腦收到回答,沒有用上";
case "Finished": return null;
default: return action;
}
};