@arbidocs/sdk 0.4.146 → 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/index.cjs CHANGED
@@ -3541,7 +3541,7 @@ function requireData(result, message) {
3541
3541
  }
3542
3542
  function requireOk(result, message) {
3543
3543
  if (result.error) {
3544
- throw new ArbiApiError(message, result.error);
3544
+ throw new ArbiApiError(message, result.error, result.response?.status);
3545
3545
  }
3546
3546
  }
3547
3547
  function getErrorMessage(err) {
@@ -5547,6 +5547,7 @@ __export(workspaces_exports, {
5547
5547
  grantTemporaryWorkspaceAccess: () => grantTemporaryWorkspaceAccess,
5548
5548
  listWorkspaceUsers: () => listWorkspaceUsers,
5549
5549
  listWorkspaces: () => listWorkspaces,
5550
+ primeWorkspaceKey: () => primeWorkspaceKey,
5550
5551
  removeWorkspaceUsers: () => removeWorkspaceUsers,
5551
5552
  setUserRole: () => setUserRole,
5552
5553
  updateWorkspace: () => updateWorkspace
@@ -5653,6 +5654,15 @@ async function getWorkspaceActivity(arbi, workspaceExtId, options = {}) {
5653
5654
  "Failed to fetch workspace activity"
5654
5655
  );
5655
5656
  }
5657
+ async function primeWorkspaceKey(arbi, workspaceExtId, sessionSealedKey) {
5658
+ requireOk(
5659
+ await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/prime-key", {
5660
+ params: { path: { workspace_ext_id: workspaceExtId } },
5661
+ body: { workspace_key: sessionSealedKey }
5662
+ }),
5663
+ "Failed to prime the workspace key"
5664
+ );
5665
+ }
5656
5666
 
5657
5667
  // src/operations/conversations.ts
5658
5668
  var conversations_exports = {};
@@ -6952,6 +6962,271 @@ async function setWorkspaceNotificationLevel(arbi, workspaceId, level) {
6952
6962
  return patch;
6953
6963
  }
6954
6964
 
