@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.
@@ -1,2 +1,2 @@
1
- export { A as ActivityKind, a as ActivityResponse, b as AgentControlStateEvent, c as AgentStepDeltaEvent, d as AgentStepEvent, e as Arbi, f as ArbiApiError, g as ArbiError, h as ArbiErrorEvent, i as ArbiOptions, k as ArtifactEvent, l as AuthContext, m as AuthHeaders, n as AuthMode, o as AuthenticatedClient, C as ChatSession, p as CitationSummary, q as CliConfig, r as CliCredentials, s as CommandDescriptor, t as ConfigStore, u as ConnectOptions, v as ConversationResponse, w as ConversationUsageResponse, x as CreateFactRequest, y as CreateFactsRequest, z as CreateWorkRequest, B as CreateWorkflowRequest, E as DecryptedDmNotification, F as DeferredInterjectionEvent, G as DmAttachmentFile, H as DmAttachmentInput, K as DocumentAutomationAction, N as DocumentSelector, Q as FactResponse, R as FactSearchRequest, S as FactSearchResponse, U as IdentityErrorCode, V as IdentityPurchase, W as IdentityState, X as IdentityStatus, Y as LinkedRun, _ as ListFactsOptions, a2 as MessageMetadataPayload, a3 as MessageQueuedEvent, a4 as OutputTokensDetails, a5 as ParsedSlashCommand, a6 as PendingAuthResponse, a7 as PlanStepsError, a8 as PlanWorkRequest, a9 as ProbeAnswerEvent, 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, 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, b2 as UpdateFactRequest, 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, bp as assistant, bq as authenticatedFetch, 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, 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, bO as formatUserName, bP as formatWorkspaceChoices, 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, 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
+ export { A as ActivityKind, a as ActivityResponse, b as AgentControlStateEvent, c as AgentStepDeltaEvent, d as AgentStepEvent, e as Arbi, f as ArbiApiError, g as ArbiError, h as ArbiErrorEvent, i as ArbiOptions, k as ArtifactEvent, l as AuthContext, m as AuthHeaders, n as AuthMode, o as AuthenticatedClient, C as ChatSession, p as CitationSummary, q as CliConfig, r as CliCredentials, s as CommandDescriptor, t as ConfigStore, u as ConnectOptions, v as ConversationResponse, w as ConversationUsageResponse, x as CreateFactRequest, y as CreateFactsRequest, z as CreateWorkRequest, B as CreateWorkflowRequest, E as DecryptedDmNotification, F as DeferredInterjectionEvent, G as DmAttachmentFile, H as DmAttachmentInput, K as DocumentAutomationAction, N as DocumentSelector, Q as FactResponse, R as FactSearchRequest, S as FactSearchResponse, U as IdentityErrorCode, V as IdentityPurchase, W as IdentityState, X as IdentityStatus, Y as LinkedRun, _ as ListFactsOptions, a2 as MessageMetadataPayload, a3 as MessageQueuedEvent, a4 as OutputTokensDetails, a5 as ParsedSlashCommand, a6 as PendingAuthResponse, a7 as PlanStepsError, a8 as PlanWorkRequest, a9 as ProbeAnswerEvent, 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, 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, b3 as UpdateFactRequest, 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, bq as assistant, br as authenticatedFetch, 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, 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, bP as formatUserName, bQ as formatWorkspaceChoices, 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, 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';
2
2
  export { LoginProfile } from '@arbidocs/client';
package/dist/browser.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as ActivityKind, a as ActivityResponse, b as AgentControlStateEvent, c as AgentStepDeltaEvent, d as AgentStepEvent, e as Arbi, f as ArbiApiError, g as ArbiError, h as ArbiErrorEvent, i as ArbiOptions, k as ArtifactEvent, l as AuthContext, m as AuthHeaders, n as AuthMode, o as AuthenticatedClient, C as ChatSession, p as CitationSummary, q as CliConfig, r as CliCredentials, s as CommandDescriptor, t as ConfigStore, u as ConnectOptions, v as ConversationResponse, w as ConversationUsageResponse, x as CreateFactRequest, y as CreateFactsRequest, z as CreateWorkRequest, B as CreateWorkflowRequest, E as DecryptedDmNotification, F as DeferredInterjectionEvent, G as DmAttachmentFile, H as DmAttachmentInput, K as DocumentAutomationAction, N as DocumentSelector, Q as FactResponse, R as FactSearchRequest, S as FactSearchResponse, U as IdentityErrorCode, V as IdentityPurchase, W as IdentityState, X as IdentityStatus, Y as LinkedRun, _ as ListFactsOptions, a2 as MessageMetadataPayload, a3 as MessageQueuedEvent, a4 as OutputTokensDetails, a5 as ParsedSlashCommand, a6 as PendingAuthResponse, a7 as PlanStepsError, a8 as PlanWorkRequest, a9 as ProbeAnswerEvent, 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, 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, b2 as UpdateFactRequest, 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, bp as assistant, bq as authenticatedFetch, 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, 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, bO as formatUserName, bP as formatWorkspaceChoices, 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, 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
+ export { A as ActivityKind, a as ActivityResponse, b as AgentControlStateEvent, c as AgentStepDeltaEvent, d as AgentStepEvent, e as Arbi, f as ArbiApiError, g as ArbiError, h as ArbiErrorEvent, i as ArbiOptions, k as ArtifactEvent, l as AuthContext, m as AuthHeaders, n as AuthMode, o as AuthenticatedClient, C as ChatSession, p as CitationSummary, q as CliConfig, r as CliCredentials, s as CommandDescriptor, t as ConfigStore, u as ConnectOptions, v as ConversationResponse, w as ConversationUsageResponse, x as CreateFactRequest, y as CreateFactsRequest, z as CreateWorkRequest, B as CreateWorkflowRequest, E as DecryptedDmNotification, F as DeferredInterjectionEvent, G as DmAttachmentFile, H as DmAttachmentInput, K as DocumentAutomationAction, N as DocumentSelector, Q as FactResponse, R as FactSearchRequest, S as FactSearchResponse, U as IdentityErrorCode, V as IdentityPurchase, W as IdentityState, X as IdentityStatus, Y as LinkedRun, _ as ListFactsOptions, a2 as MessageMetadataPayload, a3 as MessageQueuedEvent, a4 as OutputTokensDetails, a5 as ParsedSlashCommand, a6 as PendingAuthResponse, a7 as PlanStepsError, a8 as PlanWorkRequest, a9 as ProbeAnswerEvent, 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, 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, b3 as UpdateFactRequest, 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, bq as assistant, br as authenticatedFetch, 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, 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, bP as formatUserName, bQ as formatWorkspaceChoices, 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, 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';
2
2
  export { LoginProfile } from '@arbidocs/client';
package/dist/browser.js CHANGED
@@ -5208,11 +5208,11 @@ async function deleteTag(arbi, tagId) {
5208
5208
  "Failed to delete tag"
5209
5209
  );
5210
5210
  }
5211
- async function updateTag(arbi, tagId, body) {
5211
+ async function updateTag(arbi, tagId, change) {
5212
5212
  return requireData(
5213
5213
  await arbi.fetch.PATCH("/v1/tag/{tag_ext_id}", {
5214
5214
  params: { path: { tag_ext_id: tagId } },
5215
- body
5215
+ body: { kind_to_children: false, ...change }
5216
5216
  }),
5217
5217
  "Failed to update tag"
5218
5218
  );
@@ -7070,6 +7070,8 @@ var Arbi = class {
7070
7070
  userProfile = null;
7071
7071
  profileListeners = /* @__PURE__ */ new Set();
7072
7072
  currentWorkspaceId = null;
7073
+ /** Wrapped workspace keys seen in the last list/create, so selecting needs no re-fetch. */
7074
+ wrappedKeys = /* @__PURE__ */ new Map();
7073
7075
  dmCryptoContext = null;
7074
7076
  sessionExpiredListeners = /* @__PURE__ */ new Set();
7075
7077
  options;
@@ -7149,47 +7151,79 @@ var Arbi = class {
7149
7151
  this.userProfile = this.loginResult.profile ?? null;
7150
7152
  return true;
7151
7153
  }
7154
+ /** Remember the wrapped keys of workspaces the server just returned. */
7155
+ rememberWorkspaces(workspaces) {
7156
+ for (const ws of workspaces) {
7157
+ if (ws.wrapped_key) this.wrappedKeys.set(ws.external_id, ws.wrapped_key);
7158
+ }
7159
+ return workspaces;
7160
+ }
7161
+ /**
7162
+ * A workspace's wrapped key: from the cache when a list or create already returned it, else from
7163
+ * a fresh workspace list (a workspace created or shared since the last list).
7164
+ */
7165
+ async wrappedKeyFor(workspaceId, refresh2 = false) {
7166
+ const cached = refresh2 ? void 0 : this.wrappedKeys.get(workspaceId);
7167
+ if (cached) return { wrappedKey: cached, fromCache: true };
7168
+ this.wrappedKeys.delete(workspaceId);
7169
+ this.rememberWorkspaces(await listWorkspaces(this.requireClient()));
7170
+ const wrappedKey = this.wrappedKeys.get(workspaceId);
7171
+ if (!wrappedKey) {
7172
+ throw new ArbiError(`Workspace ${workspaceId} not found or has no encryption key`);
7173
+ }
7174
+ return { wrappedKey, fromCache: false };
7175
+ }
7176
+ /**
7177
+ * Run `withKey` with the workspace's wrapped key. A cached key that no longer works (access was
7178
+ * re-granted with a new key) is dropped and the call retried once with a fresh list.
7179
+ */
7180
+ async withWrappedKey(workspaceId, withKey) {
7181
+ const { wrappedKey, fromCache } = await this.wrappedKeyFor(workspaceId);
7182
+ try {
7183
+ return await withKey(wrappedKey);
7184
+ } catch (error) {
7185
+ if (!fromCache) throw error;
7186
+ const fresh = await this.wrappedKeyFor(workspaceId, true);
7187
+ return withKey(fresh.wrappedKey);
7188
+ }
7189
+ }
7152
7190
  /** A workspace's key, sealed to the caller's own session (what `/open` and `POST /workspace/users` take). */
7153
7191
  async sealWorkspaceKey(workspaceId) {
7154
7192
  const client = this.requireClient();
7155
7193
  const lr2 = this.requireLogin();
7156
- const all = await listWorkspaces(client);
7157
- const ws = all.find((w2) => w2.external_id === workspaceId);
7158
- if (!ws || !ws.wrapped_key) {
7159
- throw new ArbiError(`Workspace ${workspaceId} not found or has no encryption key`);
7160
- }
7161
- return generateEncryptedWorkspaceKey(
7162
- client,
7163
- ws.wrapped_key,
7164
- lr2.serverSessionKey,
7165
- client.crypto.bytesToBase64(lr2.signingPrivateKey)
7194
+ return this.withWrappedKey(
7195
+ workspaceId,
7196
+ (wrappedKey) => generateEncryptedWorkspaceKey(
7197
+ client,
7198
+ wrappedKey,
7199
+ lr2.serverSessionKey,
7200
+ client.crypto.bytesToBase64(lr2.signingPrivateKey)
7201
+ )
7166
7202
  );
7167
7203
  }
7168
7204
  /**
7169
- * Select a workspace by ID. Fetches the workspace list, finds the matching
7170
- * workspace, decrypts the wrapped key, and sets up auth headers.
7205
+ * Select a workspace by ID. Uses the wrapped key from the last workspace list or create (the
7206
+ * list is fetched only when the workspace is not known yet), decrypts it, and opens the
7207
+ * workspace on the server.
7171
7208
  */
7172
7209
  async selectWorkspace(workspaceId) {
7173
7210
  const client = this.requireClient();
7174
7211
  const lr2 = this.requireLogin();
7175
- const allWorkspaces = await listWorkspaces(client);
7176
- const ws = allWorkspaces.find((w2) => w2.external_id === workspaceId);
7177
- if (!ws || !ws.wrapped_key) {
7178
- throw new ArbiError(`Workspace ${workspaceId} not found or has no encryption key`);
7179
- }
7180
7212
  const signingPrivateKeyBase64 = client.crypto.bytesToBase64(lr2.signingPrivateKey);
7181
- const sealedKey = await selectWorkspace(
7182
- client,
7183
- ws.external_id,
7184
- ws.wrapped_key,
7185
- lr2.serverSessionKey,
7186
- signingPrivateKeyBase64
7187
- );
7188
- await client.fetch.POST("/v1/workspace/{workspace_ext_id}/open", {
7189
- params: { path: { workspace_ext_id: ws.external_id } },
7190
- body: { workspace_key: sealedKey }
7213
+ await this.withWrappedKey(workspaceId, async (wrappedKey) => {
7214
+ const sealedKey = await selectWorkspace(
7215
+ client,
7216
+ workspaceId,
7217
+ wrappedKey,
7218
+ lr2.serverSessionKey,
7219
+ signingPrivateKeyBase64
7220
+ );
7221
+ await client.fetch.POST("/v1/workspace/{workspace_ext_id}/open", {
7222
+ params: { path: { workspace_ext_id: workspaceId } },
7223
+ body: { workspace_key: sealedKey }
7224
+ });
7191
7225
  });
7192
- this.currentWorkspaceId = ws.external_id;
7226
+ this.currentWorkspaceId = workspaceId;
7193
7227
  }
7194
7228
  /**
7195
7229
  * Subscribe to "the session cannot be recovered". Fires when a request failed with 401 or
@@ -7209,6 +7243,7 @@ var Arbi = class {
7209
7243
  this.loginResult = null;
7210
7244
  this.userProfile = null;
7211
7245
  this.currentWorkspaceId = null;
7246
+ this.wrappedKeys.clear();
7212
7247
  this.dmCryptoContext = null;
7213
7248
  this.client?.session.clear();
7214
7249
  for (const listener of [...this.sessionExpiredListeners]) listener();
@@ -7254,6 +7289,7 @@ var Arbi = class {
7254
7289
  this.loginResult = null;
7255
7290
  this.userProfile = null;
7256
7291
  this.currentWorkspaceId = null;
7292
+ this.wrappedKeys.clear();
7257
7293
  this.dmCryptoContext = null;
7258
7294
  }
7259
7295
  // ── Accessors ─────────────────────────────────────────────────────────
@@ -7395,6 +7431,7 @@ var Arbi = class {
7395
7431
  }
7396
7432
  );
7397
7433
  this.loginResult = { ...lr2, signingPrivateKey: result.newSigningPrivateKey };
7434
+ this.wrappedKeys.clear();
7398
7435
  return result;
7399
7436
  },
7400
7437
  /** Close the account (soft delete) and sign out. Refused while a subscription is active. */
@@ -7449,7 +7486,7 @@ var Arbi = class {
7449
7486
  }
7450
7487
  // ── Workspaces ────────────────────────────────────────────────────────
7451
7488
  workspaces = {
7452
- list: () => listWorkspaces(this.requireClient()),
7489
+ list: async () => this.rememberWorkspaces(await listWorkspaces(this.requireClient())),
7453
7490
  create: async (name, projectExtId, description, isPublic) => {
7454
7491
  const client = this.requireClient();
7455
7492
  const lr2 = this.requireLogin();
@@ -7458,7 +7495,7 @@ var Arbi = class {
7458
7495
  await sodium.ready;
7459
7496
  const workspaceKey = sodium.randombytes_buf(32);
7460
7497
  const encryptedKey = await client.crypto.sealKeyForSession(workspaceKey, lr2.serverSessionKey);
7461
- return createWorkspace(
7498
+ const created = await createWorkspace(
7462
7499
  client,
7463
7500
  name,
7464
7501
  encryptedKey,
@@ -7466,8 +7503,13 @@ var Arbi = class {
7466
7503
  description,
7467
7504
  isPublic
7468
7505
  );
7506
+ this.rememberWorkspaces([created]);
7507
+ return created;
7508
+ },
7509
+ delete: async (workspaceIds) => {
7510
+ await deleteWorkspaces(this.requireClient(), workspaceIds);
7511
+ for (const id of workspaceIds) this.wrappedKeys.delete(id);
7469
7512
  },
7470
- delete: (workspaceIds) => deleteWorkspaces(this.requireClient(), workspaceIds),
7471
7513
  update: (body) => updateWorkspace(this.requireClient(), body),
7472
7514
  listUsers: () => listWorkspaceUsers(this.requireClient()),
7473
7515
  addUsers: (emails, role) => addWorkspaceUsers(this.requireClient(), emails, role),
@@ -7738,7 +7780,7 @@ var Arbi = class {
7738
7780
  workspaceId: options.workspaceId ?? this.requireWorkspace()
7739
7781
  }),
7740
7782
  delete: (tagId) => deleteTag(this.requireClient(), tagId),
7741
- update: (tagId, body) => updateTag(this.requireClient(), tagId, body),
7783
+ update: (tagId, change) => updateTag(this.requireClient(), tagId, change),
7742
7784
  /** Replace a tag's own field definitions and/or merge-patch its values (`null` clears one). */
7743
7785
  updateFields: (tagId, change) => updateTagFields(this.requireClient(), tagId, change),
7744
7786
  /** Tags as rows (a parent's children, or the given tags) with field values, docs and facts. */