@arbidocs/sdk 0.3.116 → 0.3.117

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.
@@ -1,2 +1,2 @@
1
- export { A as AgentStepDeltaEvent, a as AgentStepEvent, b as Arbi, c as ArbiApiError, d as ArbiError, e as ArbiErrorEvent, f as ArbiOptions, g as ArtifactEvent, h as AuthContext, i as AuthHeaders, j as AuthenticatedClient, C as ChatSession, k as CitationSummary, l as CliConfig, m as CliCredentials, n as CommandDescriptor, o as ConfigStore, p as ConnectOptions, q as CreateMemoryRequest, r as CreateTaskRequest, M as MemoryResponse, z as MemorySearchRequest, B as MemorySearchResponse, G as MessageMetadataPayload, H as MessageQueuedEvent, O as OutputTokensDetails, P as ParsedSlashCommand, I as ProjectInvoicesResponse, J as ProjectUsageResponse, Q as QueryOptions, R as ReconnectOptions, K as ReconnectableWsConnection, N as ResolvedCitation, S as ResponseCompletedEvent, T as ResponseContentPartAddedEvent, U as ResponseCreatedEvent, V as ResponseFailedEvent, W as ResponseOutputItemAddedEvent, X as ResponseOutputItemDoneEvent, Y as ResponseOutputTextDeltaEvent, Z as ResponseOutputTextDoneEvent, _ as ResponseUsage, $ as SSEEvent, a0 as SSEStreamCallbacks, a1 as SSEStreamResult, a2 as SSEStreamStartData, a4 as SkillSummary, a6 as TaskResponse, a7 as UpdateMemoryRequest, a8 as UpdateTaskRequest, ae as UserDailyUsageResponse, af as UserInfo, ag as UserInputRequestEvent, ah as UserMessageEvent, ai as WebSocketAuthError, aj as WorkspaceChronologyOut, ak as WorkspaceContext, al as WsConnection, am as agentconfig, an as assistant, ao as authenticatedFetch, ap as buildRetrievalChunkTool, aq as buildRetrievalFullContextTool, ar as buildRetrievalTocTool, as as connectWebSocket, at as connectWithReconnect, au as consumeSSEStream, av as contacts, aw as conversations, ax as countCitations, ay as createAuthenticatedClient, aA as dm, aB as doctags, aC as documents, aD as files, aE as filterSkills, aF as formatAgentStepLabel, aG as formatFileSize, aI as formatUserName, aJ as formatWorkspaceChoices, aO as getErrorMessage, aP as getRawWorkspaceKey, aQ as health, aR as memory, aS as parseSSEEvents, aT as parseSlashCommand, aU as parseSlashTokenInProgress, aV as performPasswordLogin, aY as projects, aZ as requireData, a_ as requireOk, a$ as resolveAuth, b0 as resolveCitations, b1 as resolveWorkspace, b2 as responses, b3 as selectWorkspace, b4 as selectWorkspaceById, b5 as settings, b6 as streamSSE, b7 as stripCitationMarkdown, b8 as summarizeCitations, b9 as tags, ba as tasks, bb as workspaces } from './browser-BS_k043E.cjs';
1
+ export { A as AgentStepDeltaEvent, a as AgentStepEvent, b as Arbi, c as ArbiApiError, d as ArbiError, e as ArbiErrorEvent, f as ArbiOptions, g as ArtifactEvent, h as AuthContext, i as AuthHeaders, j as AuthenticatedClient, C as ChatSession, k as CitationSummary, l as CliConfig, m as CliCredentials, n as CommandDescriptor, o as ConfigStore, p as ConnectOptions, q as CreateMemoryRequest, r as CreateTaskRequest, M as MemoryResponse, z as MemorySearchRequest, B as MemorySearchResponse, G as MessageMetadataPayload, H as MessageQueuedEvent, O as OutputTokensDetails, P as ParsedSlashCommand, I as ProjectInvoicesResponse, J as ProjectUsageResponse, Q as QueryOptions, R as ReconnectOptions, K as ReconnectableWsConnection, N as ResolvedCitation, T as ResponseCompletedEvent, U as ResponseContentPartAddedEvent, V as ResponseCreatedEvent, W as ResponseFailedEvent, X as ResponseOutputItemAddedEvent, Y as ResponseOutputItemDoneEvent, Z as ResponseOutputTextDeltaEvent, _ as ResponseOutputTextDoneEvent, $ as ResponseUsage, a0 as SSEEvent, a1 as SSEStreamCallbacks, a2 as SSEStreamResult, a3 as SSEStreamStartData, a5 as SkillSummary, a7 as TaskResponse, a8 as UpdateMemoryRequest, a9 as UpdateTaskRequest, af as UserDailyUsageResponse, ag as UserInfo, ah as UserInputRequestEvent, ai as UserMessageEvent, aj as WebSocketAuthError, ak as WorkspaceChronologyOut, al as WorkspaceContext, am as WsConnection, an as agentconfig, ao as assistant, ap as authenticatedFetch, aq as buildRetrievalChunkTool, ar as buildRetrievalFullContextTool, as as buildRetrievalTocTool, at as connectWebSocket, au as connectWithReconnect, av as consumeSSEStream, aw as contacts, ax as conversations, ay as countCitations, az as createAuthenticatedClient, aB as dm, aC as doctags, aD as documents, aE as files, aF as filterSkills, aG as formatAgentStepLabel, aH as formatFileSize, aJ as formatUserName, aK as formatWorkspaceChoices, aP as getErrorMessage, aQ as getRawWorkspaceKey, aR as health, aS as memory, aT as parseSSEEvents, aU as parseSlashCommand, aV as parseSlashTokenInProgress, aW as performPasswordLogin, aZ as projects, a_ as requireData, a$ as requireOk, b0 as resolveAuth, b1 as resolveCitations, b2 as resolveWorkspace, b3 as responses, b4 as selectWorkspace, b5 as selectWorkspaceById, b6 as settings, b7 as streamSSE, b8 as stripCitationMarkdown, b9 as summarizeCitations, ba as tags, bb as tasks, bc as workspaces } from './browser-CxTSIAhf.cjs';
2
2
  import '@arbidocs/client';
