@sideboard-ai/core 0.1.122 → 0.1.124

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.
@@ -349,6 +349,46 @@ function turnCostUsdFromCursorUsage(before, after) {
349
349
  if (!(delta >= 0) || !Number.isFinite(delta)) return void 0;
350
350
  return delta / 100;
351
351
  }
352
+ function costUsdFromRunSnapshot(usage, runId) {
353
+ if (!usage?.runs?.length || !runId.trim()) return void 0;
354
+ const row = usage.runs.find((r) => r.runId === runId);
355
+ const cents = preferredCursorCostCents(row?.cost);
356
+ return cents != null ? cents / 100 : void 0;
357
+ }
358
+ function cursorGetUsageRunId(runId) {
359
+ const id = runId?.trim();
360
+ if (!id || id.startsWith("run-")) return void 0;
361
+ return id;
362
+ }
363
+ var CURSOR_COST_POLL_MS = [0, 400, 800, 1600, 3200];
364
+ function sleep(ms) {
365
+ return new Promise((resolve) => {
366
+ setTimeout(resolve, ms);
367
+ });
368
+ }
369
+ async function fetchCursorTurnCostUsd(getUsage, usageBefore, opts) {
370
+ const lookupRunId = cursorGetUsageRunId(opts?.runId);
371
+ for (const delay of CURSOR_COST_POLL_MS) {
372
+ if (delay > 0) await sleep(delay);
373
+ try {
374
+ if (lookupRunId) {
375
+ const scoped = await getUsage({ runId: lookupRunId });
376
+ const direct = costUsdFromRunSnapshot(scoped, lookupRunId);
377
+ if (direct != null) return direct;
378
+ }
379
+ const after = await getUsage();
380
+ const delta = turnCostUsdFromCursorUsage(usageBefore, after);
381
+ if (delta != null) return delta;
382
+ } catch (err) {
383
+ if (isCursorUsageUnavailableError(err)) return void 0;
384
+ }
385
+ }
386
+ return void 0;
387
+ }
388
+ function isCursorUsageUnavailableError(err) {
389
+ const msg = err instanceof Error ? err.message : String(err);
390
+ return /feature_unavailable|feature unavailable|not available for your account/i.test(msg);
391
+ }
352
392
  function cursorCostOnlyUsageEvent(costUsd) {
353
393
  return {
354
394
  type: "usage",
@@ -782,6 +822,7 @@ async function main() {
782
822
  usageBefore = await agent.getUsage();
783
823
  } catch {
784
824
  }
825
+ let lastUsageRunId;
785
826
  const run2 = await sendPrompt(agent, {
786
827
  onDelta: ({ update }) => {
787
828
  bump();
@@ -807,6 +848,10 @@ async function main() {
807
848
  activity
808
849
  )) {
809
850
  bump();
851
+ const sdkMsg = msg;
852
+ if (sdkMsg.type === "usage" && typeof sdkMsg.run_id === "string" && sdkMsg.run_id.trim()) {
853
+ lastUsageRunId = sdkMsg.run_id.trim();
854
+ }
810
855
  for (const event of cursorSdkMessageToEvents(msg)) {
811
856
  stream.push(event);
812
857
  }
@@ -828,15 +873,11 @@ async function main() {
828
873
  }
829
874
  if (result.status === "cancelled") return 0;
830
875
  try {
831
- let usageAfter = await agent.getUsage();
832
- let costUsd = turnCostUsdFromCursorUsage(usageBefore, usageAfter);
833
- if (costUsd == null) {
834
- await new Promise((resolve) => {
835
- setTimeout(resolve, 400);
836
- });
837
- usageAfter = await agent.getUsage();
838
- costUsd = turnCostUsdFromCursorUsage(usageBefore, usageAfter);
839
- }
876
+ const costUsd = await fetchCursorTurnCostUsd(
877
+ (opts) => agent.getUsage(opts),
878
+ usageBefore,
879
+ { runId: lastUsageRunId }
880
+ );
840
881
  if (costUsd != null) {
841
882
  emit(cursorCostOnlyUsageEvent(costUsd));
842
883
  }
@@ -10,9 +10,9 @@ import {
10
10
  cursorDeltaToEvents,
11
11
  cursorSdkMessageToEvents,
12
12
  ensureCursorRipgrepPath,
13
- formatUnknownDetail,
14
- turnCostUsdFromCursorUsage
15
- } from "../chunk-3M5CVKHK.js";
13
+ fetchCursorTurnCostUsd,
14
+ formatUnknownDetail
15
+ } from "../chunk-IUJOI7KK.js";
16
16
  import {
17
17
  dropNestedElectronEnvFromProcess
18
18
  } from "../chunk-4TR3HZFT.js";
@@ -266,6 +266,7 @@ async function main() {
266
266
  usageBefore = await agent.getUsage();
267
267
  } catch {
268
268
  }
269
+ let lastUsageRunId;
269
270
  const run = await sendPrompt(agent, {
270
271
  onDelta: ({ update }) => {
271
272
  bump();
@@ -291,6 +292,10 @@ async function main() {
291
292
  activity
292
293
  )) {
293
294
  bump();
295
+ const sdkMsg = msg;
296
+ if (sdkMsg.type === "usage" && typeof sdkMsg.run_id === "string" && sdkMsg.run_id.trim()) {
297
+ lastUsageRunId = sdkMsg.run_id.trim();
298
+ }
294
299
  for (const event of cursorSdkMessageToEvents(msg)) {
295
300
  stream.push(event);
296
301
  }
@@ -312,15 +317,11 @@ async function main() {
312
317
  }
313
318
  if (result.status === "cancelled") return 0;
314
319
  try {
315
- let usageAfter = await agent.getUsage();
316
- let costUsd = turnCostUsdFromCursorUsage(usageBefore, usageAfter);
317
- if (costUsd == null) {
318
- await new Promise((resolve) => {
319
- setTimeout(resolve, 400);
320
- });
321
- usageAfter = await agent.getUsage();
322
- costUsd = turnCostUsdFromCursorUsage(usageBefore, usageAfter);
323
- }
320
+ const costUsd = await fetchCursorTurnCostUsd(
321
+ (opts) => agent.getUsage(opts),
322
+ usageBefore,
323
+ { runId: lastUsageRunId }
324
+ );
324
325
  if (costUsd != null) {
325
326
  emit(cursorCostOnlyUsageEvent(costUsd));
326
327
  }
@@ -28,7 +28,7 @@ import {
28
28
  resolveCursorModelId,
29
29
  resolveLoginCommand,
30
30
  resolveQuotaFallbackAgent
31
- } from "./chunk-QHST4DZQ.js";
31
+ } from "./chunk-7Y3AYQWT.js";
32
32
  import "./chunk-EKIDHL2T.js";
33
33
  import {
34
34
  ORCHESTRATOR_AGENT_KINDS,
@@ -42,7 +42,7 @@ import {
42
42
  parseCursorRunnerLine,
43
43
  preferredCursorCostCents,
44
44
  turnCostUsdFromCursorUsage
45
- } from "./chunk-3M5CVKHK.js";
45
+ } from "./chunk-IUJOI7KK.js";
46
46
  import "./chunk-UAVZ2JSO.js";
47
47
  import "./chunk-FKOIHGKV.js";
48
48
  import "./chunk-FXQPY2KU.js";
@@ -34,7 +34,7 @@ import {
34
34
  resolveLoginCommand,
35
35
  resolveQuotaFallbackAgent,
36
36
  turnCostUsdFromCursorUsage
37
- } from "./chunk-OEBYW4TO.js";
37
+ } from "./chunk-JNAIKICO.js";
38
38
  import "./chunk-YMRT2DU6.js";
39
39
  import {
40
40
  ORCHESTRATOR_AGENT_KINDS,
@@ -20,7 +20,7 @@ import {
20
20
  packagedMcpStdioPath,
21
21
  parseCursorRunnerLine,
22
22
  resolveNodeLaunch
23
- } from "./chunk-3M5CVKHK.js";
23
+ } from "./chunk-IUJOI7KK.js";
24
24
  import {
25
25
  codexUnattendedGitConfigArgs,
26
26
  mergeAgentGitAuthEnv,
@@ -520,6 +520,46 @@ function turnCostUsdFromCursorUsage(before, after) {
520
520
  if (!(delta >= 0) || !Number.isFinite(delta)) return void 0;
521
521
  return delta / 100;
522
522
  }
523
+ function costUsdFromRunSnapshot(usage, runId) {
524
+ if (!usage?.runs?.length || !runId.trim()) return void 0;
525
+ const row = usage.runs.find((r) => r.runId === runId);
526
+ const cents = preferredCursorCostCents(row?.cost);
527
+ return cents != null ? cents / 100 : void 0;
528
+ }
529
+ function cursorGetUsageRunId(runId) {
530
+ const id = runId?.trim();
531
+ if (!id || id.startsWith("run-")) return void 0;
532
+ return id;
533
+ }
534
+ var CURSOR_COST_POLL_MS = [0, 400, 800, 1600, 3200];
535
+ function sleep(ms) {
536
+ return new Promise((resolve) => {
537
+ setTimeout(resolve, ms);
538
+ });
539
+ }
540
+ async function fetchCursorTurnCostUsd(getUsage, usageBefore, opts) {
541
+ const lookupRunId = cursorGetUsageRunId(opts?.runId);
542
+ for (const delay of CURSOR_COST_POLL_MS) {
543
+ if (delay > 0) await sleep(delay);
544
+ try {
545
+ if (lookupRunId) {
546
+ const scoped = await getUsage({ runId: lookupRunId });
547
+ const direct = costUsdFromRunSnapshot(scoped, lookupRunId);
548
+ if (direct != null) return direct;
549
+ }
550
+ const after = await getUsage();
551
+ const delta = turnCostUsdFromCursorUsage(usageBefore, after);
552
+ if (delta != null) return delta;
553
+ } catch (err) {
554
+ if (isCursorUsageUnavailableError(err)) return void 0;
555
+ }
556
+ }
557
+ return void 0;
558
+ }
559
+ function isCursorUsageUnavailableError(err) {
560
+ const msg = err instanceof Error ? err.message : String(err);
561
+ return /feature_unavailable|feature unavailable|not available for your account/i.test(msg);
562
+ }
523
563
  function cursorCostOnlyUsageEvent(costUsd) {
524
564
  return {
525
565
  type: "usage",
@@ -831,6 +871,7 @@ export {
831
871
  resolveNodeLaunch,
832
872
  preferredCursorCostCents,
833
873
  turnCostUsdFromCursorUsage,
874
+ fetchCursorTurnCostUsd,
834
875
  cursorCostOnlyUsageEvent,
835
876
  cursorSdkMessageToEvents,
836
877
  cursorDeltaToEvents,
@@ -18,7 +18,7 @@ import {
18
18
  stripBrightsyNdjsonNoise,
19
19
  sumUsageList,
20
20
  toolDescription
21
- } from "./chunk-QHST4DZQ.js";
21
+ } from "./chunk-7Y3AYQWT.js";
22
22
  import {
23
23
  addWorkspace,
24
24
  ensureWorkspace,
@@ -64,7 +64,7 @@ import {
64
64
  shouldRetryFailedAgentTurn,
65
65
  summarizeTurnStderr,
66
66
  turnFailChatText
67
- } from "./chunk-3M5CVKHK.js";
67
+ } from "./chunk-IUJOI7KK.js";
68
68
  import {
69
69
  releaseCaffeinateHoldForThread
70
70
  } from "./chunk-DCOZABNT.js";
@@ -456,7 +456,7 @@ async function continueSourceThread(threadId, prompt) {
456
456
  await continueOnReply(threadId, prompt);
457
457
  return;
458
458
  }
459
- const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-JE5MSVED.js");
459
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-JS3EHI4E.js");
460
460
  await getOrchestrator2().send(threadId, prompt);
461
461
  } catch {
462
462
  }
@@ -680,7 +680,7 @@ async function refreshSlackReplyBadges(opts) {
680
680
  if (!ws) continue;
681
681
  let token;
682
682
  try {
683
- token = slackTokenFor(ws, "read");
683
+ token = slackTokenFor(ws, "write");
684
684
  } catch {
685
685
  continue;
686
686
  }
@@ -2487,7 +2487,7 @@ async function createThread(input, _onSetupLine) {
2487
2487
  return readThread(thread.id) ?? thread;
2488
2488
  }
2489
2489
  async function listLinearIssues(agent, repoPath) {
2490
- const { getAdapter: getAdapter2 } = await import("./agents-DRJMECCE.js");
2490
+ const { getAdapter: getAdapter2 } = await import("./agents-DCXXLTXF.js");
2491
2491
  await requireAgent(agent, { requireLinear: true });
2492
2492
  const adapter = getAdapter2(agent);
2493
2493
  if (!adapter.listLinearIssues) {
@@ -5156,7 +5156,7 @@ function formatScheduledPrompt(name, prompt) {
5156
5156
  ${prompt}`;
5157
5157
  }
5158
5158
  async function defaultDeps() {
5159
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-JE5MSVED.js");
5159
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-JS3EHI4E.js");
5160
5160
  const orch = getOrchestrator2();
5161
5161
  return {
5162
5162
  findThread: (id) => findThreadByRef(id),
@@ -29,7 +29,7 @@ import {
29
29
  summarizeTurnStderr,
30
30
  toolDescription,
31
31
  turnFailChatText
32
- } from "./chunk-OEBYW4TO.js";
32
+ } from "./chunk-JNAIKICO.js";
33
33
  import {
34
34
  addWorkspace,
35
35
  ensureWorkspace,
@@ -395,7 +395,7 @@ async function continueSourceThread(threadId, prompt) {
395
395
  await continueOnReply(threadId, prompt);
396
396
  return;
397
397
  }
398
- const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-EYU7OUFA.js");
398
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-VJQ5EWZZ.js");
399
399
  await getOrchestrator2().send(threadId, prompt);
400
400
  } catch {
401
401
  }
@@ -606,7 +606,7 @@ async function refreshSlackReplyBadges(opts) {
606
606
  if (!ws) continue;
607
607
  let token;
608
608
  try {
609
- token = slackTokenFor(ws, "read");
609
+ token = slackTokenFor(ws, "write");
610
610
  } catch {
611
611
  continue;
612
612
  }
@@ -2442,7 +2442,7 @@ async function createThread(input, _onSetupLine) {
2442
2442
  return readThread(thread.id) ?? thread;
2443
2443
  }
2444
2444
  async function listLinearIssues(agent, repoPath) {
2445
- const { getAdapter: getAdapter2 } = await import("./agents-U5PWL3AJ.js");
2445
+ const { getAdapter: getAdapter2 } = await import("./agents-DPR2TDNF.js");
2446
2446
  await requireAgent(agent, { requireLinear: true });
2447
2447
  const adapter = getAdapter2(agent);
2448
2448
  if (!adapter.listLinearIssues) {
@@ -4985,7 +4985,7 @@ function formatScheduledPrompt(name, prompt) {
4985
4985
  ${prompt}`;
4986
4986
  }
4987
4987
  async function defaultDeps() {
4988
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-EYU7OUFA.js");
4988
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-VJQ5EWZZ.js");
4989
4989
  const orch = getOrchestrator2();
4990
4990
  return {
4991
4991
  findThread: (id) => findThreadByRef(id),
package/dist/index.cjs CHANGED
@@ -6500,7 +6500,7 @@ async function refreshSlackReplyBadges(opts) {
6500
6500
  if (!ws) continue;
6501
6501
  let token;
6502
6502
  try {
6503
- token = slackTokenFor(ws, "read");
6503
+ token = slackTokenFor(ws, "write");
6504
6504
  } catch {
6505
6505
  continue;
6506
6506
  }
package/dist/index.d.cts CHANGED
@@ -987,7 +987,7 @@ declare function caffeinateWhileCloudConnectEnabled(settings?: AppSettings): boo
987
987
  declare function deleteBranchOnPurgeEnabled(settings?: AppSettings): boolean;
988
988
  /** Default off. When on, create may use the project checkout on the default branch. */
989
989
  declare function cowboyModeEnabled(settings?: AppSettings): boolean;
990
- /** Settings → Advanced → Show cost (default off). */
990
+ /** Settings → Advanced → Show cost (when available) (default off). */
991
991
  declare function showCostEnabled(settings?: AppSettings): boolean;
992
992
  /** Conductor-style opt-in — default off. */
993
993
  declare function autoArchiveOnMergeEnabled(settings?: AppSettings): boolean;
@@ -2060,6 +2060,7 @@ type CursorSdkStreamMessage = {
2060
2060
  cacheReadTokens?: number;
2061
2061
  cacheWriteTokens?: number;
2062
2062
  };
2063
+ run_id?: string;
2063
2064
  };
2064
2065
  /** Cursor SDK `UsageCost` — dollar amounts in float cents. */
2065
2066
  type CursorUsageCost = {
package/dist/index.d.ts CHANGED
@@ -987,7 +987,7 @@ declare function caffeinateWhileCloudConnectEnabled(settings?: AppSettings): boo
987
987
  declare function deleteBranchOnPurgeEnabled(settings?: AppSettings): boolean;
988
988
  /** Default off. When on, create may use the project checkout on the default branch. */
989
989
  declare function cowboyModeEnabled(settings?: AppSettings): boolean;
990
- /** Settings → Advanced → Show cost (default off). */
990
+ /** Settings → Advanced → Show cost (when available) (default off). */
991
991
  declare function showCostEnabled(settings?: AppSettings): boolean;
992
992
  /** Conductor-style opt-in — default off. */
993
993
  declare function autoArchiveOnMergeEnabled(settings?: AppSettings): boolean;
@@ -2060,6 +2060,7 @@ type CursorSdkStreamMessage = {
2060
2060
  cacheReadTokens?: number;
2061
2061
  cacheWriteTokens?: number;
2062
2062
  };
2063
+ run_id?: string;
2063
2064
  };
2064
2065
  /** Cursor SDK `UsageCost` — dollar amounts in float cents. */
2065
2066
  type CursorUsageCost = {
package/dist/index.js CHANGED
@@ -171,7 +171,7 @@ import {
171
171
  worktreeCleanupSettings,
172
172
  wrapReviewSkillMarkdown,
173
173
  writeWorktreeFile
174
- } from "./chunk-EQHXMN7O.js";
174
+ } from "./chunk-MZDAEI3Y.js";
175
175
  import {
176
176
  BRIGHTSY_MCP_ALLOWED_TOOLS,
177
177
  CLAUDE_MODEL_CATALOG,
@@ -250,7 +250,7 @@ import {
250
250
  withEventParentId,
251
251
  withEventsParentId,
252
252
  writeInjectedMcpConfig
253
- } from "./chunk-QHST4DZQ.js";
253
+ } from "./chunk-7Y3AYQWT.js";
254
254
  import {
255
255
  brightsyConfigPath,
256
256
  brightsyMcpServerName,
@@ -327,7 +327,7 @@ import {
327
327
  preferredCursorCostCents,
328
328
  turnCostUsdFromCursorUsage,
329
329
  withMaxOldSpaceSize
330
- } from "./chunk-3M5CVKHK.js";
330
+ } from "./chunk-IUJOI7KK.js";
331
331
  import {
332
332
  caffeinateHoldPath,
333
333
  getCaffeinateHold,
@@ -1300,7 +1300,7 @@ async function refreshSlackReplyBadges(opts) {
1300
1300
  if (!ws) continue;
1301
1301
  let token;
1302
1302
  try {
1303
- token = slackTokenFor(ws, "read");
1303
+ token = slackTokenFor(ws, "write");
1304
1304
  } catch {
1305
1305
  continue;
1306
1306
  }
@@ -19,11 +19,11 @@ import {
19
19
  slackApi,
20
20
  slackTokenFor,
21
21
  updateSchedule
22
- } from "../chunk-KRM3A5UK.js";
22
+ } from "../chunk-SDCPQL27.js";
23
23
  import {
24
24
  listModelsForAgent,
25
25
  sideboardMcpProfile
26
- } from "../chunk-OEBYW4TO.js";
26
+ } from "../chunk-JNAIKICO.js";
27
27
  import "../chunk-YMRT2DU6.js";
28
28
  import "../chunk-RBVVWBVB.js";
29
29
  import "../chunk-N5PM7HGQ.js";
@@ -4,15 +4,15 @@ import {
4
4
  isPidAlive,
5
5
  startOrchestration,
6
6
  waitForPidExit
7
- } from "./chunk-EQHXMN7O.js";
8
- import "./chunk-QHST4DZQ.js";
7
+ } from "./chunk-MZDAEI3Y.js";
8
+ import "./chunk-7Y3AYQWT.js";
9
9
  import "./chunk-EKIDHL2T.js";
10
10
  import "./chunk-HZLE6LJJ.js";
11
11
  import "./chunk-KWGP6RZM.js";
12
12
  import "./chunk-2X7I6MDW.js";
13
13
  import "./chunk-QTUESPAW.js";
14
14
  import "./chunk-AXQ4ZWHK.js";
15
- import "./chunk-3M5CVKHK.js";
15
+ import "./chunk-IUJOI7KK.js";
16
16
  import "./chunk-DCOZABNT.js";
17
17
  import "./chunk-UAVZ2JSO.js";
18
18
  import "./chunk-FKOIHGKV.js";
@@ -6,8 +6,8 @@ import {
6
6
  isPidAlive,
7
7
  startOrchestration,
8
8
  waitForPidExit
9
- } from "./chunk-KRM3A5UK.js";
10
- import "./chunk-OEBYW4TO.js";
9
+ } from "./chunk-SDCPQL27.js";
10
+ import "./chunk-JNAIKICO.js";
11
11
  import "./chunk-YMRT2DU6.js";
12
12
  import "./chunk-RBVVWBVB.js";
13
13
  import "./chunk-N5PM7HGQ.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sideboard-ai/core",
3
- "version": "0.1.122",
3
+ "version": "0.1.124",
4
4
  "description": "Sideboard core — orchestration, agents, git worktrees, MCP server",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
File without changes