A desktop coding agent with free access to frontier models.
TypeScript
fix: daily cap per slot
ogsamrat5da00080561b
diff --git a/apps/desktop/electron/placements-desktop.test.mjs b/apps/desktop/electron/placements-desktop.test.mjsindex 9fcdb571..84c90e23 100644--- a/apps/desktop/electron/placements-desktop.test.mjs+++ b/apps/desktop/electron/placements-desktop.test.mjs@@ -134,16 +134,16 @@ test("shared: caps, snooze and expiry", async () => {assert.equal(e.claim("home_banner"), null, "ended");});-test("shared: one id in both slots: both entries kept, the count shared by id", async () => {- const both = [placement({ id: "plc_both", slot: "home_banner", max_per_day: 2 }), placement({ id: "plc_both", slot: "turn_footer", title: "Turn copy", max_per_day: 2 })];+test("shared: one id in both slots: both entries kept, a day's count per slot", async () => {+ const both = [placement({ id: "plc_both", slot: "home_banner", max_per_day: 1 }), placement({ id: "plc_both", slot: "turn_footer", title: "Turn copy", max_per_day: 1 })];assert.equal(parseAnswer(answer(both)).placements.length, 2);const { d } = desktop({ routes: () => ({ status: 200, data: answer(both) }) });assert.equal((await d.placement({ slot: "home_banner" })).slot, "home_banner");const turn = await d.placement({ slot: "turn_footer", sessionId: "ses_1" });assert.equal(turn.slot, "turn_footer");assert.equal(turn.title, "Turn copy");- assert.equal(d.service.state().shown.plc_both.count, 2);- assert.equal(await d.placement({ slot: "turn_footer", sessionId: "ses_2" }), null, "shared max_per_day");+ assert.deepEqual([d.service.state().shown["home_banner:plc_both"].count, d.service.state().shown["turn_footer:plc_both"].count], [1, 1], "the home card did not use up the turn line");+ assert.equal(await d.placement({ slot: "turn_footer", sessionId: "ses_2" }), null, "the turn slot's own max_per_day 1");assert.deepEqual(await d.action({ id: "plc_both", action: "dismiss" }), { ok: true });assert.equal(d.service.current("turn_footer"), null);});diff --git a/apps/desktop/electron/placements/PARITY.sha256 b/apps/desktop/electron/placements/PARITY.sha256index f67a7e9b..5d78d051 100644--- a/apps/desktop/electron/placements/PARITY.sha256+++ b/apps/desktop/electron/placements/PARITY.sha256@@ -1,3 +1,3 @@# Sponsored placements: the same file in omnirush-cli (assets/extensions/omnirush/placements/)# and omnirush-gui (apps/desktop/electron/placements/). A change to one must be ported to the other and this list updated in both.-47323966e54972473adb398c358af34ed9451d452e9deb977e7fffcbf12ccc74 placements.mjs+88be687252554537b9ff48d20733a9883b051a8852d5686091d069667859e1f4 placements.mjsdiff --git a/apps/desktop/electron/placements/placements.mjs b/apps/desktop/electron/placements/placements.mjsindex e5fb29cd..4b615ca6 100644--- a/apps/desktop/electron/placements/placements.mjs+++ b/apps/desktop/electron/placements/placements.mjs@@ -11,7 +11,7 @@// start-up never waits for it.//// Local rules, on top of the server's: a placement's window (starts_at,-// ends_at), `max_per_day` displays per placement per local day, at most+// ends_at), `max_per_day` displays per placement and slot per local day, at most// `max_per_advertiser_per_day` (default 3) displays per `advertiser_id` (else// per sponsor name) per local day, `snooze_days` after a dismissal, the turn// slot once per session. Copy is plain text,@@ -359,6 +359,9 @@ export function refreshDue(state, now) {return now - state.fetched_at >= every || state.fetched_at - now > DAY_MS;}+/** The day's count of a placement is per slot: one id served in both slots has a `max_per_day` in each. */+export const shownKey = (placement) => `${placement.slot}:${placement.id}`;+/** Whether `placement` may show in `slot` now (window, snooze, the day's counts, hidden). */export function eligible(placement, slot, state, now) {if (placement.slot !== slot) return false;@@ -367,7 +370,7 @@ export function eligible(placement, slot, state, now) {if (state.hidden_until && now < state.hidden_until) return false;const snoozedUntil = state.snoozed[placement.id];if (Number.isFinite(snoozedUntil) && now < snoozedUntil) return false;- const shown = state.shown[placement.id];+ const shown = state.shown[shownKey(placement)];if (shown && shown.day === localDay(now) && shown.count >= placement.maxPerDay) return false;const advertiser = state.advertisers?.[placement.advertiser];if (advertiser && advertiser.day === localDay(now) && advertiser.count >= placement.maxPerAdvertiserPerDay) return false;@@ -489,8 +492,8 @@ export function createPlacements({let displayId = String(newDisplayId()).toLowerCase();while (Object.hasOwn(state.displays, displayId)) displayId = String(newDisplayId()).toLowerCase();const day = localDay(at);- const shown = state.shown[placement.id];- state.shown[placement.id] = { day, count: shown && shown.day === day ? shown.count + 1 : 1 };+ const shown = state.shown[shownKey(placement)];+ state.shown[shownKey(placement)] = { day, count: shown && shown.day === day ? shown.count + 1 : 1 };const advertiser = state.advertisers[placement.advertiser];state.advertisers[placement.advertiser] = { day, count: advertiser && advertiser.day === day ? advertiser.count + 1 : 1 };// Old days are forgotten.