6965
+ // src/operations/connectors.ts
6966
+ var connectors_exports = {};
6967
+ __export(connectors_exports, {
6968
+ DRIVE_SYNC_VENDORS: () => DRIVE_SYNC_VENDORS,
6969
+ GOOGLE_VENDORS: () => GOOGLE_VENDORS,
6970
+ IMANAGE_VENDORS: () => IMANAGE_VENDORS,
6971
+ MAILBOX_SYNC_VENDORS: () => MAILBOX_SYNC_VENDORS,
6972
+ MICROSOFT_VENDORS: () => MICROSOFT_VENDORS,
6973
+ SHAREPOINT_VENDORS: () => SHAREPOINT_VENDORS,
6974
+ authorize: () => authorize,
6975
+ authorizeSlack: () => authorizeSlack,
6976
+ bridgeConnectorTokens: () => bridgeConnectorTokens,
6977
+ cancelDriveSync: () => cancelDriveSync,
6978
+ cancelMailboxSync: () => cancelMailboxSync,
6979
+ connectErrorMessage: () => connectErrorMessage,
6980
+ depositSessionTokens: () => depositSessionTokens,
6981
+ disconnect: () => disconnect,
6982
+ disconnectSlack: () => disconnectSlack,
6983
+ driveFolderDocCount: () => driveFolderDocCount,
6984
+ driveSyncEstimate: () => driveSyncEstimate,
6985
+ driveSyncProgress: () => driveSyncProgress,
6986
+ enableDriveSync: () => enableDriveSync,
6987
+ enableMailboxSync: () => enableMailboxSync,
6988
+ getSealedTokens: () => getSealedTokens,
6989
+ isConnectorVendorVisible: () => isConnectorVendorVisible,
6990
+ isDriveSyncVendor: () => isDriveSyncVendor,
6991
+ isMailboxSyncVendor: () => isMailboxSyncVendor,
6992
+ isSharePointVendor: () => isSharePointVendor,
6993
+ listCatalog: () => listCatalog,
6994
+ listDriveFolderChildren: () => listDriveFolderChildren,
6995
+ listDriveFolders: () => listDriveFolders,
6996
+ listMailboxFolders: () => listMailboxFolders,
6997
+ listMine: () => listMine,
6998
+ mailboxSyncProgress: () => mailboxSyncProgress,
6999
+ slackStatus: () => slackStatus,
7000
+ triggerDriveSync: () => triggerDriveSync,
7001
+ triggerMailboxSync: () => triggerMailboxSync
7002
+ });
7003
+ var vendorPath = (vendor) => ({ path: { vendor } });
7004
+ var vendorKeyPath = (vendor) => ({
7005
+ path: { vendor_key: vendor }
7006
+ });
7007
+ async function listCatalog(arbi) {
7008
+ return requireData(await arbi.fetch.GET("/v1/connectors"), "Failed to load connectors");
7009
+ }
7010
+ async function listMine(arbi) {
7011
+ return requireData(await arbi.fetch.GET("/v1/connectors/me"), "Failed to load your connections");
7012
+ }
7013
+ async function disconnect(arbi, vendor) {
7014
+ requireOk(
7015
+ await arbi.fetch.DELETE("/v1/connectors/{vendor_key}", { params: vendorKeyPath(vendor) }),
7016
+ "Failed to disconnect"
7017
+ );
7018
+ }
7019
+ async function authorize(arbi, vendor, returnTo) {
7020
+ const data = requireData(
7021
+ await arbi.fetch.GET("/v1/connectors/{vendor_key}/authorize", {
7022
+ params: { ...vendorKeyPath(vendor), query: returnTo ? { return_to: returnTo } : {} }
7023
+ }),
7024
+ "Could not start the connection"
7025
+ );
7026
+ return data.url;
7027
+ }
7028
+ async function getSealedTokens(arbi) {
7029
+ return requireData(
7030
+ await arbi.fetch.GET("/v1/connectors/sealed-tokens"),
7031
+ "Failed to load connector tokens"
7032
+ );
7033
+ }
7034
+ async function depositSessionTokens(arbi, body) {
7035
+ requireOk(
7036
+ await arbi.fetch.POST("/v1/connectors/session-tokens", { body }),
7037
+ "Failed to bridge connector tokens"
7038
+ );
7039
+ }
7040
+ async function listMailboxFolders(arbi, vendor) {
7041
+ return requireData(
7042
+ await arbi.fetch.GET("/v1/connectors/{vendor}/folders", { params: vendorPath(vendor) }),
7043
+ "Failed to load folders"
7044
+ );
7045
+ }
7046
+ async function enableMailboxSync(arbi, vendor, body) {
7047
+ return requireData(
7048
+ await arbi.fetch.POST("/v1/connectors/{vendor}/enable-sync", {
7049
+ params: vendorPath(vendor),
7050
+ body
7051
+ }),
7052
+ "Failed to enable sync"
7053
+ );
7054
+ }
7055
+ async function triggerMailboxSync(arbi, vendor, workspaceExtId) {
7056
+ return requireData(
7057
+ await arbi.fetch.POST("/v1/connectors/{vendor}/sync", {
7058
+ params: {
7059
+ ...vendorPath(vendor),
7060
+ query: workspaceExtId ? { workspace_ext_id: workspaceExtId } : {}
7061
+ }
7062
+ }),
7063
+ "Failed to start the sync"
7064
+ );
7065
+ }
7066
+ async function mailboxSyncProgress(arbi, vendor, workspaceExtId) {
7067
+ return requireData(
7068
+ await arbi.fetch.GET("/v1/connectors/{vendor}/sync-progress", {
7069
+ params: { ...vendorPath(vendor), query: { workspace_ext_id: workspaceExtId } }
7070
+ }),
7071
+ "Failed to read the sync progress"
7072
+ );
7073
+ }
7074
+ async function cancelMailboxSync(arbi, vendor, workspaceExtId) {
7075
+ requireOk(
7076
+ await arbi.fetch.POST("/v1/connectors/{vendor}/sync/cancel", {
7077
+ params: { ...vendorPath(vendor), query: { workspace_ext_id: workspaceExtId } }
7078
+ }),
7079
+ "Failed to cancel the sync"
7080
+ );
7081
+ }
7082
+ async function listDriveFolders(arbi, vendor) {
7083
+ return requireData(
7084
+ await arbi.fetch.GET("/v1/connectors/{vendor}/drive-folders", { params: vendorPath(vendor) }),
7085
+ "Failed to load folders"
7086
+ );
7087
+ }
7088
+ async function listDriveFolderChildren(arbi, vendor, itemId) {
7089
+ return requireData(
7090
+ await arbi.fetch.GET("/v1/connectors/{vendor}/drive-folder-children", {
7091
+ params: { ...vendorPath(vendor), query: { item_id: itemId } }
7092
+ }),
7093
+ "Failed to load folders"
7094
+ );
7095
+ }
7096
+ async function driveFolderDocCount(arbi, vendor, itemId) {
7097
+ const data = requireData(
7098
+ await arbi.fetch.GET("/v1/connectors/{vendor}/drive-folder-doc-count", {
7099
+ params: { ...vendorPath(vendor), query: { item_id: itemId } }
7100
+ }),
7101
+ "Failed to count documents"
7102
+ );
7103
+ return data.count;
7104
+ }
7105
+ async function enableDriveSync(arbi, vendor, body) {
7106
+ requireOk(
7107
+ await arbi.fetch.POST("/v1/connectors/{vendor}/enable-drive-sync", {
7108
+ params: vendorPath(vendor),
7109
+ body
7110
+ }),
7111
+ "Failed to enable sync"
7112
+ );
7113
+ }
7114
+ async function triggerDriveSync(arbi, vendor) {
7115
+ return requireData(
7116
+ await arbi.fetch.POST("/v1/connectors/{vendor}/drive-sync", { params: vendorPath(vendor) }),
7117
+ "Failed to start the sync"
7118
+ );
7119
+ }
7120
+ async function driveSyncEstimate(arbi, vendor) {
7121
+ return requireData(
7122
+ await arbi.fetch.GET("/v1/connectors/{vendor}/drive-sync-estimate", {
7123
+ params: vendorPath(vendor)
7124
+ }),
7125
+ "Failed to estimate the sync"
7126
+ );
7127
+ }
7128
+ async function driveSyncProgress(arbi, vendor) {
7129
+ return requireData(
7130
+ await arbi.fetch.GET("/v1/connectors/{vendor}/drive-sync-progress", {
7131
+ params: vendorPath(vendor)
7132
+ }),
7133
+ "Failed to read the sync progress"
7134
+ );
7135
+ }
7136
+ async function cancelDriveSync(arbi, vendor) {
7137
+ requireOk(
7138
+ await arbi.fetch.POST("/v1/connectors/{vendor}/drive-sync/cancel", {
7139
+ params: vendorPath(vendor)
7140
+ }),
7141
+ "Failed to cancel the sync"
7142
+ );
7143
+ }
7144
+ async function slackStatus(arbi) {
7145
+ return requireData(
7146
+ await arbi.fetch.GET("/v1/slack/me"),
7147
+ "Failed to load the Slack connection"
7148
+ );
7149
+ }
7150
+ async function authorizeSlack(arbi, agentExtId) {
7151
+ const data = requireData(
7152
+ await arbi.fetch.GET("/v1/slack/authorize", {
7153
+ params: { query: { agent_ext_id: agentExtId } }
7154
+ }),
7155
+ "Could not start Slack authorization"
7156
+ );
7157
+ return data.url;
7158
+ }
7159
+ async function disconnectSlack(arbi) {
7160
+ requireOk(await arbi.fetch.DELETE("/v1/slack/me"), "Failed to disconnect Slack");
7161
+ }
7162
+ var MAILBOX_SYNC_VENDORS = ["microsoft", "gmail"];
7163
+ var DRIVE_SYNC_VENDORS = [
7164
+ "microsoft",
7165
+ "gmail",
7166
+ "microsoft_sharepoint",
7167
+ "clio",
7168
+ "box",
7169
+ "dropbox",
7170
+ "onenote"
7171
+ ];
7172
+ var MICROSOFT_VENDORS = ["microsoft", "ms365_mail"];
7173
+ var GOOGLE_VENDORS = ["gmail", "gdrive"];
7174
+ var IMANAGE_VENDORS = ["imanage"];
7175
+ var SHAREPOINT_VENDORS = ["microsoft_sharepoint"];
7176
+ var includes = (list, vendor) => list.includes(vendor);
7177
+ var isMailboxSyncVendor = (vendor) => includes(MAILBOX_SYNC_VENDORS, vendor);
7178
+ var isDriveSyncVendor = (vendor) => includes(DRIVE_SYNC_VENDORS, vendor);
7179
+ var isSharePointVendor = (vendor) => includes(SHAREPOINT_VENDORS, vendor);
7180
+ function isConnectorVendorVisible(settings, vendor) {
7181
+ if (includes(MICROSOFT_VENDORS, vendor)) return settings?.show_connector_microsoft ?? true;
7182
+ if (includes(GOOGLE_VENDORS, vendor)) return settings?.show_connector_google ?? true;
7183
+ if (includes(IMANAGE_VENDORS, vendor)) return settings?.show_connector_imanage ?? false;
7184
+ if (includes(SHAREPOINT_VENDORS, vendor)) return settings?.show_connector_sharepoint ?? false;
7185
+ return true;
7186
+ }
7187
+ var CONNECT_ERROR_PRODUCTS = {
7188
+ microsoft: "Microsoft",
7189
+ microsoft_sharepoint: "SharePoint",
7190
+ gmail: "Google",
7191
+ gdrive: "Google Drive",
7192
+ imanage: "iManage",
7193
+ slack: "Slack"
7194
+ };
7195
+ function connectErrorMessage(vendor) {
7196
+ const product = vendor && CONNECT_ERROR_PRODUCTS[vendor] || "the account";
7197
+ return `Couldn't connect ${product}. The connection was cancelled or not approved.`;
7198
+ }
7199
+ async function bridgeConnectorTokens(arbi, keys, { vendor, autoSyncWorkspaceExtId } = {}) {
7200
+ await client.initSodium();
7201
+ const keypair = client.encryptionKeypairFromSigningKey(keys.signingPrivateKey);
7202
+ try {
7203
+ let sealed = await getSealedTokens(arbi);
7204
+ if (vendor) sealed = sealed.filter((token) => token.vendor_key === vendor);
7205
+ for (const token of sealed) {
7206
+ try {
7207
+ const reseal = async (wrapped) => {
7208
+ const plain = client.sealedBoxDecrypt(wrapped, keypair.secretKey);
7209
+ try {
7210
+ return await client.sealKeyForSession(plain, keys.serverSessionKey);
7211
+ } finally {
7212
+ plain.fill(0);
7213
+ }
7214
+ };
7215
+ await depositSessionTokens(arbi, {
7216
+ vendor_key: token.vendor_key,
7217
+ access: await reseal(token.access_token),
7218
+ refresh: token.refresh_token ? await reseal(token.refresh_token) : null,
7219
+ ...autoSyncWorkspaceExtId ? { auto_sync_workspace_ext_id: autoSyncWorkspaceExtId } : {}
7220
+ });
7221
+ } catch (err) {
7222
+ console.error("[connectors] Could not bridge the token of", token.vendor_key, err);
7223
+ }
7224
+ }
7225
+ } finally {
7226
+ keypair.secretKey.fill(0);
7227
+ }
7228
+ }
7229
+
6955
7230
  // src/operations/agentconfig.ts
