@workerdeck/core 2.8.0 → 2.9.0

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.
package/build/index.d.mts CHANGED
@@ -104,6 +104,7 @@ interface Runner {
104
104
  eventAt?(seq: number): SessionEvent | undefined;
105
105
  sendMessage(text: string, attachments?: readonly AttachmentInput[]): void;
106
106
  queueLocalCommand?(result: LocalCommandResult): void;
107
+ refreshUsage?(): Promise<void>;
107
108
  mcpServers?(): Promise<McpServerStatusInfo[] | undefined>;
108
109
  reconnectMcpServer?(name: string): Promise<void>;
109
110
  setMcpServerEnabled?(name: string, enabled: boolean): Promise<void>;
@@ -176,6 +177,7 @@ declare class SessionRunner implements Runner {
176
177
  close(reason?: 'client' | 'server' | 'error'): void;
177
178
  eventAt(seq: number): SessionEvent | undefined;
178
179
  subscribe(listener: SessionEventListener, afterSeq?: number, options?: SubscribeOptions): () => void;
180
+ refreshUsage(minIntervalMs?: number): Promise<void>;
179
181
  }
180
182
  //#endregion
181
183
  //#region src/lib/replay.d.ts
package/build/index.mjs CHANGED
@@ -904,6 +904,7 @@ function toolUseBlocks(content) {
904
904
  }
905
905
  //#endregion
906
906
  //#region src/engines/claude/runner.ts
907
+ const USAGE_REFRESH_MIN_MS = 6e4;
907
908
  var SessionRunner = class {
908
909
  id;
909
910
  createdAt;
@@ -929,8 +930,11 @@ var SessionRunner = class {
929
930
  #idleWhileCompacting = false;
930
931
  #query;
931
932
  #capabilitiesEmitted = false;
933
+ #models;
934
+ #defaultModel;
932
935
  #subscriptionType;
933
936
  #engineTitle;
937
+ #lastRateLimitPoll = 0;
934
938
  #started = false;
935
939
  #closed = false;
936
940
  #runPromise;
@@ -1254,6 +1258,10 @@ var SessionRunner = class {
1254
1258
  else if (msg.state === "running") this.#setStatus("running");
1255
1259
  return;
1256
1260
  }
1261
+ if (msg.type === "system" && msg.subtype === "commands_changed") {
1262
+ if (this.#capabilitiesEmitted && !this.#closed) this.#emitCapabilities(msg.commands);
1263
+ return;
1264
+ }
1257
1265
  if (msg.type === "system" && msg.subtype === "status") this.#handleCompactionStatus(msg);
1258
1266
  if (msg.type === "system" && msg.subtype === "compact_boundary") {
1259
1267
  const meta = msg.compact_metadata;
@@ -1330,19 +1338,24 @@ var SessionRunner = class {
1330
1338
  const [models, commands] = await Promise.all([query.supportedModels(), query.supportedCommands()]);
1331
1339
  if (this.#closed || this.#capabilitiesEmitted) return;
1332
1340
  this.#capabilitiesEmitted = true;
1333
- this.#emit({
1334
- type: "capabilities",
1335
- models: modelOptionsFromSdk(models),
1336
- defaultModel: defaultModelFromSdk(models),
1337
- commands: commands.map((c) => ({
1338
- name: c.name,
1339
- description: c.description,
1340
- argumentHint: c.argumentHint,
1341
- aliases: c.aliases
1342
- }))
1343
- });
1341
+ this.#models = modelOptionsFromSdk(models);
1342
+ this.#defaultModel = defaultModelFromSdk(models);
1343
+ this.#emitCapabilities(commands);
1344
1344
  } catch {}
1345
1345
  }
1346
+ #emitCapabilities(commands) {
1347
+ this.#emit({
1348
+ type: "capabilities",
1349
+ models: this.#models ?? [],
1350
+ defaultModel: this.#defaultModel,
1351
+ commands: commands.map((c) => ({
1352
+ name: c.name,
1353
+ description: c.description,
1354
+ argumentHint: c.argumentHint,
1355
+ aliases: c.aliases
1356
+ }))
1357
+ });
1358
+ }
1346
1359
  async #fetchEngineTitle() {
1347
1360
  if (hostTitle(this.#config.meta)) return;
1348
1361
  const sdkSessionId = this.#sdkSessionId;
@@ -1378,7 +1391,12 @@ var SessionRunner = class {
1378
1391
  });
1379
1392
  } catch {}
1380
1393
  }
1394
+ async refreshUsage(minIntervalMs = USAGE_REFRESH_MIN_MS) {
1395
+ if (Date.now() - this.#lastRateLimitPoll < minIntervalMs) return;
1396
+ await this.#fetchRateLimits();
1397
+ }
1381
1398
  async #fetchRateLimits() {
1399
+ this.#lastRateLimitPoll = Date.now();
1382
1400
  const query = this.#query;
1383
1401
  const fetchUsage = query?.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET;
1384
1402
  if (typeof fetchUsage !== "function") return;