package/dist/browser.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as AgentStepDeltaEvent, a as AgentStepEvent, b as Arbi, c as ArbiApiError, d as ArbiError, e as ArbiErrorEvent, f as ArbiOptions, g as ArtifactEvent, h as AuthContext, i as AuthHeaders, j as AuthenticatedClient, C as ChatSession, k as CitationSummary, l as CliConfig, m as CliCredentials, n as CommandDescriptor, o as ConfigStore, p as ConnectOptions, q as CreateMemoryRequest, r as CreateTaskRequest, M as MemoryResponse, z as MemorySearchRequest, B as MemorySearchResponse, G as MessageMetadataPayload, H as MessageQueuedEvent, O as OutputTokensDetails, P as ParsedSlashCommand, I as ProjectInvoicesResponse, J as ProjectUsageResponse, Q as QueryOptions, R as ReconnectOptions, K as ReconnectableWsConnection, N as ResolvedCitation, S as ResponseCompletedEvent, T as ResponseContentPartAddedEvent, U as ResponseCreatedEvent, V as ResponseFailedEvent, W as ResponseOutputItemAddedEvent, X as ResponseOutputItemDoneEvent, Y as ResponseOutputTextDeltaEvent, Z as ResponseOutputTextDoneEvent, _ as ResponseUsage, $ as SSEEvent, a0 as SSEStreamCallbacks, a1 as SSEStreamResult, a2 as SSEStreamStartData, a4 as SkillSummary, a6 as TaskResponse, a7 as UpdateMemoryRequest, a8 as UpdateTaskRequest, ae as UserDailyUsageResponse, af as UserInfo, ag as UserInputRequestEvent, ah as UserMessageEvent, ai as WebSocketAuthError, aj as WorkspaceChronologyOut, ak as WorkspaceContext, al as WsConnection, am as agentconfig, an as assistant, ao as authenticatedFetch, ap as buildRetrievalChunkTool, aq as buildRetrievalFullContextTool, ar as buildRetrievalTocTool, as as connectWebSocket, at as connectWithReconnect, au as consumeSSEStream, av as contacts, aw as conversations, ax as countCitations, ay as createAuthenticatedClient, aA as dm, aB as doctags, aC as documents, aD as files, aE as filterSkills, aF as formatAgentStepLabel, aG as formatFileSize, aI as formatUserName, aJ as formatWorkspaceChoices, aO as getErrorMessage, aP as getRawWorkspaceKey, aQ as health, aR as memory, aS as parseSSEEvents, aT as parseSlashCommand, aU as parseSlashTokenInProgress, aV as performPasswordLogin, aY as projects, aZ as requireData, a_ as requireOk, a$ as resolveAuth, b0 as resolveCitations, b1 as resolveWorkspace, b2 as responses, b3 as selectWorkspace, b4 as selectWorkspaceById, b5 as settings, b6 as streamSSE, b7 as stripCitationMarkdown, b8 as summarizeCitations, b9 as tags, ba as tasks, bb as workspaces } from './browser-BS_k043E.js';
1
+ export { A as AgentStepDeltaEvent, a as AgentStepEvent, b as Arbi, c as ArbiApiError, d as ArbiError, e as ArbiErrorEvent, f as ArbiOptions, g as ArtifactEvent, h as AuthContext, i as AuthHeaders, j as AuthenticatedClient, C as ChatSession, k as CitationSummary, l as CliConfig, m as CliCredentials, n as CommandDescriptor, o as ConfigStore, p as ConnectOptions, q as CreateMemoryRequest, r as CreateTaskRequest, M as MemoryResponse, z as MemorySearchRequest, B as MemorySearchResponse, G as MessageMetadataPayload, H as MessageQueuedEvent, O as OutputTokensDetails, P as ParsedSlashCommand, I as ProjectInvoicesResponse, J as ProjectUsageResponse, Q as QueryOptions, R as ReconnectOptions, K as ReconnectableWsConnection, N as ResolvedCitation, T as ResponseCompletedEvent, U as ResponseContentPartAddedEvent, V as ResponseCreatedEvent, W as ResponseFailedEvent, X as ResponseOutputItemAddedEvent, Y as ResponseOutputItemDoneEvent, Z as ResponseOutputTextDeltaEvent, _ as ResponseOutputTextDoneEvent, $ as ResponseUsage, a0 as SSEEvent, a1 as SSEStreamCallbacks, a2 as SSEStreamResult, a3 as SSEStreamStartData, a5 as SkillSummary, a7 as TaskResponse, a8 as UpdateMemoryRequest, a9 as UpdateTaskRequest, af as UserDailyUsageResponse, ag as UserInfo, ah as UserInputRequestEvent, ai as UserMessageEvent, aj as WebSocketAuthError, ak as WorkspaceChronologyOut, al as WorkspaceContext, am as WsConnection, an as agentconfig, ao as assistant, ap as authenticatedFetch, aq as buildRetrievalChunkTool, ar as buildRetrievalFullContextTool, as as buildRetrievalTocTool, at as connectWebSocket, au as connectWithReconnect, av as consumeSSEStream, aw as contacts, ax as conversations, ay as countCitations, az as createAuthenticatedClient, aB as dm, aC as doctags, aD as documents, aE as files, aF as filterSkills, aG as formatAgentStepLabel, aH as formatFileSize, aJ as formatUserName, aK as formatWorkspaceChoices, aP as getErrorMessage, aQ as getRawWorkspaceKey, aR as health, aS as memory, aT as parseSSEEvents, aU as parseSlashCommand, aV as parseSlashTokenInProgress, aW as performPasswordLogin, aZ as projects, a_ as requireData, a$ as requireOk, b0 as resolveAuth, b1 as resolveCitations, b2 as resolveWorkspace, b3 as responses, b4 as selectWorkspace, b5 as selectWorkspaceById, b6 as settings, b7 as streamSSE, b8 as stripCitationMarkdown, b9 as summarizeCitations, ba as tags, bb as tasks, bc as workspaces } from './browser-CxTSIAhf.js';
2
2
  import '@arbidocs/client';
