@arbidocs/sdk 0.4.158 → 0.4.160
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-Dnc05Tkf.d.cts → browser-coa0VhYO.d.cts} +302 -50
- package/dist/{browser-Dnc05Tkf.d.ts → browser-coa0VhYO.d.ts} +302 -50
- package/dist/browser.cjs +292 -55
- 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 +292 -57
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +296 -58
- 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 +297 -60
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -3533,6 +3533,14 @@ var ArbiApiError = class extends ArbiError {
|
|
|
3533
3533
|
this.detail = apiErrorDetail(apiError);
|
|
3534
3534
|
}
|
|
3535
3535
|
};
|
|
3536
|
+
var DuplicateContactError = class extends ArbiApiError {
|
|
3537
|
+
contactId;
|
|
3538
|
+
constructor(message, contactId, apiError) {
|
|
3539
|
+
super(message, apiError ?? { detail: message }, 409);
|
|
3540
|
+
this.name = "DuplicateContactError";
|
|
3541
|
+
this.contactId = contactId;
|
|
3542
|
+
}
|
|
3543
|
+
};
|
|
3536
3544
|
function refusalReason(err, fallback) {
|
|
3537
3545
|
if (err instanceof ArbiApiError) return err.detail || fallback;
|
|
3538
3546
|
return apiErrorDetail(err) || fallback;
|
|
@@ -5027,8 +5035,20 @@ var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
5027
5035
|
function sanitizeFolderPath(folderPath) {
|
|
5028
5036
|
return folderPath.replace(/[\x00-\x1f\x7f]/g, "").replace(/\\/g, "/").replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "").trim();
|
|
5029
5037
|
}
|
|
5030
|
-
async function listDocuments(arbi) {
|
|
5031
|
-
|
|
5038
|
+
async function listDocuments(arbi, workspaceExtId) {
|
|
5039
|
+
if (!workspaceExtId) {
|
|
5040
|
+
return requireData(await arbi.fetch.GET("/v1/document/list"), "Failed to fetch documents");
|
|
5041
|
+
}
|
|
5042
|
+
const docs = requireData(
|
|
5043
|
+
await arbi.fetch.GET("/v1/document/list", {
|
|
5044
|
+
params: { query: { workspace_ext_id: workspaceExtId } }
|
|
5045
|
+
}),
|
|
5046
|
+
"Failed to fetch documents"
|
|
5047
|
+
);
|
|
5048
|
+
if (docs.some((doc) => doc.workspace_ext_id !== workspaceExtId)) {
|
|
5049
|
+
throw new ArbiError(`This server cannot list workspace ${workspaceExtId} without opening it`);
|
|
5050
|
+
}
|
|
5051
|
+
return docs;
|
|
5032
5052
|
}
|
|
5033
5053
|
async function* listPaginated(arbi, options = {}) {
|
|
5034
5054
|
const {
|
|
@@ -5474,12 +5494,14 @@ async function suggestSignatureFields(arbi, docId, version) {
|
|
|
5474
5494
|
return data.fields;
|
|
5475
5495
|
}
|
|
5476
5496
|
function assignSuggestions(suggestions, signers) {
|
|
5477
|
-
const groups = [...new Set(suggestions.map((s2) => s2.group))];
|
|
5497
|
+
const groups = [...new Set(suggestions.filter((s2) => !s2.signer_email).map((s2) => s2.group))];
|
|
5478
5498
|
return suggestions.flatMap((s2, i2) => {
|
|
5479
|
-
const signer = signers[groups.indexOf(s2.group)];
|
|
5499
|
+
const signer = s2.signer_email ?? signers[groups.indexOf(s2.group)];
|
|
5480
5500
|
if (!signer) return [];
|
|
5481
5501
|
const { type, page, x: x2, y: y2, width, height } = s2;
|
|
5482
|
-
return [
|
|
5502
|
+
return [
|
|
5503
|
+
{ id: `s${i2 + 1}`, type, page, x: x2, y: y2, width, height, signer, required: s2.required ?? true }
|
|
5504
|
+
];
|
|
5483
5505
|
});
|
|
5484
5506
|
}
|
|
5485
5507
|
async function createSignatureRequest(arbi, docId, { fields, version, message, send = true }) {
|
|
@@ -5673,10 +5695,13 @@ async function grantTemporaryWorkspaceAccess(arbi, params) {
|
|
|
5673
5695
|
"Failed to grant temporary access"
|
|
5674
5696
|
);
|
|
5675
5697
|
}
|
|
5676
|
-
async function removeWorkspaceUsers(arbi, userIds) {
|
|
5698
|
+
async function removeWorkspaceUsers(arbi, userIds, workspaceExtId) {
|
|
5677
5699
|
requireOk(
|
|
5678
5700
|
await arbi.fetch.DELETE("/v1/workspace/users", {
|
|
5679
|
-
body: {
|
|
5701
|
+
body: {
|
|
5702
|
+
users: userIds.map((id) => ({ user_ext_id: id })),
|
|
5703
|
+
...workspaceExtId ? { workspace_ext_id: workspaceExtId } : {}
|
|
5704
|
+
}
|
|
5680
5705
|
}),
|
|
5681
5706
|
"Failed to remove users"
|
|
5682
5707
|
);
|
|
@@ -5983,7 +6008,7 @@ async function listSkills(arbi, options) {
|
|
|
5983
6008
|
return result.skills;
|
|
5984
6009
|
}
|
|
5985
6010
|
function isSharedSkill(skill) {
|
|
5986
|
-
return skill.is_owner
|
|
6011
|
+
return (skill.is_owner ?? true) && skill.visibility === "global";
|
|
5987
6012
|
}
|
|
5988
6013
|
function uploadSkill(auth, slug, markdown, options) {
|
|
5989
6014
|
return uploadFile(auth, new Blob([markdown], { type: "text/markdown" }), "SKILL.md", {
|
|
@@ -6255,11 +6280,23 @@ __export(contacts_exports, {
|
|
|
6255
6280
|
createContact: () => createContact,
|
|
6256
6281
|
deleteContact: () => deleteContact,
|
|
6257
6282
|
groupContactsByStatus: () => groupContactsByStatus,
|
|
6283
|
+
importContacts: () => importContacts,
|
|
6258
6284
|
inviteContacts: () => inviteContacts,
|
|
6285
|
+
linkContact: () => linkContact,
|
|
6259
6286
|
listContacts: () => listContacts,
|
|
6260
6287
|
searchContacts: () => searchContacts,
|
|
6261
6288
|
updateContact: () => updateContact
|
|
6262
6289
|
});
|
|
6290
|
+
function requireContact(result, message) {
|
|
6291
|
+
const error = result.error;
|
|
6292
|
+
if (result.response?.status === 409 && error && typeof error === "object" && "contact_id" in error)
|
|
6293
|
+
throw new DuplicateContactError(
|
|
6294
|
+
apiErrorDetail(error) ?? "This person is already in your contacts",
|
|
6295
|
+
error.contact_id || null,
|
|
6296
|
+
error
|
|
6297
|
+
);
|
|
6298
|
+
return requireData(result, message);
|
|
6299
|
+
}
|
|
6263
6300
|
async function listContacts(arbi) {
|
|
6264
6301
|
return requireData(await arbi.fetch.GET("/v1/contacts/"), "Failed to fetch contacts");
|
|
6265
6302
|
}
|
|
@@ -6270,10 +6307,13 @@ async function inviteContacts(arbi, emails) {
|
|
|
6270
6307
|
);
|
|
6271
6308
|
}
|
|
6272
6309
|
async function createContact(arbi, body) {
|
|
6273
|
-
return
|
|
6310
|
+
return requireContact(
|
|
6311
|
+
await arbi.fetch.POST("/v1/contacts/", { body }),
|
|
6312
|
+
"Failed to create contact"
|
|
6313
|
+
);
|
|
6274
6314
|
}
|
|
6275
6315
|
async function updateContact(arbi, contactId, card) {
|
|
6276
|
-
return
|
|
6316
|
+
return requireContact(
|
|
6277
6317
|
await arbi.fetch.PATCH("/v1/contacts/{cnt_id}", {
|
|
6278
6318
|
params: { path: { cnt_id: contactId } },
|
|
6279
6319
|
body: { card, invite: false }
|
|
@@ -6281,12 +6321,32 @@ async function updateContact(arbi, contactId, card) {
|
|
|
6281
6321
|
"Failed to update contact"
|
|
6282
6322
|
);
|
|
6283
6323
|
}
|
|
6324
|
+
async function linkContact(arbi, contactId, email, card) {
|
|
6325
|
+
return requireContact(
|
|
6326
|
+
await arbi.fetch.PATCH("/v1/contacts/{cnt_id}", {
|
|
6327
|
+
params: { path: { cnt_id: contactId } },
|
|
6328
|
+
body: { card, email, invite: true }
|
|
6329
|
+
}),
|
|
6330
|
+
"Failed to link contact"
|
|
6331
|
+
);
|
|
6332
|
+
}
|
|
6284
6333
|
async function deleteContact(arbi, contactId) {
|
|
6285
6334
|
requireOk(
|
|
6286
6335
|
await arbi.fetch.DELETE("/v1/contacts/{cnt_id}", { params: { path: { cnt_id: contactId } } }),
|
|
6287
6336
|
"Failed to delete contact"
|
|
6288
6337
|
);
|
|
6289
6338
|
}
|
|
6339
|
+
async function importContacts(arbi, file) {
|
|
6340
|
+
const form = new FormData();
|
|
6341
|
+
form.append("file", file);
|
|
6342
|
+
return requireData(
|
|
6343
|
+
await arbi.fetch.POST("/v1/contacts/import", {
|
|
6344
|
+
body: { file: "" },
|
|
6345
|
+
bodySerializer: () => form
|
|
6346
|
+
}),
|
|
6347
|
+
"Failed to import contacts"
|
|
6348
|
+
);
|
|
6349
|
+
}
|
|
6290
6350
|
async function searchContacts(arbi, q2) {
|
|
6291
6351
|
return requireData(
|
|
6292
6352
|
await arbi.fetch.GET("/v1/contacts/search", { params: { query: { q: q2 } } }),
|
|
@@ -6358,8 +6418,11 @@ var chats_exports = {};
|
|
|
6358
6418
|
__export(chats_exports, {
|
|
6359
6419
|
CHAT_ATTACHMENT_MAX_BYTES: () => CHAT_ATTACHMENT_MAX_BYTES,
|
|
6360
6420
|
CHAT_ATTACHMENT_MAX_FILES: () => CHAT_ATTACHMENT_MAX_FILES,
|
|
6421
|
+
CHAT_PAGE_SIZE: () => CHAT_PAGE_SIZE,
|
|
6361
6422
|
DECRYPTION_FAILED: () => DECRYPTION_FAILED,
|
|
6423
|
+
ENCRYPTED_PREVIEW: () => ENCRYPTED_PREVIEW,
|
|
6362
6424
|
addChatMembers: () => addChatMembers,
|
|
6425
|
+
chatMessagePreview: () => chatMessagePreview,
|
|
6363
6426
|
chatMessageTombstone: () => chatMessageTombstone,
|
|
6364
6427
|
checkChatAttachmentLimits: () => checkChatAttachmentLimits,
|
|
6365
6428
|
createChatCryptoContext: () => createChatCryptoContext,
|
|
@@ -6376,6 +6439,7 @@ __export(chats_exports, {
|
|
|
6376
6439
|
getChat: () => getChat,
|
|
6377
6440
|
hasRead: () => hasRead,
|
|
6378
6441
|
isAgentExtId: () => isAgentExtId,
|
|
6442
|
+
isTranscriptMessage: () => isTranscriptMessage,
|
|
6379
6443
|
listChatMessages: () => listChatMessages,
|
|
6380
6444
|
listChats: () => listChats,
|
|
6381
6445
|
loadDecryptedChat: () => loadDecryptedChat,
|
|
@@ -6383,6 +6447,8 @@ __export(chats_exports, {
|
|
|
6383
6447
|
openChatKeyRing: () => openChatKeyRing,
|
|
6384
6448
|
openDirectChat: () => openDirectChat,
|
|
6385
6449
|
parseChatAttachmentManifest: () => parseChatAttachmentManifest,
|
|
6450
|
+
parseTranscriptContent: () => parseTranscriptContent,
|
|
6451
|
+
readByOthers: () => readByOthers,
|
|
6386
6452
|
removeChatMember: () => removeChatMember,
|
|
6387
6453
|
renameChat: () => renameChat,
|
|
6388
6454
|
resolveRecipient: () => resolveRecipient,
|
|
@@ -6679,6 +6745,39 @@ function chatMessageTombstone(message) {
|
|
|
6679
6745
|
delete row.attachmentsError;
|
|
6680
6746
|
return row;
|
|
6681
6747
|
}
|
|
6748
|
+
function isTranscriptMessage(message) {
|
|
6749
|
+
return message.kind === "transcript";
|
|
6750
|
+
}
|
|
6751
|
+
function parseTranscriptContent(content) {
|
|
6752
|
+
if (!content) return null;
|
|
6753
|
+
try {
|
|
6754
|
+
const parsed = JSON.parse(content);
|
|
6755
|
+
if (!parsed || typeof parsed !== "object") return null;
|
|
6756
|
+
const p2 = parsed;
|
|
6757
|
+
if (typeof p2.text !== "string") return null;
|
|
6758
|
+
return {
|
|
6759
|
+
text: p2.text,
|
|
6760
|
+
speaker_identity: typeof p2.speaker_identity === "string" ? p2.speaker_identity : "",
|
|
6761
|
+
speaker_name: typeof p2.speaker_name === "string" ? p2.speaker_name : "",
|
|
6762
|
+
started_at: typeof p2.started_at === "string" ? p2.started_at : null
|
|
6763
|
+
};
|
|
6764
|
+
} catch {
|
|
6765
|
+
return null;
|
|
6766
|
+
}
|
|
6767
|
+
}
|
|
6768
|
+
var ENCRYPTED_PREVIEW = "[Encrypted]";
|
|
6769
|
+
function chatMessagePreview(message) {
|
|
6770
|
+
if (message.deleted) return null;
|
|
6771
|
+
if (message.kind === "call") return "Call";
|
|
6772
|
+
if (message.kind === "recording") return "Recording";
|
|
6773
|
+
if (message.decryptFailed) return ENCRYPTED_PREVIEW;
|
|
6774
|
+
const transcript = isTranscriptMessage(message) ? parseTranscriptContent(message.content) : null;
|
|
6775
|
+
if (transcript) {
|
|
6776
|
+
return `Transcript \xB7 ${transcript.speaker_name ? `${transcript.speaker_name}: ` : ""}${transcript.text}`;
|
|
6777
|
+
}
|
|
6778
|
+
if (message.content) return message.content;
|
|
6779
|
+
return message.attachmentFiles?.length ? `\u{1F4CE} ${message.attachmentFiles.map((f2) => f2.name).join(", ")}` : null;
|
|
6780
|
+
}
|
|
6682
6781
|
async function decryptChatMessage(ring, message) {
|
|
6683
6782
|
if (message.deleted) return chatMessageTombstone(message);
|
|
6684
6783
|
const key = ring.keys.get(message.key_version);
|
|
@@ -6779,12 +6878,18 @@ async function renameChat(arbi, ring, title) {
|
|
|
6779
6878
|
"Failed to rename chat"
|
|
6780
6879
|
);
|
|
6781
6880
|
}
|
|
6782
|
-
async function addChatMembers(arbi, ring, members) {
|
|
6881
|
+
async function addChatMembers(arbi, ring, members, options = {}) {
|
|
6783
6882
|
if (ring.kind === "direct") {
|
|
6784
6883
|
throw new Error("A direct chat cannot gain members: create a group instead");
|
|
6785
6884
|
}
|
|
6786
6885
|
if (members.some((m2) => isAgentExtId(m2.external_id))) {
|
|
6787
|
-
throw new Error(
|
|
6886
|
+
throw new Error(
|
|
6887
|
+
ring.kind === "meeting" ? "Personal agents cannot join a meeting chat" : "Personal agents cannot join a group chat"
|
|
6888
|
+
);
|
|
6889
|
+
}
|
|
6890
|
+
const callKey = options.callKey ?? null;
|
|
6891
|
+
if (ring.kind === "meeting" && !callKey) {
|
|
6892
|
+
throw new Error("You do not hold this meeting\u2019s call key");
|
|
6788
6893
|
}
|
|
6789
6894
|
const key = keyFor(ring, ring.currentVersion);
|
|
6790
6895
|
return requireData(
|
|
@@ -6794,7 +6899,8 @@ async function addChatMembers(arbi, ring, members) {
|
|
|
6794
6899
|
members: await Promise.all(
|
|
6795
6900
|
members.map(async (m2) => ({
|
|
6796
6901
|
user_ext_id: m2.external_id,
|
|
6797
|
-
sealed_key: await client.sealChatKey(key, m2.encryption_public_key)
|
|
6902
|
+
sealed_key: await client.sealChatKey(key, m2.encryption_public_key),
|
|
6903
|
+
...callKey ? { call_sealed_key: await client.sealCallKey(callKey, m2.encryption_public_key) } : {}
|
|
6798
6904
|
}))
|
|
6799
6905
|
)
|
|
6800
6906
|
}
|
|
@@ -6847,6 +6953,7 @@ async function ensureChatKeyCurrent(arbi, chat, crypto2) {
|
|
|
6847
6953
|
throw err;
|
|
6848
6954
|
}
|
|
6849
6955
|
}
|
|
6956
|
+
var CHAT_PAGE_SIZE = 50;
|
|
6850
6957
|
async function listChatMessages(arbi, chatExtId, options) {
|
|
6851
6958
|
return requireData(
|
|
6852
6959
|
await arbi.fetch.GET("/v1/chats/{chat_ext_id}/messages", {
|
|
@@ -6909,6 +7016,10 @@ function hasRead(member, message) {
|
|
|
6909
7016
|
if (!member?.last_read_at) return false;
|
|
6910
7017
|
return Date.parse(member.last_read_at) >= Date.parse(message.created_at);
|
|
6911
7018
|
}
|
|
7019
|
+
function readByOthers(chat, myExtId, message) {
|
|
7020
|
+
const others = chat.members.filter((m2) => m2.user.external_id !== myExtId);
|
|
7021
|
+
return others.every((m2) => hasRead(m2, message));
|
|
7022
|
+
}
|
|
6912
7023
|
async function resolveRecipient(arbi, ref) {
|
|
6913
7024
|
const isEmail = ref.includes("@");
|
|
6914
7025
|
const matchKey = isEmail ? "email" : "external_id";
|
|
@@ -7450,7 +7561,6 @@ async function getFileContent(auth, fileId) {
|
|
|
7450
7561
|
// src/operations/sessions.ts
|
|
7451
7562
|
var sessions_exports = {};
|
|
7452
7563
|
__export(sessions_exports, {
|
|
7453
|
-
currentSessionId: () => currentSessionId,
|
|
7454
7564
|
listSessions: () => listSessions,
|
|
7455
7565
|
logoutAllSessions: () => logoutAllSessions,
|
|
7456
7566
|
terminateSession: () => terminateSession
|
|
@@ -7473,16 +7583,6 @@ async function logoutAllSessions(arbi) {
|
|
|
7473
7583
|
"Failed to sign out of all sessions"
|
|
7474
7584
|
);
|
|
7475
7585
|
}
|
|
7476
|
-
function currentSessionId(accessToken) {
|
|
7477
|
-
const payload = accessToken?.split(".")[1];
|
|
7478
|
-
if (!payload) return null;
|
|
7479
|
-
try {
|
|
7480
|
-
const claims = JSON.parse(atob(payload.replace(/-/g, "+").replace(/_/g, "/")));
|
|
7481
|
-
return typeof claims.sk === "string" ? claims.sk.slice(0, 12) : null;
|
|
7482
|
-
} catch {
|
|
7483
|
-
return null;
|
|
7484
|
-
}
|
|
7485
|
-
}
|
|
7486
7586
|
|
|
7487
7587
|
// src/operations/profile.ts
|
|
7488
7588
|
var profile_exports = {};
|
|
@@ -7520,9 +7620,13 @@ async function topUpFirmPool(arbi, aiAddons) {
|
|
|
7520
7620
|
var account_exports = {};
|
|
7521
7621
|
__export(account_exports, {
|
|
7522
7622
|
confirmEmailChange: () => confirmEmailChange,
|
|
7623
|
+
getEntitlements: () => getEntitlements,
|
|
7523
7624
|
requestDeletion: () => requestDeletion,
|
|
7524
7625
|
requestEmailChange: () => requestEmailChange
|
|
7525
7626
|
});
|
|
7627
|
+
async function getEntitlements(arbi) {
|
|
7628
|
+
return requireData(await arbi.fetch.GET("/v1/user/entitlements"), "Failed to load entitlements");
|
|
7629
|
+
}
|
|
7526
7630
|
async function requestEmailChange(arbi, newEmail) {
|
|
7527
7631
|
requireOk(
|
|
7528
7632
|
await arbi.fetch.POST("/v1/user/request-email-change", { body: { new_email: newEmail } }),
|
|
@@ -9429,15 +9533,8 @@ async function cancelPublicBooking(baseUrl, slug, token) {
|
|
|
9429
9533
|
|
|
9430
9534
|
// src/arbi.ts
|
|
9431
9535
|
function tokenExpiresWithin(token, seconds) {
|
|
9432
|
-
const
|
|
9433
|
-
|
|
9434
|
-
try {
|
|
9435
|
-
const json2 = atob(payload.replace(/-/g, "+").replace(/_/g, "/"));
|
|
9436
|
-
const { exp } = JSON.parse(json2);
|
|
9437
|
-
return typeof exp === "number" && exp * 1e3 - Date.now() < seconds * 1e3;
|
|
9438
|
-
} catch {
|
|
9439
|
-
return false;
|
|
9440
|
-
}
|
|
9536
|
+
const expiresAt = client.readSessionClaims(token)?.expiresAt;
|
|
9537
|
+
return expiresAt != null && expiresAt - Date.now() < seconds * 1e3;
|
|
9441
9538
|
}
|
|
9442
9539
|
var Arbi = class {
|
|
9443
9540
|
client = null;
|
|
@@ -9447,7 +9544,12 @@ var Arbi = class {
|
|
|
9447
9544
|
currentWorkspaceId = null;
|
|
9448
9545
|
/** Wrapped workspace keys seen in the last list/create, so selecting needs no re-fetch. */
|
|
9449
9546
|
wrappedKeys = /* @__PURE__ */ new Map();
|
|
9547
|
+
/** Workspaces whose key this server session holds (`workspaces.open`), keyed per session key. */
|
|
9548
|
+
openedWorkspaces = /* @__PURE__ */ new Map();
|
|
9549
|
+
openedForSessionKey = null;
|
|
9450
9550
|
chatCryptoContext = null;
|
|
9551
|
+
/** The chat keys I hold, opened once per set of epochs (`chatRingSignature`). */
|
|
9552
|
+
chatRings = /* @__PURE__ */ new Map();
|
|
9451
9553
|
sessionExpiredListeners = /* @__PURE__ */ new Set();
|
|
9452
9554
|
options;
|
|
9453
9555
|
constructor(options) {
|
|
@@ -9583,9 +9685,41 @@ var Arbi = class {
|
|
|
9583
9685
|
);
|
|
9584
9686
|
}
|
|
9585
9687
|
/**
|
|
9586
|
-
*
|
|
9587
|
-
*
|
|
9588
|
-
*
|
|
9688
|
+
* Make a workspace usable for requests that name it, WITHOUT changing the current workspace (on
|
|
9689
|
+
* the server or here): its key, sealed to this server session, is deposited with `/prime-key`.
|
|
9690
|
+
* Idempotent: cached per server session (a re-login rotates it), concurrent calls share one
|
|
9691
|
+
* request, and the current workspace is already open.
|
|
9692
|
+
*/
|
|
9693
|
+
openWorkspace(workspaceId) {
|
|
9694
|
+
if (workspaceId === this.currentWorkspaceId) return Promise.resolve();
|
|
9695
|
+
const lr2 = this.requireLogin();
|
|
9696
|
+
if (this.openedForSessionKey !== lr2.serverSessionKey) {
|
|
9697
|
+
this.openedWorkspaces.clear();
|
|
9698
|
+
this.openedForSessionKey = lr2.serverSessionKey;
|
|
9699
|
+
}
|
|
9700
|
+
const cached = this.openedWorkspaces.get(workspaceId);
|
|
9701
|
+
if (cached) return cached;
|
|
9702
|
+
const opening = this.sealWorkspaceKey(workspaceId).then(
|
|
9703
|
+
(sealedKey) => primeWorkspaceKey(this.requireClient(), workspaceId, sealedKey)
|
|
9704
|
+
);
|
|
9705
|
+
this.openedWorkspaces.set(workspaceId, opening);
|
|
9706
|
+
opening.catch(() => {
|
|
9707
|
+
if (this.openedWorkspaces.get(workspaceId) === opening)
|
|
9708
|
+
this.openedWorkspaces.delete(workspaceId);
|
|
9709
|
+
});
|
|
9710
|
+
return opening;
|
|
9711
|
+
}
|
|
9712
|
+
/** The workspace a call names, opened for this session; `undefined` for the current one. */
|
|
9713
|
+
async targetWorkspace(workspaceId) {
|
|
9714
|
+
if (!workspaceId || workspaceId === this.currentWorkspaceId) return void 0;
|
|
9715
|
+
await this.openWorkspace(workspaceId);
|
|
9716
|
+
return workspaceId;
|
|
9717
|
+
}
|
|
9718
|
+
/**
|
|
9719
|
+
* Make a workspace the CURRENT one: decrypt its key, open it on the server (which makes it the
|
|
9720
|
+
* session's active workspace) and record it in the session. This is navigation: only the host's
|
|
9721
|
+
* workspace switch calls it. Package code that needs another workspace calls
|
|
9722
|
+
* `workspaces.open(id)` and passes the workspace to the request instead.
|
|
9589
9723
|
*/
|
|
9590
9724
|
async selectWorkspace(workspaceId) {
|
|
9591
9725
|
const client = this.requireClient();
|
|
@@ -9626,6 +9760,7 @@ var Arbi = class {
|
|
|
9626
9760
|
this.currentWorkspaceId = null;
|
|
9627
9761
|
this.wrappedKeys.clear();
|
|
9628
9762
|
this.chatCryptoContext = null;
|
|
9763
|
+
this.chatRings.clear();
|
|
9629
9764
|
this.client?.session.clear();
|
|
9630
9765
|
for (const listener of [...this.sessionExpiredListeners]) listener();
|
|
9631
9766
|
}
|
|
@@ -9672,6 +9807,7 @@ var Arbi = class {
|
|
|
9672
9807
|
this.currentWorkspaceId = null;
|
|
9673
9808
|
this.wrappedKeys.clear();
|
|
9674
9809
|
this.chatCryptoContext = null;
|
|
9810
|
+
this.chatRings.clear();
|
|
9675
9811
|
}
|
|
9676
9812
|
// ── Accessors ─────────────────────────────────────────────────────────
|
|
9677
9813
|
/** Get the underlying ArbiClient (throws if not initialized). */
|
|
@@ -9812,6 +9948,8 @@ var Arbi = class {
|
|
|
9812
9948
|
};
|
|
9813
9949
|
// ── Account ───────────────────────────────────────────────────────────
|
|
9814
9950
|
account = {
|
|
9951
|
+
/** Which paid features (native mail, the calendar, hosting calls) this person may use, and why not. */
|
|
9952
|
+
entitlements: () => getEntitlements(this.requireClient()),
|
|
9815
9953
|
/** Send a verification code to the new address (not for SSO accounts). */
|
|
9816
9954
|
requestEmailChange: (newEmail) => requestEmailChange(this.requireClient(), newEmail),
|
|
9817
9955
|
/** Confirm the email change with the emailed code; the session and profile follow. */
|
|
@@ -9892,6 +10030,13 @@ var Arbi = class {
|
|
|
9892
10030
|
}
|
|
9893
10031
|
// ── Workspaces ────────────────────────────────────────────────────────
|
|
9894
10032
|
workspaces = {
|
|
10033
|
+
/**
|
|
10034
|
+
* Make a workspace usable for requests that name it, WITHOUT changing the current workspace
|
|
10035
|
+
* (on the server or in the host). `removeUsers` and `documents.list` open the workspace they
|
|
10036
|
+
* are given themselves; `documents.upload` with `workspaceExtId` needs it opened first.
|
|
10037
|
+
* Idempotent and cached per server session. Navigation uses `selectWorkspace`.
|
|
10038
|
+
*/
|
|
10039
|
+
open: (workspaceId) => this.openWorkspace(workspaceId),
|
|
9895
10040
|
/** Hand this server session a workspace's key (sealed to the session) without opening it. */
|
|
9896
10041
|
primeKey: (workspaceExtId, sessionSealedKey) => primeWorkspaceKey(this.requireClient(), workspaceExtId, sessionSealedKey),
|
|
9897
10042
|
list: async () => this.rememberWorkspaces(await listWorkspaces(this.requireClient())),
|
|
@@ -9959,7 +10104,12 @@ var Arbi = class {
|
|
|
9959
10104
|
workspaceExtId: params.workspaceId,
|
|
9960
10105
|
workspaceKey: await this.sealWorkspaceKey(params.workspaceId)
|
|
9961
10106
|
}),
|
|
9962
|
-
|
|
10107
|
+
/** Remove users (or agents) from the current workspace, or from `options.workspaceId`. */
|
|
10108
|
+
removeUsers: async (userIds, options) => removeWorkspaceUsers(
|
|
10109
|
+
this.requireClient(),
|
|
10110
|
+
userIds,
|
|
10111
|
+
await this.targetWorkspace(options?.workspaceId)
|
|
10112
|
+
),
|
|
9963
10113
|
setUserRole: (userIds, role) => setUserRole(this.requireClient(), userIds, role),
|
|
9964
10114
|
/**
|
|
9965
10115
|
* Ask another user to grant you workspace access. Builds the E2E-encrypted
|
|
@@ -9989,7 +10139,11 @@ var Arbi = class {
|
|
|
9989
10139
|
};
|
|
9990
10140
|
// ── Documents ─────────────────────────────────────────────────────────
|
|
9991
10141
|
documents = {
|
|
9992
|
-
|
|
10142
|
+
/** The current workspace's documents, or `options.workspaceId`'s (opened, not switched to). */
|
|
10143
|
+
list: async (options) => listDocuments(
|
|
10144
|
+
this.requireClient(),
|
|
10145
|
+
await this.targetWorkspace(options?.workspaceId)
|
|
10146
|
+
),
|
|
9993
10147
|
/**
|
|
9994
10148
|
* Async iterator that yields pages of documents sequentially.
|
|
9995
10149
|
* Use this for large workspaces to stream output as pages arrive.
|
|
@@ -10242,6 +10396,16 @@ var Arbi = class {
|
|
|
10242
10396
|
respond: (assistantMessageExtId, answer) => respondToAgent(this.requireClient(), assistantMessageExtId, answer),
|
|
10243
10397
|
/** The skills the caller can run (own + shared marketplace), metadata only. */
|
|
10244
10398
|
listSkills: (options) => listSkills(this.requireClient(), options),
|
|
10399
|
+
/**
|
|
10400
|
+
* Save a SKILL.md as the caller's skill ``slug``: private unless ``shared`` (pass
|
|
10401
|
+
* ``shared: isSharedSkill(skill)`` when changing an existing skill, so a shared one stays shared).
|
|
10402
|
+
*/
|
|
10403
|
+
uploadSkill: (slug, markdown, options) => {
|
|
10404
|
+
this.requireWorkspace();
|
|
10405
|
+
return this.recovering(
|
|
10406
|
+
() => uploadSkill(this.getAuthHeaders(), slug, markdown, options)
|
|
10407
|
+
);
|
|
10408
|
+
},
|
|
10245
10409
|
/**
|
|
10246
10410
|
* Search documents without LLM generation (retrieval only). No `docIds` searches the whole
|
|
10247
10411
|
* workspace; `searchChunks(result)` ranks the passages found.
|
|
@@ -10299,7 +10463,11 @@ var Arbi = class {
|
|
|
10299
10463
|
invite: (emails) => inviteContacts(this.requireClient(), emails),
|
|
10300
10464
|
create: (body) => this.withCalendarKeys((c2) => createContact(c2, body)),
|
|
10301
10465
|
update: (contactId, card) => this.withCalendarKeys((c2) => updateContact(c2, contactId, card)),
|
|
10466
|
+
/** Link a card-only contact to `email` (invites it, or links the account at once). */
|
|
10467
|
+
link: (contactId, email, card) => this.withCalendarKeys((c2) => linkContact(c2, contactId, email, card)),
|
|
10302
10468
|
delete: (contactId) => this.withCalendarKeys((c2) => deleteContact(c2, contactId)),
|
|
10469
|
+
/** Import one .vcf file (Pro). */
|
|
10470
|
+
import: (file) => this.withCalendarKeys((c2) => importContacts(c2, file)),
|
|
10303
10471
|
search: (q2) => this.withCalendarKeys((c2) => searchContacts(c2, q2)),
|
|
10304
10472
|
groupByStatus: groupContactsByStatus
|
|
10305
10473
|
};
|
|
@@ -10402,14 +10570,36 @@ var Arbi = class {
|
|
|
10402
10570
|
return this.chatCryptoContext;
|
|
10403
10571
|
}
|
|
10404
10572
|
/** Fetch a chat, sealing a new epoch first when it is `rotation_required`. */
|
|
10405
|
-
async readyChat(
|
|
10573
|
+
async readyChat(chat) {
|
|
10406
10574
|
const client = this.requireClient();
|
|
10407
10575
|
return ensureChatKeyCurrent(
|
|
10408
10576
|
client,
|
|
10409
|
-
await getChat(client,
|
|
10577
|
+
typeof chat === "string" ? await getChat(client, chat) : chat,
|
|
10410
10578
|
await this.requireChatCrypto()
|
|
10411
10579
|
);
|
|
10412
10580
|
}
|
|
10581
|
+
/**
|
|
10582
|
+
* The keys of `chat` I hold, opened once per set of epochs: a direct chat's pair key depends on
|
|
10583
|
+
* the members' public keys, a group's on the epochs sealed to me.
|
|
10584
|
+
*/
|
|
10585
|
+
chatRing(chat) {
|
|
10586
|
+
const sig = chat.kind === "direct" ? `d:${chat.members.map((m2) => `${m2.user.external_id}=${m2.user.encryption_public_key}`).join(",")}` : `g:${chat.key_version}:${(chat.my_keys ?? []).map((k2) => `${k2.version}=${k2.sealed_key}`).join(",")}`;
|
|
10587
|
+
const cached = this.chatRings.get(chat.external_id);
|
|
10588
|
+
if (cached && cached.sig === sig) return cached.ring;
|
|
10589
|
+
const ring = this.requireChatCrypto().then((crypto2) => openChatKeyRing(chat, crypto2));
|
|
10590
|
+
ring.catch(() => {
|
|
10591
|
+
if (this.chatRings.get(chat.external_id)?.ring === ring)
|
|
10592
|
+
this.chatRings.delete(chat.external_id);
|
|
10593
|
+
});
|
|
10594
|
+
this.chatRings.set(chat.external_id, { sig, ring });
|
|
10595
|
+
return ring;
|
|
10596
|
+
}
|
|
10597
|
+
/**
|
|
10598
|
+
* Chats: direct (a person, myself, or my own agent), group and meeting. Every message, title and
|
|
10599
|
+
* attachment is end-to-end encrypted under the chat key in this process; a caller passes and
|
|
10600
|
+
* gets plaintext and never handles keys. Operations on an open chat take the `ChatResponse`
|
|
10601
|
+
* (no refetch); the by-id forms fetch it first.
|
|
10602
|
+
*/
|
|
10413
10603
|
chats = {
|
|
10414
10604
|
/** My chats, most recently active first (raw: titles/last messages are ciphertext). */
|
|
10415
10605
|
list: (kind) => listChats(this.requireClient(), kind),
|
|
@@ -10418,6 +10608,33 @@ var Arbi = class {
|
|
|
10418
10608
|
openDirect: (peerExtId) => openDirectChat(this.requireClient(), peerExtId),
|
|
10419
10609
|
/** Create a group (epoch 1 sealed to every member). Agents are refused. */
|
|
10420
10610
|
createGroup: async (params) => createGroupChat(this.requireClient(), await this.requireChatCrypto(), params),
|
|
10611
|
+
/** Who I am in chats: my external id and the X25519 public key chat keys are sealed to. */
|
|
10612
|
+
identity: async () => {
|
|
10613
|
+
const crypto2 = await this.requireChatCrypto();
|
|
10614
|
+
return {
|
|
10615
|
+
externalId: crypto2.userExtId,
|
|
10616
|
+
publicKey: client.bytesToBase64(crypto2.encryptionKeypair.publicKey)
|
|
10617
|
+
};
|
|
10618
|
+
},
|
|
10619
|
+
/** The keys of a chat I hold (cached per set of epochs). */
|
|
10620
|
+
ring: (chat) => this.chatRing(chat),
|
|
10621
|
+
/** Make a chat postable: seal the next epoch when it is `rotation_required`. */
|
|
10622
|
+
ready: (chat) => this.readyChat(chat),
|
|
10623
|
+
/** One page of messages decrypted, oldest first; page back with `before` (the oldest id). */
|
|
10624
|
+
page: async (chat, options = {}) => {
|
|
10625
|
+
const limit = options.limit ?? CHAT_PAGE_SIZE;
|
|
10626
|
+
const raw = await listChatMessages(this.requireClient(), chat.external_id, {
|
|
10627
|
+
before: options.before,
|
|
10628
|
+
limit
|
|
10629
|
+
});
|
|
10630
|
+
const ring = await this.chatRing(chat);
|
|
10631
|
+
const messages = (await decryptChatMessages(ring, raw)).reverse();
|
|
10632
|
+
return { messages, hasMore: raw.length === limit };
|
|
10633
|
+
},
|
|
10634
|
+
/** Decrypt one message of `chat` (never throws: a failure is marked on the row). */
|
|
10635
|
+
decrypt: async (chat, message) => decryptChatMessage(await this.chatRing(chat), message),
|
|
10636
|
+
/** A group's title in plaintext; null when it has none or it does not open. */
|
|
10637
|
+
title: async (chat) => chat.title ? decryptChatTitle(await this.chatRing(chat), chat) : null,
|
|
10421
10638
|
/** A chat with its keys opened, title and newest messages decrypted (oldest first). */
|
|
10422
10639
|
load: async (chatExtId, options) => {
|
|
10423
10640
|
const chat = await this.readyChat(chatExtId);
|
|
@@ -10428,30 +10645,50 @@ var Arbi = class {
|
|
|
10428
10645
|
options
|
|
10429
10646
|
);
|
|
10430
10647
|
},
|
|
10431
|
-
/** Post plaintext to a chat (encrypted under its current epoch). */
|
|
10432
|
-
send: async (
|
|
10433
|
-
const
|
|
10434
|
-
|
|
10435
|
-
|
|
10648
|
+
/** Post plaintext to a chat (encrypted under its current epoch). Returns it decrypted. */
|
|
10649
|
+
send: async (chat, text, options) => {
|
|
10650
|
+
const ready = await this.readyChat(chat);
|
|
10651
|
+
return sendChatMessage(
|
|
10652
|
+
this.requireClient(),
|
|
10653
|
+
await this.chatRing(ready),
|
|
10654
|
+
text,
|
|
10655
|
+
options
|
|
10656
|
+
);
|
|
10436
10657
|
},
|
|
10437
|
-
rename: async (
|
|
10438
|
-
const
|
|
10439
|
-
|
|
10440
|
-
return renameChat(this.requireClient(), ring, title);
|
|
10658
|
+
rename: async (chat, title) => {
|
|
10659
|
+
const ready = await this.readyChat(chat);
|
|
10660
|
+
return renameChat(this.requireClient(), await this.chatRing(ready), title);
|
|
10441
10661
|
},
|
|
10442
|
-
|
|
10443
|
-
|
|
10444
|
-
const
|
|
10445
|
-
return addChatMembers(
|
|
10662
|
+
/** Add people; a meeting chat also needs its call key, sealed to each (`callKey`). */
|
|
10663
|
+
addMembers: async (chat, members, options) => {
|
|
10664
|
+
const ready = await this.readyChat(chat);
|
|
10665
|
+
return addChatMembers(
|
|
10666
|
+
this.requireClient(),
|
|
10667
|
+
await this.chatRing(ready),
|
|
10668
|
+
members,
|
|
10669
|
+
options
|
|
10670
|
+
);
|
|
10446
10671
|
},
|
|
10447
|
-
/**
|
|
10448
|
-
|
|
10672
|
+
/**
|
|
10673
|
+
* Remove a member (owner) or leave (own id). Removing someone seals the next epoch to the rest
|
|
10674
|
+
* straight away; when that fails, the next member to open the chat does it.
|
|
10675
|
+
*/
|
|
10676
|
+
removeMember: async (chat, userExtId) => {
|
|
10677
|
+
const chatExtId = typeof chat === "string" ? chat : chat.external_id;
|
|
10449
10678
|
await removeChatMember(this.requireClient(), chatExtId, userExtId);
|
|
10450
10679
|
const crypto2 = await this.requireChatCrypto();
|
|
10451
|
-
if (userExtId
|
|
10680
|
+
if (userExtId === crypto2.userExtId) return;
|
|
10681
|
+
try {
|
|
10682
|
+
await this.readyChat(chatExtId);
|
|
10683
|
+
} catch {
|
|
10684
|
+
}
|
|
10452
10685
|
},
|
|
10453
10686
|
markRead: (chatExtId, messageExtId) => markChatRead(this.requireClient(), chatExtId, messageExtId),
|
|
10454
|
-
deleteMessage: (chatExtId, messageExtId) => deleteChatMessage(this.requireClient(), chatExtId, messageExtId)
|
|
10687
|
+
deleteMessage: (chatExtId, messageExtId) => deleteChatMessage(this.requireClient(), chatExtId, messageExtId),
|
|
10688
|
+
/** Encrypt each file with its own key and upload the ciphertext (limits checked first). */
|
|
10689
|
+
uploadAttachments: (files) => uploadChatAttachments(this.requireClient(), files),
|
|
10690
|
+
/** Fetch, decrypt and size-check one attachment. */
|
|
10691
|
+
downloadAttachment: (file) => downloadChatAttachment(this.requireClient(), file)
|
|
10455
10692
|
};
|
|
10456
10693
|
/** Direct-chat conveniences addressed by peer (email or `usr-`/`agt-` id). */
|
|
10457
10694
|
dm = {
|
|
@@ -10658,7 +10895,7 @@ var Arbi = class {
|
|
|
10658
10895
|
sessions = {
|
|
10659
10896
|
list: () => listSessions(this.requireClient()),
|
|
10660
10897
|
/** The id this device's session is listed under in `list()`; `null` when unknown. */
|
|
10661
|
-
currentId: () =>
|
|
10898
|
+
currentId: () => client.readSessionClaims(this.client?.session.getState().accessToken)?.sessionId ?? null,
|
|
10662
10899
|
/** End one of your own sessions now (not the one this device is on: that is `logout`). */
|
|
10663
10900
|
terminate: (sessionId) => terminateSession(this.requireClient(), sessionId),
|
|
10664
10901
|
/** Sign out of every device on the server, then clear this instance. */
|
|
@@ -11880,6 +12117,7 @@ exports.ClaudeOrchestrator = ClaudeOrchestrator;
|
|
|
11880
12117
|
exports.DEFAULT_AI_USD_PER_GBP = DEFAULT_AI_USD_PER_GBP;
|
|
11881
12118
|
exports.DOC_TERMINAL_STATUSES = DOC_TERMINAL_STATUSES;
|
|
11882
12119
|
exports.DRIVE_SYNC_VENDORS = DRIVE_SYNC_VENDORS;
|
|
12120
|
+
exports.DuplicateContactError = DuplicateContactError;
|
|
11883
12121
|
exports.ENTITY_KINDS = ENTITY_KINDS;
|
|
11884
12122
|
exports.FLAT_TAG_KINDS = FLAT_TAG_KINDS;
|
|
11885
12123
|
exports.FileConfigStore = FileConfigStore;
|