Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Drop expired browser grants on save

Fei24119aa4c33f63c5
diff --git a/ds-bot/client.js b/ds-bot/client.js
index e6ae4eb8..5e7ea3f6 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -2776,7 +2776,7 @@ button.bt-set-row:hover{background:var(--bt-hover)}
.bt-browser-action-choice{display:inline-flex;align-items:center;gap:4px;font-size:12px;white-space:nowrap}
.bt-browser-duration-choice{border:1px solid var(--bt-line);border-radius:8px;padding:5px 8px;background:var(--bt-card);color:var(--bt-ink-2);font:inherit;font-size:12px;cursor:pointer}
.bt-browser-duration-choice[aria-pressed=true]{background:var(--bt-hover);color:var(--bt-ink)}
-.bt-browser-form-row>.bt-set-control{flex:1;min-width:0}
+.bt-browser-form>.bt-set-row>.bt-set-control{flex:1;min-width:0}
.bt-browser-form>.bt-set-row+.bt-set-row{border-top:.5px solid var(--bt-line)}
.bt-browser-site{max-width:320px}
.bt-browser-form-foot{display:flex;justify-content:flex-end;padding:10px 12px;border-top:.5px solid var(--bt-line)}
@@ -14177,6 +14177,7 @@ function ConnectorsPage({ roster, actions }) {
var import_react33 = require("react");
var ACTIONS = [["post", "Post"], ["upload", "Upload"], ["download", "Download"], ["delete", "Delete"]];
var DURATIONS = [["hour", "1 hour"], ["today", "Today"], ["week", "7 days"], ["permanent", "Permanent"]];
+var expired = (grant) => Number.isFinite(grant.until) && grant.until <= Date.now();
function siteValue(value) {
return value.trim().toLowerCase().replace(/^[a-z][a-z\d+.-]*:\/\//, "").split(/[/?#]/, 1)[0].replace(/:\d+$/, "") || "*";
}
@@ -14205,10 +14206,10 @@ function BrowserPage({ roster, actions, run: run2, Section, Row: Row3 }) {
bot,
grant,
index,
- expired: Number.isFinite(grant.until) && grant.until <= Date.now()
+ expired: expired(grant)
})));
const remove = (bot, index) => {
- const next = (bot.browserGrants ?? []).filter((_grant, position) => position !== index);
+ const next = (bot.browserGrants ?? []).filter((grant, position) => position !== index && !expired(grant));
void run2(actions.updateBot(bot.id, { browserGrants: next.length ? next : null }));
};
const add = (event) => {
@@ -14225,7 +14226,7 @@ function BrowserPage({ roster, actions, run: run2, Section, Row: Row3 }) {
const grant = { site: siteValue(site), kinds: [...kinds], ...until !== void 0 ? { until } : {} };
setBusy(true);
void run2(actions.updateBot(selectedBot.id, {
- browserGrants: [...selectedBot.browserGrants ?? [], grant]
+ browserGrants: [...(selectedBot.browserGrants ?? []).filter((grant2) => !expired(grant2)), grant]
})).finally(() => setBusy(false));
};
const toggleKind = (kind, checked) => {
@@ -14242,11 +14243,11 @@ function BrowserPage({ roster, actions, run: run2, Section, Row: Row3 }) {
(0, import_react33.createElement)(
Section,
{ title: t("Allowed actions") },
- grants.length === 0 ? (0, import_react33.createElement)(Row3, { label: t("Nothing allowed yet.") }) : grants.map(({ bot, grant, index, expired }) => (0, import_react33.createElement)(
+ grants.length === 0 ? (0, import_react33.createElement)(Row3, { label: t("Nothing allowed yet.") }) : grants.map(({ bot, grant, index, expired: expired2 }) => (0, import_react33.createElement)(
"div",
{
key: `${bot.id}:${index}`,
- className: `bt-browser-grant${expired ? " bt-browser-grant-expired" : ""}`
+ className: `bt-browser-grant${expired2 ? " bt-browser-grant-expired" : ""}`
},
(0, import_react33.createElement)(
"div",
@@ -14277,7 +14278,7 @@ function BrowserPage({ roster, actions, run: run2, Section, Row: Row3 }) {
{ className: "bt-browser-form", onSubmit: add },
(0, import_react33.createElement)(
Row3,
- { className: "bt-browser-form-row", label: t("Bot") },
+ { label: t("Bot") },
(0, import_react33.createElement)(
"select",
{ className: "bt-select", value: botId, onChange: (event) => setBotId(event.target.value), disabled: bots.length === 0 },
@@ -14286,7 +14287,7 @@ function BrowserPage({ roster, actions, run: run2, Section, Row: Row3 }) {
),
(0, import_react33.createElement)(
Row3,
- { className: "bt-browser-form-row", label: t("Site") },
+ { label: t("Site") },
(0, import_react33.createElement)("input", {
className: "bt-select bt-browser-site",
type: "text",
@@ -14297,7 +14298,7 @@ function BrowserPage({ roster, actions, run: run2, Section, Row: Row3 }) {
),
(0, import_react33.createElement)(
Row3,
- { className: "bt-browser-form-row", label: t("Actions") },
+ { label: t("Actions") },
(0, import_react33.createElement)(
"div",
{ className: "bt-browser-action-list" },
@@ -14315,7 +14316,7 @@ function BrowserPage({ roster, actions, run: run2, Section, Row: Row3 }) {
),
(0, import_react33.createElement)(
Row3,
- { className: "bt-browser-form-row", label: t("Duration") },
+ { label: t("Duration") },
(0, import_react33.createElement)(
"div",
{ className: "bt-browser-duration", role: "group", "aria-label": t("Duration") },
diff --git a/ds-bot/src/client/browser-settings.js b/ds-bot/src/client/browser-settings.js
index 20a18896..358c10ee 100644
--- a/ds-bot/src/client/browser-settings.js
+++ b/ds-bot/src/client/browser-settings.js
@@ -4,6 +4,7 @@ import { dateLocale, t } from './i18n.js'
const ACTIONS = [['post', 'Post'], ['upload', 'Upload'], ['download', 'Download'], ['delete', 'Delete']]
const DURATIONS = [['hour', '1 hour'], ['today', 'Today'], ['week', '7 days'], ['permanent', 'Permanent']]
+const expired = grant => Number.isFinite(grant.until) && grant.until <= Date.now()
function siteValue(value) {
return value.trim().toLowerCase()
@@ -38,10 +39,10 @@ export function BrowserPage({ roster, actions, run, Section, Row }) {
}, [bots, botId])
const grants = bots.flatMap(bot => (bot.browserGrants ?? []).map((grant, index) => ({
- bot, grant, index, expired: Number.isFinite(grant.until) && grant.until <= Date.now(),
+ bot, grant, index, expired: expired(grant),
})))
const remove = (bot, index) => {
- const next = (bot.browserGrants ?? []).filter((_grant, position) => position !== index)
+ const next = (bot.browserGrants ?? []).filter((grant, position) => position !== index && !expired(grant))
void run(actions.updateBot(bot.id, { browserGrants: next.length ? next : null }))
}
const add = event => {
@@ -58,7 +59,7 @@ export function BrowserPage({ roster, actions, run, Section, Row }) {
const grant = { site: siteValue(site), kinds: [...kinds], ...(until !== undefined ? { until } : {}) }
setBusy(true)
void run(actions.updateBot(selectedBot.id, {
- browserGrants: [...(selectedBot.browserGrants ?? []), grant],
+ browserGrants: [...(selectedBot.browserGrants ?? []).filter(grant => !expired(grant)), grant],
})).finally(() => setBusy(false))
}
const toggleKind = (kind, checked) => {
@@ -90,10 +91,10 @@ export function BrowserPage({ roster, actions, run, Section, Row }) {
}, t('Remove grant'))))),
h(Section, { title: t('Allow an action') },
h('form', { className: 'bt-browser-form', onSubmit: add },
- h(Row, { className: 'bt-browser-form-row', label: t('Bot') },
+ h(Row, { label: t('Bot') },
h('select', { className: 'bt-select', value: botId, onChange: event => setBotId(event.target.value), disabled: bots.length === 0 },
bots.map(bot => h('option', { key: bot.id, value: bot.id }, bot.name)))),
- h(Row, { className: 'bt-browser-form-row', label: t('Site') },
+ h(Row, { label: t('Site') },
h('input', {
className: 'bt-select bt-browser-site',
type: 'text',
@@ -101,7 +102,7 @@ export function BrowserPage({ roster, actions, run, Section, Row }) {
placeholder: t('example.com — leave empty for all sites'),
onChange: event => setSite(event.target.value),
})),
- h(Row, { className: 'bt-browser-form-row', label: t('Actions') },
+ h(Row, { label: t('Actions') },
h('div', { className: 'bt-browser-action-list' },
ACTIONS.map(([kind, label]) => h('label', { key: kind, className: 'bt-browser-action-choice' },
h('input', {
@@ -110,7 +111,7 @@ export function BrowserPage({ roster, actions, run, Section, Row }) {
onChange: event => toggleKind(kind, event.target.checked),
}),
t(label))))),
- h(Row, { className: 'bt-browser-form-row', label: t('Duration') },
+ h(Row, { label: t('Duration') },
h('div', { className: 'bt-browser-duration', role: 'group', 'aria-label': t('Duration') },
DURATIONS.map(([key, label]) => h('button', {
key,
diff --git a/ds-bot/src/client/styles.js b/ds-bot/src/client/styles.js
index 190e20f7..a6f607f0 100644
--- a/ds-bot/src/client/styles.js
+++ b/ds-bot/src/client/styles.js
@@ -515,7 +515,7 @@ button.bt-set-row:hover{background:var(--bt-hover)}
.bt-browser-action-choice{display:inline-flex;align-items:center;gap:4px;font-size:12px;white-space:nowrap}
.bt-browser-duration-choice{border:1px solid var(--bt-line);border-radius:8px;padding:5px 8px;background:var(--bt-card);color:var(--bt-ink-2);font:inherit;font-size:12px;cursor:pointer}
.bt-browser-duration-choice[aria-pressed=true]{background:var(--bt-hover);color:var(--bt-ink)}
-.bt-browser-form-row>.bt-set-control{flex:1;min-width:0}
+.bt-browser-form>.bt-set-row>.bt-set-control{flex:1;min-width:0}
.bt-browser-form>.bt-set-row+.bt-set-row{border-top:.5px solid var(--bt-line)}
.bt-browser-site{max-width:320px}
.bt-browser-form-foot{display:flex;justify-content:flex-end;padding:10px 12px;border-top:.5px solid var(--bt-line)}
diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.js
index 106dc39e..b4b79a9d 100644
--- a/ds-bot/src/host/roster.js
+++ b/ds-bot/src/host/roster.js
@@ -17,16 +17,19 @@ function cleanBrowserGrants(input) {
if (entry === null || typeof entry !== 'object' || Array.isArray(entry)) {
throw new Error('Each browser grant must have a site and kinds')
}
+ const until = entry.until
+ if (until !== undefined) {
+ if (typeof until !== 'number' || !Number.isFinite(until)) {
+ throw new Error('Browser grant until must be a future epoch-millisecond timestamp')
+ }
+ if (until <= Date.now()) continue
+ }
const site = typeof entry.site === 'string' ? entry.site.trim().toLowerCase() : ''
if (site !== '*' && !HOSTNAME.test(site)) throw new Error('Browser grant site must be * or a hostname')
if (!Array.isArray(entry.kinds) || entry.kinds.length === 0
|| entry.kinds.some(kind => typeof kind !== 'string' || !BROWSER_GRANT_KINDS.has(kind))) {
throw new Error('Browser grant kinds must be a non-empty subset of post, upload, download, delete, *')
}
- const until = entry.until
- if (until !== undefined && (typeof until !== 'number' || !Number.isFinite(until) || until <= Date.now())) {
- throw new Error('Browser grant until must be a future epoch-millisecond timestamp')
- }
const kinds = [...new Set(entry.kinds)].sort()
const key = `${site}\0${kinds.join('\0')}\0${until ?? ''}`
if (seen.has(key)) continue
diff --git a/ds-bot/test/browser-plugins.test.js b/ds-bot/test/browser-plugins.test.js
index a4a833b9..df421729 100644
--- a/ds-bot/test/browser-plugins.test.js
+++ b/ds-bot/test/browser-plugins.test.js
@@ -393,10 +393,22 @@ test('browser grants are user-only, normalized, deduplicated, expiring, and clea
/Browser grant kinds must be a non-empty subset/,
)
}
- await assert.rejects(
- rt.updateBot('b2', { browserGrants: [{ site: '*', kinds: ['post'], until: Date.now() - 1 }] }),
- /future epoch-millisecond timestamp/,
- )
+ for (const until of ['later', Number.NaN, Infinity]) {
+ await assert.rejects(
+ rt.updateBot('b2', { browserGrants: [{ site: '*', kinds: ['post'], until }] }),
+ /future epoch-millisecond timestamp/,
+ )
+ }
+ const expiredGrant = { site: '*', kinds: ['post'], until: Date.now() - 1 }
+ const expired = await call('update-bot', { id: 'b2', browserGrants: [expiredGrant] })
+ assert.equal(expired.ok, true)
+ assert.deepEqual(expired.value.browserGrants, [])
+ const freshGrant = { site: 'fresh.example', kinds: ['delete'], until: Date.now() + 60_000 }
+ const mixed = await call('update-bot', { id: 'b2', browserGrants: [expiredGrant, freshGrant] })
+ assert.equal(mixed.ok, true)
+ assert.deepEqual(mixed.value.browserGrants, [
+ { site: 'fresh.example', kinds: ['delete'], until: freshGrant.until },
+ ])
await assert.rejects(
rt.updateBot('b2', { browserGrants: Array.from({ length: 51 }, () => ({ site: '*', kinds: ['*'] })) }),
/array of at most 50 entries/,