@arbidocs/sdk 0.4.3 → 0.4.5

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
@@ -5028,6 +5028,7 @@ async function uploadFile(auth, fileData, fileName, options) {
5028
5028
  if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
5029
5029
  if (options?.configExtId) params.set("config_ext_id", options.configExtId);
5030
5030
  if (options?.wpType) params.set("wp_type", options.wpType);
5031
+ if (options?.parentExtId) params.set("parent_ext_id", options.parentExtId);
5031
5032
  const qs = params.toString();
5032
5033
  const res = await authenticatedFetch({
5033
5034
  ...auth,
@@ -5044,6 +5045,7 @@ async function uploadFiles(auth, files, options) {
5044
5045
  if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
5045
5046
  if (options?.configExtId) params.set("config_ext_id", options.configExtId);
5046
5047
  if (options?.wpType) params.set("wp_type", options.wpType);
5048
+ if (options?.parentExtId) params.set("parent_ext_id", options.parentExtId);
5047
5049
  const qs = params.toString();
5048
5050
  const res = await authenticatedFetch({
5049
5051
  ...auth,
@@ -5225,6 +5227,7 @@ __export(workspaces_exports, {
5225
5227
  copyDocuments: () => copyDocuments,
5226
5228
  createWorkspace: () => createWorkspace,
5227
5229
  deleteWorkspaces: () => deleteWorkspaces,
5230
+ grantTemporaryWorkspaceAccess: () => grantTemporaryWorkspaceAccess,
5228
5231
  listWorkspaceUsers: () => listWorkspaceUsers,
5229
5232
  listWorkspaces: () => listWorkspaces,
5230
5233
  removeWorkspaceUsers: () => removeWorkspaceUsers,
@@ -5265,14 +5268,33 @@ async function updateWorkspace(arbi, body) {
5265
5268
  async function listWorkspaceUsers(arbi) {
5266
5269
  return requireData(await arbi.fetch.GET("/v1/workspace/users"), "Failed to fetch workspace users");
5267
5270
  }
5268
- async function addWorkspaceUsers(arbi, emails, role = "collaborator") {
5271
+ async function addWorkspaceUsers(arbi, emails, role = "collaborator", target) {
5269
5272
  return requireData(
5270
5273
  await arbi.fetch.POST("/v1/workspace/users", {
5271
- body: { emails, role }
5274
+ body: target ? {
5275
+ emails,
5276
+ role,
5277
+ workspace_ext_id: target.workspaceExtId,
5278
+ workspace_key: target.workspaceKey
5279
+ } : { emails, role }
5272
5280
  }),
5273
5281
  "Failed to add users"
5274
5282
  );
5275
5283
  }
5284
+ async function grantTemporaryWorkspaceAccess(arbi, params) {
5285
+ return requireData(
5286
+ await arbi.fetch.POST("/v1/workspace/users", {
5287
+ body: {
5288
+ emails: params.emails,
5289
+ role: params.role ?? "collaborator",
5290
+ workspace_ext_id: params.workspaceExtId,
5291
+ workspace_key: params.workspaceKey,
5292
+ session_pubkey_b64: params.sessionPubkeyB64
5293
+ }
5294
+ }),
5295
+ "Failed to grant temporary access"
5296
+ );
5297
+ }
5276
5298
  async function removeWorkspaceUsers(arbi, userIds) {
5277
5299
  requireOk(
5278
5300
  await arbi.fetch.DELETE("/v1/workspace/users", {
@@ -5668,9 +5690,11 @@ __export(dm_exports, {
5668
5690
  // src/operations/agents.ts
5669
5691
  var agents_exports = {};
5670
5692
  __export(agents_exports, {
5693
+ authorizeAgent: () => authorizeAgent,
5671
5694
  createAgent: () => createAgent,
5672
5695
  deleteAgents: () => deleteAgents,
5673
5696
  getAgentConfig: () => getAgentConfig,
5697
+ getAuthorizeLimits: () => getAuthorizeLimits,
5674
5698
  listAgentWorkspaces: () => listAgentWorkspaces,
5675
5699
  listAgents: () => listAgents
5676
5700
  });
@@ -5705,6 +5729,21 @@ async function deleteAgents(arbi, agentExtIds) {
5705
5729
  "Failed to delete agents"
5706
5730
  );
5707
5731
  }
5732
+ async function authorizeAgent(arbi, agentExtId, workspaceExtId, ttlSeconds) {
5733
+ return requireData(
5734
+ await arbi.fetch.POST("/v1/agents/{agent_ext_id}/authorize", {
5735
+ params: { path: { agent_ext_id: agentExtId } },
5736
+ body: { workspace_ext_id: workspaceExtId, ttl_seconds: ttlSeconds ?? null }
5737
+ }),
5738
+ "Failed to authorize agent"
5739
+ );
5740
+ }
5741
+ async function getAuthorizeLimits(arbi) {
5742
+ return requireData(
5743
+ await arbi.fetch.GET("/v1/agents/authorize-limits"),
5744
+ "Failed to fetch authorize limits"
5745
+ );
5746
+ }
5708
5747
 
5709
5748
  // src/operations/dm.ts
5710
5749
  function createDmCryptoContext(arbi, signingPrivateKeyBytes, userExtId) {
@@ -6091,6 +6130,7 @@ __export(tasks_exports, {
6091
6130
  createTask: () => createTask,
6092
6131
  deleteTask: () => deleteTask,
6093
6132
  getTask: () => getTask,
6133
+ listTaskRuns: () => listTaskRuns,
6094
6134
  listTasks: () => listTasks,
6095
6135
  runTask: () => runTask,
6096
6136
  updateTask: () => updateTask
@@ -6128,6 +6168,12 @@ async function runTask(arbi, taskId) {
6128
6168
  "Failed to run task"
6129
6169
  );
6130
6170
  }
6171
+ async function listTaskRuns(arbi, taskId) {
6172
+ return requireData(
6173
+ await arbi.fetch.GET("/v1/tasks/{task_id}/runs", { params: { path: { task_id: taskId } } }),
6174
+ "Failed to list task runs"
6175
+ );
6176
+ }
6131
6177
 
6132
6178
  // src/operations/facts.ts
6133
6179
  var facts_exports = {};
@@ -6269,6 +6315,22 @@ var Arbi = class {
6269
6315
  const signingPrivateKey = client.crypto.base64ToBytes(signingPrivateKeyBase64);
6270
6316
  this.loginResult = await client.auth.loginWithKey({ email, signingPrivateKey });
6271
6317
  }
6318
+ /** A workspace's key, sealed to the caller's own session (what `/open` and `POST /workspace/users` take). */
6319
+ async sealWorkspaceKey(workspaceId) {
6320
+ const client = this.requireClient();
6321
+ const lr2 = this.requireLogin();
6322
+ const all = await listWorkspaces(client);
6323
+ const ws = all.find((w2) => w2.external_id === workspaceId);
6324
+ if (!ws || !ws.wrapped_key) {
6325
+ throw new ArbiError(`Workspace ${workspaceId} not found or has no encryption key`);
6326
+ }
6327
+ return generateEncryptedWorkspaceKey(
6328
+ client,
6329
+ ws.wrapped_key,
6330
+ lr2.serverSessionKey,
6331
+ client.crypto.bytesToBase64(lr2.signingPrivateKey)
6332
+ );
6333
+ }
6272
6334
  /**
6273
6335
  * Select a workspace by ID. Fetches the workspace list, finds the matching
6274
6336
  * workspace, decrypts the wrapped key, and sets up auth headers.
@@ -6451,6 +6513,30 @@ var Arbi = class {
6451
6513
  update: (body) => updateWorkspace(this.requireClient(), body),
6452
6514
  listUsers: () => listWorkspaceUsers(this.requireClient()),
6453
6515
  addUsers: (emails, role) => addWorkspaceUsers(this.requireClient(), emails, role),
6516
+ /**
6517
+ * Grant users a temporary key scoped to ONE session (identified by its public key), for
6518
+ * example an agent's run session minted by `agents.authorize()`. Nothing standing is created:
6519
+ * the grant expires with that session. Works for any workspace the caller holds a key for;
6520
+ * it does not need to be the open one.
6521
+ */
6522
+ grantTemporaryAccess: async (params) => {
6523
+ const client = this.requireClient();
6524
+ return grantTemporaryWorkspaceAccess(client, {
6525
+ emails: params.emails,
6526
+ workspaceExtId: params.workspaceId,
6527
+ workspaceKey: await this.sealWorkspaceKey(params.workspaceId),
6528
+ sessionPubkeyB64: params.sessionPubkeyB64,
6529
+ role: params.role
6530
+ });
6531
+ },
6532
+ /**
6533
+ * Add users (standing, permanent membership) to ANY workspace the caller holds a key for,
6534
+ * without opening it. `addUsers` does the same for the currently open workspace.
6535
+ */
6536
+ grantAccess: async (params) => addWorkspaceUsers(this.requireClient(), params.emails, params.role, {
6537
+ workspaceExtId: params.workspaceId,
6538
+ workspaceKey: await this.sealWorkspaceKey(params.workspaceId)
6539
+ }),
6454
6540
  removeUsers: (userIds) => removeWorkspaceUsers(this.requireClient(), userIds),
6455
6541
  setUserRole: (userIds, role) => setUserRole(this.requireClient(), userIds, role),
6456
6542
  /**
@@ -6508,12 +6594,7 @@ var Arbi = class {
6508
6594
  uploadFile: (fileData, fileName, options) => {
6509
6595
  this.requireWorkspace();
6510
6596
  return this.recovering(
6511
- () => uploadFile(
6512
- this.getAuthHeaders(),
6513
- fileData,
6514
- fileName,
6515
- options?.folder ? { folder: options.folder } : void 0
6516
- )
6597
+ () => uploadFile(this.getAuthHeaders(), fileData, fileName, options)
6517
6598
  );
6518
6599
  },
6519
6600
  download: (docId) => this.recovering(() => downloadDocument(this.getAuthHeaders(), docId)),
@@ -6566,6 +6647,8 @@ var Arbi = class {
6566
6647
  * Respond to an agent's question during a human-in-the-loop workflow.
6567
6648
  */
6568
6649
  respond: (assistantMessageExtId, answer) => respondToAgent(this.requireClient(), assistantMessageExtId, answer),
6650
+ /** The skills the caller can run (own + shared marketplace), metadata only. */
6651
+ listSkills: (options) => listSkills(this.requireClient(), options),
6569
6652
  /**
6570
6653
  * Search documents without LLM generation (retrieval only).
6571
6654
  */
@@ -6722,7 +6805,28 @@ var Arbi = class {
6722
6805
  create: (name) => createAgent(this.requireClient(), name),
6723
6806
  getConfig: (agentExtId) => getAgentConfig(this.requireClient(), agentExtId),
6724
6807
  listWorkspaces: (agentExtId) => listAgentWorkspaces(this.requireClient(), agentExtId),
6725
- delete: (agentExtIds) => deleteAgents(this.requireClient(), agentExtIds)
6808
+ delete: (agentExtIds) => deleteAgents(this.requireClient(), agentExtIds),
6809
+ /** Mint a TTL'd run session for an agent; see `grantTemporaryAccess` to also deposit a key. */
6810
+ authorize: (agentExtId, workspaceId, ttlSeconds) => authorizeAgent(this.requireClient(), agentExtId, workspaceId, ttlSeconds),
6811
+ authorizeLimits: () => getAuthorizeLimits(this.requireClient()),
6812
+ /**
6813
+ * Give an agent temporary, session-scoped access to a workspace: mint its run session, then
6814
+ * deposit the workspace key on it. Returns the session details (`ttl` in seconds).
6815
+ */
6816
+ grantTemporaryAccess: async (agentExtId, workspaceId, ttlSeconds) => {
6817
+ const session = await authorizeAgent(
6818
+ this.requireClient(),
6819
+ agentExtId,
6820
+ workspaceId,
6821
+ ttlSeconds
6822
+ );
6823
+ await this.workspaces.grantTemporaryAccess({
6824
+ workspaceId,
6825
+ emails: [session.agent_email],
6826
+ sessionPubkeyB64: session.session_pubkey_b64
6827
+ });
6828
+ return session;
6829
+ }
6726
6830
  };
6727
6831
  // ── Scheduled tasks ───────────────────────────────────────────────────
6728
6832
  tasks = {
@@ -6731,7 +6835,26 @@ var Arbi = class {
6731
6835
  get: (taskId) => getTask(this.requireClient(), taskId),
6732
6836
  update: (taskId, body) => updateTask(this.requireClient(), taskId, body),
6733
6837
  delete: (taskId) => deleteTask(this.requireClient(), taskId),
6734
- run: (taskId) => runTask(this.requireClient(), taskId)
6838
+ run: (taskId) => runTask(this.requireClient(), taskId),
6839
+ listRuns: (taskId) => listTaskRuns(this.requireClient(), taskId),
6840
+ /**
6841
+ * Run a task and, when the run is parked waiting for workspace access (a temporary
6842
+ * authorization tier), grant the agent's run session a temporary key and run it again.
6843
+ * A task that needs no approval returns from the first call already running.
6844
+ */
6845
+ runWithAuth: async (taskId) => {
6846
+ const client = this.requireClient();
6847
+ const first = await runTask(client, taskId);
6848
+ if (!first.pending_auth_request_id || !first.pending_auth_session_pubkey || !first.pending_auth_agent_email || !first.workspace_ext_id) {
6849
+ return first;
6850
+ }
6851
+ await this.workspaces.grantTemporaryAccess({
6852
+ workspaceId: first.workspace_ext_id,
6853
+ emails: [first.pending_auth_agent_email],
6854
+ sessionPubkeyB64: first.pending_auth_session_pubkey
6855
+ });
6856
+ return runTask(client, taskId);
6857
+ }
6735
6858
  };
6736
6859
  // ── Workspace facts ─────────────────────────────────────────────────
6737
6860
  facts = {