@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.
- package/dist/{browser-BS_k043E.d.cts → browser-CxTSIAhf.d.cts} +3286 -3225
- package/dist/{browser-BS_k043E.d.ts → browser-CxTSIAhf.d.ts} +3286 -3225
- package/dist/browser.cjs +148 -35
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +148 -35
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +156 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +156 -43
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -5629,9 +5629,53 @@ __export(dm_exports, {
|
|
|
5629
5629
|
listDecryptedDMs: () => listDecryptedDMs,
|
|
5630
5630
|
markRead: () => markRead,
|
|
5631
5631
|
requestWorkspaceAccess: () => requestWorkspaceAccess,
|
|
5632
|
+
resolveRecipient: () => resolveRecipient,
|
|
5632
5633
|
sendDM: () => sendDM,
|
|
5633
5634
|
sendEncryptedDM: () => sendEncryptedDM
|
|
5634
5635
|
});
|
|
5636
|
+
|
|
5637
|
+
// src/operations/agents.ts
|
|
5638
|
+
var agents_exports = {};
|
|
5639
|
+
__export(agents_exports, {
|
|
5640
|
+
createAgent: () => createAgent,
|
|
5641
|
+
deleteAgents: () => deleteAgents,
|
|
5642
|
+
getAgentConfig: () => getAgentConfig,
|
|
5643
|
+
listAgentWorkspaces: () => listAgentWorkspaces,
|
|
5644
|
+
listAgents: () => listAgents
|
|
5645
|
+
});
|
|
5646
|
+
async function listAgents(arbi) {
|
|
5647
|
+
return requireData(await arbi.fetch.GET("/v1/agents"), "Failed to fetch agents");
|
|
5648
|
+
}
|
|
5649
|
+
async function createAgent(arbi, name) {
|
|
5650
|
+
const body = { name };
|
|
5651
|
+
return requireData(await arbi.fetch.POST("/v1/agents", { body }), "Failed to create agent");
|
|
5652
|
+
}
|
|
5653
|
+
async function getAgentConfig(arbi, agentExtId) {
|
|
5654
|
+
return requireData(
|
|
5655
|
+
await arbi.fetch.GET("/v1/agents/{agent_ext_id}/config", {
|
|
5656
|
+
params: { path: { agent_ext_id: agentExtId } }
|
|
5657
|
+
}),
|
|
5658
|
+
"Failed to fetch agent config"
|
|
5659
|
+
);
|
|
5660
|
+
}
|
|
5661
|
+
async function listAgentWorkspaces(arbi, agentExtId) {
|
|
5662
|
+
return requireData(
|
|
5663
|
+
await arbi.fetch.GET("/v1/agents/{agent_ext_id}/workspaces", {
|
|
5664
|
+
params: { path: { agent_ext_id: agentExtId } }
|
|
5665
|
+
}),
|
|
5666
|
+
"Failed to fetch agent workspaces"
|
|
5667
|
+
);
|
|
5668
|
+
}
|
|
5669
|
+
async function deleteAgents(arbi, agentExtIds) {
|
|
5670
|
+
return requireData(
|
|
5671
|
+
await arbi.fetch.DELETE("/v1/agents", {
|
|
5672
|
+
body: { agent_ext_ids: agentExtIds }
|
|
5673
|
+
}),
|
|
5674
|
+
"Failed to delete agents"
|
|
5675
|
+
);
|
|
5676
|
+
}
|
|
5677
|
+
|
|
5678
|
+
// src/operations/dm.ts
|
|
5635
5679
|
function createDmCryptoContext(arbi, signingPrivateKeyBytes, userExtId) {
|
|
5636
5680
|
const ed25519PublicKey = signingPrivateKeyBytes.slice(32, 64);
|
|
5637
5681
|
const encryptionKeypair = arbi.crypto.deriveEncryptionKeypairFromSigning({
|
|
@@ -5694,6 +5738,37 @@ async function listActivity(arbi, options) {
|
|
|
5694
5738
|
"Failed to fetch activity"
|
|
5695
5739
|
);
|
|
5696
5740
|
}
|
|
5741
|
+
async function resolveRecipient(arbi, ref) {
|
|
5742
|
+
const isEmail = ref.includes("@");
|
|
5743
|
+
const matchKey = isEmail ? "email" : "external_id";
|
|
5744
|
+
const contacts = await listContacts(arbi);
|
|
5745
|
+
const contactMatch = contacts.find(
|
|
5746
|
+
(c2) => isEmail ? c2.email === ref : c2.user?.external_id === ref || c2.external_id === ref
|
|
5747
|
+
);
|
|
5748
|
+
if (contactMatch?.user?.encryption_public_key) {
|
|
5749
|
+
return {
|
|
5750
|
+
extId: contactMatch.user.external_id,
|
|
5751
|
+
pubKey: contactMatch.user.encryption_public_key
|
|
5752
|
+
};
|
|
5753
|
+
}
|
|
5754
|
+
try {
|
|
5755
|
+
const agents = await listAgents(arbi);
|
|
5756
|
+
const agentMatch = agents.find((a2) => a2[matchKey] === ref);
|
|
5757
|
+
if (agentMatch?.encryption_public_key) {
|
|
5758
|
+
return { extId: agentMatch.external_id, pubKey: agentMatch.encryption_public_key };
|
|
5759
|
+
}
|
|
5760
|
+
} catch {
|
|
5761
|
+
}
|
|
5762
|
+
try {
|
|
5763
|
+
const wsUsers = await listWorkspaceUsers(arbi);
|
|
5764
|
+
const wsMatch = wsUsers.find((wu) => wu.user[matchKey] === ref);
|
|
5765
|
+
if (wsMatch?.user.encryption_public_key) {
|
|
5766
|
+
return { extId: wsMatch.user.external_id, pubKey: wsMatch.user.encryption_public_key };
|
|
5767
|
+
}
|
|
5768
|
+
} catch {
|
|
5769
|
+
}
|
|
5770
|
+
return null;
|
|
5771
|
+
}
|
|
5697
5772
|
async function sendEncryptedDM(arbi, messages, crypto) {
|
|
5698
5773
|
const encrypted = await Promise.all(
|
|
5699
5774
|
messages.map(async (msg) => ({
|
|
@@ -5890,47 +5965,6 @@ async function getFileContent(auth, fileId) {
|
|
|
5890
5965
|
});
|
|
5891
5966
|
}
|
|
5892
5967
|
|
|
5893
|
-
// src/operations/agents.ts
|
|
5894
|
-
var agents_exports = {};
|
|
5895
|
-
__export(agents_exports, {
|
|
5896
|
-
createAgent: () => createAgent,
|
|
5897
|
-
deleteAgents: () => deleteAgents,
|
|
5898
|
-
getAgentConfig: () => getAgentConfig,
|
|
5899
|
-
listAgentWorkspaces: () => listAgentWorkspaces,
|
|
5900
|
-
listAgents: () => listAgents
|
|
5901
|
-
});
|
|
5902
|
-
async function listAgents(arbi) {
|
|
5903
|
-
return requireData(await arbi.fetch.GET("/v1/agents"), "Failed to fetch agents");
|
|
5904
|
-
}
|
|
5905
|
-
async function createAgent(arbi, name) {
|
|
5906
|
-
const body = { name };
|
|
5907
|
-
return requireData(await arbi.fetch.POST("/v1/agents", { body }), "Failed to create agent");
|
|
5908
|
-
}
|
|
5909
|
-
async function getAgentConfig(arbi, agentExtId) {
|
|
5910
|
-
return requireData(
|
|
5911
|
-
await arbi.fetch.GET("/v1/agents/{agent_ext_id}/config", {
|
|
5912
|
-
params: { path: { agent_ext_id: agentExtId } }
|
|
5913
|
-
}),
|
|
5914
|
-
"Failed to fetch agent config"
|
|
5915
|
-
);
|
|
5916
|
-
}
|
|
5917
|
-
async function listAgentWorkspaces(arbi, agentExtId) {
|
|
5918
|
-
return requireData(
|
|
5919
|
-
await arbi.fetch.GET("/v1/agents/{agent_ext_id}/workspaces", {
|
|
5920
|
-
params: { path: { agent_ext_id: agentExtId } }
|
|
5921
|
-
}),
|
|
5922
|
-
"Failed to fetch agent workspaces"
|
|
5923
|
-
);
|
|
5924
|
-
}
|
|
5925
|
-
async function deleteAgents(arbi, agentExtIds) {
|
|
5926
|
-
return requireData(
|
|
5927
|
-
await arbi.fetch.DELETE("/v1/agents", {
|
|
5928
|
-
body: { agent_ext_ids: agentExtIds }
|
|
5929
|
-
}),
|
|
5930
|
-
"Failed to delete agents"
|
|
5931
|
-
);
|
|
5932
|
-
}
|
|
5933
|
-
|
|
5934
5968
|
// src/operations/sessions.ts
|
|
5935
5969
|
var sessions_exports = {};
|
|
5936
5970
|
__export(sessions_exports, {
|
|
@@ -6066,6 +6100,7 @@ var Arbi = class {
|
|
|
6066
6100
|
client = null;
|
|
6067
6101
|
loginResult = null;
|
|
6068
6102
|
currentWorkspaceId = null;
|
|
6103
|
+
dmCryptoContext = null;
|
|
6069
6104
|
options;
|
|
6070
6105
|
constructor(options) {
|
|
6071
6106
|
this.options = options;
|
|
@@ -6152,6 +6187,7 @@ var Arbi = class {
|
|
|
6152
6187
|
}
|
|
6153
6188
|
this.loginResult = null;
|
|
6154
6189
|
this.currentWorkspaceId = null;
|
|
6190
|
+
this.dmCryptoContext = null;
|
|
6155
6191
|
}
|
|
6156
6192
|
// ── Accessors ─────────────────────────────────────────────────────────
|
|
6157
6193
|
/** Get the underlying ArbiClient (throws if not initialized). */
|
|
@@ -6207,6 +6243,16 @@ var Arbi = class {
|
|
|
6207
6243
|
};
|
|
6208
6244
|
// ── User (account-scoped usage) ───────────────────────────────────────
|
|
6209
6245
|
user = {
|
|
6246
|
+
/**
|
|
6247
|
+
* The authenticated user's identity from the current session
|
|
6248
|
+
* (`external_id` + `email`), established at login. Returns `null` when not
|
|
6249
|
+
* logged in. This is the canonical "who am I" accessor — DM direction and
|
|
6250
|
+
* ownership checks read it instead of re-deriving identity per call.
|
|
6251
|
+
*/
|
|
6252
|
+
identity: () => {
|
|
6253
|
+
const state = this.requireClient().session.getState();
|
|
6254
|
+
return state.userExtId && state.userEmail ? { externalId: state.userExtId, email: state.userEmail } : null;
|
|
6255
|
+
},
|
|
6210
6256
|
/** Today's deployment-wide credit spend for the current user. */
|
|
6211
6257
|
usageToday: () => getUserUsageToday(this.requireClient())
|
|
6212
6258
|
};
|
|
@@ -6390,9 +6436,76 @@ var Arbi = class {
|
|
|
6390
6436
|
groupByStatus: groupContactsByStatus
|
|
6391
6437
|
};
|
|
6392
6438
|
// ── Direct Messages ───────────────────────────────────────────────────
|
|
6439
|
+
/**
|
|
6440
|
+
* Build (and cache) the DM crypto context for the current session.
|
|
6441
|
+
*
|
|
6442
|
+
* Derives the user's curve25519 keypair from the stored signing key and pairs
|
|
6443
|
+
* it with their external_id — everything `list()`/`send()` need to encrypt and
|
|
6444
|
+
* decrypt. Cached for the session and cleared on logout. Consumers never touch
|
|
6445
|
+
* this: it's an internal of the `dm` surface.
|
|
6446
|
+
*/
|
|
6447
|
+
async requireDmCrypto() {
|
|
6448
|
+
if (this.dmCryptoContext) return this.dmCryptoContext;
|
|
6449
|
+
const client = this.requireClient();
|
|
6450
|
+
const session = await client.storage.getSession();
|
|
6451
|
+
if (!session) {
|
|
6452
|
+
throw new ArbiError("Not authenticated \u2014 no session available for DM encryption");
|
|
6453
|
+
}
|
|
6454
|
+
const userExtId = client.session.getState().userExtId;
|
|
6455
|
+
if (!userExtId) {
|
|
6456
|
+
throw new ArbiError("No user identity in session \u2014 cannot set up DM encryption");
|
|
6457
|
+
}
|
|
6458
|
+
this.dmCryptoContext = createDmCryptoContext(client, session.signingPrivateKey, userExtId);
|
|
6459
|
+
return this.dmCryptoContext;
|
|
6460
|
+
}
|
|
6393
6461
|
dm = {
|
|
6394
|
-
|
|
6395
|
-
|
|
6462
|
+
/**
|
|
6463
|
+
* List direct messages, newest first, with content already **decrypted**.
|
|
6464
|
+
* (A message that can't be decrypted comes back as `[Decryption failed]`.)
|
|
6465
|
+
*/
|
|
6466
|
+
list: async () => listDecryptedDMs(this.requireClient(), await this.requireDmCrypto()),
|
|
6467
|
+
/**
|
|
6468
|
+
* Send an E2E-encrypted DM to a recipient (email or `usr-`/`agt-` id).
|
|
6469
|
+
* Resolves the recipient's public key and encrypts internally — the caller
|
|
6470
|
+
* passes plaintext and never handles keys or ciphertext.
|
|
6471
|
+
*/
|
|
6472
|
+
send: async (recipient, text) => {
|
|
6473
|
+
const client = this.requireClient();
|
|
6474
|
+
const resolved = await resolveRecipient(client, recipient);
|
|
6475
|
+
if (!resolved) {
|
|
6476
|
+
throw new ArbiError(
|
|
6477
|
+
`Could not resolve DM recipient "${recipient}" (not a known contact, agent, or workspace member)`
|
|
6478
|
+
);
|
|
6479
|
+
}
|
|
6480
|
+
return sendEncryptedDM(
|
|
6481
|
+
client,
|
|
6482
|
+
[
|
|
6483
|
+
{
|
|
6484
|
+
recipient_ext_id: resolved.extId,
|
|
6485
|
+
content: text,
|
|
6486
|
+
recipient_encryption_public_key: resolved.pubKey
|
|
6487
|
+
}
|
|
6488
|
+
],
|
|
6489
|
+
await this.requireDmCrypto()
|
|
6490
|
+
);
|
|
6491
|
+
},
|
|
6492
|
+
/**
|
|
6493
|
+
* Send to a recipient whose external_id + public key are already known
|
|
6494
|
+
* (e.g. from a message's `sender`), skipping directory resolution.
|
|
6495
|
+
*/
|
|
6496
|
+
sendTo: async (recipientExtId, recipientPublicKey, text) => sendEncryptedDM(
|
|
6497
|
+
this.requireClient(),
|
|
6498
|
+
[
|
|
6499
|
+
{
|
|
6500
|
+
recipient_ext_id: recipientExtId,
|
|
6501
|
+
content: text,
|
|
6502
|
+
recipient_encryption_public_key: recipientPublicKey
|
|
6503
|
+
}
|
|
6504
|
+
],
|
|
6505
|
+
await this.requireDmCrypto()
|
|
6506
|
+
),
|
|
6507
|
+
/** Resolve a recipient reference to `{ extId, pubKey }` (contacts → agents → workspace). */
|
|
6508
|
+
resolveRecipient: (recipient) => resolveRecipient(this.requireClient(), recipient),
|
|
6396
6509
|
markRead: (messageIds) => markRead(this.requireClient(), messageIds),
|
|
6397
6510
|
delete: (messageIds) => deleteDMs(this.requireClient(), messageIds),
|
|
6398
6511
|
/** List the current user's durable activity feed (never unread; excluded from DMs). */
|