@arbidocs/sdk 0.4.81 → 0.4.83

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 { t as ConfigStore, q as CliConfig, r as CliCredentials, C as ChatSession, aI as SkippedFile, b8 as UploadResult, m as AuthHeaders, b4 as UploadBatchResult, b7 as UploadOptions, b5 as UploadDirectOptions, b6 as UploadDirectResult, aF as SUPPORTED_EXTENSIONS, a0 as MailAttachment, I as DmCryptoContext } from './browser-tT-eGij9.cjs';
2
- export { A as ActivityKind, a as ActivityResponse, d as AgentStepEvent, e as Arbi, f as ArbiApiError, g as ArbiError, i as ArbiOptions, j as ArbiSessionExpiredError, k as ArtifactEvent, l as AuthContext, n as AuthMode, o as AuthenticatedClient, p as CitationSummary, s as CommandDescriptor, u as ConnectOptions, v as ConversationResponse, w as ConversationUsageResponse, z as CreateWorkRequest, B as CreateWorkflowRequest, D as DOC_TERMINAL_STATUSES, E as DecryptedDmNotification, G as DmAttachmentFile, H as DmAttachmentInput, J as DocNameMap, K as DocumentAutomationAction, L as DocumentListFields, M as DocumentListOrder, N as DocumentSelector, O as DocumentWaiter, P as DocumentWaiterOptions, T as FormattedWsMessage, U as IdentityErrorCode, V as IdentityPurchase, W as IdentityState, X as IdentityStatus, Y as LinkedRun, Z as ListAllOptions, $ as ListPaginatedOptions, a1 as MessageLevel, a2 as MessageMetadataPayload, a3 as MessageQueuedEvent, a4 as OutputTokensDetails, a5 as ParsedSlashCommand, a6 as PendingAuthResponse, a7 as PlanStepsError, a8 as PlanWorkRequest, aa as ProjectBudget, ab as ProjectConversationUsageResponse, ac as ProjectDetails, ad as ProjectEventKind, ae as ProjectEventResponse, af as ProjectInvoicesResponse, ag as ProjectResponse, ah as ProjectUpdateRequest, ai as ProjectUsageResponse, aj as QueryOptions, ak as RaisedSignal, al as ReconnectOptions, am as ReconnectableWsConnection, an as ResolvedCitation, ao as ResolvedRecipient, ap as ResponseCompletedEvent, aq as ResponseContentPartAddedEvent, ar as ResponseCreatedEvent, as as ResponseFailedEvent, at as ResponseOutputItemAddedEvent, au as ResponseOutputItemDoneEvent, av as ResponseOutputTextDeltaEvent, aw as ResponseOutputTextDoneEvent, ax as ResponseUsage, ay as RunProgress, az as RunStep, aA as RunWaitingOn, aB as SSEEvent, aC as SSEStreamCallbacks, aD as SSEStreamResult, aE as SSEStreamStartData, aG as SendBack, aH as SkillSummary, aJ as StepActionRequest, aK as StepActivityEvent, aL as StepAssignee, aM as StepField, aN as StepKind, aO as StepPhase, aP as StepSignal, aQ as StepSignalWhen, aR as StepState, aS as StepStatus, aT as SubmitBackgroundQueryOptions, aU as TagField, aV as TagFieldDefinition, aW as TagMatrixResponse, aX as TagMatrixRow, aY as TagMatrixSelection, aZ as TagResponse, a_ as TaskPlan, a$ as TaskPlanStep, b0 as TokenBudgetContext, b1 as UpdateConversationRequest, b3 as UpdateWorkflowRequest, b9 as UsageBreakdown, ba as UserDailyUsageResponse, bb as UserInfo, bc as UserInputRequestEvent, bd as UserMessageEvent, be as WebSocketAuthError, bf as WorkStatus, bg as WorkflowAuthMode, bh as WorkflowResponse, bi as WorkflowRunHistoryResponse, bj as WorkflowRunResponse, bk as WorkspaceContext, bl as WsConnection, bm as account, bn as agentconfig, bo as agents, bp as assistant, bq as authenticatedFetch, br as buildDocNameMap, bs as buildFactsContextTool, bt as buildRetrievalChunkTool, bu as buildRetrievalFullContextTool, bv as buildRetrievalTocTool, bw as connectWebSocket, bx as connectWithReconnect, by as consumeSSEStream, bz as contacts, bA as conversations, bB as countCitations, bC as createAuthenticatedClient, bD as createDocumentWaiter, bE as dm, bF as doctags, bG as documents, bH as facts, bI as files, bJ as filterSkills, bK as formatAgentStepLabel, bL as formatFileSize, bM as formatItemLabel, bN as formatStreamSummary, bO as formatUserName, bP as formatWorkspaceChoices, bQ as formatWsMessage, bR as generateEncryptedWorkspaceKey, bS as generateNewWorkspaceKey, bT as getErrorCode, bU as getErrorMessage, bV as getRawWorkspaceKey, bW as health, bY as identityErrorCode, bX as identityVerification, bZ as mail, b_ as parseSSEEvents, b$ as parseSlashCommand, c0 as parseSlashTokenInProgress, c1 as performPasswordLogin, c2 as performSigningKeyLogin, c3 as performSsoDeviceFlowLogin, c4 as profile, c5 as projects, c6 as requireData, c7 as requireOk, c8 as resolveAuth, c9 as resolveCitations, ca as resolveWorkspace, cb as responses, cc as selectWorkspace, cd as selectWorkspaceById, ce as sessions, cf as settings, cg as streamSSE, ch as stripCitationMarkdown, ci as summarizeCitations, cj as tags, ck as work, cl as workflowSteps, cm as workflows, cn as workspaces } from './browser-tT-eGij9.cjs';
1
+ import { t as ConfigStore, q as CliConfig, r as CliCredentials, C as ChatSession, aI as SkippedFile, b9 as UploadResult, m as AuthHeaders, b5 as UploadBatchResult, b8 as UploadOptions, b6 as UploadDirectOptions, b7 as UploadDirectResult, aF as SUPPORTED_EXTENSIONS, a0 as MailAttachment, I as DmCryptoContext } from './browser-uyIwS2cN.cjs';
2
+ export { A as ActivityKind, a as ActivityResponse, d as AgentStepEvent, e as Arbi, f as ArbiApiError, g as ArbiError, i as ArbiOptions, j as ArbiSessionExpiredError, k as ArtifactEvent, l as AuthContext, n as AuthMode, o as AuthenticatedClient, p as CitationSummary, s as CommandDescriptor, u as ConnectOptions, v as ConversationResponse, w as ConversationUsageResponse, z as CreateWorkRequest, B as CreateWorkflowRequest, D as DOC_TERMINAL_STATUSES, E as DecryptedDmNotification, G as DmAttachmentFile, H as DmAttachmentInput, J as DocNameMap, K as DocumentAutomationAction, L as DocumentListFields, M as DocumentListOrder, N as DocumentSelector, O as DocumentWaiter, P as DocumentWaiterOptions, T as FormattedWsMessage, U as IdentityErrorCode, V as IdentityPurchase, W as IdentityState, X as IdentityStatus, Y as LinkedRun, Z as ListAllOptions, $ as ListPaginatedOptions, a1 as MessageLevel, a2 as MessageMetadataPayload, a3 as MessageQueuedEvent, a4 as OutputTokensDetails, a5 as ParsedSlashCommand, a6 as PendingAuthResponse, a7 as PlanStepsError, a8 as PlanWorkRequest, aa as ProjectBudget, ab as ProjectConversationUsageResponse, ac as ProjectDetails, ad as ProjectEventKind, ae as ProjectEventResponse, af as ProjectInvoicesResponse, ag as ProjectResponse, ah as ProjectUpdateRequest, ai as ProjectUsageResponse, aj as QueryOptions, ak as RaisedSignal, al as ReconnectOptions, am as ReconnectableWsConnection, an as ResolvedCitation, ao as ResolvedRecipient, ap as ResponseCompletedEvent, aq as ResponseContentPartAddedEvent, ar as ResponseCreatedEvent, as as ResponseFailedEvent, at as ResponseOutputItemAddedEvent, au as ResponseOutputItemDoneEvent, av as ResponseOutputTextDeltaEvent, aw as ResponseOutputTextDoneEvent, ax as ResponseUsage, ay as RunProgress, az as RunStep, aA as RunWaitingOn, aB as SSEEvent, aC as SSEStreamCallbacks, aD as SSEStreamResult, aE as SSEStreamStartData, aG as SendBack, aH as SkillSummary, aJ as StepActionRequest, aK as StepActivityEvent, aL as StepAssignee, aM as StepField, aN as StepKind, aO as StepPhase, aP as StepSignal, aQ as StepSignalWhen, aR as StepState, aS as StepStatus, aT as SubmitBackgroundQueryOptions, aU as TagChange, aV as TagField, aW as TagFieldDefinition, aX as TagMatrixResponse, aY as TagMatrixRow, aZ as TagMatrixSelection, a_ as TagResponse, a$ as TaskPlan, b0 as TaskPlanStep, b1 as TokenBudgetContext, b2 as UpdateConversationRequest, b4 as UpdateWorkflowRequest, ba as UsageBreakdown, bb as UserDailyUsageResponse, bc as UserInfo, bd as UserInputRequestEvent, be as UserMessageEvent, bf as WebSocketAuthError, bg as WorkStatus, bh as WorkflowAuthMode, bi as WorkflowResponse, bj as WorkflowRunHistoryResponse, bk as WorkflowRunResponse, bl as WorkspaceContext, bm as WsConnection, bn as account, bo as agentconfig, bp as agents, bq as assistant, br as authenticatedFetch, bs as buildDocNameMap, bt as buildFactsContextTool, bu as buildRetrievalChunkTool, bv as buildRetrievalFullContextTool, bw as buildRetrievalTocTool, bx as connectWebSocket, by as connectWithReconnect, bz as consumeSSEStream, bA as contacts, bB as conversations, bC as countCitations, bD as createAuthenticatedClient, bE as createDocumentWaiter, bF as dm, bG as doctags, bH as documents, bI as facts, bJ as files, bK as filterSkills, bL as formatAgentStepLabel, bM as formatFileSize, bN as formatItemLabel, bO as formatStreamSummary, bP as formatUserName, bQ as formatWorkspaceChoices, bR as formatWsMessage, bS as generateEncryptedWorkspaceKey, bT as generateNewWorkspaceKey, bU as getErrorCode, bV as getErrorMessage, bW as getRawWorkspaceKey, bX as health, bZ as identityErrorCode, bY as identityVerification, b_ as mail, b$ as parseSSEEvents, c0 as parseSlashCommand, c1 as parseSlashTokenInProgress, c2 as performPasswordLogin, c3 as performSigningKeyLogin, c4 as performSsoDeviceFlowLogin, c5 as profile, c6 as projects, c7 as requireData, c8 as requireOk, c9 as resolveAuth, ca as resolveCitations, cb as resolveWorkspace, cc as responses, cd as selectWorkspace, ce as selectWorkspaceById, cf as sessions, cg as settings, ch as streamSSE, ci as stripCitationMarkdown, cj as summarizeCitations, ck as tags, cl as work, cm as workflowSteps, cn as workflows, co as workspaces } from './browser-uyIwS2cN.cjs';
3
3
  import { SessionStorageProvider, ArbiClient } from '@arbidocs/client';
