@arbidocs/sdk 0.3.65 → 0.3.66
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-D2dkZnc9.d.cts → browser-6H2O896Y.d.cts} +55 -15
- package/dist/{browser-D2dkZnc9.d.ts → browser-6H2O896Y.d.ts} +55 -15
- package/dist/browser.cjs +96 -60
- 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 +96 -60
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +110 -62
- 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 +110 -62
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, S as SkippedFile, U as UploadResult, A as AuthHeaders, d as UploadBatchResult, e as UploadOptions, f as UploadDirectOptions, g as UploadDirectResult, h as SUPPORTED_EXTENSIONS, D as DmCryptoContext } from './browser-
|
|
2
|
-
export { i as AgentStepEvent, j as Arbi, k as ArbiApiError, l as ArbiError, m as ArbiOptions, n as ArtifactEvent, o as AuthContext, p as AuthenticatedClient, q as CitationSummary, r as ConnectOptions, s as DOC_TERMINAL_STATUSES, t as DocumentListFields, u as DocumentListOrder, v as DocumentWaiter, w as DocumentWaiterOptions, F as FormattedWsMessage, L as ListAllOptions, x as ListPaginatedOptions, M as MessageLevel, y as MessageMetadataPayload, z as MessageQueuedEvent, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, B as ReconnectableWsConnection, E as ResolvedCitation, G as ResponseCompletedEvent, H as ResponseContentPartAddedEvent, I as ResponseCreatedEvent, J as ResponseFailedEvent, K as ResponseOutputItemAddedEvent, N as ResponseOutputItemDoneEvent, P as ResponseOutputTextDeltaEvent, T as ResponseOutputTextDoneEvent, V as ResponseUsage, W as SSEEvent, X as SSEStreamCallbacks, Y as SSEStreamResult, Z as SSEStreamStartData, _ as UserInfo, $ as UserInputRequestEvent, a0 as UserMessageEvent, a1 as WorkspaceContext, a2 as WsConnection, a3 as agentconfig, a4 as assistant, a5 as authenticatedFetch, a6 as buildRetrievalChunkTool, a7 as buildRetrievalFullContextTool, a8 as buildRetrievalTocTool, a9 as connectWebSocket, aa as connectWithReconnect, ab as consumeSSEStream, ac as contacts, ad as conversations, ae as countCitations, af as createAuthenticatedClient, ag as createDocumentWaiter, ah as dm, ai as doctags, aj as documents, ak as files, al as formatAgentStepLabel, am as formatFileSize, an as formatStreamSummary, ao as formatUserName, ap as formatWorkspaceChoices, aq as formatWsMessage, ar as generateEncryptedWorkspaceKey, as as generateNewWorkspaceKey, at as getErrorCode, au as getErrorMessage, av as getRawWorkspaceKey, aw as health, ax as parseSSEEvents, ay as performPasswordLogin, az as performSigningKeyLogin, aA as performSsoDeviceFlowLogin, aB as requireData, aC as requireOk, aD as resolveAuth, aE as resolveCitations, aF as resolveWorkspace, aG as responses, aH as selectWorkspace, aI as selectWorkspaceById, aJ as settings, aK as streamSSE, aL as stripCitationMarkdown, aM as summarizeCitations, aN as tags, aO as workspaces } from './browser-
|
|
1
|
+
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, S as SkippedFile, U as UploadResult, A as AuthHeaders, d as UploadBatchResult, e as UploadOptions, f as UploadDirectOptions, g as UploadDirectResult, h as SUPPORTED_EXTENSIONS, D as DmCryptoContext } from './browser-6H2O896Y.cjs';
|
|
2
|
+
export { i as AgentStepEvent, j as Arbi, k as ArbiApiError, l as ArbiError, m as ArbiOptions, n as ArtifactEvent, o as AuthContext, p as AuthenticatedClient, q as CitationSummary, r as ConnectOptions, s as DOC_TERMINAL_STATUSES, t as DocumentListFields, u as DocumentListOrder, v as DocumentWaiter, w as DocumentWaiterOptions, F as FormattedWsMessage, L as ListAllOptions, x as ListPaginatedOptions, M as MessageLevel, y as MessageMetadataPayload, z as MessageQueuedEvent, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, B as ReconnectableWsConnection, E as ResolvedCitation, G as ResponseCompletedEvent, H as ResponseContentPartAddedEvent, I as ResponseCreatedEvent, J as ResponseFailedEvent, K as ResponseOutputItemAddedEvent, N as ResponseOutputItemDoneEvent, P as ResponseOutputTextDeltaEvent, T as ResponseOutputTextDoneEvent, V as ResponseUsage, W as SSEEvent, X as SSEStreamCallbacks, Y as SSEStreamResult, Z as SSEStreamStartData, _ as UserInfo, $ as UserInputRequestEvent, a0 as UserMessageEvent, a1 as WorkspaceContext, a2 as WsConnection, a3 as agentconfig, a4 as assistant, a5 as authenticatedFetch, a6 as buildRetrievalChunkTool, a7 as buildRetrievalFullContextTool, a8 as buildRetrievalTocTool, a9 as connectWebSocket, aa as connectWithReconnect, ab as consumeSSEStream, ac as contacts, ad as conversations, ae as countCitations, af as createAuthenticatedClient, ag as createDocumentWaiter, ah as dm, ai as doctags, aj as documents, ak as files, al as formatAgentStepLabel, am as formatFileSize, an as formatStreamSummary, ao as formatUserName, ap as formatWorkspaceChoices, aq as formatWsMessage, ar as generateEncryptedWorkspaceKey, as as generateNewWorkspaceKey, at as getErrorCode, au as getErrorMessage, av as getRawWorkspaceKey, aw as health, ax as parseSSEEvents, ay as performPasswordLogin, az as performSigningKeyLogin, aA as performSsoDeviceFlowLogin, aB as requireData, aC as requireOk, aD as resolveAuth, aE as resolveCitations, aF as resolveWorkspace, aG as responses, aH as selectWorkspace, aI as selectWorkspaceById, aJ as settings, aK as streamSSE, aL as stripCitationMarkdown, aM as summarizeCitations, aN as tags, aO as workspaces } from './browser-6H2O896Y.cjs';
|
|
3
3
|
import { SessionStorageProvider, ArbiClient, components } from '@arbidocs/client';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, S as SkippedFile, U as UploadResult, A as AuthHeaders, d as UploadBatchResult, e as UploadOptions, f as UploadDirectOptions, g as UploadDirectResult, h as SUPPORTED_EXTENSIONS, D as DmCryptoContext } from './browser-
|
|
2
|
-
export { i as AgentStepEvent, j as Arbi, k as ArbiApiError, l as ArbiError, m as ArbiOptions, n as ArtifactEvent, o as AuthContext, p as AuthenticatedClient, q as CitationSummary, r as ConnectOptions, s as DOC_TERMINAL_STATUSES, t as DocumentListFields, u as DocumentListOrder, v as DocumentWaiter, w as DocumentWaiterOptions, F as FormattedWsMessage, L as ListAllOptions, x as ListPaginatedOptions, M as MessageLevel, y as MessageMetadataPayload, z as MessageQueuedEvent, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, B as ReconnectableWsConnection, E as ResolvedCitation, G as ResponseCompletedEvent, H as ResponseContentPartAddedEvent, I as ResponseCreatedEvent, J as ResponseFailedEvent, K as ResponseOutputItemAddedEvent, N as ResponseOutputItemDoneEvent, P as ResponseOutputTextDeltaEvent, T as ResponseOutputTextDoneEvent, V as ResponseUsage, W as SSEEvent, X as SSEStreamCallbacks, Y as SSEStreamResult, Z as SSEStreamStartData, _ as UserInfo, $ as UserInputRequestEvent, a0 as UserMessageEvent, a1 as WorkspaceContext, a2 as WsConnection, a3 as agentconfig, a4 as assistant, a5 as authenticatedFetch, a6 as buildRetrievalChunkTool, a7 as buildRetrievalFullContextTool, a8 as buildRetrievalTocTool, a9 as connectWebSocket, aa as connectWithReconnect, ab as consumeSSEStream, ac as contacts, ad as conversations, ae as countCitations, af as createAuthenticatedClient, ag as createDocumentWaiter, ah as dm, ai as doctags, aj as documents, ak as files, al as formatAgentStepLabel, am as formatFileSize, an as formatStreamSummary, ao as formatUserName, ap as formatWorkspaceChoices, aq as formatWsMessage, ar as generateEncryptedWorkspaceKey, as as generateNewWorkspaceKey, at as getErrorCode, au as getErrorMessage, av as getRawWorkspaceKey, aw as health, ax as parseSSEEvents, ay as performPasswordLogin, az as performSigningKeyLogin, aA as performSsoDeviceFlowLogin, aB as requireData, aC as requireOk, aD as resolveAuth, aE as resolveCitations, aF as resolveWorkspace, aG as responses, aH as selectWorkspace, aI as selectWorkspaceById, aJ as settings, aK as streamSSE, aL as stripCitationMarkdown, aM as summarizeCitations, aN as tags, aO as workspaces } from './browser-
|
|
1
|
+
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, S as SkippedFile, U as UploadResult, A as AuthHeaders, d as UploadBatchResult, e as UploadOptions, f as UploadDirectOptions, g as UploadDirectResult, h as SUPPORTED_EXTENSIONS, D as DmCryptoContext } from './browser-6H2O896Y.js';
|
|
2
|
+
export { i as AgentStepEvent, j as Arbi, k as ArbiApiError, l as ArbiError, m as ArbiOptions, n as ArtifactEvent, o as AuthContext, p as AuthenticatedClient, q as CitationSummary, r as ConnectOptions, s as DOC_TERMINAL_STATUSES, t as DocumentListFields, u as DocumentListOrder, v as DocumentWaiter, w as DocumentWaiterOptions, F as FormattedWsMessage, L as ListAllOptions, x as ListPaginatedOptions, M as MessageLevel, y as MessageMetadataPayload, z as MessageQueuedEvent, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, B as ReconnectableWsConnection, E as ResolvedCitation, G as ResponseCompletedEvent, H as ResponseContentPartAddedEvent, I as ResponseCreatedEvent, J as ResponseFailedEvent, K as ResponseOutputItemAddedEvent, N as ResponseOutputItemDoneEvent, P as ResponseOutputTextDeltaEvent, T as ResponseOutputTextDoneEvent, V as ResponseUsage, W as SSEEvent, X as SSEStreamCallbacks, Y as SSEStreamResult, Z as SSEStreamStartData, _ as UserInfo, $ as UserInputRequestEvent, a0 as UserMessageEvent, a1 as WorkspaceContext, a2 as WsConnection, a3 as agentconfig, a4 as assistant, a5 as authenticatedFetch, a6 as buildRetrievalChunkTool, a7 as buildRetrievalFullContextTool, a8 as buildRetrievalTocTool, a9 as connectWebSocket, aa as connectWithReconnect, ab as consumeSSEStream, ac as contacts, ad as conversations, ae as countCitations, af as createAuthenticatedClient, ag as createDocumentWaiter, ah as dm, ai as doctags, aj as documents, ak as files, al as formatAgentStepLabel, am as formatFileSize, an as formatStreamSummary, ao as formatUserName, ap as formatWorkspaceChoices, aq as formatWsMessage, ar as generateEncryptedWorkspaceKey, as as generateNewWorkspaceKey, at as getErrorCode, au as getErrorMessage, av as getRawWorkspaceKey, aw as health, ax as parseSSEEvents, ay as performPasswordLogin, az as performSigningKeyLogin, aA as performSsoDeviceFlowLogin, aB as requireData, aC as requireOk, aD as resolveAuth, aE as resolveCitations, aF as resolveWorkspace, aG as responses, aH as selectWorkspace, aI as selectWorkspaceById, aJ as settings, aK as streamSSE, aL as stripCitationMarkdown, aM as summarizeCitations, aN as tags, aO as workspaces } from './browser-6H2O896Y.js';
|
|
3
3
|
import { SessionStorageProvider, ArbiClient, components } from '@arbidocs/client';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/index.js
CHANGED
|
@@ -3593,7 +3593,7 @@ var FileConfigStore = class {
|
|
|
3593
3593
|
sessionFile;
|
|
3594
3594
|
metadataFile;
|
|
3595
3595
|
constructor(configDir) {
|
|
3596
|
-
const arbiBase = process.env.ARBI_CONFIG_DIR ?? path2.join(os2.homedir(), ".arbi");
|
|
3596
|
+
const arbiBase = process.env.ARBI_CONFIG_DIR ?? (fs2.existsSync(path2.join(process.cwd(), ".arbi", "credentials.json")) ? path2.join(process.cwd(), ".arbi") : path2.join(os2.homedir(), ".arbi"));
|
|
3597
3597
|
const arbiId = process.env.ARBI_ID;
|
|
3598
3598
|
this.configDir = configDir ?? (arbiId ? path2.join(arbiBase, arbiId) : arbiBase);
|
|
3599
3599
|
this.configFile = path2.join(this.configDir, "config.json");
|
|
@@ -3691,12 +3691,12 @@ var FileConfigStore = class {
|
|
|
3691
3691
|
...existing,
|
|
3692
3692
|
signingPrivateKeyBase64: b64encode(data.signingPrivateKey),
|
|
3693
3693
|
serverSessionKeyBase64: data.serverSessionKey ? b64encode(data.serverSessionKey) : existing.serverSessionKeyBase64,
|
|
3694
|
-
// A fresh server session
|
|
3695
|
-
//
|
|
3696
|
-
// re-
|
|
3694
|
+
// A fresh server session = a fresh ``session.workspaces``
|
|
3695
|
+
// dict. The previous session's deposits do not transfer, so
|
|
3696
|
+
// wipe the client mirror to force re-deposit on next touch.
|
|
3697
3697
|
accessToken: void 0,
|
|
3698
|
-
|
|
3699
|
-
|
|
3698
|
+
tokenTimestamp: void 0,
|
|
3699
|
+
openedWorkspaces: void 0
|
|
3700
3700
|
});
|
|
3701
3701
|
}
|
|
3702
3702
|
};
|
|
@@ -3895,6 +3895,7 @@ function sleep(ms) {
|
|
|
3895
3895
|
}
|
|
3896
3896
|
|
|
3897
3897
|
// src/auth.ts
|
|
3898
|
+
var TOKEN_MAX_AGE_MS = 50 * 60 * 1e3;
|
|
3898
3899
|
function formatWorkspaceChoices(wsList) {
|
|
3899
3900
|
return wsList.map((ws) => {
|
|
3900
3901
|
const totalDocs = ws.shared_document_count + ws.private_document_count;
|
|
@@ -3925,11 +3926,11 @@ async function createAuthenticatedClient(config, creds, store) {
|
|
|
3925
3926
|
});
|
|
3926
3927
|
store.saveCredentials({
|
|
3927
3928
|
...creds,
|
|
3929
|
+
userExtId: loginResult.userExtId ?? creds.userExtId,
|
|
3928
3930
|
serverSessionKeyBase64: arbi.crypto.bytesToBase64(loginResult.serverSessionKey),
|
|
3929
3931
|
accessToken: void 0,
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
tokenTimestamp: void 0
|
|
3932
|
+
tokenTimestamp: void 0,
|
|
3933
|
+
openedWorkspaces: void 0
|
|
3933
3934
|
});
|
|
3934
3935
|
return { arbi, loginResult };
|
|
3935
3936
|
}
|
|
@@ -3939,13 +3940,18 @@ async function performPasswordLogin(config, email, password, store) {
|
|
|
3939
3940
|
const loginResult = await arbi.auth.login({ email, password });
|
|
3940
3941
|
store.saveCredentials({
|
|
3941
3942
|
email,
|
|
3943
|
+
userExtId: loginResult.userExtId,
|
|
3942
3944
|
signingPrivateKeyBase64: arbi.crypto.bytesToBase64(loginResult.signingPrivateKey),
|
|
3943
3945
|
serverSessionKeyBase64: arbi.crypto.bytesToBase64(loginResult.serverSessionKey),
|
|
3944
|
-
//
|
|
3946
|
+
// `parent_ext_id` is set for persistent agent accounts (the user is
|
|
3947
|
+
// an Assistant owned by another user). Persisting it makes the CLI's
|
|
3948
|
+
// `arbi listen` work — it requires this to confirm a real agent
|
|
3949
|
+
// identity. Regular users get `null`, which we store as `undefined`.
|
|
3950
|
+
parentExtId: loginResult.parentExtId ?? void 0,
|
|
3951
|
+
// New session = no workspaces deposited yet.
|
|
3945
3952
|
accessToken: void 0,
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
tokenTimestamp: void 0
|
|
3953
|
+
tokenTimestamp: void 0,
|
|
3954
|
+
openedWorkspaces: void 0
|
|
3949
3955
|
});
|
|
3950
3956
|
return { arbi, loginResult, config };
|
|
3951
3957
|
}
|
|
@@ -3956,12 +3962,13 @@ async function performSigningKeyLogin(config, email, signingPrivateKeyBase64, st
|
|
|
3956
3962
|
const loginResult = await arbi.auth.loginWithKey({ email, signingPrivateKey });
|
|
3957
3963
|
store.saveCredentials({
|
|
3958
3964
|
email,
|
|
3965
|
+
userExtId: loginResult.userExtId,
|
|
3959
3966
|
signingPrivateKeyBase64,
|
|
3960
3967
|
serverSessionKeyBase64: arbi.crypto.bytesToBase64(loginResult.serverSessionKey),
|
|
3968
|
+
parentExtId: loginResult.parentExtId ?? void 0,
|
|
3961
3969
|
accessToken: void 0,
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
tokenTimestamp: void 0
|
|
3970
|
+
tokenTimestamp: void 0,
|
|
3971
|
+
openedWorkspaces: void 0
|
|
3965
3972
|
});
|
|
3966
3973
|
return { arbi, loginResult, config };
|
|
3967
3974
|
}
|
|
@@ -3985,13 +3992,14 @@ async function performSsoDeviceFlowLogin(config, email, password, store, callbac
|
|
|
3985
3992
|
const loginResult = await arbi.auth.login({ email, password, ssoToken });
|
|
3986
3993
|
store.saveCredentials({
|
|
3987
3994
|
email,
|
|
3995
|
+
userExtId: loginResult.userExtId,
|
|
3988
3996
|
signingPrivateKeyBase64: arbi.crypto.bytesToBase64(loginResult.signingPrivateKey),
|
|
3989
3997
|
serverSessionKeyBase64: arbi.crypto.bytesToBase64(loginResult.serverSessionKey),
|
|
3998
|
+
parentExtId: loginResult.parentExtId ?? void 0,
|
|
3990
3999
|
ssoToken,
|
|
3991
4000
|
accessToken: void 0,
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
tokenTimestamp: void 0
|
|
4001
|
+
tokenTimestamp: void 0,
|
|
4002
|
+
openedWorkspaces: void 0
|
|
3995
4003
|
});
|
|
3996
4004
|
return { arbi, loginResult, config };
|
|
3997
4005
|
}
|
|
@@ -4041,38 +4049,79 @@ async function getRawWorkspaceKey(arbi, workspaceId, signingPrivateKeyBase64) {
|
|
|
4041
4049
|
});
|
|
4042
4050
|
return sealedBoxDecrypt(ws.wrapped_key, encryptionKeyPair.secretKey);
|
|
4043
4051
|
}
|
|
4052
|
+
async function openWorkspaceEntry(arbi, ws, serverSessionKey, signingPrivateKeyBase64) {
|
|
4053
|
+
if (ws.wrapped_key) {
|
|
4054
|
+
const sealedKey = await selectWorkspace(
|
|
4055
|
+
arbi,
|
|
4056
|
+
ws.external_id,
|
|
4057
|
+
ws.wrapped_key,
|
|
4058
|
+
serverSessionKey,
|
|
4059
|
+
signingPrivateKeyBase64
|
|
4060
|
+
);
|
|
4061
|
+
const { error: error2 } = await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/open", {
|
|
4062
|
+
params: { path: { workspace_ext_id: ws.external_id } },
|
|
4063
|
+
body: { workspace_key: sealedKey }
|
|
4064
|
+
});
|
|
4065
|
+
if (error2) {
|
|
4066
|
+
throw new ArbiError(`Workspace open failed for ${ws.external_id}: ${JSON.stringify(error2)}`);
|
|
4067
|
+
}
|
|
4068
|
+
return sealedKey;
|
|
4069
|
+
}
|
|
4070
|
+
arbi.session.setSelectedWorkspace(ws.external_id);
|
|
4071
|
+
const { error } = await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/open", {
|
|
4072
|
+
params: { path: { workspace_ext_id: ws.external_id } },
|
|
4073
|
+
body: {}
|
|
4074
|
+
});
|
|
4075
|
+
if (error) {
|
|
4076
|
+
throw new ArbiError(`Workspace open failed for ${ws.external_id}: ${JSON.stringify(error)}`);
|
|
4077
|
+
}
|
|
4078
|
+
return null;
|
|
4079
|
+
}
|
|
4044
4080
|
async function selectWorkspaceById(arbi, workspaceId, serverSessionKey, signingPrivateKeyBase64) {
|
|
4045
4081
|
const { data: workspaces, error } = await arbi.fetch.GET("/v1/user/workspaces");
|
|
4046
4082
|
if (error || !workspaces) {
|
|
4047
4083
|
throw new ArbiError("Failed to fetch workspaces");
|
|
4048
4084
|
}
|
|
4049
4085
|
const ws = workspaces.find((w2) => w2.external_id === workspaceId);
|
|
4050
|
-
if (!ws
|
|
4051
|
-
throw new ArbiError(`Workspace ${workspaceId} not found
|
|
4086
|
+
if (!ws) {
|
|
4087
|
+
throw new ArbiError(`Workspace ${workspaceId} not found`);
|
|
4052
4088
|
}
|
|
4053
|
-
const sealedKey = await
|
|
4054
|
-
|
|
4055
|
-
ws.external_id,
|
|
4056
|
-
ws.
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4089
|
+
const sealedKey = await openWorkspaceEntry(arbi, ws, serverSessionKey, signingPrivateKeyBase64);
|
|
4090
|
+
return {
|
|
4091
|
+
external_id: ws.external_id,
|
|
4092
|
+
name: ws.name,
|
|
4093
|
+
wrapped_key: ws.wrapped_key ?? null,
|
|
4094
|
+
sealed_key: sealedKey
|
|
4095
|
+
};
|
|
4096
|
+
}
|
|
4097
|
+
function isSessionAlive(creds) {
|
|
4098
|
+
return !!(creds.accessToken && creds.tokenTimestamp && Date.now() - new Date(creds.tokenTimestamp).getTime() < TOKEN_MAX_AGE_MS);
|
|
4099
|
+
}
|
|
4100
|
+
async function buildAuthFromCache(config, creds, store) {
|
|
4101
|
+
const arbi = createArbiClient(buildClientOptions(config, store, creds.email));
|
|
4102
|
+
await arbi.crypto.initSodium();
|
|
4103
|
+
arbi.session.setUser(creds.email, creds.userExtId);
|
|
4104
|
+
arbi.session.setAccessToken(creds.accessToken);
|
|
4105
|
+
const signingPrivateKey = base64ToBytes(creds.signingPrivateKeyBase64);
|
|
4106
|
+
const serverSessionKey = base64ToBytes(creds.serverSessionKeyBase64);
|
|
4107
|
+
const loginResult = {
|
|
4108
|
+
accessToken: creds.accessToken,
|
|
4109
|
+
userExtId: creds.userExtId,
|
|
4110
|
+
signingPrivateKey,
|
|
4111
|
+
serverSessionKey
|
|
4112
|
+
};
|
|
4113
|
+
return { arbi, loginResult };
|
|
4065
4114
|
}
|
|
4066
4115
|
async function resolveAuth(store) {
|
|
4067
4116
|
const config = store.requireConfig();
|
|
4068
4117
|
const creds = store.requireCredentials();
|
|
4118
|
+
if (isSessionAlive(creds)) {
|
|
4119
|
+
const { arbi: arbi2, loginResult: loginResult2 } = await buildAuthFromCache(config, creds, store);
|
|
4120
|
+
return { arbi: arbi2, loginResult: loginResult2, config };
|
|
4121
|
+
}
|
|
4069
4122
|
const { arbi, loginResult } = await createAuthenticatedClient(config, creds, store);
|
|
4070
4123
|
return { arbi, loginResult, config };
|
|
4071
4124
|
}
|
|
4072
|
-
var TOKEN_MAX_AGE_MS = 50 * 60 * 1e3;
|
|
4073
|
-
function isCachedTokenValid(creds, workspaceId) {
|
|
4074
|
-
return !!(creds.accessToken && creds.sealedWorkspaceKey && creds.workspaceId === workspaceId && creds.tokenTimestamp && Date.now() - new Date(creds.tokenTimestamp).getTime() < TOKEN_MAX_AGE_MS);
|
|
4075
|
-
}
|
|
4076
4125
|
async function resolveWorkspace(store, workspaceOpt) {
|
|
4077
4126
|
const config = store.requireConfig();
|
|
4078
4127
|
const creds = store.requireCredentials();
|
|
@@ -4080,53 +4129,52 @@ async function resolveWorkspace(store, workspaceOpt) {
|
|
|
4080
4129
|
if (!workspaceId) {
|
|
4081
4130
|
throw new ArbiError("No workspace selected. Run: arbi workspace select <id>");
|
|
4082
4131
|
}
|
|
4083
|
-
if (
|
|
4084
|
-
const arbi2 =
|
|
4085
|
-
await arbi2.crypto.initSodium();
|
|
4086
|
-
arbi2.session.setUser(creds.email);
|
|
4132
|
+
if (isSessionAlive(creds)) {
|
|
4133
|
+
const { arbi: arbi2, loginResult: loginResult2 } = await buildAuthFromCache(config, creds, store);
|
|
4087
4134
|
arbi2.session.setSelectedWorkspace(workspaceId);
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4135
|
+
await selectWorkspaceById(
|
|
4136
|
+
arbi2,
|
|
4137
|
+
workspaceId,
|
|
4138
|
+
loginResult2.serverSessionKey,
|
|
4139
|
+
creds.signingPrivateKeyBase64
|
|
4140
|
+
);
|
|
4141
|
+
const nextOpened = Array.from(/* @__PURE__ */ new Set([...creds.openedWorkspaces ?? [], workspaceId]));
|
|
4142
|
+
store.saveCredentials({
|
|
4143
|
+
...store.requireCredentials(),
|
|
4144
|
+
openedWorkspaces: nextOpened
|
|
4145
|
+
});
|
|
4096
4146
|
return {
|
|
4097
4147
|
arbi: arbi2,
|
|
4098
4148
|
loginResult: loginResult2,
|
|
4099
4149
|
config,
|
|
4100
4150
|
workspaceId,
|
|
4101
|
-
accessToken: creds.accessToken
|
|
4102
|
-
sealedWorkspaceKey: creds.sealedWorkspaceKey
|
|
4151
|
+
accessToken: creds.accessToken
|
|
4103
4152
|
};
|
|
4104
4153
|
}
|
|
4105
4154
|
const { arbi, loginResult } = await createAuthenticatedClient(config, creds, store);
|
|
4106
|
-
|
|
4155
|
+
await selectWorkspaceById(
|
|
4107
4156
|
arbi,
|
|
4108
4157
|
workspaceId,
|
|
4109
4158
|
loginResult.serverSessionKey,
|
|
4110
4159
|
creds.signingPrivateKeyBase64
|
|
4111
4160
|
);
|
|
4112
4161
|
const accessToken = arbi.session.getState().accessToken;
|
|
4113
|
-
const sealedWorkspaceKey = await generateEncryptedWorkspaceKey(
|
|
4114
|
-
arbi,
|
|
4115
|
-
wsInfo.wrapped_key,
|
|
4116
|
-
loginResult.serverSessionKey,
|
|
4117
|
-
creds.signingPrivateKeyBase64
|
|
4118
|
-
);
|
|
4119
4162
|
if (!accessToken) {
|
|
4120
4163
|
throw new ArbiError("Authentication error \u2014 missing token");
|
|
4121
4164
|
}
|
|
4122
4165
|
store.saveCredentials({
|
|
4123
4166
|
...store.requireCredentials(),
|
|
4124
4167
|
accessToken,
|
|
4125
|
-
|
|
4126
|
-
workspaceId
|
|
4127
|
-
tokenTimestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4168
|
+
tokenTimestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4169
|
+
openedWorkspaces: [workspaceId]
|
|
4128
4170
|
});
|
|
4129
|
-
return {
|
|
4171
|
+
return {
|
|
4172
|
+
arbi,
|
|
4173
|
+
loginResult,
|
|
4174
|
+
config,
|
|
4175
|
+
workspaceId,
|
|
4176
|
+
accessToken
|
|
4177
|
+
};
|
|
4130
4178
|
}
|
|
4131
4179
|
|
|
4132
4180
|
// src/sse.ts
|