@arbidocs/sdk 0.4.108 → 0.4.111
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-yXZhW9gn.d.cts → browser-IUaO7L7D.d.cts} +692 -518
- package/dist/{browser-yXZhW9gn.d.ts → browser-IUaO7L7D.d.ts} +692 -518
- package/dist/browser.cjs +525 -250
- 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 +525 -251
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +587 -292
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -16
- package/dist/index.d.ts +69 -16
- package/dist/index.js +586 -293
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/browser.cjs
CHANGED
|
@@ -4361,6 +4361,7 @@ __export(documents_exports, {
|
|
|
4361
4361
|
listPaginated: () => listPaginated,
|
|
4362
4362
|
listVersions: () => listVersions,
|
|
4363
4363
|
mimeFromName: () => mimeFromName,
|
|
4364
|
+
presignedPut: () => presignedPut,
|
|
4364
4365
|
sanitizeFolderPath: () => sanitizeFolderPath,
|
|
4365
4366
|
updateDocuments: () => updateDocuments,
|
|
4366
4367
|
uploadDocumentsDirect: () => uploadDocumentsDirect,
|
|
@@ -4633,12 +4634,15 @@ function mimeFromName(name) {
|
|
|
4633
4634
|
return void 0;
|
|
4634
4635
|
}
|
|
4635
4636
|
}
|
|
4636
|
-
async function presignedPut(url, body, onProgress) {
|
|
4637
|
+
async function presignedPut(url, body, onProgress, headers) {
|
|
4637
4638
|
const XhrGlobal = globalThis.XMLHttpRequest;
|
|
4638
4639
|
if (XhrGlobal) {
|
|
4639
4640
|
await new Promise((resolve, reject) => {
|
|
4640
4641
|
const xhr = new XhrGlobal();
|
|
4641
4642
|
xhr.open("PUT", url);
|
|
4643
|
+
for (const [name, value] of Object.entries(headers ?? {})) {
|
|
4644
|
+
xhr.setRequestHeader(name, value);
|
|
4645
|
+
}
|
|
4642
4646
|
if (onProgress) {
|
|
4643
4647
|
xhr.upload.addEventListener("progress", (e) => {
|
|
4644
4648
|
if (e.lengthComputable) onProgress(e.loaded, e.total);
|
|
@@ -4658,7 +4662,7 @@ async function presignedPut(url, body, onProgress) {
|
|
|
4658
4662
|
});
|
|
4659
4663
|
return;
|
|
4660
4664
|
}
|
|
4661
|
-
const putRes = await fetch(url, { method: "PUT", body });
|
|
4665
|
+
const putRes = await fetch(url, { method: "PUT", body, ...headers ? { headers } : {} });
|
|
4662
4666
|
if (!putRes.ok) {
|
|
4663
4667
|
const snippet = await putRes.text().catch(() => "");
|
|
4664
4668
|
throw new Error(`Presigned PUT failed: ${putRes.status} ${snippet.slice(0, 200)}`);
|
|
@@ -5409,37 +5413,57 @@ function mergeKindFieldDefinitions(current, wanted, { keepOthers = false } = {})
|
|
|
5409
5413
|
// src/operations/contacts.ts
|
|
5410
5414
|
var contacts_exports = {};
|
|
5411
5415
|
__export(contacts_exports, {
|
|
5412
|
-
|
|
5416
|
+
createContact: () => createContact,
|
|
5417
|
+
deleteContact: () => deleteContact,
|
|
5413
5418
|
groupContactsByStatus: () => groupContactsByStatus,
|
|
5419
|
+
inviteContacts: () => inviteContacts,
|
|
5414
5420
|
listContacts: () => listContacts,
|
|
5415
|
-
|
|
5421
|
+
searchContacts: () => searchContacts,
|
|
5422
|
+
updateContact: () => updateContact
|
|
5416
5423
|
});
|
|
5417
5424
|
async function listContacts(arbi) {
|
|
5418
|
-
return requireData(await arbi.fetch.GET("/v1/
|
|
5425
|
+
return requireData(await arbi.fetch.GET("/v1/contacts/"), "Failed to fetch contacts");
|
|
5426
|
+
}
|
|
5427
|
+
async function inviteContacts(arbi, emails) {
|
|
5428
|
+
return requireData(
|
|
5429
|
+
await arbi.fetch.POST("/v1/contacts/invitations", { body: { emails } }),
|
|
5430
|
+
"Failed to invite contacts"
|
|
5431
|
+
);
|
|
5432
|
+
}
|
|
5433
|
+
async function createContact(arbi, body) {
|
|
5434
|
+
return requireData(await arbi.fetch.POST("/v1/contacts/", { body }), "Failed to create contact");
|
|
5419
5435
|
}
|
|
5420
|
-
async function
|
|
5436
|
+
async function updateContact(arbi, contactId, card) {
|
|
5421
5437
|
return requireData(
|
|
5422
|
-
await arbi.fetch.
|
|
5423
|
-
|
|
5438
|
+
await arbi.fetch.PATCH("/v1/contacts/{cnt_id}", {
|
|
5439
|
+
params: { path: { cnt_id: contactId } },
|
|
5440
|
+
body: { card, invite: false }
|
|
5441
|
+
}),
|
|
5442
|
+
"Failed to update contact"
|
|
5424
5443
|
);
|
|
5425
5444
|
}
|
|
5426
|
-
async function
|
|
5445
|
+
async function deleteContact(arbi, contactId) {
|
|
5427
5446
|
requireOk(
|
|
5428
|
-
await arbi.fetch.DELETE("/v1/
|
|
5429
|
-
"Failed to
|
|
5447
|
+
await arbi.fetch.DELETE("/v1/contacts/{cnt_id}", { params: { path: { cnt_id: contactId } } }),
|
|
5448
|
+
"Failed to delete contact"
|
|
5449
|
+
);
|
|
5450
|
+
}
|
|
5451
|
+
async function searchContacts(arbi, q2) {
|
|
5452
|
+
return requireData(
|
|
5453
|
+
await arbi.fetch.GET("/v1/contacts/search", { params: { query: { q: q2 } } }),
|
|
5454
|
+
"Failed to search contacts"
|
|
5430
5455
|
);
|
|
5431
5456
|
}
|
|
5432
5457
|
function groupContactsByStatus(contactList) {
|
|
5433
5458
|
const registered = [];
|
|
5434
5459
|
const pending = [];
|
|
5460
|
+
const cards = [];
|
|
5435
5461
|
for (const c2 of contactList) {
|
|
5436
|
-
if (c2.status === "registered")
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
pending.push(c2);
|
|
5440
|
-
}
|
|
5462
|
+
if (c2.status === "registered") registered.push(c2);
|
|
5463
|
+
else if (c2.status === "card") cards.push(c2);
|
|
5464
|
+
else pending.push(c2);
|
|
5441
5465
|
}
|
|
5442
|
-
return { registered, pending };
|
|
5466
|
+
return { registered, pending, cards };
|
|
5443
5467
|
}
|
|
5444
5468
|
|
|
5445
5469
|
// src/operations/doctags.ts
|
|
@@ -5485,32 +5509,45 @@ async function generateDocTags(arbi, tagIds, docIds, options) {
|
|
|
5485
5509
|
);
|
|
5486
5510
|
}
|
|
5487
5511
|
|
|
5488
|
-
// src/operations/
|
|
5489
|
-
var
|
|
5490
|
-
__export(
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5512
|
+
// src/operations/chats.ts
|
|
5513
|
+
var chats_exports = {};
|
|
5514
|
+
__export(chats_exports, {
|
|
5515
|
+
CHAT_ATTACHMENT_MAX_BYTES: () => CHAT_ATTACHMENT_MAX_BYTES,
|
|
5516
|
+
CHAT_ATTACHMENT_MAX_FILES: () => CHAT_ATTACHMENT_MAX_FILES,
|
|
5517
|
+
DECRYPTION_FAILED: () => DECRYPTION_FAILED,
|
|
5518
|
+
addChatMembers: () => addChatMembers,
|
|
5519
|
+
chatMessageTombstone: () => chatMessageTombstone,
|
|
5520
|
+
checkChatAttachmentLimits: () => checkChatAttachmentLimits,
|
|
5521
|
+
createChatCryptoContext: () => createChatCryptoContext,
|
|
5522
|
+
createGroupChat: () => createGroupChat,
|
|
5523
|
+
decryptChatAttachmentManifest: () => decryptChatAttachmentManifest,
|
|
5524
|
+
decryptChatMessage: () => decryptChatMessage,
|
|
5525
|
+
decryptChatMessages: () => decryptChatMessages,
|
|
5526
|
+
decryptChatTitle: () => decryptChatTitle,
|
|
5527
|
+
deleteChatMessage: () => deleteChatMessage,
|
|
5528
|
+
directPeer: () => directPeer,
|
|
5529
|
+
downloadChatAttachment: () => downloadChatAttachment,
|
|
5530
|
+
encryptChatAttachmentManifest: () => encryptChatAttachmentManifest,
|
|
5531
|
+
ensureChatKeyCurrent: () => ensureChatKeyCurrent,
|
|
5532
|
+
getChat: () => getChat,
|
|
5533
|
+
hasRead: () => hasRead,
|
|
5534
|
+
isAgentExtId: () => isAgentExtId,
|
|
5535
|
+
listChatMessages: () => listChatMessages,
|
|
5536
|
+
listChats: () => listChats,
|
|
5537
|
+
loadDecryptedChat: () => loadDecryptedChat,
|
|
5538
|
+
markChatRead: () => markChatRead,
|
|
5539
|
+
openChatKeyRing: () => openChatKeyRing,
|
|
5540
|
+
openDirectChat: () => openDirectChat,
|
|
5541
|
+
parseChatAttachmentManifest: () => parseChatAttachmentManifest,
|
|
5542
|
+
removeChatMember: () => removeChatMember,
|
|
5543
|
+
renameChat: () => renameChat,
|
|
5508
5544
|
resolveRecipient: () => resolveRecipient,
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5545
|
+
rotateChatKey: () => rotateChatKey,
|
|
5546
|
+
sendChatMessage: () => sendChatMessage,
|
|
5547
|
+
sendDirectMessage: () => sendDirectMessage,
|
|
5548
|
+
serializeChatAttachmentManifest: () => serializeChatAttachmentManifest,
|
|
5549
|
+
uploadChatAttachment: () => uploadChatAttachment,
|
|
5550
|
+
uploadChatAttachments: () => uploadChatAttachments
|
|
5514
5551
|
});
|
|
5515
5552
|
|
|
5516
5553
|
// src/operations/agents.ts
|
|
@@ -5602,27 +5639,27 @@ async function stageAgentFile(auth, agentId, file, name) {
|
|
|
5602
5639
|
});
|
|
5603
5640
|
return response.json();
|
|
5604
5641
|
}
|
|
5605
|
-
var
|
|
5606
|
-
var
|
|
5642
|
+
var CHAT_ATTACHMENT_MAX_BYTES = 15 * 1024 * 1024;
|
|
5643
|
+
var CHAT_ATTACHMENT_MAX_FILES = 10;
|
|
5607
5644
|
var ATTACHMENT_ID = /^att-[a-zA-Z0-9]{8}$/;
|
|
5608
5645
|
var MANIFEST_VERSION = 1;
|
|
5609
5646
|
var MB = 1024 * 1024;
|
|
5610
|
-
function
|
|
5611
|
-
if (files.length >
|
|
5647
|
+
function checkChatAttachmentLimits(files) {
|
|
5648
|
+
if (files.length > CHAT_ATTACHMENT_MAX_FILES) {
|
|
5612
5649
|
throw new Error(
|
|
5613
|
-
`You can attach at most ${
|
|
5650
|
+
`You can attach at most ${CHAT_ATTACHMENT_MAX_FILES} files to a message (this one has ${files.length}).`
|
|
5614
5651
|
);
|
|
5615
5652
|
}
|
|
5616
5653
|
for (const file of files) {
|
|
5617
|
-
if (file.size >
|
|
5654
|
+
if (file.size > CHAT_ATTACHMENT_MAX_BYTES) {
|
|
5618
5655
|
throw new Error(
|
|
5619
|
-
`${file.name} is too large (${(file.size / MB).toFixed(1)} MB). Files can be at most ${
|
|
5656
|
+
`${file.name} is too large (${(file.size / MB).toFixed(1)} MB). Files can be at most ${CHAT_ATTACHMENT_MAX_BYTES / MB} MB.`
|
|
5620
5657
|
);
|
|
5621
5658
|
}
|
|
5622
5659
|
}
|
|
5623
5660
|
}
|
|
5624
|
-
async function
|
|
5625
|
-
|
|
5661
|
+
async function uploadChatAttachment(arbi, input) {
|
|
5662
|
+
checkChatAttachmentLimits([{ name: input.name, size: input.bytes.length }]);
|
|
5626
5663
|
await client.initSodium();
|
|
5627
5664
|
const key = globalThis.crypto.getRandomValues(new Uint8Array(32));
|
|
5628
5665
|
try {
|
|
@@ -5633,13 +5670,13 @@ async function uploadDmAttachment(arbi, input) {
|
|
|
5633
5670
|
new Blob([ciphertext], { type: "application/octet-stream" }),
|
|
5634
5671
|
"attachment.bin"
|
|
5635
5672
|
);
|
|
5636
|
-
const result = await arbi.fetch.POST("/v1/
|
|
5673
|
+
const result = await arbi.fetch.POST("/v1/chats/attachments", {
|
|
5637
5674
|
body: { file: "" },
|
|
5638
5675
|
bodySerializer: () => form
|
|
5639
5676
|
});
|
|
5640
5677
|
if (result.response?.status === 413) {
|
|
5641
5678
|
throw new ArbiApiError(
|
|
5642
|
-
`${input.name} is too large. Files can be at most ${
|
|
5679
|
+
`${input.name} is too large. Files can be at most ${CHAT_ATTACHMENT_MAX_BYTES / MB} MB.`,
|
|
5643
5680
|
result.error,
|
|
5644
5681
|
413
|
|
5645
5682
|
);
|
|
@@ -5656,19 +5693,19 @@ async function uploadDmAttachment(arbi, input) {
|
|
|
5656
5693
|
key.fill(0);
|
|
5657
5694
|
}
|
|
5658
5695
|
}
|
|
5659
|
-
async function
|
|
5660
|
-
|
|
5696
|
+
async function uploadChatAttachments(arbi, inputs) {
|
|
5697
|
+
checkChatAttachmentLimits(inputs.map((i2) => ({ name: i2.name, size: i2.bytes.length })));
|
|
5661
5698
|
const files = [];
|
|
5662
|
-
for (const input of inputs) files.push(await
|
|
5699
|
+
for (const input of inputs) files.push(await uploadChatAttachment(arbi, input));
|
|
5663
5700
|
return files;
|
|
5664
5701
|
}
|
|
5665
|
-
function
|
|
5702
|
+
function serializeChatAttachmentManifest(files) {
|
|
5666
5703
|
return JSON.stringify({
|
|
5667
5704
|
v: MANIFEST_VERSION,
|
|
5668
5705
|
files: files.map(({ id, name, type, size, key }) => ({ id, name, type, size, key }))
|
|
5669
5706
|
});
|
|
5670
5707
|
}
|
|
5671
|
-
function
|
|
5708
|
+
function parseChatAttachmentManifest(json2) {
|
|
5672
5709
|
const manifest = JSON.parse(json2);
|
|
5673
5710
|
if (manifest?.v !== MANIFEST_VERSION || !Array.isArray(manifest.files)) {
|
|
5674
5711
|
throw new Error("Unsupported attachment manifest");
|
|
@@ -5687,27 +5724,15 @@ function parseDmAttachmentManifest(json2) {
|
|
|
5687
5724
|
};
|
|
5688
5725
|
});
|
|
5689
5726
|
}
|
|
5690
|
-
async function
|
|
5691
|
-
return
|
|
5692
|
-
serializeDmAttachmentManifest(files),
|
|
5693
|
-
recipientEncryptionPubKeyBase64,
|
|
5694
|
-
senderEncryptionSecretKey
|
|
5695
|
-
);
|
|
5727
|
+
async function encryptChatAttachmentManifest(files, chatKey) {
|
|
5728
|
+
return client.encryptWithChatKey(serializeChatAttachmentManifest(files), chatKey);
|
|
5696
5729
|
}
|
|
5697
|
-
async function
|
|
5698
|
-
|
|
5699
|
-
const isSent = notification.sender.external_id === crypto2.userExtId;
|
|
5700
|
-
const otherParty = isSent ? notification.recipient : notification.sender;
|
|
5701
|
-
const json2 = await arbi.crypto.decryptMessage(
|
|
5702
|
-
notification.attachments,
|
|
5703
|
-
otherParty.encryption_public_key,
|
|
5704
|
-
crypto2.encryptionKeypair.secretKey
|
|
5705
|
-
);
|
|
5706
|
-
return parseDmAttachmentManifest(json2);
|
|
5730
|
+
async function decryptChatAttachmentManifest(manifest, chatKey) {
|
|
5731
|
+
return parseChatAttachmentManifest(await client.decryptWithChatKey(manifest, chatKey));
|
|
5707
5732
|
}
|
|
5708
|
-
async function
|
|
5733
|
+
async function downloadChatAttachment(arbi, file) {
|
|
5709
5734
|
if (!ATTACHMENT_ID.test(file.id)) throw new Error(`Invalid attachment id: ${file.id}`);
|
|
5710
|
-
const result = await arbi.fetch.GET("/v1/
|
|
5735
|
+
const result = await arbi.fetch.GET("/v1/chats/attachments/{external_id}", {
|
|
5711
5736
|
params: { path: { external_id: file.id } },
|
|
5712
5737
|
parseAs: "arrayBuffer"
|
|
5713
5738
|
});
|
|
@@ -5735,78 +5760,289 @@ async function downloadDmAttachment(arbi, file) {
|
|
|
5735
5760
|
return plain;
|
|
5736
5761
|
}
|
|
5737
5762
|
|
|
5738
|
-
// src/operations/
|
|
5739
|
-
function
|
|
5740
|
-
const
|
|
5741
|
-
|
|
5742
|
-
publicKey: ed25519PublicKey,
|
|
5763
|
+
// src/operations/chats.ts
|
|
5764
|
+
function createChatCryptoContext(signingPrivateKeyBytes, userExtId) {
|
|
5765
|
+
const encryptionKeypair = client.deriveEncryptionKeypairFromSigning({
|
|
5766
|
+
publicKey: signingPrivateKeyBytes.slice(32, 64),
|
|
5743
5767
|
secretKey: signingPrivateKeyBytes
|
|
5744
5768
|
});
|
|
5745
5769
|
return { encryptionKeypair, userExtId };
|
|
5746
5770
|
}
|
|
5747
|
-
|
|
5748
|
-
return
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
);
|
|
5753
|
-
}
|
|
5754
|
-
async function
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
|
|
5762
|
-
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
continue;
|
|
5771
|
+
function isAgentExtId(extId) {
|
|
5772
|
+
return !!extId && extId.startsWith("agt-");
|
|
5773
|
+
}
|
|
5774
|
+
function directPeer(chat, myExtId) {
|
|
5775
|
+
if (chat.kind !== "direct") return void 0;
|
|
5776
|
+
return chat.members.find((m2) => m2.user.external_id !== myExtId)?.user;
|
|
5777
|
+
}
|
|
5778
|
+
async function openChatKeyRing(chat, crypto2) {
|
|
5779
|
+
const keys = /* @__PURE__ */ new Map();
|
|
5780
|
+
if (chat.kind === "direct") {
|
|
5781
|
+
const peer = directPeer(chat, crypto2.userExtId);
|
|
5782
|
+
const peerPub = peer?.encryption_public_key ?? client.bytesToBase64(crypto2.encryptionKeypair.publicKey);
|
|
5783
|
+
keys.set(0, await client.deriveDirectChatKey(peerPub, crypto2.encryptionKeypair.secretKey));
|
|
5784
|
+
} else {
|
|
5785
|
+
for (const k2 of chat.my_keys ?? []) {
|
|
5786
|
+
try {
|
|
5787
|
+
keys.set(
|
|
5788
|
+
k2.version,
|
|
5789
|
+
await client.openSealedChatKey(k2.sealed_key, crypto2.encryptionKeypair.secretKey)
|
|
5790
|
+
);
|
|
5791
|
+
} catch {
|
|
5792
|
+
}
|
|
5770
5793
|
}
|
|
5771
|
-
|
|
5794
|
+
}
|
|
5795
|
+
return { chatExtId: chat.external_id, kind: chat.kind, currentVersion: chat.key_version, keys };
|
|
5796
|
+
}
|
|
5797
|
+
function keyFor(ring, version) {
|
|
5798
|
+
const key = ring.keys.get(version);
|
|
5799
|
+
if (!key) throw new Error(`No key for epoch ${version} of ${ring.chatExtId}`);
|
|
5800
|
+
return key;
|
|
5801
|
+
}
|
|
5802
|
+
var DECRYPTION_FAILED = "[Decryption failed]";
|
|
5803
|
+
function chatMessageTombstone(message) {
|
|
5804
|
+
const row = {
|
|
5805
|
+
...message,
|
|
5806
|
+
deleted: true,
|
|
5807
|
+
content: null,
|
|
5808
|
+
attachments: null,
|
|
5809
|
+
dedupe_key: null
|
|
5810
|
+
};
|
|
5811
|
+
delete row.decryptFailed;
|
|
5812
|
+
delete row.attachmentFiles;
|
|
5813
|
+
delete row.attachmentsError;
|
|
5814
|
+
return row;
|
|
5815
|
+
}
|
|
5816
|
+
async function decryptChatMessage(ring, message) {
|
|
5817
|
+
if (message.deleted) return chatMessageTombstone(message);
|
|
5818
|
+
const key = ring.keys.get(message.key_version);
|
|
5819
|
+
const row = { ...message };
|
|
5820
|
+
if (message.content) {
|
|
5772
5821
|
try {
|
|
5773
|
-
|
|
5822
|
+
if (!key) throw new Error("no key");
|
|
5823
|
+
row.content = await client.decryptWithChatKey(message.content, key);
|
|
5774
5824
|
} catch {
|
|
5775
|
-
row =
|
|
5825
|
+
row.content = DECRYPTION_FAILED;
|
|
5826
|
+
row.decryptFailed = true;
|
|
5776
5827
|
}
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5828
|
+
}
|
|
5829
|
+
if (message.attachments) {
|
|
5830
|
+
try {
|
|
5831
|
+
if (!key) throw new Error("no key");
|
|
5832
|
+
row.attachmentFiles = await decryptChatAttachmentManifest(message.attachments, key);
|
|
5833
|
+
} catch {
|
|
5834
|
+
row.attachmentFiles = [];
|
|
5835
|
+
row.attachmentsError = "The attachments could not be decrypted";
|
|
5784
5836
|
}
|
|
5785
|
-
results.push(row);
|
|
5786
5837
|
}
|
|
5787
|
-
return
|
|
5838
|
+
return row;
|
|
5788
5839
|
}
|
|
5789
|
-
async function
|
|
5790
|
-
return
|
|
5840
|
+
async function decryptChatMessages(ring, messages) {
|
|
5841
|
+
return Promise.all(messages.map((m2) => decryptChatMessage(ring, m2)));
|
|
5791
5842
|
}
|
|
5792
|
-
async function
|
|
5793
|
-
|
|
5794
|
-
|
|
5843
|
+
async function decryptChatTitle(ring, chat) {
|
|
5844
|
+
if (!chat.title) return null;
|
|
5845
|
+
const key = ring.keys.get(chat.key_version);
|
|
5846
|
+
if (!key) return null;
|
|
5847
|
+
try {
|
|
5848
|
+
return await client.decryptWithChatKey(chat.title, key);
|
|
5849
|
+
} catch {
|
|
5850
|
+
return null;
|
|
5851
|
+
}
|
|
5795
5852
|
}
|
|
5796
|
-
async function
|
|
5853
|
+
async function listChats(arbi, kind) {
|
|
5797
5854
|
return requireData(
|
|
5798
|
-
await arbi.fetch.GET("/v1/
|
|
5855
|
+
await arbi.fetch.GET("/v1/chats/", { params: { query: kind ? { kind } : {} } }),
|
|
5856
|
+
"Failed to list chats"
|
|
5857
|
+
);
|
|
5858
|
+
}
|
|
5859
|
+
async function getChat(arbi, chatExtId) {
|
|
5860
|
+
return requireData(
|
|
5861
|
+
await arbi.fetch.GET("/v1/chats/{chat_ext_id}", {
|
|
5862
|
+
params: { path: { chat_ext_id: chatExtId } }
|
|
5863
|
+
}),
|
|
5864
|
+
"Failed to load chat"
|
|
5865
|
+
);
|
|
5866
|
+
}
|
|
5867
|
+
async function openDirectChat(arbi, peerExtId) {
|
|
5868
|
+
return requireData(
|
|
5869
|
+
await arbi.fetch.POST("/v1/chats/", { body: { kind: "direct", peer_ext_id: peerExtId } }),
|
|
5870
|
+
"Failed to open chat"
|
|
5871
|
+
);
|
|
5872
|
+
}
|
|
5873
|
+
async function createGroupChat(arbi, crypto2, params) {
|
|
5874
|
+
const members = params.members.filter((m2) => m2.external_id !== crypto2.userExtId);
|
|
5875
|
+
if (members.length === 0) throw new Error("A group needs at least one other member");
|
|
5876
|
+
const agent = members.find((m2) => isAgentExtId(m2.external_id));
|
|
5877
|
+
if (agent) throw new Error("Personal agents cannot join a group chat");
|
|
5878
|
+
const key = await client.generateChatKey();
|
|
5879
|
+
try {
|
|
5880
|
+
const title = params.title?.trim();
|
|
5881
|
+
return requireData(
|
|
5882
|
+
await arbi.fetch.POST("/v1/chats/", {
|
|
5883
|
+
body: {
|
|
5884
|
+
kind: "group",
|
|
5885
|
+
title: title ? await client.encryptWithChatKey(title, key) : null,
|
|
5886
|
+
members: await Promise.all(
|
|
5887
|
+
members.map(async (m2) => ({
|
|
5888
|
+
user_ext_id: m2.external_id,
|
|
5889
|
+
sealed_key: await client.sealChatKey(key, m2.encryption_public_key)
|
|
5890
|
+
}))
|
|
5891
|
+
),
|
|
5892
|
+
creator_sealed_key: await client.sealChatKey(
|
|
5893
|
+
key,
|
|
5894
|
+
client.bytesToBase64(crypto2.encryptionKeypair.publicKey)
|
|
5895
|
+
)
|
|
5896
|
+
}
|
|
5897
|
+
}),
|
|
5898
|
+
"Failed to create group"
|
|
5899
|
+
);
|
|
5900
|
+
} finally {
|
|
5901
|
+
key.fill(0);
|
|
5902
|
+
}
|
|
5903
|
+
}
|
|
5904
|
+
async function renameChat(arbi, ring, title) {
|
|
5905
|
+
const trimmed = title?.trim();
|
|
5906
|
+
return requireData(
|
|
5907
|
+
await arbi.fetch.PATCH("/v1/chats/{chat_ext_id}", {
|
|
5908
|
+
params: { path: { chat_ext_id: ring.chatExtId } },
|
|
5909
|
+
body: {
|
|
5910
|
+
title: trimmed ? await client.encryptWithChatKey(trimmed, keyFor(ring, ring.currentVersion)) : null
|
|
5911
|
+
}
|
|
5912
|
+
}),
|
|
5913
|
+
"Failed to rename chat"
|
|
5914
|
+
);
|
|
5915
|
+
}
|
|
5916
|
+
async function addChatMembers(arbi, ring, members) {
|
|
5917
|
+
if (ring.kind === "direct") {
|
|
5918
|
+
throw new Error("A direct chat cannot gain members: create a group instead");
|
|
5919
|
+
}
|
|
5920
|
+
if (members.some((m2) => isAgentExtId(m2.external_id))) {
|
|
5921
|
+
throw new Error("Personal agents cannot join a group chat");
|
|
5922
|
+
}
|
|
5923
|
+
const key = keyFor(ring, ring.currentVersion);
|
|
5924
|
+
return requireData(
|
|
5925
|
+
await arbi.fetch.POST("/v1/chats/{chat_ext_id}/members", {
|
|
5926
|
+
params: { path: { chat_ext_id: ring.chatExtId } },
|
|
5927
|
+
body: {
|
|
5928
|
+
members: await Promise.all(
|
|
5929
|
+
members.map(async (m2) => ({
|
|
5930
|
+
user_ext_id: m2.external_id,
|
|
5931
|
+
sealed_key: await client.sealChatKey(key, m2.encryption_public_key)
|
|
5932
|
+
}))
|
|
5933
|
+
)
|
|
5934
|
+
}
|
|
5935
|
+
}),
|
|
5936
|
+
"Failed to add members"
|
|
5937
|
+
);
|
|
5938
|
+
}
|
|
5939
|
+
async function removeChatMember(arbi, chatExtId, userExtId) {
|
|
5940
|
+
requireOk(
|
|
5941
|
+
await arbi.fetch.DELETE("/v1/chats/{chat_ext_id}/members/{user_ext_id}", {
|
|
5942
|
+
params: { path: { chat_ext_id: chatExtId, user_ext_id: userExtId } }
|
|
5943
|
+
}),
|
|
5944
|
+
"Failed to remove member"
|
|
5945
|
+
);
|
|
5946
|
+
}
|
|
5947
|
+
async function rotateChatKey(arbi, chat, ring) {
|
|
5948
|
+
if (chat.kind === "direct") throw new Error("Direct chats have no epochs");
|
|
5949
|
+
const oldTitle = await decryptChatTitle(ring, chat);
|
|
5950
|
+
if (chat.title && oldTitle === null) {
|
|
5951
|
+
throw new Error("Cannot re-encrypt the chat title: its key is not available");
|
|
5952
|
+
}
|
|
5953
|
+
const key = await client.generateChatKey();
|
|
5954
|
+
try {
|
|
5955
|
+
const sealed = {};
|
|
5956
|
+
for (const m2 of chat.members) {
|
|
5957
|
+
sealed[m2.user.external_id] = await client.sealChatKey(key, m2.user.encryption_public_key);
|
|
5958
|
+
}
|
|
5959
|
+
return requireData(
|
|
5960
|
+
await arbi.fetch.POST("/v1/chats/{chat_ext_id}/keys", {
|
|
5961
|
+
params: { path: { chat_ext_id: chat.external_id } },
|
|
5962
|
+
body: {
|
|
5963
|
+
version: chat.key_version + 1,
|
|
5964
|
+
sealed_keys: sealed,
|
|
5965
|
+
...oldTitle !== null ? { title: await client.encryptWithChatKey(oldTitle, key) } : {}
|
|
5966
|
+
}
|
|
5967
|
+
}),
|
|
5968
|
+
"Failed to rotate chat key"
|
|
5969
|
+
);
|
|
5970
|
+
} finally {
|
|
5971
|
+
key.fill(0);
|
|
5972
|
+
}
|
|
5973
|
+
}
|
|
5974
|
+
async function ensureChatKeyCurrent(arbi, chat, crypto2) {
|
|
5975
|
+
if (!chat.rotation_required || chat.kind === "direct") return chat;
|
|
5976
|
+
if (!chat.members.some((m2) => m2.user.external_id === crypto2.userExtId)) return chat;
|
|
5977
|
+
try {
|
|
5978
|
+
return await rotateChatKey(arbi, chat, await openChatKeyRing(chat, crypto2));
|
|
5979
|
+
} catch (err) {
|
|
5980
|
+
if (err instanceof ArbiApiError && err.status === 409) return getChat(arbi, chat.external_id);
|
|
5981
|
+
throw err;
|
|
5982
|
+
}
|
|
5983
|
+
}
|
|
5984
|
+
async function listChatMessages(arbi, chatExtId, options) {
|
|
5985
|
+
return requireData(
|
|
5986
|
+
await arbi.fetch.GET("/v1/chats/{chat_ext_id}/messages", {
|
|
5799
5987
|
params: {
|
|
5988
|
+
path: { chat_ext_id: chatExtId },
|
|
5800
5989
|
query: {
|
|
5801
|
-
|
|
5802
|
-
...options?.limit
|
|
5803
|
-
...options?.offset != null ? { offset: options.offset } : {}
|
|
5990
|
+
...options?.before ? { before: options.before } : {},
|
|
5991
|
+
...options?.limit ? { limit: options.limit } : {}
|
|
5804
5992
|
}
|
|
5805
5993
|
}
|
|
5806
5994
|
}),
|
|
5807
|
-
"Failed to
|
|
5995
|
+
"Failed to load messages"
|
|
5996
|
+
);
|
|
5997
|
+
}
|
|
5998
|
+
async function sendChatMessage(arbi, ring, text, options = {}) {
|
|
5999
|
+
const attachments = options.attachments ?? [];
|
|
6000
|
+
checkChatAttachmentLimits(attachments);
|
|
6001
|
+
const key = keyFor(ring, ring.currentVersion);
|
|
6002
|
+
const created = requireData(
|
|
6003
|
+
await arbi.fetch.POST("/v1/chats/{chat_ext_id}/messages", {
|
|
6004
|
+
params: { path: { chat_ext_id: ring.chatExtId } },
|
|
6005
|
+
body: {
|
|
6006
|
+
content: await client.encryptWithChatKey(text, key),
|
|
6007
|
+
key_version: ring.currentVersion,
|
|
6008
|
+
kind: "text",
|
|
6009
|
+
...attachments.length ? {
|
|
6010
|
+
attachments: await encryptChatAttachmentManifest(attachments, key),
|
|
6011
|
+
attachment_ext_ids: attachments.map((f2) => f2.id)
|
|
6012
|
+
} : {},
|
|
6013
|
+
...options.workspaceExtId ? { workspace_ext_id: options.workspaceExtId } : {},
|
|
6014
|
+
context_only: !!options.contextOnly
|
|
6015
|
+
}
|
|
6016
|
+
}),
|
|
6017
|
+
"Failed to send message"
|
|
6018
|
+
);
|
|
6019
|
+
return {
|
|
6020
|
+
...created,
|
|
6021
|
+
content: text,
|
|
6022
|
+
...attachments.length ? { attachmentFiles: attachments } : {}
|
|
6023
|
+
};
|
|
6024
|
+
}
|
|
6025
|
+
async function deleteChatMessage(arbi, chatExtId, messageExtId) {
|
|
6026
|
+
requireOk(
|
|
6027
|
+
await arbi.fetch.DELETE("/v1/chats/{chat_ext_id}/messages/{message_ext_id}", {
|
|
6028
|
+
params: { path: { chat_ext_id: chatExtId, message_ext_id: messageExtId } }
|
|
6029
|
+
}),
|
|
6030
|
+
"Failed to delete message"
|
|
6031
|
+
);
|
|
6032
|
+
}
|
|
6033
|
+
async function markChatRead(arbi, chatExtId, messageExtId) {
|
|
6034
|
+
return requireData(
|
|
6035
|
+
await arbi.fetch.POST("/v1/chats/{chat_ext_id}/read", {
|
|
6036
|
+
params: { path: { chat_ext_id: chatExtId } },
|
|
6037
|
+
body: messageExtId ? { message_ext_id: messageExtId } : {}
|
|
6038
|
+
}),
|
|
6039
|
+
"Failed to mark chat read"
|
|
5808
6040
|
);
|
|
5809
6041
|
}
|
|
6042
|
+
function hasRead(member, message) {
|
|
6043
|
+
if (!member?.last_read_at) return false;
|
|
6044
|
+
return Date.parse(member.last_read_at) >= Date.parse(message.created_at);
|
|
6045
|
+
}
|
|
5810
6046
|
async function resolveRecipient(arbi, ref) {
|
|
5811
6047
|
const isEmail = ref.includes("@");
|
|
5812
6048
|
const matchKey = isEmail ? "email" : "external_id";
|
|
@@ -5838,52 +6074,63 @@ async function resolveRecipient(arbi, ref) {
|
|
|
5838
6074
|
}
|
|
5839
6075
|
return null;
|
|
5840
6076
|
}
|
|
5841
|
-
async function
|
|
5842
|
-
const
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
6077
|
+
async function sendDirectMessage(arbi, crypto2, peerExtId, text, options) {
|
|
6078
|
+
const chat = await openDirectChat(arbi, peerExtId);
|
|
6079
|
+
return sendChatMessage(arbi, await openChatKeyRing(chat, crypto2), text, options);
|
|
6080
|
+
}
|
|
6081
|
+
async function loadDecryptedChat(arbi, crypto2, chat, options) {
|
|
6082
|
+
const ring = await openChatKeyRing(chat, crypto2);
|
|
6083
|
+
const raw = await listChatMessages(arbi, chat.external_id, { limit: options?.limit });
|
|
6084
|
+
const messages = (await decryptChatMessages(ring, raw)).reverse();
|
|
6085
|
+
return { chat, ring, title: await decryptChatTitle(ring, chat), messages };
|
|
6086
|
+
}
|
|
6087
|
+
|
|
6088
|
+
// src/operations/notifications.ts
|
|
6089
|
+
var notifications_exports = {};
|
|
6090
|
+
__export(notifications_exports, {
|
|
6091
|
+
deleteNotifications: () => deleteNotifications,
|
|
6092
|
+
listActivity: () => listActivity,
|
|
6093
|
+
listNotifications: () => listNotifications,
|
|
6094
|
+
markNotificationsRead: () => markNotificationsRead,
|
|
6095
|
+
requestWorkspaceAccess: () => requestWorkspaceAccess
|
|
6096
|
+
});
|
|
6097
|
+
async function listNotifications(arbi) {
|
|
6098
|
+
return requireData(await arbi.fetch.GET("/v1/notifications/"), "Failed to fetch notifications");
|
|
6099
|
+
}
|
|
6100
|
+
async function listActivity(arbi, options) {
|
|
6101
|
+
return requireData(
|
|
6102
|
+
await arbi.fetch.GET("/v1/notifications/", {
|
|
6103
|
+
params: {
|
|
6104
|
+
query: {
|
|
6105
|
+
type: "activity",
|
|
6106
|
+
...options?.limit != null ? { limit: options.limit } : {},
|
|
6107
|
+
...options?.offset != null ? { offset: options.offset } : {}
|
|
6108
|
+
}
|
|
5870
6109
|
}
|
|
5871
6110
|
}),
|
|
5872
|
-
"Failed to
|
|
6111
|
+
"Failed to fetch activity"
|
|
6112
|
+
);
|
|
6113
|
+
}
|
|
6114
|
+
async function markNotificationsRead(arbi, ids) {
|
|
6115
|
+
return requireData(
|
|
6116
|
+
await arbi.fetch.PATCH("/v1/notifications/", {
|
|
6117
|
+
body: { updates: ids.map((id) => ({ external_id: id, read: true })) }
|
|
6118
|
+
}),
|
|
6119
|
+
"Failed to update notifications"
|
|
6120
|
+
);
|
|
6121
|
+
}
|
|
6122
|
+
async function deleteNotifications(arbi, ids) {
|
|
6123
|
+
requireOk(
|
|
6124
|
+
await arbi.fetch.DELETE("/v1/notifications/", { body: { external_ids: ids } }),
|
|
6125
|
+
"Failed to delete notifications"
|
|
5873
6126
|
);
|
|
5874
|
-
return created.map((n2) => ({
|
|
5875
|
-
...n2,
|
|
5876
|
-
content: plaintextFor.get(n2.recipient.external_id) ?? n2.content,
|
|
5877
|
-
...attachments.length ? { attachmentFiles: attachments } : {}
|
|
5878
|
-
}));
|
|
5879
6127
|
}
|
|
5880
6128
|
async function requestWorkspaceAccess(arbi, params, crypto2) {
|
|
5881
6129
|
const payload = JSON.stringify({
|
|
5882
6130
|
session_pubkey_b64: params.sessionPubkeyB64,
|
|
5883
6131
|
note: params.note?.trim() || void 0
|
|
5884
6132
|
});
|
|
5885
|
-
const content = await
|
|
5886
|
-
arbi,
|
|
6133
|
+
const content = await client.encryptMessage(
|
|
5887
6134
|
payload,
|
|
5888
6135
|
params.recipientEncryptionPublicKey,
|
|
5889
6136
|
crypto2.encryptionKeypair.secretKey
|
|
@@ -5899,28 +6146,6 @@ async function requestWorkspaceAccess(arbi, params, crypto2) {
|
|
|
5899
6146
|
"Failed to request workspace access"
|
|
5900
6147
|
);
|
|
5901
6148
|
}
|
|
5902
|
-
async function sendDM(arbi, messages) {
|
|
5903
|
-
return requireData(
|
|
5904
|
-
await arbi.fetch.POST("/v1/notifications/", {
|
|
5905
|
-
body: { messages, context_only: false }
|
|
5906
|
-
}),
|
|
5907
|
-
"Failed to send message"
|
|
5908
|
-
);
|
|
5909
|
-
}
|
|
5910
|
-
async function markRead(arbi, messageIds) {
|
|
5911
|
-
return requireData(
|
|
5912
|
-
await arbi.fetch.PATCH("/v1/notifications/", {
|
|
5913
|
-
body: { updates: messageIds.map((id) => ({ external_id: id, read: true })) }
|
|
5914
|
-
}),
|
|
5915
|
-
"Failed to update messages"
|
|
5916
|
-
);
|
|
5917
|
-
}
|
|
5918
|
-
async function deleteDMs(arbi, messageIds) {
|
|
5919
|
-
requireOk(
|
|
5920
|
-
await arbi.fetch.DELETE("/v1/notifications/", { body: { external_ids: messageIds } }),
|
|
5921
|
-
"Failed to delete messages"
|
|
5922
|
-
);
|
|
5923
|
-
}
|
|
5924
6149
|
|
|
5925
6150
|
// src/operations/settings.ts
|
|
5926
6151
|
var settings_exports = {};
|
|
@@ -6144,6 +6369,17 @@ async function updateProfile(arbi, body) {
|
|
|
6144
6369
|
);
|
|
6145
6370
|
}
|
|
6146
6371
|
|
|
6372
|
+
// src/operations/firm.ts
|
|
6373
|
+
async function getFirmPool(arbi) {
|
|
6374
|
+
return requireData(await arbi.fetch.GET("/v1/firm/pool"), "Failed to fetch the firm AI usage");
|
|
6375
|
+
}
|
|
6376
|
+
async function topUpFirmPool(arbi, aiAddons) {
|
|
6377
|
+
return requireData(
|
|
6378
|
+
await arbi.fetch.POST("/v1/firm/pool/topup", { body: { ai_addons: aiAddons } }),
|
|
6379
|
+
"Failed to add firm AI usage"
|
|
6380
|
+
);
|
|
6381
|
+
}
|
|
6382
|
+
|
|
6147
6383
|
// src/operations/account.ts
|
|
6148
6384
|
var account_exports = {};
|
|
6149
6385
|
__export(account_exports, {
|
|
@@ -7376,10 +7612,10 @@ function attachmentFromBytes(name, contentType, bytes) {
|
|
|
7376
7612
|
name,
|
|
7377
7613
|
content_type: contentType,
|
|
7378
7614
|
size: bytes.length,
|
|
7379
|
-
content_base64:
|
|
7615
|
+
content_base64: bytesToBase643(bytes)
|
|
7380
7616
|
};
|
|
7381
7617
|
}
|
|
7382
|
-
function
|
|
7618
|
+
function bytesToBase643(bytes) {
|
|
7383
7619
|
let binary = "";
|
|
7384
7620
|
for (let i2 = 0; i2 < bytes.length; i2 += 32768) {
|
|
7385
7621
|
binary += String.fromCharCode(...bytes.subarray(i2, i2 + 32768));
|
|
@@ -7407,7 +7643,7 @@ var Arbi = class {
|
|
|
7407
7643
|
currentWorkspaceId = null;
|
|
7408
7644
|
/** Wrapped workspace keys seen in the last list/create, so selecting needs no re-fetch. */
|
|
7409
7645
|
wrappedKeys = /* @__PURE__ */ new Map();
|
|
7410
|
-
|
|
7646
|
+
chatCryptoContext = null;
|
|
7411
7647
|
sessionExpiredListeners = /* @__PURE__ */ new Set();
|
|
7412
7648
|
options;
|
|
7413
7649
|
constructor(options) {
|
|
@@ -7579,7 +7815,7 @@ var Arbi = class {
|
|
|
7579
7815
|
this.userProfile = null;
|
|
7580
7816
|
this.currentWorkspaceId = null;
|
|
7581
7817
|
this.wrappedKeys.clear();
|
|
7582
|
-
this.
|
|
7818
|
+
this.chatCryptoContext = null;
|
|
7583
7819
|
this.client?.session.clear();
|
|
7584
7820
|
for (const listener of [...this.sessionExpiredListeners]) listener();
|
|
7585
7821
|
}
|
|
@@ -7625,7 +7861,7 @@ var Arbi = class {
|
|
|
7625
7861
|
this.userProfile = null;
|
|
7626
7862
|
this.currentWorkspaceId = null;
|
|
7627
7863
|
this.wrappedKeys.clear();
|
|
7628
|
-
this.
|
|
7864
|
+
this.chatCryptoContext = null;
|
|
7629
7865
|
}
|
|
7630
7866
|
// ── Accessors ─────────────────────────────────────────────────────────
|
|
7631
7867
|
/** Get the underlying ArbiClient (throws if not initialized). */
|
|
@@ -7724,6 +7960,13 @@ var Arbi = class {
|
|
|
7724
7960
|
*/
|
|
7725
7961
|
me: () => getCurrentUser(this.requireClient())
|
|
7726
7962
|
};
|
|
7963
|
+
// ── Firm ──────────────────────────────────────────────────────────────
|
|
7964
|
+
firm = {
|
|
7965
|
+
/** The firm's pooled monthly £ of AI usage (`has_pool` false where there is none). */
|
|
7966
|
+
pool: () => getFirmPool(this.requireClient()),
|
|
7967
|
+
/** Buy `aiAddons` renewing add-ons (+£10 of AI usage a month each) for the firm. Box admins only. */
|
|
7968
|
+
topUp: (aiAddons) => topUpFirmPool(this.requireClient(), aiAddons)
|
|
7969
|
+
};
|
|
7727
7970
|
// ── Profile ───────────────────────────────────────────────────────────
|
|
7728
7971
|
profile = {
|
|
7729
7972
|
/** Update the display profile; pass only what changes (`''` clears family name or picture). */
|
|
@@ -7889,9 +8132,13 @@ var Arbi = class {
|
|
|
7889
8132
|
const lr2 = this.requireLogin();
|
|
7890
8133
|
const userExtId = lr2.userExtId ?? client.session.getState().userExtId;
|
|
7891
8134
|
if (!userExtId) throw new ArbiError("No user id in session \u2014 cannot request access");
|
|
7892
|
-
const crypto2 =
|
|
8135
|
+
const crypto2 = createChatCryptoContext(lr2.signingPrivateKey, userExtId);
|
|
7893
8136
|
const sessionPubkeyB64 = client.crypto.bytesToBase64(lr2.serverSessionKey);
|
|
7894
|
-
return requestWorkspaceAccess(
|
|
8137
|
+
return requestWorkspaceAccess(
|
|
8138
|
+
client,
|
|
8139
|
+
{ ...params, sessionPubkeyB64 },
|
|
8140
|
+
crypto2
|
|
8141
|
+
);
|
|
7895
8142
|
},
|
|
7896
8143
|
copyDocuments: (targetWorkspaceId, docIds, targetWorkspaceKey) => copyDocuments(
|
|
7897
8144
|
this.requireClient(),
|
|
@@ -8181,92 +8428,119 @@ var Arbi = class {
|
|
|
8181
8428
|
// ── Contacts ──────────────────────────────────────────────────────────
|
|
8182
8429
|
contacts = {
|
|
8183
8430
|
list: () => listContacts(this.requireClient()),
|
|
8184
|
-
|
|
8185
|
-
|
|
8431
|
+
invite: (emails) => inviteContacts(this.requireClient(), emails),
|
|
8432
|
+
create: (body) => createContact(this.requireClient(), body),
|
|
8433
|
+
update: (contactId, card) => updateContact(this.requireClient(), contactId, card),
|
|
8434
|
+
delete: (contactId) => deleteContact(this.requireClient(), contactId),
|
|
8435
|
+
search: (q2) => searchContacts(this.requireClient(), q2),
|
|
8186
8436
|
groupByStatus: groupContactsByStatus
|
|
8187
8437
|
};
|
|
8188
|
-
// ──
|
|
8438
|
+
// ── Chats (direct + group) ────────────────────────────────────────────
|
|
8189
8439
|
/**
|
|
8190
|
-
* Build (and cache) the
|
|
8191
|
-
*
|
|
8192
|
-
* Derives the user's curve25519 keypair from their signing key and pairs it
|
|
8193
|
-
* with their external_id — everything `list()`/`send()` need to encrypt and
|
|
8194
|
-
* decrypt. Cached for the session and cleared on logout. Consumers never touch
|
|
8195
|
-
* this: it's an internal of the `dm` surface.
|
|
8440
|
+
* Build (and cache) the chat crypto context for the current session: my X25519 keypair
|
|
8441
|
+
* (derived from the signing key) and external id. Cleared on logout.
|
|
8196
8442
|
*
|
|
8197
|
-
* The key comes from the live login result first, exactly as `selectWorkspace`
|
|
8198
|
-
*
|
|
8199
|
-
*
|
|
8200
|
-
* breaks whenever persistence is unavailable — `saveSession` deliberately
|
|
8201
|
-
* no-ops without Web Crypto (a non-secure origin, tracking prevention, an
|
|
8202
|
-
* embedded widget), so a perfectly authenticated user with a working workspace
|
|
8203
|
-
* would be told they are "not authenticated" the moment they opened Messages.
|
|
8443
|
+
* The key comes from the live login result first, exactly as `selectWorkspace` sources it, and
|
|
8444
|
+
* only then from persisted storage (which is what restores a session on reload) — persistence
|
|
8445
|
+
* deliberately no-ops without Web Crypto, and chats must not be the one feature that breaks then.
|
|
8204
8446
|
*/
|
|
8205
|
-
async
|
|
8206
|
-
if (this.
|
|
8447
|
+
async requireChatCrypto() {
|
|
8448
|
+
if (this.chatCryptoContext) return this.chatCryptoContext;
|
|
8207
8449
|
const client = this.requireClient();
|
|
8208
8450
|
const signingPrivateKey = this.loginResult?.signingPrivateKey ?? (await client.storage.getSession())?.signingPrivateKey;
|
|
8209
8451
|
if (!signingPrivateKey) {
|
|
8210
|
-
throw new ArbiError("Not authenticated \u2014 no session available for
|
|
8452
|
+
throw new ArbiError("Not authenticated \u2014 no session available for chat encryption");
|
|
8211
8453
|
}
|
|
8212
8454
|
const userExtId = client.session.getState().userExtId;
|
|
8213
8455
|
if (!userExtId) {
|
|
8214
|
-
throw new ArbiError("No user identity in session \u2014 cannot set up
|
|
8456
|
+
throw new ArbiError("No user identity in session \u2014 cannot set up chat encryption");
|
|
8215
8457
|
}
|
|
8216
|
-
this.
|
|
8217
|
-
return this.
|
|
8458
|
+
this.chatCryptoContext = createChatCryptoContext(signingPrivateKey, userExtId);
|
|
8459
|
+
return this.chatCryptoContext;
|
|
8460
|
+
}
|
|
8461
|
+
/** Fetch a chat, sealing a new epoch first when it is `rotation_required`. */
|
|
8462
|
+
async readyChat(chatExtId) {
|
|
8463
|
+
const client = this.requireClient();
|
|
8464
|
+
return ensureChatKeyCurrent(
|
|
8465
|
+
client,
|
|
8466
|
+
await getChat(client, chatExtId),
|
|
8467
|
+
await this.requireChatCrypto()
|
|
8468
|
+
);
|
|
8218
8469
|
}
|
|
8470
|
+
chats = {
|
|
8471
|
+
/** My chats, most recently active first (raw: titles/last messages are ciphertext). */
|
|
8472
|
+
list: (kind) => listChats(this.requireClient(), kind),
|
|
8473
|
+
get: (chatExtId) => getChat(this.requireClient(), chatExtId),
|
|
8474
|
+
/** Get-or-create the direct chat with a peer. */
|
|
8475
|
+
openDirect: (peerExtId) => openDirectChat(this.requireClient(), peerExtId),
|
|
8476
|
+
/** Create a group (epoch 1 sealed to every member). Agents are refused. */
|
|
8477
|
+
createGroup: async (params) => createGroupChat(this.requireClient(), await this.requireChatCrypto(), params),
|
|
8478
|
+
/** A chat with its keys opened, title and newest messages decrypted (oldest first). */
|
|
8479
|
+
load: async (chatExtId, options) => {
|
|
8480
|
+
const chat = await this.readyChat(chatExtId);
|
|
8481
|
+
return loadDecryptedChat(
|
|
8482
|
+
this.requireClient(),
|
|
8483
|
+
await this.requireChatCrypto(),
|
|
8484
|
+
chat,
|
|
8485
|
+
options
|
|
8486
|
+
);
|
|
8487
|
+
},
|
|
8488
|
+
/** Post plaintext to a chat (encrypted under its current epoch). */
|
|
8489
|
+
send: async (chatExtId, text, options) => {
|
|
8490
|
+
const chat = await this.readyChat(chatExtId);
|
|
8491
|
+
const ring = await openChatKeyRing(chat, await this.requireChatCrypto());
|
|
8492
|
+
return sendChatMessage(this.requireClient(), ring, text, options);
|
|
8493
|
+
},
|
|
8494
|
+
rename: async (chatExtId, title) => {
|
|
8495
|
+
const chat = await this.readyChat(chatExtId);
|
|
8496
|
+
const ring = await openChatKeyRing(chat, await this.requireChatCrypto());
|
|
8497
|
+
return renameChat(this.requireClient(), ring, title);
|
|
8498
|
+
},
|
|
8499
|
+
addMembers: async (chatExtId, members) => {
|
|
8500
|
+
const chat = await this.readyChat(chatExtId);
|
|
8501
|
+
const ring = await openChatKeyRing(chat, await this.requireChatCrypto());
|
|
8502
|
+
return addChatMembers(this.requireClient(), ring, members);
|
|
8503
|
+
},
|
|
8504
|
+
/** Remove a member (owner) or leave (own id); a remaining member seals the next epoch. */
|
|
8505
|
+
removeMember: async (chatExtId, userExtId) => {
|
|
8506
|
+
await removeChatMember(this.requireClient(), chatExtId, userExtId);
|
|
8507
|
+
const crypto2 = await this.requireChatCrypto();
|
|
8508
|
+
if (userExtId !== crypto2.userExtId) await this.readyChat(chatExtId);
|
|
8509
|
+
},
|
|
8510
|
+
markRead: (chatExtId, messageExtId) => markChatRead(this.requireClient(), chatExtId, messageExtId),
|
|
8511
|
+
deleteMessage: (chatExtId, messageExtId) => deleteChatMessage(this.requireClient(), chatExtId, messageExtId)
|
|
8512
|
+
};
|
|
8513
|
+
/** Direct-chat conveniences addressed by peer (email or `usr-`/`agt-` id). */
|
|
8219
8514
|
dm = {
|
|
8220
8515
|
/**
|
|
8221
|
-
*
|
|
8222
|
-
*
|
|
8223
|
-
*/
|
|
8224
|
-
list: async () => listDecryptedDMs(this.requireClient(), await this.requireDmCrypto()),
|
|
8225
|
-
/**
|
|
8226
|
-
* Send an E2E-encrypted DM to a recipient (email or `usr-`/`agt-` id).
|
|
8227
|
-
* Resolves the recipient's public key and encrypts internally — the caller
|
|
8228
|
-
* passes plaintext and never handles keys or ciphertext.
|
|
8516
|
+
* Send an E2E-encrypted direct message: resolves the peer, opens (get-or-create) the direct
|
|
8517
|
+
* chat and posts under the pair key. The caller passes plaintext and never handles keys.
|
|
8229
8518
|
*/
|
|
8230
8519
|
send: async (recipient, text) => {
|
|
8231
8520
|
const client = this.requireClient();
|
|
8232
8521
|
const resolved = await resolveRecipient(client, recipient);
|
|
8233
8522
|
if (!resolved) {
|
|
8234
8523
|
throw new ArbiError(
|
|
8235
|
-
`Could not resolve
|
|
8524
|
+
`Could not resolve recipient "${recipient}" (not a known contact, agent, or workspace member)`
|
|
8236
8525
|
);
|
|
8237
8526
|
}
|
|
8238
|
-
return
|
|
8527
|
+
return sendDirectMessage(
|
|
8239
8528
|
client,
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
content: text,
|
|
8244
|
-
recipient_encryption_public_key: resolved.pubKey
|
|
8245
|
-
}
|
|
8246
|
-
],
|
|
8247
|
-
await this.requireDmCrypto()
|
|
8529
|
+
await this.requireChatCrypto(),
|
|
8530
|
+
resolved.extId,
|
|
8531
|
+
text
|
|
8248
8532
|
);
|
|
8249
8533
|
},
|
|
8250
|
-
/**
|
|
8251
|
-
|
|
8252
|
-
* (e.g. from a message's `sender`), skipping directory resolution.
|
|
8253
|
-
*/
|
|
8254
|
-
sendTo: async (recipientExtId, recipientPublicKey, text) => sendEncryptedDM(
|
|
8534
|
+
/** Send to a peer whose external id is already known, skipping directory resolution. */
|
|
8535
|
+
sendTo: async (peerExtId, text) => sendDirectMessage(
|
|
8255
8536
|
this.requireClient(),
|
|
8256
|
-
|
|
8257
|
-
|
|
8258
|
-
|
|
8259
|
-
content: text,
|
|
8260
|
-
recipient_encryption_public_key: recipientPublicKey
|
|
8261
|
-
}
|
|
8262
|
-
],
|
|
8263
|
-
await this.requireDmCrypto()
|
|
8537
|
+
await this.requireChatCrypto(),
|
|
8538
|
+
peerExtId,
|
|
8539
|
+
text
|
|
8264
8540
|
),
|
|
8265
8541
|
/** Resolve a recipient reference to `{ extId, pubKey }` (contacts → agents → workspace). */
|
|
8266
8542
|
resolveRecipient: (recipient) => resolveRecipient(this.requireClient(), recipient),
|
|
8267
|
-
|
|
8268
|
-
delete: (messageIds) => deleteDMs(this.requireClient(), messageIds),
|
|
8269
|
-
/** List the current user's durable activity feed (never unread; excluded from DMs). */
|
|
8543
|
+
/** List the current user's durable activity feed. */
|
|
8270
8544
|
listActivity: (options) => listActivity(this.requireClient(), options)
|
|
8271
8545
|
};
|
|
8272
8546
|
// ── Settings ──────────────────────────────────────────────────────────
|
|
@@ -8423,6 +8697,7 @@ exports.buildFactsContextTool = buildFactsContextTool;
|
|
|
8423
8697
|
exports.buildRetrievalChunkTool = buildRetrievalChunkTool;
|
|
8424
8698
|
exports.buildRetrievalFullContextTool = buildRetrievalFullContextTool;
|
|
8425
8699
|
exports.buildRetrievalTocTool = buildRetrievalTocTool;
|
|
8700
|
+
exports.chats = chats_exports;
|
|
8426
8701
|
exports.connectWebSocket = connectWebSocket;
|
|
8427
8702
|
exports.connectWithReconnect = connectWithReconnect;
|
|
8428
8703
|
exports.consumeSSEStream = consumeSSEStream;
|
|
@@ -8430,7 +8705,6 @@ exports.contacts = contacts_exports;
|
|
|
8430
8705
|
exports.conversations = conversations_exports;
|
|
8431
8706
|
exports.countCitations = countCitations;
|
|
8432
8707
|
exports.createAuthenticatedClient = createAuthenticatedClient;
|
|
8433
|
-
exports.dm = dm_exports;
|
|
8434
8708
|
exports.doctags = doctags_exports;
|
|
8435
8709
|
exports.documents = documents_exports;
|
|
8436
8710
|
exports.facts = facts_exports;
|
|
@@ -8449,6 +8723,7 @@ exports.health = health_exports;
|
|
|
8449
8723
|
exports.identityErrorCode = identityErrorCode;
|
|
8450
8724
|
exports.identityVerification = identity_exports;
|
|
8451
8725
|
exports.mail = mail_exports;
|
|
8726
|
+
exports.notifications = notifications_exports;
|
|
8452
8727
|
exports.parseSSEEvents = parseSSEEvents;
|
|
8453
8728
|
exports.parseSlashCommand = parseSlashCommand;
|
|
8454
8729
|
exports.parseSlashTokenInProgress = parseSlashTokenInProgress;
|