4
4
  export { LoginProfile } from '@arbidocs/client';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { t as ConfigStore, q as CliConfig, r as CliCredentials, C as ChatSession, aI as SkippedFile, b8 as UploadResult, m as AuthHeaders, b4 as UploadBatchResult, b7 as UploadOptions, b5 as UploadDirectOptions, b6 as UploadDirectResult, aF as SUPPORTED_EXTENSIONS, a0 as MailAttachment, I as DmCryptoContext } from './browser-tT-eGij9.js';
2
- export { A as ActivityKind, a as ActivityResponse, d as AgentStepEvent, e as Arbi, f as ArbiApiError, g as ArbiError, i as ArbiOptions, j as ArbiSessionExpiredError, k as ArtifactEvent, l as AuthContext, n as AuthMode, o as AuthenticatedClient, p as CitationSummary, s as CommandDescriptor, u as ConnectOptions, v as ConversationResponse, w as ConversationUsageResponse, z as CreateWorkRequest, B as CreateWorkflowRequest, D as DOC_TERMINAL_STATUSES, E as DecryptedDmNotification, G as DmAttachmentFile, H as DmAttachmentInput, J as DocNameMap, K as DocumentAutomationAction, L as DocumentListFields, M as DocumentListOrder, N as DocumentSelector, O as DocumentWaiter, P as DocumentWaiterOptions, T as FormattedWsMessage, U as IdentityErrorCode, V as IdentityPurchase, W as IdentityState, X as IdentityStatus, Y as LinkedRun, Z as ListAllOptions, $ as ListPaginatedOptions, a1 as MessageLevel, a2 as MessageMetadataPayload, a3 as MessageQueuedEvent, a4 as OutputTokensDetails, a5 as ParsedSlashCommand, a6 as PendingAuthResponse, a7 as PlanStepsError, a8 as PlanWorkRequest, aa as ProjectBudget, ab as ProjectConversationUsageResponse, ac as ProjectDetails, ad as ProjectEventKind, ae as ProjectEventResponse, af as ProjectInvoicesResponse, ag as ProjectResponse, ah as ProjectUpdateRequest, ai as ProjectUsageResponse, aj as QueryOptions, ak as RaisedSignal, al as ReconnectOptions, am as ReconnectableWsConnection, an as ResolvedCitation, ao as ResolvedRecipient, ap as ResponseCompletedEvent, aq as ResponseContentPartAddedEvent, ar as ResponseCreatedEvent, as as ResponseFailedEvent, at as ResponseOutputItemAddedEvent, au as ResponseOutputItemDoneEvent, av as ResponseOutputTextDeltaEvent, aw as ResponseOutputTextDoneEvent, ax as ResponseUsage, ay as RunProgress, az as RunStep, aA as RunWaitingOn, aB as SSEEvent, aC as SSEStreamCallbacks, aD as SSEStreamResult, aE as SSEStreamStartData, aG as SendBack, aH as SkillSummary, aJ as StepActionRequest, aK as StepActivityEvent, aL as StepAssignee, aM as StepField, aN as StepKind, aO as StepPhase, aP as StepSignal, aQ as StepSignalWhen, aR as StepState, aS as StepStatus, aT as SubmitBackgroundQueryOptions, aU as TagField, aV as TagFieldDefinition, aW as TagMatrixResponse, aX as TagMatrixRow, aY as TagMatrixSelection, aZ as TagResponse, a_ as TaskPlan, a$ as TaskPlanStep, b0 as TokenBudgetContext, b1 as UpdateConversationRequest, b3 as UpdateWorkflowRequest, b9 as UsageBreakdown, ba as UserDailyUsageResponse, bb as UserInfo, bc as UserInputRequestEvent, bd as UserMessageEvent, be as WebSocketAuthError, bf as WorkStatus, bg as WorkflowAuthMode, bh as WorkflowResponse, bi as WorkflowRunHistoryResponse, bj as WorkflowRunResponse, bk as WorkspaceContext, bl as WsConnection, bm as account, bn as agentconfig, bo as agents, bp as assistant, bq as authenticatedFetch, br as buildDocNameMap, bs as buildFactsContextTool, bt as buildRetrievalChunkTool, bu as buildRetrievalFullContextTool, bv as buildRetrievalTocTool, bw as connectWebSocket, bx as connectWithReconnect, by as consumeSSEStream, bz as contacts, bA as conversations, bB as countCitations, bC as createAuthenticatedClient, bD as createDocumentWaiter, bE as dm, bF as doctags, bG as documents, bH as facts, bI as files, bJ as filterSkills, bK as formatAgentStepLabel, bL as formatFileSize, bM as formatItemLabel, bN as formatStreamSummary, bO as formatUserName, bP as formatWorkspaceChoices, bQ as formatWsMessage, bR as generateEncryptedWorkspaceKey, bS as generateNewWorkspaceKey, bT as getErrorCode, bU as getErrorMessage, bV as getRawWorkspaceKey, bW as health, bY as identityErrorCode, bX as identityVerification, bZ as mail, b_ as parseSSEEvents, b$ as parseSlashCommand, c0 as parseSlashTokenInProgress, c1 as performPasswordLogin, c2 as performSigningKeyLogin, c3 as performSsoDeviceFlowLogin, c4 as profile, c5 as projects, c6 as requireData, c7 as requireOk, c8 as resolveAuth, c9 as resolveCitations, ca as resolveWorkspace, cb as responses, cc as selectWorkspace, cd as selectWorkspaceById, ce as sessions, cf as settings, cg as streamSSE, ch as stripCitationMarkdown, ci as summarizeCitations, cj as tags, ck as work, cl as workflowSteps, cm as workflows, cn as workspaces } from './browser-tT-eGij9.js';
1
+ import { t as ConfigStore, q as CliConfig, r as CliCredentials, C as ChatSession, aI as SkippedFile, b9 as UploadResult, m as AuthHeaders, b5 as UploadBatchResult, b8 as UploadOptions, b6 as UploadDirectOptions, b7 as UploadDirectResult, aF as SUPPORTED_EXTENSIONS, a0 as MailAttachment, I as DmCryptoContext } from './browser-uyIwS2cN.js';
2
+ export { A as ActivityKind, a as ActivityResponse, d as AgentStepEvent, e as Arbi, f as ArbiApiError, g as ArbiError, i as ArbiOptions, j as ArbiSessionExpiredError, k as ArtifactEvent, l as AuthContext, n as AuthMode, o as AuthenticatedClient, p as CitationSummary, s as CommandDescriptor, u as ConnectOptions, v as ConversationResponse, w as ConversationUsageResponse, z as CreateWorkRequest, B as CreateWorkflowRequest, D as DOC_TERMINAL_STATUSES, E as DecryptedDmNotification, G as DmAttachmentFile, H as DmAttachmentInput, J as DocNameMap, K as DocumentAutomationAction, L as DocumentListFields, M as DocumentListOrder, N as DocumentSelector, O as DocumentWaiter, P as DocumentWaiterOptions, T as FormattedWsMessage, U as IdentityErrorCode, V as IdentityPurchase, W as IdentityState, X as IdentityStatus, Y as LinkedRun, Z as ListAllOptions, $ as ListPaginatedOptions, a1 as MessageLevel, a2 as MessageMetadataPayload, a3 as MessageQueuedEvent, a4 as OutputTokensDetails, a5 as ParsedSlashCommand, a6 as PendingAuthResponse, a7 as PlanStepsError, a8 as PlanWorkRequest, aa as ProjectBudget, ab as ProjectConversationUsageResponse, ac as ProjectDetails, ad as ProjectEventKind, ae as ProjectEventResponse, af as ProjectInvoicesResponse, ag as ProjectResponse, ah as ProjectUpdateRequest, ai as ProjectUsageResponse, aj as QueryOptions, ak as RaisedSignal, al as ReconnectOptions, am as ReconnectableWsConnection, an as ResolvedCitation, ao as ResolvedRecipient, ap as ResponseCompletedEvent, aq as ResponseContentPartAddedEvent, ar as ResponseCreatedEvent, as as ResponseFailedEvent, at as ResponseOutputItemAddedEvent, au as ResponseOutputItemDoneEvent, av as ResponseOutputTextDeltaEvent, aw as ResponseOutputTextDoneEvent, ax as ResponseUsage, ay as RunProgress, az as RunStep, aA as RunWaitingOn, aB as SSEEvent, aC as SSEStreamCallbacks, aD as SSEStreamResult, aE as SSEStreamStartData, aG as SendBack, aH as SkillSummary, aJ as StepActionRequest, aK as StepActivityEvent, aL as StepAssignee, aM as StepField, aN as StepKind, aO as StepPhase, aP as StepSignal, aQ as StepSignalWhen, aR as StepState, aS as StepStatus, aT as SubmitBackgroundQueryOptions, aU as TagChange, aV as TagField, aW as TagFieldDefinition, aX as TagMatrixResponse, aY as TagMatrixRow, aZ as TagMatrixSelection, a_ as TagResponse, a$ as TaskPlan, b0 as TaskPlanStep, b1 as TokenBudgetContext, b2 as UpdateConversationRequest, b4 as UpdateWorkflowRequest, ba as UsageBreakdown, bb as UserDailyUsageResponse, bc as UserInfo, bd as UserInputRequestEvent, be as UserMessageEvent, bf as WebSocketAuthError, bg as WorkStatus, bh as WorkflowAuthMode, bi as WorkflowResponse, bj as WorkflowRunHistoryResponse, bk as WorkflowRunResponse, bl as WorkspaceContext, bm as WsConnection, bn as account, bo as agentconfig, bp as agents, bq as assistant, br as authenticatedFetch, bs as buildDocNameMap, bt as buildFactsContextTool, bu as buildRetrievalChunkTool, bv as buildRetrievalFullContextTool, bw as buildRetrievalTocTool, bx as connectWebSocket, by as connectWithReconnect, bz as consumeSSEStream, bA as contacts, bB as conversations, bC as countCitations, bD as createAuthenticatedClient, bE as createDocumentWaiter, bF as dm, bG as doctags, bH as documents, bI as facts, bJ as files, bK as filterSkills, bL as formatAgentStepLabel, bM as formatFileSize, bN as formatItemLabel, bO as formatStreamSummary, bP as formatUserName, bQ as formatWorkspaceChoices, bR as formatWsMessage, bS as generateEncryptedWorkspaceKey, bT as generateNewWorkspaceKey, bU as getErrorCode, bV as getErrorMessage, bW as getRawWorkspaceKey, bX as health, bZ as identityErrorCode, bY as identityVerification, b_ as mail, b$ as parseSSEEvents, c0 as parseSlashCommand, c1 as parseSlashTokenInProgress, c2 as performPasswordLogin, c3 as performSigningKeyLogin, c4 as performSsoDeviceFlowLogin, c5 as profile, c6 as projects, c7 as requireData, c8 as requireOk, c9 as resolveAuth, ca as resolveCitations, cb as resolveWorkspace, cc as responses, cd as selectWorkspace, ce as selectWorkspaceById, cf as sessions, cg as settings, ch as streamSSE, ci as stripCitationMarkdown, cj as summarizeCitations, ck as tags, cl as work, cm as workflowSteps, cn as workflows, co as workspaces } from './browser-uyIwS2cN.js';
3
3
  import { SessionStorageProvider, ArbiClient } from '@arbidocs/client';