package/dist/browser.js CHANGED
@@ -5081,9 +5081,45 @@ __export(dm_exports, {
5081
5081
  listDecryptedDMs: () => listDecryptedDMs,
5082
5082
  markRead: () => markRead,
5083
5083
  requestWorkspaceAccess: () => requestWorkspaceAccess,
5084
+ resolveRecipient: () => resolveRecipient,
5084
5085
  sendDM: () => sendDM,
5085
5086
  sendEncryptedDM: () => sendEncryptedDM
5086
5087
  });
5088
+
5089
+ // src/operations/agents.ts
5090
+ async function listAgents(arbi) {
5091
+ return requireData(await arbi.fetch.GET("/v1/agents"), "Failed to fetch agents");
5092
+ }
5093
+ async function createAgent(arbi, name) {
5094
+ const body = { name };
5095
+ return requireData(await arbi.fetch.POST("/v1/agents", { body }), "Failed to create agent");
5096
+ }
5097
+ async function getAgentConfig(arbi, agentExtId) {
5098
+ return requireData(
5099
+ await arbi.fetch.GET("/v1/agents/{agent_ext_id}/config", {
5100
+ params: { path: { agent_ext_id: agentExtId } }
5101
+ }),
5102
+ "Failed to fetch agent config"
5103
+ );
5104
+ }
5105
+ async function listAgentWorkspaces(arbi, agentExtId) {
5106
+ return requireData(
5107
+ await arbi.fetch.GET("/v1/agents/{agent_ext_id}/workspaces", {
5108
+ params: { path: { agent_ext_id: agentExtId } }
5109
+ }),
5110
+ "Failed to fetch agent workspaces"
5111
+ );
5112
+ }
5113
+ async function deleteAgents(arbi, agentExtIds) {
5114
+ return requireData(
5115
+ await arbi.fetch.DELETE("/v1/agents", {
5116
+ body: { agent_ext_ids: agentExtIds }
5117
+ }),
5118
+ "Failed to delete agents"
5119
+ );
5120
+ }
5121
+
5122
+ // src/operations/dm.ts
5087
5123
  function createDmCryptoContext(arbi, signingPrivateKeyBytes, userExtId) {
5088
5124
  const ed25519PublicKey = signingPrivateKeyBytes.slice(32, 64);
5089
5125
  const encryptionKeypair = arbi.crypto.deriveEncryptionKeypairFromSigning({
@@ -5146,6 +5182,37 @@ async function listActivity(arbi, options) {
5146
5182
  "Failed to fetch activity"
5147
5183
  );
5148
5184
  }
5185
+ async function resolveRecipient(arbi, ref) {
5186
+ const isEmail = ref.includes("@");
5187
+ const matchKey = isEmail ? "email" : "external_id";
5188
+ const contacts = await listContacts(arbi);
5189
+ const contactMatch = contacts.find(
5190
+ (c2) => isEmail ? c2.email === ref : c2.user?.external_id === ref || c2.external_id === ref
5191
+ );
5192
+ if (contactMatch?.user?.encryption_public_key) {
5193
+ return {
5194
+ extId: contactMatch.user.external_id,
5195
+ pubKey: contactMatch.user.encryption_public_key
5196
+ };
5197
+ }
5198
+ try {
5199
+ const agents = await listAgents(arbi);
5200
+ const agentMatch = agents.find((a2) => a2[matchKey] === ref);
5201
+ if (agentMatch?.encryption_public_key) {
5202
+ return { extId: agentMatch.external_id, pubKey: agentMatch.encryption_public_key };
5203
+ }
5204
+ } catch {
5205
+ }
5206
+ try {
5207
+ const wsUsers = await listWorkspaceUsers(arbi);
5208
+ const wsMatch = wsUsers.find((wu) => wu.user[matchKey] === ref);
5209
+ if (wsMatch?.user.encryption_public_key) {
5210
+ return { extId: wsMatch.user.external_id, pubKey: wsMatch.user.encryption_public_key };
5211
+ }
5212
+ } catch {
5213
+ }
5214
+ return null;
5215
+ }
5149
5216
  async function sendEncryptedDM(arbi, messages, crypto) {
5150
5217
  const encrypted = await Promise.all(
5151
5218
  messages.map(async (msg) => ({
@@ -5342,39 +5409,6 @@ async function getFileContent(auth, fileId) {
5342
5409
  });
5343
5410
  }
5344
5411
 
5345
- // src/operations/agents.ts
5346
- async function listAgents(arbi) {
5347
- return requireData(await arbi.fetch.GET("/v1/agents"), "Failed to fetch agents");
5348
- }
5349
- async function createAgent(arbi, name) {
5350
- const body = { name };
5351
- return requireData(await arbi.fetch.POST("/v1/agents", { body }), "Failed to create agent");
5352
- }
5353
- async function getAgentConfig(arbi, agentExtId) {
5354
- return requireData(
5355
- await arbi.fetch.GET("/v1/agents/{agent_ext_id}/config", {
5356
- params: { path: { agent_ext_id: agentExtId } }
5357
- }),
5358
- "Failed to fetch agent config"
5359
- );
5360
- }
5361
- async function listAgentWorkspaces(arbi, agentExtId) {
5362
- return requireData(
5363
- await arbi.fetch.GET("/v1/agents/{agent_ext_id}/workspaces", {
5364
- params: { path: { agent_ext_id: agentExtId } }
5365
- }),
5366
- "Failed to fetch agent workspaces"
5367
- );
5368
- }
5369
- async function deleteAgents(arbi, agentExtIds) {
5370
- return requireData(
5371
- await arbi.fetch.DELETE("/v1/agents", {
5372
- body: { agent_ext_ids: agentExtIds }
5373
- }),
5374
- "Failed to delete agents"
5375
- );
5376
- }
5377
-
5378
5412
  // src/operations/sessions.ts
5379
5413
  async function listSessions(arbi) {
5380
5414
  return requireData(await arbi.fetch.GET("/v1/user/sessions"), "Failed to fetch sessions");
@@ -5523,6 +5557,7 @@ var Arbi = class {
5523
5557
  client = null;
5524
5558
  loginResult = null;
5525
5559
  currentWorkspaceId = null;
5560
+ dmCryptoContext = null;
5526
5561
  options;
5527
5562
  constructor(options) {
5528
5563
  this.options = options;
@@ -5609,6 +5644,7 @@ var Arbi = class {
5609
5644
  }
5610
5645
  this.loginResult = null;
5611
5646
  this.currentWorkspaceId = null;
5647
+ this.dmCryptoContext = null;
5612
5648
  }
5613
5649
  // ── Accessors ─────────────────────────────────────────────────────────
5614
5650
  /** Get the underlying ArbiClient (throws if not initialized). */
@@ -5664,6 +5700,16 @@ var Arbi = class {
5664
5700
  };
5665
5701
  // ── User (account-scoped usage) ───────────────────────────────────────
5666
5702
  user = {
5703
+ /**
5704
+ * The authenticated user's identity from the current session
5705
+ * (`external_id` + `email`), established at login. Returns `null` when not
5706
+ * logged in. This is the canonical "who am I" accessor — DM direction and
5707
+ * ownership checks read it instead of re-deriving identity per call.
5708
+ */
5709
+ identity: () => {
5710
+ const state = this.requireClient().session.getState();
5711
+ return state.userExtId && state.userEmail ? { externalId: state.userExtId, email: state.userEmail } : null;
5712
+ },
5667
5713
  /** Today's deployment-wide credit spend for the current user. */
5668
5714
  usageToday: () => getUserUsageToday(this.requireClient())
5669
5715
  };
@@ -5847,9 +5893,76 @@ var Arbi = class {
5847
5893
  groupByStatus: groupContactsByStatus
5848
5894
  };
5849
5895
  // ── Direct Messages ───────────────────────────────────────────────────
5896
+ /**
5897
+ * Build (and cache) the DM crypto context for the current session.
5898
+ *
5899
+ * Derives the user's curve25519 keypair from the stored signing key and pairs
5900
+ * it with their external_id — everything `list()`/`send()` need to encrypt and
5901
+ * decrypt. Cached for the session and cleared on logout. Consumers never touch
5902
+ * this: it's an internal of the `dm` surface.
5903
+ */
5904
+ async requireDmCrypto() {
5905
+ if (this.dmCryptoContext) return this.dmCryptoContext;
5906
+ const client = this.requireClient();
5907
+ const session = await client.storage.getSession();
5908
+ if (!session) {
5909
+ throw new ArbiError("Not authenticated \u2014 no session available for DM encryption");
5910
+ }
5911
+ const userExtId = client.session.getState().userExtId;
5912
+ if (!userExtId) {
5913
+ throw new ArbiError("No user identity in session \u2014 cannot set up DM encryption");
5914
+ }
5915
+ this.dmCryptoContext = createDmCryptoContext(client, session.signingPrivateKey, userExtId);
5916
+ return this.dmCryptoContext;
5917
+ }
5850
5918
  dm = {
5851
- list: () => listDMs(this.requireClient()),
5852
- send: (messages) => sendDM(this.requireClient(), messages),
5919
+ /**
5920
+ * List direct messages, newest first, with content already **decrypted**.
5921
+ * (A message that can't be decrypted comes back as `[Decryption failed]`.)
5922
+ */
5923
+ list: async () => listDecryptedDMs(this.requireClient(), await this.requireDmCrypto()),
5924
+ /**
5925
+ * Send an E2E-encrypted DM to a recipient (email or `usr-`/`agt-` id).
5926
+ * Resolves the recipient's public key and encrypts internally — the caller
5927
+ * passes plaintext and never handles keys or ciphertext.
5928
+ */
5929
+ send: async (recipient, text) => {
5930
+ const client = this.requireClient();
5931
+ const resolved = await resolveRecipient(client, recipient);
5932
+ if (!resolved) {
5933
+ throw new ArbiError(
5934
+ `Could not resolve DM recipient "${recipient}" (not a known contact, agent, or workspace member)`
5935
+ );
5936
+ }
5937
+ return sendEncryptedDM(
5938
+ client,
5939
+ [
5940
+ {
5941
+ recipient_ext_id: resolved.extId,
5942
+ content: text,
5943
+ recipient_encryption_public_key: resolved.pubKey
5944
+ }
5945
+ ],
5946
+ await this.requireDmCrypto()
5947
+ );
5948
+ },
5949
+ /**
5950
+ * Send to a recipient whose external_id + public key are already known
5951
+ * (e.g. from a message's `sender`), skipping directory resolution.
5952
+ */
5953
+ sendTo: async (recipientExtId, recipientPublicKey, text) => sendEncryptedDM(
5954
+ this.requireClient(),
5955
+ [
5956
+ {
5957
+ recipient_ext_id: recipientExtId,
5958
+ content: text,
5959
+ recipient_encryption_public_key: recipientPublicKey
5960
+ }
5961
+ ],
5962
+ await this.requireDmCrypto()
5963
+ ),
5964
+ /** Resolve a recipient reference to `{ extId, pubKey }` (contacts → agents → workspace). */
5965
+ resolveRecipient: (recipient) => resolveRecipient(this.requireClient(), recipient),
5853
5966
  markRead: (messageIds) => markRead(this.requireClient(), messageIds),
5854
5967
  delete: (messageIds) => deleteDMs(this.requireClient(), messageIds),
5855
5968
  /** List the current user's durable activity feed (never unread; excluded from DMs). */