@arbidocs/sdk 0.3.65 → 0.3.67

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/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-D2dkZnc9.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-D2dkZnc9.cjs';
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-B5xRfc7b.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, P as ParsedSlashCommand, 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, T as ResponseOutputTextDeltaEvent, V as ResponseOutputTextDoneEvent, W as ResponseUsage, X as SSEEvent, Y as SSEStreamCallbacks, Z as SSEStreamResult, _ as SSEStreamStartData, $ as SkillSummary, a0 as UserInfo, a1 as UserInputRequestEvent, a2 as UserMessageEvent, a3 as WorkspaceContext, a4 as WsConnection, a5 as agentconfig, a6 as assistant, a7 as authenticatedFetch, a8 as buildRetrievalChunkTool, a9 as buildRetrievalFullContextTool, aa as buildRetrievalTocTool, ab as connectWebSocket, ac as connectWithReconnect, ad as consumeSSEStream, ae as contacts, af as conversations, ag as countCitations, ah as createAuthenticatedClient, ai as createDocumentWaiter, aj as dm, ak as doctags, al as documents, am as files, an as filterSkills, ao as formatAgentStepLabel, ap as formatFileSize, aq as formatStreamSummary, ar as formatUserName, as as formatWorkspaceChoices, at as formatWsMessage, au as generateEncryptedWorkspaceKey, av as generateNewWorkspaceKey, aw as getErrorCode, ax as getErrorMessage, ay as getRawWorkspaceKey, az as health, aA as parseSSEEvents, aB as parseSlashCommand, aC as parseSlashTokenInProgress, aD as performPasswordLogin, aE as performSigningKeyLogin, aF as performSsoDeviceFlowLogin, aG as requireData, aH as requireOk, aI as resolveAuth, aJ as resolveCitations, aK as resolveWorkspace, aL as responses, aM as selectWorkspace, aN as selectWorkspaceById, aO as settings, aP as streamSSE, aQ as stripCitationMarkdown, aR as summarizeCitations, aS as tags, aT as workspaces } from './browser-B5xRfc7b.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-D2dkZnc9.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-D2dkZnc9.js';
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-B5xRfc7b.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, P as ParsedSlashCommand, 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, T as ResponseOutputTextDeltaEvent, V as ResponseOutputTextDoneEvent, W as ResponseUsage, X as SSEEvent, Y as SSEStreamCallbacks, Z as SSEStreamResult, _ as SSEStreamStartData, $ as SkillSummary, a0 as UserInfo, a1 as UserInputRequestEvent, a2 as UserMessageEvent, a3 as WorkspaceContext, a4 as WsConnection, a5 as agentconfig, a6 as assistant, a7 as authenticatedFetch, a8 as buildRetrievalChunkTool, a9 as buildRetrievalFullContextTool, aa as buildRetrievalTocTool, ab as connectWebSocket, ac as connectWithReconnect, ad as consumeSSEStream, ae as contacts, af as conversations, ag as countCitations, ah as createAuthenticatedClient, ai as createDocumentWaiter, aj as dm, ak as doctags, al as documents, am as files, an as filterSkills, ao as formatAgentStepLabel, ap as formatFileSize, aq as formatStreamSummary, ar as formatUserName, as as formatWorkspaceChoices, at as formatWsMessage, au as generateEncryptedWorkspaceKey, av as generateNewWorkspaceKey, aw as getErrorCode, ax as getErrorMessage, ay as getRawWorkspaceKey, az as health, aA as parseSSEEvents, aB as parseSlashCommand, aC as parseSlashTokenInProgress, aD as performPasswordLogin, aE as performSigningKeyLogin, aF as performSsoDeviceFlowLogin, aG as requireData, aH as requireOk, aI as resolveAuth, aJ as resolveCitations, aK as resolveWorkspace, aL as responses, aM as selectWorkspace, aN as selectWorkspaceById, aO as settings, aP as streamSSE, aQ as stripCitationMarkdown, aR as summarizeCitations, aS as tags, aT as workspaces } from './browser-B5xRfc7b.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 key invalidates any cached
3695
- // workspace-scoped token, so wipe those so the next request
3696
- // re-derives them from the new session.
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
- sealedWorkspaceKey: void 0,
3699
- tokenTimestamp: void 0
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
- sealedWorkspaceKey: void 0,
3931
- workspaceId: void 0,
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
- // Clear any cached workspace tokens new session key invalidates them
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
- sealedWorkspaceKey: void 0,
3947
- workspaceId: void 0,
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
- sealedWorkspaceKey: void 0,
3963
- workspaceId: void 0,
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
- sealedWorkspaceKey: void 0,
3993
- workspaceId: void 0,
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 || !ws.wrapped_key) {
4051
- throw new ArbiError(`Workspace ${workspaceId} not found or has no encryption key`);
4086
+ if (!ws) {
4087
+ throw new ArbiError(`Workspace ${workspaceId} not found`);
4052
4088
  }
4053
- const sealedKey = await selectWorkspace(
4054
- arbi,
4055
- ws.external_id,
4056
- ws.wrapped_key,
4057
- serverSessionKey,
4058
- signingPrivateKeyBase64
4059
- );
4060
- await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/open", {
4061
- params: { path: { workspace_ext_id: ws.external_id } },
4062
- body: { workspace_key: sealedKey }
4063
- });
4064
- return { external_id: ws.external_id, name: ws.name, wrapped_key: ws.wrapped_key };
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 (isCachedTokenValid(creds, workspaceId)) {
4084
- const arbi2 = createArbiClient(buildClientOptions(config, store, creds.email));
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
- arbi2.session.setAccessToken(creds.accessToken);
4089
- const signingPrivateKey = base64ToBytes(creds.signingPrivateKeyBase64);
4090
- const serverSessionKey = base64ToBytes(creds.serverSessionKeyBase64);
4091
- const loginResult2 = {
4092
- accessToken: creds.accessToken,
4093
- signingPrivateKey,
4094
- serverSessionKey
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
- const wsInfo = await selectWorkspaceById(
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
- sealedWorkspaceKey,
4126
- workspaceId,
4127
- tokenTimestamp: (/* @__PURE__ */ new Date()).toISOString()
4168
+ tokenTimestamp: (/* @__PURE__ */ new Date()).toISOString(),
4169
+ openedWorkspaces: [workspaceId]
4128
4170
  });
4129
- return { arbi, loginResult, config, workspaceId, accessToken, sealedWorkspaceKey };
4171
+ return {
4172
+ arbi,
4173
+ loginResult,
4174
+ config,
4175
+ workspaceId,
4176
+ accessToken
4177
+ };
4130
4178
  }