4
4
  export { LoginProfile } from '@arbidocs/client';
5
5
 
package/dist/index.js CHANGED
@@ -5751,11 +5751,11 @@ async function deleteTag(arbi, tagId) {
5751
5751
  "Failed to delete tag"
5752
5752
  );
5753
5753
  }
5754
- async function updateTag(arbi, tagId, body) {
5754
+ async function updateTag(arbi, tagId, change) {
5755
5755
  return requireData(
5756
5756
  await arbi.fetch.PATCH("/v1/tag/{tag_ext_id}", {
5757
5757
  params: { path: { tag_ext_id: tagId } },
5758
- body
5758
+ body: { kind_to_children: false, ...change }
5759
5759
  }),
5760
5760
  "Failed to update tag"
5761
5761
  );
@@ -7628,6 +7628,8 @@ var Arbi = class {
7628
7628
  userProfile = null;
7629
7629
  profileListeners = /* @__PURE__ */ new Set();
7630
7630
  currentWorkspaceId = null;
7631
+ /** Wrapped workspace keys seen in the last list/create, so selecting needs no re-fetch. */
7632
+ wrappedKeys = /* @__PURE__ */ new Map();
7631
7633
  dmCryptoContext = null;
7632
7634
  sessionExpiredListeners = /* @__PURE__ */ new Set();
7633
7635
  options;
@@ -7707,47 +7709,79 @@ var Arbi = class {
7707
7709
  this.userProfile = this.loginResult.profile ?? null;
7708
7710
  return true;
7709
7711
  }
7712
+ /** Remember the wrapped keys of workspaces the server just returned. */
7713
+ rememberWorkspaces(workspaces) {
7714
+ for (const ws of workspaces) {
7715
+ if (ws.wrapped_key) this.wrappedKeys.set(ws.external_id, ws.wrapped_key);
7716
+ }
7717
+ return workspaces;
7718
+ }
7719
+ /**
7720
+ * A workspace's wrapped key: from the cache when a list or create already returned it, else from
7721
+ * a fresh workspace list (a workspace created or shared since the last list).
7722
+ */
7723
+ async wrappedKeyFor(workspaceId, refresh2 = false) {
7724
+ const cached = refresh2 ? void 0 : this.wrappedKeys.get(workspaceId);
7725
+ if (cached) return { wrappedKey: cached, fromCache: true };
7726
+ this.wrappedKeys.delete(workspaceId);
7727
+ this.rememberWorkspaces(await listWorkspaces(this.requireClient()));
7728
+ const wrappedKey = this.wrappedKeys.get(workspaceId);
7729
+ if (!wrappedKey) {
7730
+ throw new ArbiError(`Workspace ${workspaceId} not found or has no encryption key`);
7731
+ }
7732
+ return { wrappedKey, fromCache: false };
7733
+ }
7734
+ /**
7735
+ * Run `withKey` with the workspace's wrapped key. A cached key that no longer works (access was
7736
+ * re-granted with a new key) is dropped and the call retried once with a fresh list.
7737
+ */
7738
+ async withWrappedKey(workspaceId, withKey) {
7739
+ const { wrappedKey, fromCache } = await this.wrappedKeyFor(workspaceId);
7740
+ try {
7741
+ return await withKey(wrappedKey);
7742
+ } catch (error) {
7743
+ if (!fromCache) throw error;
7744
+ const fresh = await this.wrappedKeyFor(workspaceId, true);
7745
+ return withKey(fresh.wrappedKey);
7746
+ }
7747
+ }
7710
7748
  /** A workspace's key, sealed to the caller's own session (what `/open` and `POST /workspace/users` take). */
7711
7749
  async sealWorkspaceKey(workspaceId) {
7712
7750
  const client = this.requireClient();
7713
7751
  const lr2 = this.requireLogin();
7714
- const all = await listWorkspaces(client);
7715
- const ws = all.find((w2) => w2.external_id === workspaceId);
7716
- if (!ws || !ws.wrapped_key) {
7717
- throw new ArbiError(`Workspace ${workspaceId} not found or has no encryption key`);
7718
- }
7719
- return generateEncryptedWorkspaceKey(
7720
- client,
7721
- ws.wrapped_key,
7722
- lr2.serverSessionKey,
7723
- client.crypto.bytesToBase64(lr2.signingPrivateKey)
7752
+ return this.withWrappedKey(
7753
+ workspaceId,
7754
+ (wrappedKey) => generateEncryptedWorkspaceKey(
7755
+ client,
7756
+ wrappedKey,
7757
+ lr2.serverSessionKey,
7758
+ client.crypto.bytesToBase64(lr2.signingPrivateKey)
7759
+ )
7724
7760
  );
7725
7761
  }
7726
7762
  /**
7727
- * Select a workspace by ID. Fetches the workspace list, finds the matching
7728
- * workspace, decrypts the wrapped key, and sets up auth headers.
7763
+ * Select a workspace by ID. Uses the wrapped key from the last workspace list or create (the
7764
+ * list is fetched only when the workspace is not known yet), decrypts it, and opens the
7765
+ * workspace on the server.
7729
7766
  */
7730
7767
  async selectWorkspace(workspaceId) {
7731
7768
  const client = this.requireClient();
7732
7769
  const lr2 = this.requireLogin();
7733
- const allWorkspaces = await listWorkspaces(client);
7734
- const ws = allWorkspaces.find((w2) => w2.external_id === workspaceId);
7735
- if (!ws || !ws.wrapped_key) {
7736
- throw new ArbiError(`Workspace ${workspaceId} not found or has no encryption key`);
7737
- }
7738
7770
  const signingPrivateKeyBase64 = client.crypto.bytesToBase64(lr2.signingPrivateKey);
7739
- const sealedKey = await selectWorkspace(
7740
- client,
7741
- ws.external_id,
7742
- ws.wrapped_key,
7743
- lr2.serverSessionKey,
7744
- signingPrivateKeyBase64
7745
- );
7746
- await client.fetch.POST("/v1/workspace/{workspace_ext_id}/open", {
7747
- params: { path: { workspace_ext_id: ws.external_id } },
7748
- body: { workspace_key: sealedKey }
7771
+ await this.withWrappedKey(workspaceId, async (wrappedKey) => {
7772
+ const sealedKey = await selectWorkspace(
7773
+ client,
7774
+ workspaceId,
7775
+ wrappedKey,
7776
+ lr2.serverSessionKey,
7777
+ signingPrivateKeyBase64
7778
+ );
7779
+ await client.fetch.POST("/v1/workspace/{workspace_ext_id}/open", {
7780
+ params: { path: { workspace_ext_id: workspaceId } },
7781
+ body: { workspace_key: sealedKey }
7782
+ });
7749
7783
  });
7750
- this.currentWorkspaceId = ws.external_id;
7784
+ this.currentWorkspaceId = workspaceId;
7751
7785
  }
7752
7786
  /**
7753
7787
  * Subscribe to "the session cannot be recovered". Fires when a request failed with 401 or
@@ -7767,6 +7801,7 @@ var Arbi = class {
7767
7801
  this.loginResult = null;
7768
7802
  this.userProfile = null;
7769
7803
  this.currentWorkspaceId = null;
7804
+ this.wrappedKeys.clear();
7770
7805
  this.dmCryptoContext = null;
7771
7806
  this.client?.session.clear();
7772
7807
  for (const listener of [...this.sessionExpiredListeners]) listener();
@@ -7812,6 +7847,7 @@ var Arbi = class {
7812
7847
  this.loginResult = null;
7813
7848
  this.userProfile = null;
7814
7849
  this.currentWorkspaceId = null;
7850
+ this.wrappedKeys.clear();
7815
7851
  this.dmCryptoContext = null;
7816
7852
  }
7817
7853
  // ── Accessors ─────────────────────────────────────────────────────────
@@ -7953,6 +7989,7 @@ var Arbi = class {
7953
7989
  }
7954
7990
  );
7955
7991
  this.loginResult = { ...lr2, signingPrivateKey: result.newSigningPrivateKey };
7992
+ this.wrappedKeys.clear();
7956
7993
  return result;
7957
7994
  },
7958
7995
  /** Close the account (soft delete) and sign out. Refused while a subscription is active. */
@@ -8007,7 +8044,7 @@ var Arbi = class {
8007
8044
  }
8008
8045
  // ── Workspaces ────────────────────────────────────────────────────────
8009
8046
  workspaces = {
8010
- list: () => listWorkspaces(this.requireClient()),
8047
+ list: async () => this.rememberWorkspaces(await listWorkspaces(this.requireClient())),
8011
8048
  create: async (name, projectExtId, description, isPublic) => {
8012
8049
  const client = this.requireClient();
8013
8050
  const lr2 = this.requireLogin();
@@ -8016,7 +8053,7 @@ var Arbi = class {
8016
8053
  await sodium.ready;
8017
8054
  const workspaceKey = sodium.randombytes_buf(32);
8018
8055
  const encryptedKey = await client.crypto.sealKeyForSession(workspaceKey, lr2.serverSessionKey);
8019
- return createWorkspace(
8056
+ const created = await createWorkspace(
8020
8057
  client,
8021
8058
  name,
8022
8059
  encryptedKey,
@@ -8024,8 +8061,13 @@ var Arbi = class {
8024
8061
  description,
8025
8062
  isPublic
8026
8063
  );
8064
+ this.rememberWorkspaces([created]);
8065
+ return created;
8066
+ },
8067
+ delete: async (workspaceIds) => {
8068
+ await deleteWorkspaces(this.requireClient(), workspaceIds);
8069
+ for (const id of workspaceIds) this.wrappedKeys.delete(id);
8027
8070
  },
8028
- delete: (workspaceIds) => deleteWorkspaces(this.requireClient(), workspaceIds),
8029
8071
  update: (body) => updateWorkspace(this.requireClient(), body),
8030
8072
  listUsers: () => listWorkspaceUsers(this.requireClient()),
8031
8073
  addUsers: (emails, role) => addWorkspaceUsers(this.requireClient(), emails, role),
@@ -8296,7 +8338,7 @@ var Arbi = class {
8296
8338
  workspaceId: options.workspaceId ?? this.requireWorkspace()
8297
8339
  }),
8298
8340
  delete: (tagId) => deleteTag(this.requireClient(), tagId),
8299
- update: (tagId, body) => updateTag(this.requireClient(), tagId, body),
8341
+ update: (tagId, change) => updateTag(this.requireClient(), tagId, change),
8300
8342
  /** Replace a tag's own field definitions and/or merge-patch its values (`null` clears one). */
8301
8343
  updateFields: (tagId, change) => updateTagFields(this.requireClient(), tagId, change),
8302
8344
  /** Tags as rows (a parent's children, or the given tags) with field values, docs and facts. */