6956
7231
  var agentconfig_exports = {};
6957
7232
  __export(agentconfig_exports, {
@@ -9447,6 +9722,8 @@ var Arbi = class {
9447
9722
  }
9448
9723
  // ── Workspaces ────────────────────────────────────────────────────────
9449
9724
  workspaces = {
9725
+ /** Hand this server session a workspace's key (sealed to the session) without opening it. */
9726
+ primeKey: (workspaceExtId, sessionSealedKey) => primeWorkspaceKey(this.requireClient(), workspaceExtId, sessionSealedKey),
9450
9727
  list: async () => this.rememberWorkspaces(await listWorkspaces(this.requireClient())),
9451
9728
  create: async (name, projectExtId, description, isPublic) => {
9452
9729
  const client = this.requireClient();
@@ -10037,6 +10314,49 @@ var Arbi = class {
10037
10314
  /** List the current user's durable activity feed. */
10038
10315
  listActivity: (options) => listActivity(this.requireClient(), options)
10039
10316
  };
10317
+ // ── Connectors ────────────────────────────────────────────────────────
10318
+ /**
10319
+ * Connectors: the catalog, the user's connections and their OAuth, mailbox and drive sync,
10320
+ * Slack. A vendor is its `vendor_key` (e.g. `microsoft`, `gmail`).
10321
+ */
10322
+ connectors = {
10323
+ catalog: () => listCatalog(this.requireClient()),
10324
+ mine: () => listMine(this.requireClient()),
10325
+ disconnect: (vendor) => disconnect(this.requireClient(), vendor),
10326
+ /** The provider consent URL; the OAuth comes back to `returnTo` (a path of this app). */
10327
+ authorize: (vendor, returnTo) => authorize(this.requireClient(), vendor, returnTo),
10328
+ /**
10329
+ * Let this server session use the user's connector grants (best effort: a failure is logged,
10330
+ * never thrown, so it cannot break a sign-in or a connect). Signed out: nothing to bridge.
10331
+ */
10332
+ bridgeTokens: async (options) => {
10333
+ const login = this.loginResult;
10334
+ if (!login) return;
10335
+ try {
10336
+ await bridgeConnectorTokens(this.requireClient(), login, options);
10337
+ } catch (err) {
10338
+ console.error("[connectors] Token bridge failed", err);
10339
+ }
10340
+ },
10341
+ mailboxFolders: (vendor) => listMailboxFolders(this.requireClient(), vendor),
10342
+ enableMailboxSync: (vendor, body) => enableMailboxSync(this.requireClient(), vendor, body),
10343
+ syncMailbox: (vendor, workspaceExtId) => triggerMailboxSync(this.requireClient(), vendor, workspaceExtId),
10344
+ mailboxSyncProgress: (vendor, workspaceExtId) => mailboxSyncProgress(this.requireClient(), vendor, workspaceExtId),
10345
+ cancelMailboxSync: (vendor, workspaceExtId) => cancelMailboxSync(this.requireClient(), vendor, workspaceExtId),
10346
+ driveFolders: (vendor) => listDriveFolders(this.requireClient(), vendor),
10347
+ driveFolderChildren: (vendor, itemId) => listDriveFolderChildren(this.requireClient(), vendor, itemId),
10348
+ driveFolderDocCount: (vendor, itemId) => driveFolderDocCount(this.requireClient(), vendor, itemId),
10349
+ enableDriveSync: (vendor, body) => enableDriveSync(this.requireClient(), vendor, body),
10350
+ syncDrive: (vendor) => triggerDriveSync(this.requireClient(), vendor),
10351
+ driveSyncEstimate: (vendor) => driveSyncEstimate(this.requireClient(), vendor),
10352
+ driveSyncProgress: (vendor) => driveSyncProgress(this.requireClient(), vendor),
10353
+ cancelDriveSync: (vendor) => cancelDriveSync(this.requireClient(), vendor),
10354
+ slack: {
10355
+ status: () => slackStatus(this.requireClient()),
10356
+ authorize: (agentExtId) => authorizeSlack(this.requireClient(), agentExtId),
10357
+ disconnect: () => disconnectSlack(this.requireClient())
10358
+ }
10359
+ };
10040
10360
  // ── Settings ──────────────────────────────────────────────────────────
10041
10361
  settings = {
10042
10362
  get: () => getSettings(this.requireClient()),
@@ -11277,11 +11597,17 @@ exports.ArbiSessionExpiredError = ArbiSessionExpiredError;
11277
11597
  exports.ClaudeOrchestrator = ClaudeOrchestrator;
11278
11598
  exports.DEFAULT_AI_USD_PER_GBP = DEFAULT_AI_USD_PER_GBP;
11279
11599
  exports.DOC_TERMINAL_STATUSES = DOC_TERMINAL_STATUSES;
11600
+ exports.DRIVE_SYNC_VENDORS = DRIVE_SYNC_VENDORS;
11280
11601
  exports.FLAT_TAG_KINDS = FLAT_TAG_KINDS;
11281
11602
  exports.FileConfigStore = FileConfigStore;
11603
+ exports.GOOGLE_VENDORS = GOOGLE_VENDORS;
11604
+ exports.IMANAGE_VENDORS = IMANAGE_VENDORS;
11605
+ exports.MAILBOX_SYNC_VENDORS = MAILBOX_SYNC_VENDORS;
11606
+ exports.MICROSOFT_VENDORS = MICROSOFT_VENDORS;
11282
11607
  exports.OpenClawOrchestrator = OpenClawOrchestrator;
11283
11608
  exports.PlanStepsError = PlanStepsError;
11284
11609
  exports.PublicBookingError = PublicBookingError;
11610
+ exports.SHAREPOINT_VENDORS = SHAREPOINT_VENDORS;
11285
11611
  exports.STEP_FIELD_OPTION_TONES = STEP_FIELD_OPTION_TONES;
11286
11612
  exports.TAG_KINDS = TAG_KINDS;
11287
11613
  exports.WebSocketAuthError = WebSocketAuthError;
@@ -11300,8 +11626,10 @@ exports.buildRetrievalTocTool = buildRetrievalTocTool;
11300
11626
  exports.calendar = calendar_exports;
11301
11627
  exports.cancelPublicBooking = cancelPublicBooking;
11302
11628
  exports.chats = chats_exports;
11629
+ exports.connectErrorMessage = connectErrorMessage;
11303
11630
  exports.connectWebSocket = connectWebSocket;
11304
11631
  exports.connectWithReconnect = connectWithReconnect;
11632
+ exports.connectors = connectors_exports;
11305
11633
  exports.consumeSSEStream = consumeSSEStream;
11306
11634
  exports.contacts = contacts_exports;
11307
11635
  exports.conversations = conversations_exports;
@@ -11335,6 +11663,10 @@ exports.health = health_exports;
11335
11663
  exports.houseTemplates = house_template_exports;
11336
11664
  exports.identityErrorCode = identityErrorCode;
11337
11665
  exports.identityVerification = identity_exports;
11666
+ exports.isConnectorVendorVisible = isConnectorVendorVisible;
11667
+ exports.isDriveSyncVendor = isDriveSyncVendor;
11668
+ exports.isMailboxSyncVendor = isMailboxSyncVendor;
11669
+ exports.isSharePointVendor = isSharePointVendor;
11338
11670
  exports.isSharedSkill = isSharedSkill;
11339
11671
  exports.listen = listen_exports;
11340
11672
  exports.mail = mail_exports;