@arbidocs/sdk 0.4.145 → 0.4.147

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/browser.cjs CHANGED
@@ -3529,7 +3529,7 @@ function requireData(result, message) {
3529
3529
  }
3530
3530
  function requireOk(result, message) {
3531
3531
  if (result.error) {
3532
- throw new ArbiApiError(message, result.error);
3532
+ throw new ArbiApiError(message, result.error, result.response?.status);
3533
3533
  }
3534
3534
  }
3535
3535
  function getErrorMessage(err) {
@@ -4972,6 +4972,7 @@ __export(workspaces_exports, {
4972
4972
  grantTemporaryWorkspaceAccess: () => grantTemporaryWorkspaceAccess,
4973
4973
  listWorkspaceUsers: () => listWorkspaceUsers,
4974
4974
  listWorkspaces: () => listWorkspaces,
4975
+ primeWorkspaceKey: () => primeWorkspaceKey,
4975
4976
  removeWorkspaceUsers: () => removeWorkspaceUsers,
4976
4977
  setUserRole: () => setUserRole,
4977
4978
  updateWorkspace: () => updateWorkspace
@@ -5010,15 +5011,17 @@ async function updateWorkspace(arbi, body) {
5010
5011
  async function listWorkspaceUsers(arbi) {
5011
5012
  return requireData(await arbi.fetch.GET("/v1/workspace/users"), "Failed to fetch workspace users");
5012
5013
  }
5013
- async function addWorkspaceUsers(arbi, emails, role = "collaborator", target) {
5014
+ async function addWorkspaceUsers(arbi, emails, role = "collaborator", target, confirmInvite = false) {
5015
+ const invite = confirmInvite ? { confirm_invite: true } : {};
5014
5016
  return requireData(
5015
5017
  await arbi.fetch.POST("/v1/workspace/users", {
5016
5018
  body: target ? {
5017
5019
  emails,
5018
5020
  role,
5019
5021
  workspace_ext_id: target.workspaceExtId,
5020
- workspace_key: target.workspaceKey
5021
- } : { emails, role }
5022
+ workspace_key: target.workspaceKey,
5023
+ ...invite
5024
+ } : { emails, role, ...invite }
5022
5025
  }),
5023
5026
  "Failed to add users"
5024
5027
  );
@@ -5076,6 +5079,15 @@ async function getWorkspaceActivity(arbi, workspaceExtId, options = {}) {
5076
5079
  "Failed to fetch workspace activity"
5077
5080
  );
5078
5081
  }
5082
+ async function primeWorkspaceKey(arbi, workspaceExtId, sessionSealedKey) {
5083
+ requireOk(
5084
+ await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/prime-key", {
5085
+ params: { path: { workspace_ext_id: workspaceExtId } },
5086
+ body: { workspace_key: sessionSealedKey }
5087
+ }),
5088
+ "Failed to prime the workspace key"
5089
+ );
5090
+ }
5079
5091
 
5080
5092
  // src/operations/conversations.ts
5081
5093
  var conversations_exports = {};
@@ -6359,6 +6371,271 @@ async function setWorkspaceNotificationLevel(arbi, workspaceId, level) {
6359
6371
  return patch;
6360
6372
  }
6361
6373
 
6374
+ // src/operations/connectors.ts
6375
+ var connectors_exports = {};
6376
+ __export(connectors_exports, {
6377
+ DRIVE_SYNC_VENDORS: () => DRIVE_SYNC_VENDORS,
6378
+ GOOGLE_VENDORS: () => GOOGLE_VENDORS,
6379
+ IMANAGE_VENDORS: () => IMANAGE_VENDORS,
6380
+ MAILBOX_SYNC_VENDORS: () => MAILBOX_SYNC_VENDORS,
6381
+ MICROSOFT_VENDORS: () => MICROSOFT_VENDORS,
6382
+ SHAREPOINT_VENDORS: () => SHAREPOINT_VENDORS,
6383
+ authorize: () => authorize,
6384
+ authorizeSlack: () => authorizeSlack,
6385
+ bridgeConnectorTokens: () => bridgeConnectorTokens,
6386
+ cancelDriveSync: () => cancelDriveSync,
6387
+ cancelMailboxSync: () => cancelMailboxSync,
6388
+ connectErrorMessage: () => connectErrorMessage,
6389
+ depositSessionTokens: () => depositSessionTokens,
6390
+ disconnect: () => disconnect,
6391
+ disconnectSlack: () => disconnectSlack,
6392
+ driveFolderDocCount: () => driveFolderDocCount,
6393
+ driveSyncEstimate: () => driveSyncEstimate,
6394
+ driveSyncProgress: () => driveSyncProgress,
6395
+ enableDriveSync: () => enableDriveSync,
6396
+ enableMailboxSync: () => enableMailboxSync,
6397
+ getSealedTokens: () => getSealedTokens,
6398
+ isConnectorVendorVisible: () => isConnectorVendorVisible,
6399
+ isDriveSyncVendor: () => isDriveSyncVendor,
6400
+ isMailboxSyncVendor: () => isMailboxSyncVendor,
6401
+ isSharePointVendor: () => isSharePointVendor,
6402
+ listCatalog: () => listCatalog,
6403
+ listDriveFolderChildren: () => listDriveFolderChildren,
6404
+ listDriveFolders: () => listDriveFolders,
6405
+ listMailboxFolders: () => listMailboxFolders,
6406
+ listMine: () => listMine,
6407
+ mailboxSyncProgress: () => mailboxSyncProgress,
6408
+ slackStatus: () => slackStatus,
6409
+ triggerDriveSync: () => triggerDriveSync,
6410
+ triggerMailboxSync: () => triggerMailboxSync
6411
+ });
6412
+ var vendorPath = (vendor) => ({ path: { vendor } });
6413
+ var vendorKeyPath = (vendor) => ({
6414
+ path: { vendor_key: vendor }
6415
+ });
6416
+ async function listCatalog(arbi) {
6417
+ return requireData(await arbi.fetch.GET("/v1/connectors"), "Failed to load connectors");
6418
+ }
6419
+ async function listMine(arbi) {
6420
+ return requireData(await arbi.fetch.GET("/v1/connectors/me"), "Failed to load your connections");
6421
+ }
6422
+ async function disconnect(arbi, vendor) {
6423
+ requireOk(
6424
+ await arbi.fetch.DELETE("/v1/connectors/{vendor_key}", { params: vendorKeyPath(vendor) }),
6425
+ "Failed to disconnect"
6426
+ );
6427
+ }
6428
+ async function authorize(arbi, vendor, returnTo) {
6429
+ const data = requireData(
6430
+ await arbi.fetch.GET("/v1/connectors/{vendor_key}/authorize", {
6431
+ params: { ...vendorKeyPath(vendor), query: returnTo ? { return_to: returnTo } : {} }
6432
+ }),
6433
+ "Could not start the connection"
6434
+ );
6435
+ return data.url;
6436
+ }
6437
+ async function getSealedTokens(arbi) {
6438
+ return requireData(
6439
+ await arbi.fetch.GET("/v1/connectors/sealed-tokens"),
6440
+ "Failed to load connector tokens"
6441
+ );
6442
+ }
6443
+ async function depositSessionTokens(arbi, body) {
6444
+ requireOk(
6445
+ await arbi.fetch.POST("/v1/connectors/session-tokens", { body }),
6446
+ "Failed to bridge connector tokens"
6447
+ );
6448
+ }
6449
+ async function listMailboxFolders(arbi, vendor) {
6450
+ return requireData(
6451
+ await arbi.fetch.GET("/v1/connectors/{vendor}/folders", { params: vendorPath(vendor) }),
6452
+ "Failed to load folders"
6453
+ );
6454
+ }
6455
+ async function enableMailboxSync(arbi, vendor, body) {
6456
+ return requireData(
6457
+ await arbi.fetch.POST("/v1/connectors/{vendor}/enable-sync", {
6458
+ params: vendorPath(vendor),
6459
+ body
6460
+ }),
6461
+ "Failed to enable sync"
6462
+ );
6463
+ }
6464
+ async function triggerMailboxSync(arbi, vendor, workspaceExtId) {
6465
+ return requireData(
6466
+ await arbi.fetch.POST("/v1/connectors/{vendor}/sync", {
6467
+ params: {
6468
+ ...vendorPath(vendor),
6469
+ query: workspaceExtId ? { workspace_ext_id: workspaceExtId } : {}
6470
+ }
6471
+ }),
6472
+ "Failed to start the sync"
6473
+ );
6474
+ }
6475
+ async function mailboxSyncProgress(arbi, vendor, workspaceExtId) {
6476
+ return requireData(
6477
+ await arbi.fetch.GET("/v1/connectors/{vendor}/sync-progress", {
6478
+ params: { ...vendorPath(vendor), query: { workspace_ext_id: workspaceExtId } }
6479
+ }),
6480
+ "Failed to read the sync progress"
6481
+ );
6482
+ }
6483
+ async function cancelMailboxSync(arbi, vendor, workspaceExtId) {
6484
+ requireOk(
6485
+ await arbi.fetch.POST("/v1/connectors/{vendor}/sync/cancel", {
6486
+ params: { ...vendorPath(vendor), query: { workspace_ext_id: workspaceExtId } }
6487
+ }),
6488
+ "Failed to cancel the sync"
6489
+ );
6490
+ }
6491
+ async function listDriveFolders(arbi, vendor) {
6492
+ return requireData(
6493
+ await arbi.fetch.GET("/v1/connectors/{vendor}/drive-folders", { params: vendorPath(vendor) }),
6494
+ "Failed to load folders"
6495
+ );
6496
+ }
6497
+ async function listDriveFolderChildren(arbi, vendor, itemId) {
6498
+ return requireData(
6499
+ await arbi.fetch.GET("/v1/connectors/{vendor}/drive-folder-children", {
6500
+ params: { ...vendorPath(vendor), query: { item_id: itemId } }
6501
+ }),
6502
+ "Failed to load folders"
6503
+ );
6504
+ }
6505
+ async function driveFolderDocCount(arbi, vendor, itemId) {
6506
+ const data = requireData(
6507
+ await arbi.fetch.GET("/v1/connectors/{vendor}/drive-folder-doc-count", {
6508
+ params: { ...vendorPath(vendor), query: { item_id: itemId } }
6509
+ }),
6510
+ "Failed to count documents"
6511
+ );
6512
+ return data.count;
6513
+ }
6514
+ async function enableDriveSync(arbi, vendor, body) {
6515
+ requireOk(
6516
+ await arbi.fetch.POST("/v1/connectors/{vendor}/enable-drive-sync", {
6517
+ params: vendorPath(vendor),
6518
+ body
6519
+ }),
6520
+ "Failed to enable sync"
6521
+ );
6522
+ }
6523
+ async function triggerDriveSync(arbi, vendor) {
6524
+ return requireData(
6525
+ await arbi.fetch.POST("/v1/connectors/{vendor}/drive-sync", { params: vendorPath(vendor) }),
6526
+ "Failed to start the sync"
6527
+ );
6528
+ }
6529
+ async function driveSyncEstimate(arbi, vendor) {
6530
+ return requireData(
6531
+ await arbi.fetch.GET("/v1/connectors/{vendor}/drive-sync-estimate", {
6532
+ params: vendorPath(vendor)
6533
+ }),
6534
+ "Failed to estimate the sync"
6535
+ );
6536
+ }
6537
+ async function driveSyncProgress(arbi, vendor) {
6538
+ return requireData(
6539
+ await arbi.fetch.GET("/v1/connectors/{vendor}/drive-sync-progress", {
6540
+ params: vendorPath(vendor)
6541
+ }),
6542
+ "Failed to read the sync progress"
6543
+ );
6544
+ }
6545
+ async function cancelDriveSync(arbi, vendor) {
6546
+ requireOk(
6547
+ await arbi.fetch.POST("/v1/connectors/{vendor}/drive-sync/cancel", {
6548
+ params: vendorPath(vendor)
6549
+ }),
6550
+ "Failed to cancel the sync"
6551
+ );
6552
+ }
6553
+ async function slackStatus(arbi) {
6554
+ return requireData(
6555
+ await arbi.fetch.GET("/v1/slack/me"),
6556
+ "Failed to load the Slack connection"
6557
+ );
6558
+ }
6559
+ async function authorizeSlack(arbi, agentExtId) {
6560
+ const data = requireData(
6561
+ await arbi.fetch.GET("/v1/slack/authorize", {
6562
+ params: { query: { agent_ext_id: agentExtId } }
6563
+ }),
6564
+ "Could not start Slack authorization"
6565
+ );
6566
+ return data.url;
6567
+ }
6568
+ async function disconnectSlack(arbi) {
6569
+ requireOk(await arbi.fetch.DELETE("/v1/slack/me"), "Failed to disconnect Slack");
6570
+ }
6571
+ var MAILBOX_SYNC_VENDORS = ["microsoft", "gmail"];
6572
+ var DRIVE_SYNC_VENDORS = [
6573
+ "microsoft",
6574
+ "gmail",
6575
+ "microsoft_sharepoint",
6576
+ "clio",
6577
+ "box",
6578
+ "dropbox",
6579
+ "onenote"
6580
+ ];
6581
+ var MICROSOFT_VENDORS = ["microsoft", "ms365_mail"];
6582
+ var GOOGLE_VENDORS = ["gmail", "gdrive"];
6583
+ var IMANAGE_VENDORS = ["imanage"];
6584
+ var SHAREPOINT_VENDORS = ["microsoft_sharepoint"];
6585
+ var includes = (list, vendor) => list.includes(vendor);
6586
+ var isMailboxSyncVendor = (vendor) => includes(MAILBOX_SYNC_VENDORS, vendor);
6587
+ var isDriveSyncVendor = (vendor) => includes(DRIVE_SYNC_VENDORS, vendor);
6588
+ var isSharePointVendor = (vendor) => includes(SHAREPOINT_VENDORS, vendor);
6589
+ function isConnectorVendorVisible(settings, vendor) {
6590
+ if (includes(MICROSOFT_VENDORS, vendor)) return settings?.show_connector_microsoft ?? true;
6591
+ if (includes(GOOGLE_VENDORS, vendor)) return settings?.show_connector_google ?? true;
6592
+ if (includes(IMANAGE_VENDORS, vendor)) return settings?.show_connector_imanage ?? false;
6593
+ if (includes(SHAREPOINT_VENDORS, vendor)) return settings?.show_connector_sharepoint ?? false;
6594
+ return true;
6595
+ }
6596
+ var CONNECT_ERROR_PRODUCTS = {
6597
+ microsoft: "Microsoft",
6598
+ microsoft_sharepoint: "SharePoint",
6599
+ gmail: "Google",
6600
+ gdrive: "Google Drive",
6601
+ imanage: "iManage",
6602
+ slack: "Slack"
6603
+ };
6604
+ function connectErrorMessage(vendor) {
6605
+ const product = vendor && CONNECT_ERROR_PRODUCTS[vendor] || "the account";
6606
+ return `Couldn't connect ${product}. The connection was cancelled or not approved.`;
6607
+ }
6608
+ async function bridgeConnectorTokens(arbi, keys, { vendor, autoSyncWorkspaceExtId } = {}) {
6609
+ await client.initSodium();
6610
+ const keypair = client.encryptionKeypairFromSigningKey(keys.signingPrivateKey);
6611
+ try {
6612
+ let sealed = await getSealedTokens(arbi);
6613
+ if (vendor) sealed = sealed.filter((token) => token.vendor_key === vendor);
6614
+ for (const token of sealed) {
6615
+ try {
6616
+ const reseal = async (wrapped) => {
6617
+ const plain = client.sealedBoxDecrypt(wrapped, keypair.secretKey);
6618
+ try {
6619
+ return await client.sealKeyForSession(plain, keys.serverSessionKey);
6620
+ } finally {
6621
+ plain.fill(0);
6622
+ }
6623
+ };
6624
+ await depositSessionTokens(arbi, {
6625
+ vendor_key: token.vendor_key,
6626
+ access: await reseal(token.access_token),
6627
+ refresh: token.refresh_token ? await reseal(token.refresh_token) : null,
6628
+ ...autoSyncWorkspaceExtId ? { auto_sync_workspace_ext_id: autoSyncWorkspaceExtId } : {}
6629
+ });
6630
+ } catch (err) {
6631
+ console.error("[connectors] Could not bridge the token of", token.vendor_key, err);
6632
+ }
6633
+ }
6634
+ } finally {
6635
+ keypair.secretKey.fill(0);
6636
+ }
6637
+ }
6638
+
6362
6639
  // src/operations/agentconfig.ts
6363
6640
  var agentconfig_exports = {};
6364
6641
  __export(agentconfig_exports, {
@@ -8849,6 +9126,8 @@ var Arbi = class {
8849
9126
  }
8850
9127
  // ── Workspaces ────────────────────────────────────────────────────────
8851
9128
  workspaces = {
9129
+ /** Hand this server session a workspace's key (sealed to the session) without opening it. */
9130
+ primeKey: (workspaceExtId, sessionSealedKey) => primeWorkspaceKey(this.requireClient(), workspaceExtId, sessionSealedKey),
8852
9131
  list: async () => this.rememberWorkspaces(await listWorkspaces(this.requireClient())),
8853
9132
  create: async (name, projectExtId, description, isPublic) => {
8854
9133
  const client = this.requireClient();
@@ -8877,7 +9156,14 @@ var Arbi = class {
8877
9156
  listUsers: () => listWorkspaceUsers(this.requireClient()),
8878
9157
  /** One page of a workspace's activity feed, newest first (see `getWorkspaceActivity`). */
8879
9158
  activity: (workspaceId, options) => getWorkspaceActivity(this.requireClient(), workspaceId, options),
8880
- addUsers: (emails, role) => addWorkspaceUsers(this.requireClient(), emails, role),
9159
+ /** Add users to the open workspace; `confirmInvite` also invites emails not on ARBI yet. */
9160
+ addUsers: (emails, role, options) => addWorkspaceUsers(
9161
+ this.requireClient(),
9162
+ emails,
9163
+ role,
9164
+ void 0,
9165
+ options?.confirmInvite
9166
+ ),
8881
9167
  /**
8882
9168
  * Grant users a temporary key scoped to ONE session (identified by its public key), for
8883
9169
  * example an agent's run session minted by `agents.authorize()`. Nothing standing is created:
@@ -9432,6 +9718,49 @@ var Arbi = class {
9432
9718
  /** List the current user's durable activity feed. */
9433
9719
  listActivity: (options) => listActivity(this.requireClient(), options)
9434
9720
  };
9721
+ // ── Connectors ────────────────────────────────────────────────────────
9722
+ /**
9723
+ * Connectors: the catalog, the user's connections and their OAuth, mailbox and drive sync,
9724
+ * Slack. A vendor is its `vendor_key` (e.g. `microsoft`, `gmail`).
9725
+ */
9726
+ connectors = {
9727
+ catalog: () => listCatalog(this.requireClient()),
9728
+ mine: () => listMine(this.requireClient()),
9729
+ disconnect: (vendor) => disconnect(this.requireClient(), vendor),
9730
+ /** The provider consent URL; the OAuth comes back to `returnTo` (a path of this app). */
9731
+ authorize: (vendor, returnTo) => authorize(this.requireClient(), vendor, returnTo),
9732
+ /**
9733
+ * Let this server session use the user's connector grants (best effort: a failure is logged,
9734
+ * never thrown, so it cannot break a sign-in or a connect). Signed out: nothing to bridge.
9735
+ */
9736
+ bridgeTokens: async (options) => {
9737
+ const login = this.loginResult;
9738
+ if (!login) return;
9739
+ try {
9740
+ await bridgeConnectorTokens(this.requireClient(), login, options);
9741
+ } catch (err) {
9742
+ console.error("[connectors] Token bridge failed", err);
9743
+ }
9744
+ },
9745
+ mailboxFolders: (vendor) => listMailboxFolders(this.requireClient(), vendor),
9746
+ enableMailboxSync: (vendor, body) => enableMailboxSync(this.requireClient(), vendor, body),
9747
+ syncMailbox: (vendor, workspaceExtId) => triggerMailboxSync(this.requireClient(), vendor, workspaceExtId),
9748
+ mailboxSyncProgress: (vendor, workspaceExtId) => mailboxSyncProgress(this.requireClient(), vendor, workspaceExtId),
9749
+ cancelMailboxSync: (vendor, workspaceExtId) => cancelMailboxSync(this.requireClient(), vendor, workspaceExtId),
9750
+ driveFolders: (vendor) => listDriveFolders(this.requireClient(), vendor),
9751
+ driveFolderChildren: (vendor, itemId) => listDriveFolderChildren(this.requireClient(), vendor, itemId),
9752
+ driveFolderDocCount: (vendor, itemId) => driveFolderDocCount(this.requireClient(), vendor, itemId),
9753
+ enableDriveSync: (vendor, body) => enableDriveSync(this.requireClient(), vendor, body),
9754
+ syncDrive: (vendor) => triggerDriveSync(this.requireClient(), vendor),
9755
+ driveSyncEstimate: (vendor) => driveSyncEstimate(this.requireClient(), vendor),
9756
+ driveSyncProgress: (vendor) => driveSyncProgress(this.requireClient(), vendor),
9757
+ cancelDriveSync: (vendor) => cancelDriveSync(this.requireClient(), vendor),
9758
+ slack: {
9759
+ status: () => slackStatus(this.requireClient()),
9760
+ authorize: (agentExtId) => authorizeSlack(this.requireClient(), agentExtId),
9761
+ disconnect: () => disconnectSlack(this.requireClient())
9762
+ }
9763
+ };
9435
9764
  // ── Settings ──────────────────────────────────────────────────────────
9436
9765
  settings = {
9437
9766
  get: () => getSettings(this.requireClient()),
@@ -9596,9 +9925,15 @@ exports.Arbi = Arbi;
9596
9925
  exports.ArbiApiError = ArbiApiError;
9597
9926
  exports.ArbiError = ArbiError;
9598
9927
  exports.DEFAULT_AI_USD_PER_GBP = DEFAULT_AI_USD_PER_GBP;
9928
+ exports.DRIVE_SYNC_VENDORS = DRIVE_SYNC_VENDORS;
9599
9929
  exports.FLAT_TAG_KINDS = FLAT_TAG_KINDS;
9930
+ exports.GOOGLE_VENDORS = GOOGLE_VENDORS;
9931
+ exports.IMANAGE_VENDORS = IMANAGE_VENDORS;
9932
+ exports.MAILBOX_SYNC_VENDORS = MAILBOX_SYNC_VENDORS;
9933
+ exports.MICROSOFT_VENDORS = MICROSOFT_VENDORS;
9600
9934
  exports.PlanStepsError = PlanStepsError;
9601
9935
  exports.PublicBookingError = PublicBookingError;
9936
+ exports.SHAREPOINT_VENDORS = SHAREPOINT_VENDORS;
9602
9937
  exports.TAG_KINDS = TAG_KINDS;
9603
9938
  exports.WebSocketAuthError = WebSocketAuthError;
9604
9939
  exports.account = account_exports;
@@ -9614,8 +9949,10 @@ exports.buildRetrievalTocTool = buildRetrievalTocTool;
9614
9949
  exports.calendar = calendar_exports;
9615
9950
  exports.cancelPublicBooking = cancelPublicBooking;
9616
9951
  exports.chats = chats_exports;
9952
+ exports.connectErrorMessage = connectErrorMessage;
9617
9953
  exports.connectWebSocket = connectWebSocket;
9618
9954
  exports.connectWithReconnect = connectWithReconnect;
9955
+ exports.connectors = connectors_exports;
9619
9956
  exports.consumeSSEStream = consumeSSEStream;
9620
9957
  exports.contacts = contacts_exports;
9621
9958
  exports.conversations = conversations_exports;
@@ -9640,6 +9977,10 @@ exports.health = health_exports;
9640
9977
  exports.houseTemplates = house_template_exports;
9641
9978
  exports.identityErrorCode = identityErrorCode;
9642
9979
  exports.identityVerification = identity_exports;
9980
+ exports.isConnectorVendorVisible = isConnectorVendorVisible;
9981
+ exports.isDriveSyncVendor = isDriveSyncVendor;
9982
+ exports.isMailboxSyncVendor = isMailboxSyncVendor;
9983
+ exports.isSharePointVendor = isSharePointVendor;
9643
9984
  exports.mail = mail_exports;
9644
9985
  exports.notifications = notifications_exports;
9645
9986
  exports.parseSSEEvents = parseSSEEvents;