@sideboard-ai/core 0.1.220 → 0.1.222

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -663,6 +663,20 @@ function cursorDeltaToEvents(update) {
663
663
  return [];
664
664
  }
665
665
 
666
+ // src/agents/cursor-model-selection.ts
667
+ function buildCursorModelSelection(model, opts) {
668
+ const raw = model && model.trim() || "";
669
+ const id = !raw || raw.toLowerCase() === "auto" || raw.toLowerCase() === "default" ? "default" : raw;
670
+ const params = [];
671
+ const effort = (opts.effort ?? "").trim().toLowerCase();
672
+ const normalized = effort === "normal" ? "medium" : effort === "low" || effort === "medium" || effort === "high" || effort === "xhigh" || effort === "max" ? effort : "";
673
+ if (normalized) {
674
+ params.push({ id: "effort", value: normalized });
675
+ }
676
+ params.push({ id: "fast", value: opts.fast ? "true" : "false" });
677
+ return { id, params };
678
+ }
679
+
666
680
  // src/agents/cursor-stream-coalesce.ts
667
681
  function isTextEvent(event) {
668
682
  return event.type === "stdout" || event.type === "thinking";
@@ -729,20 +743,6 @@ function emit(event) {
729
743
  process.stdout.write(`${JSON.stringify(event)}
730
744
  `);
731
745
  }
732
- function modelSelection(model, opts) {
733
- const raw = model && model.trim() || "";
734
- const id = !raw || raw.toLowerCase() === "auto" || raw.toLowerCase() === "default" ? "default" : raw;
735
- const params = [];
736
- const effort = (opts.effort ?? "").trim().toLowerCase();
737
- const normalized = effort === "normal" ? "medium" : effort === "low" || effort === "medium" || effort === "high" || effort === "xhigh" || effort === "max" ? effort : "";
738
- if (normalized) {
739
- params.push({ id: "effort", value: normalized });
740
- }
741
- if (opts.fast) {
742
- params.push({ id: "fast", value: "true" });
743
- }
744
- return params.length > 0 ? { id, params } : { id };
745
- }
746
746
  function localAgentStore(threadId) {
747
747
  const root = cursorSdkStoreDir(threadId);
748
748
  (0, import_node_fs12.mkdirSync)(root, { recursive: true });
@@ -798,7 +798,7 @@ async function main() {
798
798
  return 1;
799
799
  }
800
800
  const apiKey = (req.apiKey || process.env.CURSOR_API_KEY || "").trim() || void 0;
801
- const model = modelSelection(req.model, {
801
+ const model = buildCursorModelSelection(req.model, {
802
802
  effort: req.effort,
803
803
  fast: Boolean(req.fast)
804
804
  });
@@ -130,14 +130,8 @@ async function* iterateUntilIdle(iterable, idleMs, onIdle, activity) {
130
130
  }
131
131
  }
132
132
 
133
- // src/agents/cursor-runner.ts
134
- dropNestedElectronEnvFromProcess();
135
- ensureCursorRipgrepPath();
136
- function emit(event) {
137
- process.stdout.write(`${JSON.stringify(event)}
138
- `);
139
- }
140
- function modelSelection(model, opts) {
133
+ // src/agents/cursor-model-selection.ts
134
+ function buildCursorModelSelection(model, opts) {
141
135
  const raw = model && model.trim() || "";
142
136
  const id = !raw || raw.toLowerCase() === "auto" || raw.toLowerCase() === "default" ? "default" : raw;
143
137
  const params = [];
@@ -146,10 +140,16 @@ function modelSelection(model, opts) {
146
140
  if (normalized) {
147
141
  params.push({ id: "effort", value: normalized });
148
142
  }
149
- if (opts.fast) {
150
- params.push({ id: "fast", value: "true" });
151
- }
152
- return params.length > 0 ? { id, params } : { id };
143
+ params.push({ id: "fast", value: opts.fast ? "true" : "false" });
144
+ return { id, params };
145
+ }
146
+
147
+ // src/agents/cursor-runner.ts
148
+ dropNestedElectronEnvFromProcess();
149
+ ensureCursorRipgrepPath();
150
+ function emit(event) {
151
+ process.stdout.write(`${JSON.stringify(event)}
152
+ `);
153
153
  }
154
154
  function localAgentStore(threadId) {
155
155
  const root = cursorSdkStoreDir(threadId);
@@ -206,7 +206,7 @@ async function main() {
206
206
  return 1;
207
207
  }
208
208
  const apiKey = (req.apiKey || process.env.CURSOR_API_KEY || "").trim() || void 0;
209
- const model = modelSelection(req.model, {
209
+ const model = buildCursorModelSelection(req.model, {
210
210
  effort: req.effort,
211
211
  fast: Boolean(req.fast)
212
212
  });
@@ -50,9 +50,9 @@ import {
50
50
  resolveQuotaFallbackAgent,
51
51
  turnCostUsdFromCursorUsage,
52
52
  whichOnPath
53
- } from "./chunk-3Y4FIARC.js";
53
+ } from "./chunk-SQHRPJ7P.js";
54
54
  import "./chunk-P2EAAM3H.js";
55
- import "./chunk-UNMMKZ4Q.js";
55
+ import "./chunk-SXFRXNBM.js";
56
56
  import "./chunk-P2BSMNHB.js";
57
57
  import "./chunk-VKQGAWHY.js";
58
58
  import "./chunk-NFWPDEN4.js";
@@ -44,12 +44,12 @@ import {
44
44
  resolveLoginCommand,
45
45
  resolveQuotaFallbackAgent,
46
46
  whichOnPath
47
- } from "./chunk-YG2X34EF.js";
47
+ } from "./chunk-VUW3VKLW.js";
48
48
  import "./chunk-N2VST3NL.js";
49
49
  import "./chunk-KTZESHYH.js";
50
50
  import "./chunk-6K64FJDD.js";
51
51
  import "./chunk-PO4M4JAJ.js";
52
- import "./chunk-QILV2BRW.js";
52
+ import "./chunk-ZXJMAKEP.js";
53
53
  import "./chunk-ROPGQRPU.js";
54
54
  import "./chunk-N7WZ6NIN.js";
55
55
  import {
@@ -42,7 +42,7 @@ import {
42
42
  summarizeTurnStderr,
43
43
  toolDescription,
44
44
  turnFailChatText
45
- } from "./chunk-3Y4FIARC.js";
45
+ } from "./chunk-SQHRPJ7P.js";
46
46
  import {
47
47
  SLACK_REPLY_FORMATTING,
48
48
  addWorkspace,
@@ -418,7 +418,7 @@ async function continueSourceThread(threadId, prompt) {
418
418
  await continueOnReply(threadId, prompt);
419
419
  return;
420
420
  }
421
- const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-P4KNHFHG.js");
421
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-ZAJ2M4UW.js");
422
422
  await getOrchestrator2().send(threadId, prompt);
423
423
  } catch {
424
424
  }
@@ -6957,7 +6957,7 @@ function formatScheduledPrompt(name, prompt) {
6957
6957
  ${prompt}`;
6958
6958
  }
6959
6959
  async function defaultDeps() {
6960
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-P4KNHFHG.js");
6960
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-ZAJ2M4UW.js");
6961
6961
  const orch = getOrchestrator2();
6962
6962
  return {
6963
6963
  findThread: (id) => findThreadByRef(id),
@@ -24,7 +24,7 @@ import {
24
24
  resolveQuotaFallbackAgent,
25
25
  stripBrightsyNdjsonNoise,
26
26
  toolDescription
27
- } from "./chunk-YG2X34EF.js";
27
+ } from "./chunk-VUW3VKLW.js";
28
28
  import {
29
29
  SLACK_REPLY_FORMATTING,
30
30
  addWorkspace,
@@ -482,7 +482,7 @@ async function continueSourceThread(threadId, prompt) {
482
482
  await continueOnReply(threadId, prompt);
483
483
  return;
484
484
  }
485
- const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-Y5IDLJ7D.js");
485
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-O3FNYIRE.js");
486
486
  await getOrchestrator2().send(threadId, prompt);
487
487
  } catch {
488
488
  }
@@ -4178,7 +4178,7 @@ async function createThread(input, _onSetupLine) {
4178
4178
  return readThread(thread.id) ?? thread;
4179
4179
  }
4180
4180
  async function listLinearIssues(agent, repoPath) {
4181
- const { getAdapter: getAdapter2 } = await import("./agents-6UOWJLXX.js");
4181
+ const { getAdapter: getAdapter2 } = await import("./agents-QQ77D7VT.js");
4182
4182
  await requireAgent(agent, { requireLinear: true });
4183
4183
  const adapter = getAdapter2(agent);
4184
4184
  if (!adapter.listLinearIssues) {
@@ -7332,7 +7332,7 @@ function formatScheduledPrompt(name, prompt) {
7332
7332
  ${prompt}`;
7333
7333
  }
7334
7334
  async function defaultDeps() {
7335
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-Y5IDLJ7D.js");
7335
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-O3FNYIRE.js");
7336
7336
  const orch = getOrchestrator2();
7337
7337
  return {
7338
7338
  findThread: (id) => findThreadByRef(id),
@@ -8,7 +8,7 @@ import {
8
8
  brightsyMcpServerName,
9
9
  ensureCliTeamTracked,
10
10
  ensureConnectedBrightsyTeamTokens
11
- } from "./chunk-UNMMKZ4Q.js";
11
+ } from "./chunk-SXFRXNBM.js";
12
12
  import {
13
13
  loadBrightsyConfig
14
14
  } from "./chunk-P2BSMNHB.js";
@@ -146,24 +146,44 @@ async function ensureConnectedBrightsyTeamTokens(opts) {
146
146
  );
147
147
  const teams = readStore();
148
148
  if (teams.length === 0) return [];
149
+ const cfg = (() => {
150
+ try {
151
+ return loadBrightsyConfig();
152
+ } catch {
153
+ return null;
154
+ }
155
+ })();
149
156
  const next = [];
150
157
  let changed = false;
151
158
  for (const team of teams) {
152
- if (!team.refresh_token || !brightsyAccessTokenNeedsRefresh(team.expires_at)) {
153
- next.push(team);
159
+ let current = team;
160
+ if (!current.oauth_client_id?.trim()) {
161
+ const endpoint = current.endpoint || "https://brightsy.ai";
162
+ const clientId = await ensureBrightsyOAuthClientId({
163
+ endpoint,
164
+ clientId: cfg?.oauth_client_id,
165
+ fetchImpl: opts?.fetchImpl
166
+ });
167
+ if (clientId && clientId !== current.oauth_client_id) {
168
+ current = { ...current, oauth_client_id: clientId };
169
+ changed = true;
170
+ }
171
+ }
172
+ if (!current.refresh_token || !brightsyAccessTokenNeedsRefresh(current.expires_at)) {
173
+ next.push(current);
154
174
  continue;
155
175
  }
156
- const refreshed = await refreshTeamToken(team, opts);
157
- if (refreshed.access_token !== team.access_token || refreshed.refresh_token !== team.refresh_token || refreshed.expires_at !== team.expires_at || refreshed.oauth_client_id !== team.oauth_client_id) {
176
+ const refreshed = await refreshTeamToken(current, opts);
177
+ if (refreshed.access_token !== current.access_token || refreshed.refresh_token !== current.refresh_token || refreshed.expires_at !== current.expires_at || refreshed.oauth_client_id !== current.oauth_client_id) {
158
178
  changed = true;
159
179
  }
160
180
  next.push(refreshed);
161
181
  }
162
182
  if (changed) writeStore(next);
163
183
  try {
164
- const cfg = loadBrightsyConfig();
165
- const active = next.find((t) => t.id === cfg.account_id);
166
- if (active && active.access_token !== cfg.access_token) {
184
+ const cfg2 = loadBrightsyConfig();
185
+ const active = next.find((t) => t.id === cfg2.account_id);
186
+ if (active && active.access_token !== cfg2.access_token) {
167
187
  applyConnectedTeamToCli(active);
168
188
  }
169
189
  } catch {
@@ -12,7 +12,7 @@ import {
12
12
  brightsyMcpServerName,
13
13
  ensureCliTeamTracked,
14
14
  ensureConnectedBrightsyTeamTokens
15
- } from "./chunk-QILV2BRW.js";
15
+ } from "./chunk-ZXJMAKEP.js";
16
16
  import {
17
17
  loadBrightsyConfig
18
18
  } from "./chunk-ROPGQRPU.js";
@@ -19,7 +19,7 @@ import { join } from "path";
19
19
 
20
20
  // src/brightsy/accounts.ts
21
21
  async function loadConnectedTeams() {
22
- const { listConnectedBrightsyTeams: listConnectedBrightsyTeams2 } = await import("./connected-teams-PRHZS6B4.js");
22
+ const { listConnectedBrightsyTeams: listConnectedBrightsyTeams2 } = await import("./connected-teams-PIBQTOJU.js");
23
23
  return listConnectedBrightsyTeams2();
24
24
  }
25
25
  async function runBrightsyTeamsJson(args) {
@@ -48,14 +48,14 @@ async function listBrightsyAccounts() {
48
48
  async function getBrightsySession() {
49
49
  try {
50
50
  const { ensureBrightsyLocalConfigFresh: ensureBrightsyLocalConfigFresh2 } = await import("./oauth-S3M7B475.js");
51
- const { ensureConnectedBrightsyTeamTokens: ensureConnectedBrightsyTeamTokens2 } = await import("./connected-teams-PRHZS6B4.js");
51
+ const { ensureConnectedBrightsyTeamTokens: ensureConnectedBrightsyTeamTokens2 } = await import("./connected-teams-PIBQTOJU.js");
52
52
  await ensureBrightsyLocalConfigFresh2();
53
53
  await ensureConnectedBrightsyTeamTokens2();
54
54
  loadBrightsyConfig();
55
55
  const data = await runBrightsyTeamsJson([]);
56
56
  const accounts = Array.isArray(data.teams) ? data.teams : [];
57
57
  const active = data.active ?? accounts.find((a) => a.active) ?? null;
58
- const { ensureCliTeamTracked: ensureCliTeamTracked2 } = await import("./connected-teams-PRHZS6B4.js");
58
+ const { ensureCliTeamTracked: ensureCliTeamTracked2 } = await import("./connected-teams-PIBQTOJU.js");
59
59
  const connectedTeams = ensureCliTeamTracked2(
60
60
  active ? { id: active.id, slug: active.slug, name: active.name } : void 0
61
61
  );
@@ -95,7 +95,7 @@ async function performBrightsyAccountSwitch(accountIdOrSlug) {
95
95
  return { cfg, target: data.active };
96
96
  }
97
97
  async function switchBrightsyAccount(accountIdOrSlug) {
98
- const { connectBrightsyTeam: connectBrightsyTeam2 } = await import("./connected-teams-PRHZS6B4.js");
98
+ const { connectBrightsyTeam: connectBrightsyTeam2 } = await import("./connected-teams-PIBQTOJU.js");
99
99
  await connectBrightsyTeam2(accountIdOrSlug);
100
100
  return getBrightsySession();
101
101
  }
@@ -187,24 +187,44 @@ async function ensureConnectedBrightsyTeamTokens(opts) {
187
187
  );
188
188
  const teams = readStore();
189
189
  if (teams.length === 0) return [];
190
+ const cfg = (() => {
191
+ try {
192
+ return loadBrightsyConfig();
193
+ } catch {
194
+ return null;
195
+ }
196
+ })();
190
197
  const next = [];
191
198
  let changed = false;
192
199
  for (const team of teams) {
193
- if (!team.refresh_token || !brightsyAccessTokenNeedsRefresh(team.expires_at)) {
194
- next.push(team);
200
+ let current = team;
201
+ if (!current.oauth_client_id?.trim()) {
202
+ const endpoint = current.endpoint || "https://brightsy.ai";
203
+ const clientId = await ensureBrightsyOAuthClientId({
204
+ endpoint,
205
+ clientId: cfg?.oauth_client_id,
206
+ fetchImpl: opts?.fetchImpl
207
+ });
208
+ if (clientId && clientId !== current.oauth_client_id) {
209
+ current = { ...current, oauth_client_id: clientId };
210
+ changed = true;
211
+ }
212
+ }
213
+ if (!current.refresh_token || !brightsyAccessTokenNeedsRefresh(current.expires_at)) {
214
+ next.push(current);
195
215
  continue;
196
216
  }
197
- const refreshed = await refreshTeamToken(team, opts);
198
- if (refreshed.access_token !== team.access_token || refreshed.refresh_token !== team.refresh_token || refreshed.expires_at !== team.expires_at || refreshed.oauth_client_id !== team.oauth_client_id) {
217
+ const refreshed = await refreshTeamToken(current, opts);
218
+ if (refreshed.access_token !== current.access_token || refreshed.refresh_token !== current.refresh_token || refreshed.expires_at !== current.expires_at || refreshed.oauth_client_id !== current.oauth_client_id) {
199
219
  changed = true;
200
220
  }
201
221
  next.push(refreshed);
202
222
  }
203
223
  if (changed) writeStore(next);
204
224
  try {
205
- const cfg = loadBrightsyConfig();
206
- const active = next.find((t) => t.id === cfg.account_id);
207
- if (active && active.access_token !== cfg.access_token) {
225
+ const cfg2 = loadBrightsyConfig();
226
+ const active = next.find((t) => t.id === cfg2.account_id);
227
+ if (active && active.access_token !== cfg2.access_token) {
208
228
  applyConnectedTeamToCli(active);
209
229
  }
210
230
  } catch {
@@ -7,7 +7,7 @@ import {
7
7
  ensureConnectedBrightsyTeamTokens,
8
8
  getConnectedBrightsyTeamsRaw,
9
9
  listConnectedBrightsyTeams
10
- } from "./chunk-QILV2BRW.js";
10
+ } from "./chunk-ZXJMAKEP.js";
11
11
  import "./chunk-ROPGQRPU.js";
12
12
  import "./chunk-N7WZ6NIN.js";
13
13
  import "./chunk-WFUDY6PC.js";
@@ -9,7 +9,7 @@ import {
9
9
  ensureConnectedBrightsyTeamTokens,
10
10
  getConnectedBrightsyTeamsRaw,
11
11
  listConnectedBrightsyTeams
12
- } from "./chunk-UNMMKZ4Q.js";
12
+ } from "./chunk-SXFRXNBM.js";
13
13
  import "./chunk-P2BSMNHB.js";
14
14
  import "./chunk-VKQGAWHY.js";
15
15
  import "./chunk-ABOBTSO6.js";
package/dist/index.cjs CHANGED
@@ -11166,24 +11166,44 @@ async function ensureConnectedBrightsyTeamTokens(opts) {
11166
11166
  );
11167
11167
  const teams = readStore4();
11168
11168
  if (teams.length === 0) return [];
11169
+ const cfg = (() => {
11170
+ try {
11171
+ return loadBrightsyConfig();
11172
+ } catch {
11173
+ return null;
11174
+ }
11175
+ })();
11169
11176
  const next = [];
11170
11177
  let changed = false;
11171
11178
  for (const team of teams) {
11172
- if (!team.refresh_token || !brightsyAccessTokenNeedsRefresh(team.expires_at)) {
11173
- next.push(team);
11179
+ let current = team;
11180
+ if (!current.oauth_client_id?.trim()) {
11181
+ const endpoint = current.endpoint || "https://brightsy.ai";
11182
+ const clientId = await ensureBrightsyOAuthClientId({
11183
+ endpoint,
11184
+ clientId: cfg?.oauth_client_id,
11185
+ fetchImpl: opts?.fetchImpl
11186
+ });
11187
+ if (clientId && clientId !== current.oauth_client_id) {
11188
+ current = { ...current, oauth_client_id: clientId };
11189
+ changed = true;
11190
+ }
11191
+ }
11192
+ if (!current.refresh_token || !brightsyAccessTokenNeedsRefresh(current.expires_at)) {
11193
+ next.push(current);
11174
11194
  continue;
11175
11195
  }
11176
- const refreshed = await refreshTeamToken(team, opts);
11177
- if (refreshed.access_token !== team.access_token || refreshed.refresh_token !== team.refresh_token || refreshed.expires_at !== team.expires_at || refreshed.oauth_client_id !== team.oauth_client_id) {
11196
+ const refreshed = await refreshTeamToken(current, opts);
11197
+ if (refreshed.access_token !== current.access_token || refreshed.refresh_token !== current.refresh_token || refreshed.expires_at !== current.expires_at || refreshed.oauth_client_id !== current.oauth_client_id) {
11178
11198
  changed = true;
11179
11199
  }
11180
11200
  next.push(refreshed);
11181
11201
  }
11182
11202
  if (changed) writeStore3(next);
11183
11203
  try {
11184
- const cfg = loadBrightsyConfig();
11185
- const active = next.find((t) => t.id === cfg.account_id);
11186
- if (active && active.access_token !== cfg.access_token) {
11204
+ const cfg2 = loadBrightsyConfig();
11205
+ const active = next.find((t) => t.id === cfg2.account_id);
11206
+ if (active && active.access_token !== cfg2.access_token) {
11187
11207
  applyConnectedTeamToCli(active);
11188
11208
  }
11189
11209
  } catch {
@@ -32329,16 +32349,29 @@ var BrightsySideboardApi = class {
32329
32349
  if (!this.cfg.refresh_token || !brightsyAccessTokenNeedsRefresh(this.cfg.expires_at)) {
32330
32350
  return;
32331
32351
  }
32352
+ const prevClientId = this.cfg.oauth_client_id;
32353
+ const clientId = await ensureBrightsyOAuthClientId({
32354
+ endpoint: this.endpoint,
32355
+ clientId: this.cfg.oauth_client_id,
32356
+ fetchImpl: this.fetchImpl
32357
+ });
32358
+ if (clientId !== this.cfg.oauth_client_id) {
32359
+ this.cfg.oauth_client_id = clientId;
32360
+ }
32332
32361
  const grant = await refreshBrightsyAccessToken({
32333
32362
  endpoint: this.endpoint,
32334
32363
  refreshToken: this.cfg.refresh_token,
32335
- clientId: this.cfg.oauth_client_id,
32364
+ clientId,
32336
32365
  fetchImpl: this.fetchImpl
32337
32366
  });
32338
- if (!grant) return;
32367
+ if (!grant) {
32368
+ if (this.cfg.oauth_client_id !== prevClientId) saveBrightsyConfig(this.cfg);
32369
+ return;
32370
+ }
32339
32371
  this.cfg.access_token = grant.access_token;
32340
32372
  if (grant.refresh_token) this.cfg.refresh_token = grant.refresh_token;
32341
32373
  if (grant.expires_at) this.cfg.expires_at = grant.expires_at;
32374
+ this.cfg.oauth_client_id = clientId;
32342
32375
  saveBrightsyConfig(this.cfg);
32343
32376
  }
32344
32377
  async getAccess() {
package/dist/index.js CHANGED
@@ -318,7 +318,7 @@ import {
318
318
  worktreeCleanupSettings,
319
319
  wrapReviewSkillMarkdown,
320
320
  writeWorktreeFile
321
- } from "./chunk-B73KKJQB.js";
321
+ } from "./chunk-MPSXJ7WU.js";
322
322
  import {
323
323
  LEGACY_PLAN_FILE_REL,
324
324
  PLAN_FILE_NAME,
@@ -435,7 +435,7 @@ import {
435
435
  withEventParentId,
436
436
  withEventsParentId,
437
437
  writeInjectedMcpConfig
438
- } from "./chunk-YG2X34EF.js";
438
+ } from "./chunk-VUW3VKLW.js";
439
439
  import {
440
440
  CLOUD_COORDINATOR_BUSY_REPLY,
441
441
  CLOUD_COORDINATOR_STOPPED_REPLY,
@@ -597,7 +597,7 @@ import {
597
597
  listBrightsyAccounts,
598
598
  listConnectedBrightsyTeams,
599
599
  switchBrightsyAccount
600
- } from "./chunk-QILV2BRW.js";
600
+ } from "./chunk-ZXJMAKEP.js";
601
601
  import {
602
602
  BRIGHTSY_OAUTH_CLIENT_ID,
603
603
  BRIGHTSY_OAUTH_REDIRECT,
@@ -6379,16 +6379,29 @@ var BrightsySideboardApi = class {
6379
6379
  if (!this.cfg.refresh_token || !brightsyAccessTokenNeedsRefresh(this.cfg.expires_at)) {
6380
6380
  return;
6381
6381
  }
6382
+ const prevClientId = this.cfg.oauth_client_id;
6383
+ const clientId = await ensureBrightsyOAuthClientId({
6384
+ endpoint: this.endpoint,
6385
+ clientId: this.cfg.oauth_client_id,
6386
+ fetchImpl: this.fetchImpl
6387
+ });
6388
+ if (clientId !== this.cfg.oauth_client_id) {
6389
+ this.cfg.oauth_client_id = clientId;
6390
+ }
6382
6391
  const grant = await refreshBrightsyAccessToken({
6383
6392
  endpoint: this.endpoint,
6384
6393
  refreshToken: this.cfg.refresh_token,
6385
- clientId: this.cfg.oauth_client_id,
6394
+ clientId,
6386
6395
  fetchImpl: this.fetchImpl
6387
6396
  });
6388
- if (!grant) return;
6397
+ if (!grant) {
6398
+ if (this.cfg.oauth_client_id !== prevClientId) saveBrightsyConfig(this.cfg);
6399
+ return;
6400
+ }
6389
6401
  this.cfg.access_token = grant.access_token;
6390
6402
  if (grant.refresh_token) this.cfg.refresh_token = grant.refresh_token;
6391
6403
  if (grant.expires_at) this.cfg.expires_at = grant.expires_at;
6404
+ this.cfg.oauth_client_id = clientId;
6392
6405
  saveBrightsyConfig(this.cfg);
6393
6406
  }
6394
6407
  async getAccess() {
@@ -9133,24 +9133,44 @@ async function ensureConnectedBrightsyTeamTokens(opts) {
9133
9133
  );
9134
9134
  const teams = readStore4();
9135
9135
  if (teams.length === 0) return [];
9136
+ const cfg = (() => {
9137
+ try {
9138
+ return loadBrightsyConfig();
9139
+ } catch {
9140
+ return null;
9141
+ }
9142
+ })();
9136
9143
  const next = [];
9137
9144
  let changed = false;
9138
9145
  for (const team of teams) {
9139
- if (!team.refresh_token || !brightsyAccessTokenNeedsRefresh(team.expires_at)) {
9140
- next.push(team);
9146
+ let current = team;
9147
+ if (!current.oauth_client_id?.trim()) {
9148
+ const endpoint = current.endpoint || "https://brightsy.ai";
9149
+ const clientId = await ensureBrightsyOAuthClientId({
9150
+ endpoint,
9151
+ clientId: cfg?.oauth_client_id,
9152
+ fetchImpl: opts?.fetchImpl
9153
+ });
9154
+ if (clientId && clientId !== current.oauth_client_id) {
9155
+ current = { ...current, oauth_client_id: clientId };
9156
+ changed = true;
9157
+ }
9158
+ }
9159
+ if (!current.refresh_token || !brightsyAccessTokenNeedsRefresh(current.expires_at)) {
9160
+ next.push(current);
9141
9161
  continue;
9142
9162
  }
9143
- const refreshed = await refreshTeamToken(team, opts);
9144
- if (refreshed.access_token !== team.access_token || refreshed.refresh_token !== team.refresh_token || refreshed.expires_at !== team.expires_at || refreshed.oauth_client_id !== team.oauth_client_id) {
9163
+ const refreshed = await refreshTeamToken(current, opts);
9164
+ if (refreshed.access_token !== current.access_token || refreshed.refresh_token !== current.refresh_token || refreshed.expires_at !== current.expires_at || refreshed.oauth_client_id !== current.oauth_client_id) {
9145
9165
  changed = true;
9146
9166
  }
9147
9167
  next.push(refreshed);
9148
9168
  }
9149
9169
  if (changed) writeStore2(next);
9150
9170
  try {
9151
- const cfg = loadBrightsyConfig();
9152
- const active = next.find((t) => t.id === cfg.account_id);
9153
- if (active && active.access_token !== cfg.access_token) {
9171
+ const cfg2 = loadBrightsyConfig();
9172
+ const active = next.find((t) => t.id === cfg2.account_id);
9173
+ if (active && active.access_token !== cfg2.access_token) {
9154
9174
  applyConnectedTeamToCli(active);
9155
9175
  }
9156
9176
  } catch {
@@ -50,7 +50,7 @@ import {
50
50
  syncBoardPins,
51
51
  updateSchedule,
52
52
  waitForDetachedJob
53
- } from "../chunk-ALDVGAIO.js";
53
+ } from "../chunk-5L66IONI.js";
54
54
  import "../chunk-JFOPOMK7.js";
55
55
  import "../chunk-YWI3IBP2.js";
56
56
  import {
@@ -61,13 +61,13 @@ import {
61
61
  materializeSystemCaBundle,
62
62
  sideboardMcpProfile,
63
63
  trustSystemCertificates
64
- } from "../chunk-3Y4FIARC.js";
64
+ } from "../chunk-SQHRPJ7P.js";
65
65
  import {
66
66
  GLOBAL_WORKSPACE_ID,
67
67
  isCloudCoordinatorThread,
68
68
  listWorkspaces
69
69
  } from "../chunk-P2EAAM3H.js";
70
- import "../chunk-UNMMKZ4Q.js";
70
+ import "../chunk-SXFRXNBM.js";
71
71
  import "../chunk-P2BSMNHB.js";
72
72
  import "../chunk-CLI5DVU4.js";
73
73
  import "../chunk-HSYE5ID6.js";
@@ -8,14 +8,14 @@ import {
8
8
  resolveSendFollowUp,
9
9
  startOrchestration,
10
10
  waitForPidExit
11
- } from "./chunk-B73KKJQB.js";
11
+ } from "./chunk-MPSXJ7WU.js";
12
12
  import "./chunk-DJU54RYW.js";
13
- import "./chunk-YG2X34EF.js";
13
+ import "./chunk-VUW3VKLW.js";
14
14
  import "./chunk-N2VST3NL.js";
15
15
  import "./chunk-KTZESHYH.js";
16
16
  import "./chunk-6K64FJDD.js";
17
17
  import "./chunk-PO4M4JAJ.js";
18
- import "./chunk-QILV2BRW.js";
18
+ import "./chunk-ZXJMAKEP.js";
19
19
  import "./chunk-ROPGQRPU.js";
20
20
  import "./chunk-N7WZ6NIN.js";
21
21
  import "./chunk-AXQ4ZWHK.js";
@@ -10,12 +10,12 @@ import {
10
10
  resolveSendFollowUp,
11
11
  startOrchestration,
12
12
  waitForPidExit
13
- } from "./chunk-ALDVGAIO.js";
13
+ } from "./chunk-5L66IONI.js";
14
14
  import "./chunk-JFOPOMK7.js";
15
15
  import "./chunk-YWI3IBP2.js";
16
- import "./chunk-3Y4FIARC.js";
16
+ import "./chunk-SQHRPJ7P.js";
17
17
  import "./chunk-P2EAAM3H.js";
18
- import "./chunk-UNMMKZ4Q.js";
18
+ import "./chunk-SXFRXNBM.js";
19
19
  import "./chunk-P2BSMNHB.js";
20
20
  import "./chunk-VKQGAWHY.js";
21
21
  import "./chunk-NFWPDEN4.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sideboard-ai/core",
3
- "version": "0.1.220",
3
+ "version": "0.1.222",
4
4
  "description": "Sideboard core — orchestration, agents, git worktrees, MCP server",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",