Skip to content

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

Keep the OAuth client for refresh and offer a GitHub token path

Fei2411b56b8e653423
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 1a7419fd..b6735fe0 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -153,6 +153,7 @@ var ZH = {
Connect: "连接",
"GitHub token": "GitHub token",
"Create a token on GitHub": "去 GitHub 生成 token",
+ "Use a token instead": "改用 token",
"Could not reach GitHub": "连不上 GitHub",
"GitHub did not accept this token": "GitHub 不接受这个 token",
"GitHub did not say who this token belongs to": "GitHub 没有返回这个 token 的账号",
@@ -10472,7 +10473,7 @@ function BrowserPanel({ connector, actions, run: run2 }) {
) : null
);
}
-function DevicePanel({ connector, actions, run: run2 }) {
+function DevicePanel({ connector, actions, run: run2, onUseToken }) {
const [copied, setCopied] = (0, import_react24.useState)(false);
return (0, import_react24.createElement)(
"div",
@@ -10492,6 +10493,7 @@ function DevicePanel({ connector, actions, run: run2 }) {
"div",
{ className: "bt-connector-form-row" },
(0, import_react24.createElement)("a", { className: "bt-connector-link", href: connector.pending.verificationUri, target: "_blank", rel: "noopener noreferrer" }, t("Open {host}", { host: connector.pending.verificationUri.replace(/^https?:\/\//, "") })),
+ connector.auth?.token === true && onUseToken ? (0, import_react24.createElement)("button", { type: "button", className: "bt-connector-link", onClick: () => void run2(actions.connectorCancel(connector.id), onUseToken) }, t("Use a token instead")) : null,
(0, import_react24.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => void run2(actions.connectorCancel(connector.id)) }, t("Cancel"))
)
);
@@ -10576,7 +10578,8 @@ function ConnectorRow({ connector, actions }) {
"span",
{ className: "bt-connector-actions" },
connector.state === "error" || connector.state === "needs-sign-in" ? (0, import_react24.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: busy, onClick: () => void run2(actions.connectorRetry(connector.id)) }, connector.state === "needs-sign-in" ? t("Sign in again") : t("Try again")) : null,
- on && !pending ? (0, import_react24.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: busy, onClick: () => void run2(actions.connectorDisconnect(connector.id)) }, connector.custom ? t("Remove") : t("Disconnect")) : pending || form ? null : (0, import_react24.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: busy, onClick: connect }, t("Connect"))
+ on && !pending ? (0, import_react24.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: busy, onClick: () => void run2(actions.connectorDisconnect(connector.id)) }, connector.custom ? t("Remove") : t("Disconnect")) : pending || form ? null : (0, import_react24.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: busy, onClick: connect }, t("Connect")),
+ !on && !pending && form === null && connector.auth?.kind === "oauth" && connector.auth.token === true && connector.auth.client?.id ? (0, import_react24.createElement)("button", { type: "button", className: "bt-connector-link", disabled: busy, onClick: () => setForm("token") }, t("Use a token instead")) : null
)
),
connector.readOnly !== void 0 && on ? (0, import_react24.createElement)(
@@ -10585,13 +10588,12 @@ function ConnectorRow({ connector, actions }) {
(0, import_react24.createElement)(SwitchRow, { label: t("Read-only"), on: connector.readOnly === true, onChange: (checked) => void run2(actions.connectorSet(connector.id, { readOnly: checked })) })
) : null,
pending?.kind === "browser" ? (0, import_react24.createElement)(BrowserPanel, { connector, actions, run: run2 }) : null,
- pending?.kind === "device" ? (0, import_react24.createElement)(DevicePanel, { connector, actions, run: run2 }) : null,
+ pending?.kind === "device" ? (0, import_react24.createElement)(DevicePanel, { connector, actions, run: run2, onUseToken: () => setForm("token") }) : null,
connector.state === "needs-client" && !pending?.kind ? (0, import_react24.createElement)(ClientPanel, { connector, actions, run: run2 }) : null,
form === "token" ? (0, import_react24.createElement)(TokenPanel, { connector, actions, run: run2, onDone: () => {
setForm(null);
setError(null);
} }) : null,
- form === null && !pending && connector.state === "off" && connector.auth?.kind === "oauth" && connector.auth.token === true && connector.auth.client?.id ? null : null,
error ? (0, import_react24.createElement)("div", { className: "bt-connector-error", role: "alert" }, error) : null,
connector.tools > 0 ? (0, import_react24.createElement)("div", { className: "bt-connector-status" }, t("{count} tools", { count: connector.tools })) : null
);
diff --git a/ds-bot/src/client/connectors.js b/ds-bot/src/client/connectors.js
index 3a366387..e2ef11c0 100644
--- a/ds-bot/src/client/connectors.js
+++ b/ds-bot/src/client/connectors.js
@@ -49,7 +49,7 @@ function BrowserPanel({ connector, actions, run }) {
h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => void run(actions.connectorSignInCode(connector.id, input.trim())) }, t('Finish sign-in'))) : null)
}
-function DevicePanel({ connector, actions, run }) {
+function DevicePanel({ connector, actions, run, onUseToken }) {
const [copied, setCopied] = useState(false)
return h('div', { className: 'bt-connector-form' },
h('div', { className: 'bt-connector-device' },
@@ -57,6 +57,7 @@ function DevicePanel({ connector, actions, run }) {
h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => { void navigator.clipboard?.writeText(connector.pending.userCode).then(() => { setCopied(true); setTimeout(() => setCopied(false), 1600) }) } }, copied ? t('Copied') : t('Copy'))),
h('div', { className: 'bt-connector-form-row' },
h('a', { className: 'bt-connector-link', href: connector.pending.verificationUri, target: '_blank', rel: 'noopener noreferrer' }, t('Open {host}', { host: connector.pending.verificationUri.replace(/^https?:\/\//, '') })),
+ connector.auth?.token === true && onUseToken ? h('button', { type: 'button', className: 'bt-connector-link', onClick: () => void run(actions.connectorCancel(connector.id), onUseToken) }, t('Use a token instead')) : null,
h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => void run(actions.connectorCancel(connector.id)) }, t('Cancel'))))
}
@@ -118,15 +119,16 @@ export function ConnectorRow({ connector, actions }) {
connector.state === 'error' || connector.state === 'needs-sign-in' ? h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy, onClick: () => void run(actions.connectorRetry(connector.id)) }, connector.state === 'needs-sign-in' ? t('Sign in again') : t('Try again')) : null,
on && !pending
? h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy, onClick: () => void run(actions.connectorDisconnect(connector.id)) }, connector.custom ? t('Remove') : t('Disconnect'))
- : pending || form ? null : h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy, onClick: connect }, t('Connect')))),
+ : pending || form ? null : h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy, onClick: connect }, t('Connect')),
+ !on && !pending && form === null && connector.auth?.kind === 'oauth' && connector.auth.token === true && connector.auth.client?.id
+ ? h('button', { type: 'button', className: 'bt-connector-link', disabled: busy, onClick: () => setForm('token') }, t('Use a token instead'))
+ : null)),
connector.readOnly !== undefined && on ? h('div', { className: 'bt-connector-ro' },
h(SwitchRow, { label: t('Read-only'), on: connector.readOnly === true, onChange: checked => void run(actions.connectorSet(connector.id, { readOnly: checked })) })) : null,
pending?.kind === 'browser' ? h(BrowserPanel, { connector, actions, run }) : null,
- pending?.kind === 'device' ? h(DevicePanel, { connector, actions, run }) : null,
+ pending?.kind === 'device' ? h(DevicePanel, { connector, actions, run, onUseToken: () => setForm('token') }) : null,
connector.state === 'needs-client' && !pending?.kind ? h(ClientPanel, { connector, actions, run }) : null,
form === 'token' ? h(TokenPanel, { connector, actions, run, onDone: () => { setForm(null); setError(null) } }) : null,
- form === null && !pending && connector.state === 'off' && connector.auth?.kind === 'oauth' && connector.auth.token === true && connector.auth.client?.id
- ? null : null,
error ? h('div', { className: 'bt-connector-error', role: 'alert' }, error) : null,
connector.tools > 0 ? h('div', { className: 'bt-connector-status' }, t('{count} tools', { count: connector.tools })) : null)
}
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index 415eee00..a6a31375 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -117,6 +117,7 @@ const ZH = {
Connect: '连接',
'GitHub token': 'GitHub token',
'Create a token on GitHub': '去 GitHub 生成 token',
+ 'Use a token instead': '改用 token',
'Could not reach GitHub': '连不上 GitHub',
'GitHub did not accept this token': 'GitHub 不接受这个 token',
'GitHub did not say who this token belongs to': 'GitHub 没有返回这个 token 的账号',
diff --git a/ds-bot/src/host/connectors/index.js b/ds-bot/src/host/connectors/index.js
index 8bc5c051..068909ce 100644
--- a/ds-bot/src/host/connectors/index.js
+++ b/ds-bot/src/host/connectors/index.js
@@ -307,6 +307,8 @@ export function install(rt) {
statuses.set(id, { state: 'needs-client' })
return
}
+ // Refresh needs to know which client signed in; DCR already persisted its result.
+ if (resolved.via !== 'dcr') await saveState(id, { client: { via: resolved.via, clientId: resolved.clientInformation.client_id } })
const stateParam = randomBytes(16).toString('base64url')
const { url, codeVerifier } = await oauth.beginBrowser(pending.discovery, resolved.clientInformation, redirectUri, { state: stateParam })
pendings.set(id, {
@@ -411,10 +413,17 @@ export function install(rt) {
if (refresh === undefined || saved?.oauth === undefined) { statuses.set(id, { state: 'needs-sign-in' }); return false }
try {
const discovery = await oauth.rediscover(saved.oauth)
- const client = saved.client?.clientId !== undefined
- ? { client_id: saved.client.clientId, ...(rt.secretValue(clientSecretOf(id)) !== undefined ? { client_secret: rt.secretValue(clientSecretOf(id)) } : {}) }
- : undefined
- if (client === undefined) { statuses.set(id, { state: 'needs-client' }); return false }
+ // Refresh with the client that signed in: catalog → the current catalog id,
+ // CIMD → the published document id, DCR/manual → the stored id (+ secret).
+ // Rows signed in before clients were persisted have no `client`: fall back to
+ // CIMD when the AS supports it, otherwise ask the user to sign in again.
+ const via = saved.client?.via
+ const clientId = via === 'catalog' ? entryFor(id)?.auth?.client?.id
+ : via === 'cimd' ? oauth.CIMD_CLIENT_ID
+ : saved.client?.clientId ?? (discovery.metadata?.client_id_metadata_document_supported === true ? oauth.CIMD_CLIENT_ID : undefined)
+ if (clientId === undefined) { statuses.set(id, { state: 'needs-sign-in' }); return false }
+ const secret = rt.secretValue(clientSecretOf(id))
+ const client = { client_id: clientId, ...(secret !== undefined ? { client_secret: secret } : {}) }
const tokens = await oauth.refreshTokens(discovery, client, refresh, { scope: saved.oauth.scope })
const purpose = `${entryFor(id)?.name ?? id} connector`
await writeSecret(tokenSecretOf(id), tokens.access_token, purpose)
diff --git a/ds-bot/test/connectors-engine.test.js b/ds-bot/test/connectors-engine.test.js
index d3eacdff..e7449106 100644
--- a/ds-bot/test/connectors-engine.test.js
+++ b/ds-bot/test/connectors-engine.test.js
@@ -301,6 +301,68 @@ test('refresh is single-flight, rotates the refresh token, and invalid_grant mea
assert.equal(rt.secretValue('CONNECTOR_NOTION_REFRESH'), 'RT-2')
})
+test('refresh uses the client that signed in: cimd, catalog, and legacy inference', async (t) => {
+ const seen = []
+ let asMeta = AS
+ const request = async (url, init) => {
+ url = String(url?.url ?? url)
+ if (url.includes('oauth-authorization-server')) return json(asMeta)
+ if (url === 'https://as.test/token') {
+ seen.push(new URLSearchParams(init?.body ?? '').get('client_id'))
+ return json({ access_token: `AT-${seen.length}`, token_type: 'Bearer' })
+ }
+ return notFound()
+ }
+ const real = globalThis.fetch
+ globalThis.fetch = request
+ t.after(() => { globalThis.fetch = real })
+ const make = async (connectors, secret, github = false) => {
+ const home = teamHome({ connectors })
+ const ctx = fakeContext()
+ const rt = createRuntime(ctx, { home, github })
+ await rt.load(); await rt.loadSecrets()
+ await rt.secretEndpoint('secret-set', secret)
+ return { rt, done: async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true }) } }
+ }
+ // A CIMD sign-in refreshes with the published document id.
+ {
+ const { rt, done } = await make(
+ { notion: { oauth: { authorizationServerUrl: 'https://as.test' }, client: { via: 'cimd', clientId: 'https://dsbot.app/oauth/client.json' } } },
+ { name: 'CONNECTOR_NOTION_REFRESH', value: 'RT-1', scope: [] })
+ t.after(done)
+ assert.equal(await rt.connectorsInternals.refreshConnector('notion'), true, JSON.stringify(rt.connectorsInternals.statuses.get('notion')))
+ assert.equal(seen.at(-1), 'https://dsbot.app/oauth/client.json')
+ }
+ // A catalog sign-in refreshes with the current catalog client id.
+ {
+ const { rt, done } = await make(
+ { github: { oauth: { authorizationServerUrl: 'https://as.test' }, client: { via: 'catalog' } } },
+ { name: 'CONNECTOR_GITHUB_REFRESH', value: 'RT-2', scope: [] }, true)
+ t.after(done)
+ assert.equal(await rt.connectorsInternals.refreshConnector('github'), true, JSON.stringify(rt.connectorsInternals.statuses.get('github')))
+ assert.equal(seen.at(-1), 'test-gh-client')
+ }
+ // Legacy rows have no `client`: CIMD when the AS supports it, else needs-sign-in.
+ {
+ asMeta = { ...AS, client_id_metadata_document_supported: true }
+ const { rt, done } = await make(
+ { notion: { oauth: { authorizationServerUrl: 'https://as.test' } } },
+ { name: 'CONNECTOR_NOTION_REFRESH', value: 'RT-3', scope: [] })
+ t.after(done)
+ assert.equal(await rt.connectorsInternals.refreshConnector('notion'), true, JSON.stringify(rt.connectorsInternals.statuses.get('notion')))
+ assert.equal(seen.at(-1), 'https://dsbot.app/oauth/client.json')
+ }
+ {
+ asMeta = AS
+ const { rt, done } = await make(
+ { notion: { oauth: { authorizationServerUrl: 'https://as.test' } } },
+ { name: 'CONNECTOR_NOTION_REFRESH', value: 'RT-4', scope: [] })
+ t.after(done)
+ assert.equal(await rt.connectorsInternals.refreshConnector('notion'), false)
+ assert.equal(rt.connectorsInternals.statuses.get('notion').state, 'needs-sign-in', JSON.stringify(rt.connectorsInternals.statuses.get('notion')))
+ }
+})
+
test('read-only windows never refresh', async (t) => {
const home = teamHome({ connectors: { notion: { oauth: { authorizationServerUrl: 'https://as.test' }, client: { via: 'dcr', clientId: 'c' } } } })
const ctx = fakeContext()