@arbidocs/sdk 0.3.109 → 0.3.111

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/dist/index.cjs CHANGED
@@ -4465,7 +4465,7 @@ var WebSocketAuthError = class extends Error {
4465
4465
  }
4466
4466
  };
4467
4467
  function connectWebSocket(options) {
4468
- const { baseUrl, accessToken, onMessage, onClose } = options;
4468
+ const { baseUrl, accessToken, onMessage, onClose, onAuthenticated } = options;
4469
4469
  const url = client.buildWebSocketUrl(baseUrl);
4470
4470
  return new Promise((resolve2, reject) => {
4471
4471
  const ws = new WebSocket(url);
@@ -4488,6 +4488,7 @@ function connectWebSocket(options) {
4488
4488
  clearTimeout(timeout);
4489
4489
  if (msg.success) {
4490
4490
  authenticated = true;
4491
+ onAuthenticated?.(msg);
4491
4492
  resolve2({ close: () => ws.close() });
4492
4493
  } else {
4493
4494
  ws.close();
@@ -4521,6 +4522,8 @@ async function connectWithReconnect(options) {
4521
4522
  onReconnectFailed,
4522
4523
  onClose,
4523
4524
  onMessage,
4525
+ onAuthenticated,
4526
+ shouldReconnect,
4524
4527
  baseUrl,
4525
4528
  accessToken
4526
4529
  } = options;
@@ -4535,10 +4538,11 @@ async function connectWithReconnect(options) {
4535
4538
  baseUrl,
4536
4539
  accessToken: token,
4537
4540
  onMessage,
4541
+ onAuthenticated,
4538
4542
  onClose: (code, reason) => {
4539
4543
  currentConnection = null;
4540
4544
  onClose?.(code, reason);
4541
- if (!closed) void scheduleReconnect();
4545
+ if (!closed && (shouldReconnect?.(code, reason) ?? true)) void scheduleReconnect();
4542
4546
  }
4543
4547
  });
4544
4548
  };
@@ -4569,7 +4573,14 @@ async function connectWithReconnect(options) {
4569
4573
  }
4570
4574
  if (!closed) onReconnectFailed?.();
4571
4575
  };
4572
- currentConnection = await connectOnce();
4576
+ try {
4577
+ currentConnection = await connectOnce();
4578
+ } catch (err) {
4579
+ if (!(err instanceof WebSocketAuthError) || !refreshAuth) throw err;
4580
+ await refreshAuth().catch(() => {
4581
+ });
4582
+ currentConnection = await connectOnce();
4583
+ }
4573
4584
  return {
4574
4585
  close: () => {
4575
4586
  closed = true;
@@ -5336,6 +5347,7 @@ __export(assistant_exports, {
5336
5347
  buildRetrievalFullContextTool: () => buildRetrievalFullContextTool,
5337
5348
  buildRetrievalTocTool: () => buildRetrievalTocTool,
5338
5349
  filterSkills: () => filterSkills,
5350
+ listCommands: () => listCommands,
5339
5351
  listSkills: () => listSkills,
5340
5352
  parseSlashCommand: () => parseSlashCommand,
5341
5353
  parseSlashTokenInProgress: () => parseSlashTokenInProgress,
@@ -5443,6 +5455,13 @@ async function listSkills(arbi, options) {
5443
5455
  );
5444
5456
  return result.skills;
5445
5457
  }
5458
+ async function listCommands(arbi) {
5459
+ const result = requireData(
5460
+ await arbi.fetch.GET("/v1/assistant/commands", {}),
5461
+ "Failed to list commands"
5462
+ );
5463
+ return result.commands;
5464
+ }
5446
5465
  function parseSlashCommand(input) {
5447
5466
  const m2 = /^\s*\/([a-zA-Z0-9_-]+)(?:\s+([\s\S]*))?$/.exec(input);
5448
5467
  if (!m2) return null;
@@ -6102,6 +6121,19 @@ var Arbi = class {
6102
6121
  get hasWorkspace() {
6103
6122
  return this.currentWorkspaceId !== null;
6104
6123
  }
6124
+ /**
6125
+ * Live connection info for opening a raw transport (e.g. a WebSocket).
6126
+ *
6127
+ * Reads the access token from the session on each call, so a token refreshed
6128
+ * elsewhere is reflected on the next (re)connect. Returns `null` when there is
6129
+ * no client/token yet (not logged in) rather than throwing, so callers can
6130
+ * poll for readiness instead of guarding against exceptions.
6131
+ */
6132
+ getConnectionInfo() {
6133
+ const accessToken = this.client?.session.getState().accessToken;
6134
+ if (!accessToken) return null;
6135
+ return { baseUrl: this.options.url, accessToken };
6136
+ }
6105
6137
  // ── Auth headers (for raw fetch operations) ───────────────────────────
6106
6138
  getAuthHeaders() {
6107
6139
  const client = this.requireClient();