4131
4179
 
4132
4180
  // src/sse.ts
@@ -4834,6 +4882,7 @@ async function uploadFile(auth, fileData, fileName, options) {
4834
4882
  const params = new URLSearchParams();
4835
4883
  if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
4836
4884
  if (options?.configExtId) params.set("config_ext_id", options.configExtId);
4885
+ if (options?.wpType) params.set("wp_type", options.wpType);
4837
4886
  const qs = params.toString();
4838
4887
  const res = await authenticatedFetch({
4839
4888
  ...auth,
@@ -4849,6 +4898,7 @@ async function uploadFiles(auth, files, options) {
4849
4898
  const params = new URLSearchParams();
4850
4899
  if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
4851
4900
  if (options?.configExtId) params.set("config_ext_id", options.configExtId);
4901
+ if (options?.wpType) params.set("wp_type", options.wpType);
4852
4902
  const qs = params.toString();
4853
4903
  const res = await authenticatedFetch({
4854
4904
  ...auth,
@@ -5174,6 +5224,10 @@ __export(assistant_exports, {
5174
5224
  buildRetrievalChunkTool: () => buildRetrievalChunkTool,
5175
5225
  buildRetrievalFullContextTool: () => buildRetrievalFullContextTool,
5176
5226
  buildRetrievalTocTool: () => buildRetrievalTocTool,
5227
+ filterSkills: () => filterSkills,
5228
+ listSkills: () => listSkills,
5229
+ parseSlashCommand: () => parseSlashCommand,
5230
+ parseSlashTokenInProgress: () => parseSlashTokenInProgress,
5177
5231
  queryAssistant: () => queryAssistant,
5178
5232
  respondToAgent: () => respondToAgent,
5179
5233
  retrieve: () => retrieve
@@ -5269,6 +5323,40 @@ async function respondToAgent(arbi, assistantMessageExtId, answer) {
5269
5323
  "Failed to respond to agent"
5270
5324
  );
5271
5325
  }
5326
+ async function listSkills(arbi, options) {
5327
+ const result = requireData(
5328
+ await arbi.fetch.GET("/v1/assistant/skills", {
5329
+ params: { query: { include_hidden: options?.includeHidden ?? false } }
5330
+ }),
5331
+ "Failed to list skills"
5332
+ );
5333
+ return result.skills;
5334
+ }
5335
+ function parseSlashCommand(input) {
5336
+ const m2 = /^\s*\/([a-zA-Z0-9_-]+)(?:\s+([\s\S]*))?$/.exec(input);
5337
+ if (!m2) return null;
5338
+ return { slug: m2[1].toLowerCase(), args: m2[2] ?? "" };
5339
+ }
5340
+ function parseSlashTokenInProgress(buffer) {
5341
+ const m2 = /^\s*\/([a-zA-Z0-9_-]*)$/.exec(buffer);
5342
+ return m2 ? m2[1].toLowerCase() : null;
5343
+ }
5344
+ function filterSkills(items, query, pinned = []) {
5345
+ const q2 = query.toLowerCase();
5346
+ const pinnedSet = new Set(pinned);
5347
+ const key = (s2) => (s2.slug ?? s2.name).toLowerCase();
5348
+ const matched = q2 ? items.filter((s2) => key(s2).includes(q2)) : items.slice();
5349
+ matched.sort((a2, b2) => {
5350
+ const aPinned = pinnedSet.has(key(a2)) ? 0 : 1;
5351
+ const bPinned = pinnedSet.has(key(b2)) ? 0 : 1;
5352
+ if (aPinned !== bPinned) return aPinned - bPinned;
5353
+ const aPrefix = key(a2).startsWith(q2) ? 0 : 1;
5354
+ const bPrefix = key(b2).startsWith(q2) ? 0 : 1;
5355
+ if (aPrefix !== bPrefix) return aPrefix - bPrefix;
5356
+ return key(a2).localeCompare(key(b2));
5357
+ });
5358
+ return matched;
5359
+ }
5272
5360
 
5273
5361
  // src/operations/tags.ts
5274
5362
  var tags_exports = {};
@@ -7132,6 +7220,6 @@ async function startDmListener(options) {
7132
7220
  };
7133
7221
  }
7134
7222
 
7135
- export { Arbi, ArbiApiError, ArbiError, ClaudeOrchestrator, DOC_TERMINAL_STATUSES, FileConfigStore, OpenClawOrchestrator, agentconfig_exports as agentconfig, agents_exports as agents, assistant_exports as assistant, authenticatedFetch, buildRetrievalChunkTool, buildRetrievalFullContextTool, buildRetrievalTocTool, connectWebSocket, connectWithReconnect, consumeSSEStream, contacts_exports as contacts, conversations_exports as conversations, countCitations, createAuthenticatedClient, createDocumentWaiter, device_flow_exports as deviceFlow, dm_exports as dm, doctags_exports as doctags, documents_exports as documents, documents_node_exports as documentsNode, files_exports as files, formatAgentStepLabel, formatFileSize, formatStreamSummary, formatUserName, formatWorkspaceChoices, formatWsMessage, generateEncryptedWorkspaceKey, generateNewWorkspaceKey, getErrorCode, getErrorMessage, getRawWorkspaceKey, health_exports as health, listen_exports as listen, parseSSEEvents, performPasswordLogin, performSigningKeyLogin, performSsoDeviceFlowLogin, projects_exports as projects, requireData, requireOk, resolveAuth, resolveCitations, resolveWorkspace, responses_exports as responses, selectWorkspace, selectWorkspaceById, sessions_exports as sessions, settings_exports as settings, startDmListener, streamSSE, stripCitationMarkdown, summarizeCitations, tags_exports as tags, workspaces_exports as workspaces };
7223
+ export { Arbi, ArbiApiError, ArbiError, ClaudeOrchestrator, DOC_TERMINAL_STATUSES, FileConfigStore, OpenClawOrchestrator, agentconfig_exports as agentconfig, agents_exports as agents, assistant_exports as assistant, authenticatedFetch, buildRetrievalChunkTool, buildRetrievalFullContextTool, buildRetrievalTocTool, connectWebSocket, connectWithReconnect, consumeSSEStream, contacts_exports as contacts, conversations_exports as conversations, countCitations, createAuthenticatedClient, createDocumentWaiter, device_flow_exports as deviceFlow, dm_exports as dm, doctags_exports as doctags, documents_exports as documents, documents_node_exports as documentsNode, files_exports as files, filterSkills, formatAgentStepLabel, formatFileSize, formatStreamSummary, formatUserName, formatWorkspaceChoices, formatWsMessage, generateEncryptedWorkspaceKey, generateNewWorkspaceKey, getErrorCode, getErrorMessage, getRawWorkspaceKey, health_exports as health, listen_exports as listen, parseSSEEvents, parseSlashCommand, parseSlashTokenInProgress, performPasswordLogin, performSigningKeyLogin, performSsoDeviceFlowLogin, projects_exports as projects, requireData, requireOk, resolveAuth, resolveCitations, resolveWorkspace, responses_exports as responses, selectWorkspace, selectWorkspaceById, sessions_exports as sessions, settings_exports as settings, startDmListener, streamSSE, stripCitationMarkdown, summarizeCitations, tags_exports as tags, workspaces_exports as workspaces };
7136
7224
  //# sourceMappingURL=index.js.map
7137
7225
  //# sourceMappingURL=index.js.map