@abraca/nuxt 2.33.0 → 2.35.0

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.
Files changed (46) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/components/ANodeSettingsPanel.d.vue.ts +11 -4
  3. package/dist/runtime/components/ANodeSettingsPanel.vue +63 -9
  4. package/dist/runtime/components/ANodeSettingsPanel.vue.d.ts +11 -4
  5. package/dist/runtime/components/chat/ANodeChatPanel.vue +4 -0
  6. package/dist/runtime/components/docs/ADocsSearch.d.vue.ts +1 -1
  7. package/dist/runtime/components/docs/ADocsSearch.vue.d.ts +1 -1
  8. package/dist/runtime/components/renderers/ASheetsRenderer.client.vue +160 -1
  9. package/dist/runtime/components/renderers/sheets/ASheetsCell.d.vue.ts +3 -0
  10. package/dist/runtime/components/renderers/sheets/ASheetsCell.vue +30 -34
  11. package/dist/runtime/components/renderers/sheets/ASheetsCell.vue.d.ts +3 -0
  12. package/dist/runtime/components/renderers/sheets/ASheetsConditionalModal.d.vue.ts +15 -0
  13. package/dist/runtime/components/renderers/sheets/ASheetsConditionalModal.vue +226 -0
  14. package/dist/runtime/components/renderers/sheets/ASheetsConditionalModal.vue.d.ts +15 -0
  15. package/dist/runtime/components/renderers/sheets/ASheetsFindPanel.d.vue.ts +31 -0
  16. package/dist/runtime/components/renderers/sheets/ASheetsFindPanel.vue +130 -0
  17. package/dist/runtime/components/renderers/sheets/ASheetsFindPanel.vue.d.ts +31 -0
  18. package/dist/runtime/components/renderers/sheets/ASheetsGrid.vue +25 -6
  19. package/dist/runtime/components/renderers/sheets/ASheetsToolbar.d.vue.ts +6 -0
  20. package/dist/runtime/components/renderers/sheets/ASheetsToolbar.vue +39 -3
  21. package/dist/runtime/components/renderers/sheets/ASheetsToolbar.vue.d.ts +6 -0
  22. package/dist/runtime/components/renderers/sheets/ASheetsValidationModal.d.vue.ts +15 -0
  23. package/dist/runtime/components/renderers/sheets/ASheetsValidationModal.vue +185 -0
  24. package/dist/runtime/components/renderers/sheets/ASheetsValidationModal.vue.d.ts +15 -0
  25. package/dist/runtime/components/settings/ASettingsAdminPanel.vue +168 -1
  26. package/dist/runtime/components/settings/ASettingsInvitesPanel.vue +73 -11
  27. package/dist/runtime/components/shell/ADocPanelSettings.d.vue.ts +25 -3
  28. package/dist/runtime/components/shell/ADocPanelSettings.vue +28 -10
  29. package/dist/runtime/components/shell/ADocPanelSettings.vue.d.ts +25 -3
  30. package/dist/runtime/components/shell/AUserMenu.d.vue.ts +2 -2
  31. package/dist/runtime/components/shell/AUserMenu.vue.d.ts +2 -2
  32. package/dist/runtime/composables/useChatUsers.d.ts +50 -4
  33. package/dist/runtime/composables/useChatUsers.js +57 -17
  34. package/dist/runtime/composables/useDocPermissions.d.ts +137 -0
  35. package/dist/runtime/composables/useDocPermissions.js +258 -0
  36. package/dist/runtime/composables/useIdentityDoc.d.ts +1 -1
  37. package/dist/runtime/composables/useOrphans.d.ts +58 -0
  38. package/dist/runtime/composables/useOrphans.js +87 -0
  39. package/dist/runtime/composables/useSheetsFind.d.ts +35 -0
  40. package/dist/runtime/composables/useSheetsFind.js +44 -0
  41. package/dist/runtime/composables/useSheetsFormat.d.ts +40 -0
  42. package/dist/runtime/composables/useSheetsFormat.js +132 -0
  43. package/dist/runtime/composables/useSheetsValidation.d.ts +22 -0
  44. package/dist/runtime/composables/useSheetsValidation.js +38 -0
  45. package/dist/runtime/types.d.ts +52 -10
  46. package/package.json +1 -1
@@ -63,18 +63,31 @@ type __VLS_Props = {
63
63
  pendingSnapshotVersion?: number | null;
64
64
  /** Whether a snapshot is currently being created */
65
65
  creatingSnapshot?: boolean;
66
+ /** Current public-access value (`'inherit' | 'none' | 'viewer' | 'editor'`). */
67
+ publicAccessValue?: string;
68
+ /** Public-access options for the editable control. */
69
+ publicAccessOptions?: {
70
+ label: string;
71
+ value: string;
72
+ description?: string;
73
+ }[];
74
+ /** When true, the public-access indicator becomes an editable select (owner only). */
75
+ canEditPublicAccess?: boolean;
76
+ /** Whether a public-access change is currently in flight. */
77
+ savingPublicAccess?: boolean;
66
78
  };
67
- declare var __VLS_223: {}, __VLS_387: {};
79
+ declare var __VLS_230: {}, __VLS_394: {};
68
80
  type __VLS_Slots = {} & {
69
- encryption?: (props: typeof __VLS_223) => any;
81
+ encryption?: (props: typeof __VLS_230) => any;
70
82
  } & {
71
- extra?: (props: typeof __VLS_387) => any;
83
+ extra?: (props: typeof __VLS_394) => any;
72
84
  };
73
85
  declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
74
86
  "update-meta": (patch: Partial<DocPageMeta>) => any;
75
87
  "grant-permission": (userId: string, role: string) => any;
76
88
  "change-role": (userId: string, role: string) => any;
77
89
  "revoke-permission": (userId: string) => any;
90
+ "set-public-access": (value: string) => any;
78
91
  "create-invite": (options: {
79
92
  role: string;
80
93
  maxUses?: number;
@@ -94,6 +107,7 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {},
94
107
  "onGrant-permission"?: ((userId: string, role: string) => any) | undefined;
95
108
  "onChange-role"?: ((userId: string, role: string) => any) | undefined;
96
109
  "onRevoke-permission"?: ((userId: string) => any) | undefined;
110
+ "onSet-public-access"?: ((value: string) => any) | undefined;
97
111
  "onCreate-invite"?: ((options: {
98
112
  role: string;
99
113
  maxUses?: number;
@@ -132,6 +146,14 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {},
132
146
  hasMoreSnapshots: boolean;
133
147
  pendingSnapshotVersion: number | null;
134
148
  creatingSnapshot: boolean;
149
+ publicAccessValue: string;
150
+ publicAccessOptions: {
151
+ label: string;
152
+ value: string;
153
+ description?: string;
154
+ }[];
155
+ canEditPublicAccess: boolean;
156
+ savingPublicAccess: boolean;
135
157
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
136
158
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
137
159
  declare const _default: typeof __VLS_export;
@@ -14,13 +14,13 @@ type __VLS_Props = {
14
14
  extraItems?: DropdownMenuItem[][];
15
15
  };
16
16
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
17
+ logout: () => any;
17
18
  "open-settings": () => any;
18
19
  "open-account": () => any;
19
- logout: () => any;
20
20
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
21
+ onLogout?: (() => any) | undefined;
21
22
  "onOpen-settings"?: (() => any) | undefined;
22
23
  "onOpen-account"?: (() => any) | undefined;
23
- onLogout?: (() => any) | undefined;
24
24
  }>, {
25
25
  color: string;
26
26
  collapsed: boolean;
@@ -14,13 +14,13 @@ type __VLS_Props = {
14
14
  extraItems?: DropdownMenuItem[][];
15
15
  };
16
16
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
17
+ logout: () => any;
17
18
  "open-settings": () => any;
18
19
  "open-account": () => any;
19
- logout: () => any;
20
20
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
21
+ onLogout?: (() => any) | undefined;
21
22
  "onOpen-settings"?: (() => any) | undefined;
22
23
  "onOpen-account"?: (() => any) | undefined;
23
- onLogout?: (() => any) | undefined;
24
24
  }>, {
25
25
  color: string;
26
26
  collapsed: boolean;
@@ -1,13 +1,33 @@
1
1
  /**
2
2
  * useChatUsers
3
3
  *
4
- * Maps awareness public keys to user appearance data (name, color, neutral).
5
- * Provides `getUserAppearance(publicKey)` and `onlineUsers` — useful when
6
- * rendering chat messages from users who may be offline.
4
+ * Maps awareness public keys to user appearance data (name, color, neutral) and
5
+ * surfaces AI-agent activity broadcast over awareness. Provides
6
+ * `getUserAppearance(publicKey)`, `onlineUsers`, and the agent layer
7
+ * (`activeAgents`, `isAgentUser`, `getAgentStatus`) that feeds
8
+ * `<AChatAgentStatus>` / agent presence UIs.
9
+ *
10
+ * Agents are ordinary awareness participants that additionally stamp
11
+ * `user.isAgent` plus per-turn `status` / `activeToolCall` / `toolHistory`
12
+ * fields (the RPC-v1 / MCP runner convention). This reads those fields from the
13
+ * active provider's awareness — no app wiring required.
7
14
  *
8
15
  * Usage:
9
- * const { getUserAppearance, onlineUsers } = useChatUsers()
16
+ * const { getUserAppearance, onlineUsers, activeAgents } = useChatUsers()
17
+ * <AChatAgentStatus :agents="activeAgents" />
10
18
  */
19
+ export interface AgentToolCall {
20
+ name: string;
21
+ target?: string;
22
+ }
23
+ export interface AgentToolHistoryEntry {
24
+ tool: string;
25
+ target?: string;
26
+ ts: number;
27
+ channel?: string | null;
28
+ /** Expandable detail (diff / code / command / text) broadcast by the agent. */
29
+ detail?: unknown;
30
+ }
11
31
  export interface ChatUserAppearance {
12
32
  name: string;
13
33
  color: string;
@@ -16,8 +36,34 @@ export interface ChatUserAppearance {
16
36
  isOnline: boolean;
17
37
  /** Doc the user is currently viewing (from awareness `docId` field). */
18
38
  docId?: string;
39
+ /** True when this participant is an AI agent (awareness `user.isAgent`). */
40
+ isAgent?: boolean;
41
+ }
42
+ /** Shape consumed by `<AChatAgentStatus :agents>`. */
43
+ export interface ActiveAgent {
44
+ name: string;
45
+ publicKey: string;
46
+ status?: 'thinking' | string | null;
47
+ statusContext?: string;
48
+ turnId?: string | null;
49
+ activeToolCall?: AgentToolCall | null;
50
+ toolHistory?: AgentToolHistoryEntry[];
51
+ /** Doc/channel the agent is currently acting in. */
52
+ docId?: string;
53
+ }
54
+ interface RawAgentState {
55
+ status?: string;
56
+ statusContext?: string;
57
+ turnId?: string | null;
58
+ activeToolCall?: AgentToolCall | null;
59
+ toolHistory?: AgentToolHistoryEntry[];
19
60
  }
20
61
  export declare function useChatUsers(): {
21
62
  onlineUsers: import("vue").ComputedRef<ChatUserAppearance[]>;
22
63
  getUserAppearance: (publicKey: string) => ChatUserAppearance;
64
+ activeAgents: import("vue").ComputedRef<ActiveAgent[]>;
65
+ agentsForChannel: (docId: string) => ActiveAgent[];
66
+ isAgentUser: (publicKey: string) => boolean;
67
+ getAgentStatus: (publicKey: string) => RawAgentState | undefined;
23
68
  };
69
+ export {};
@@ -3,26 +3,30 @@ import { deriveColorFromPubKey } from "../types.js";
3
3
  import { useAbracadabra } from "./useAbracadabra.js";
4
4
  export function useChatUsers() {
5
5
  const { provider } = useAbracadabra();
6
- const onlineUsers = computed(() => {
6
+ function readStates() {
7
7
  if (!provider.value?.awareness) return [];
8
- const result = [];
9
8
  try {
10
- const states = provider.value.awareness.states;
11
- for (const state of states.values()) {
12
- const u = state.user;
13
- if (u?.publicKey) {
14
- result.push({
15
- name: u.name ?? "Anonymous",
16
- color: u.color ?? "#888",
17
- neutralName: "zinc",
18
- publicKey: u.publicKey,
19
- isOnline: true,
20
- docId: typeof state.docId === "string" ? state.docId : void 0
21
- });
22
- }
23
- }
9
+ return [...provider.value.awareness.states.values()];
24
10
  } catch (e) {
25
11
  if (import.meta.dev) console.warn("[abracadabra] chat-users: failed to read awareness states:", e);
12
+ return [];
13
+ }
14
+ }
15
+ const onlineUsers = computed(() => {
16
+ const result = [];
17
+ for (const state of readStates()) {
18
+ const u = state.user;
19
+ if (u?.publicKey) {
20
+ result.push({
21
+ name: u.name ?? "Anonymous",
22
+ color: u.color ?? "#888",
23
+ neutralName: u.colorNeutral ?? "zinc",
24
+ publicKey: u.publicKey,
25
+ isOnline: true,
26
+ docId: typeof state.docId === "string" ? state.docId : void 0,
27
+ isAgent: !!u.isAgent
28
+ });
29
+ }
26
30
  }
27
31
  return result;
28
32
  });
@@ -38,5 +42,41 @@ export function useChatUsers() {
38
42
  isOnline: false
39
43
  };
40
44
  }
41
- return { onlineUsers, getUserAppearance };
45
+ const activeAgents = computed(
46
+ () => readStates().filter((s) => s.user?.publicKey && s.user?.isAgent).map((s) => ({
47
+ name: s.user.name ?? "Agent",
48
+ publicKey: s.user.publicKey,
49
+ status: s.status ?? null,
50
+ statusContext: s.statusContext,
51
+ turnId: s.turnId ?? null,
52
+ activeToolCall: s.activeToolCall ?? null,
53
+ toolHistory: Array.isArray(s.toolHistory) ? s.toolHistory : void 0,
54
+ docId: typeof s.docId === "string" ? s.docId : void 0
55
+ }))
56
+ );
57
+ function agentsForChannel(docId) {
58
+ return activeAgents.value.filter((a) => a.docId === docId);
59
+ }
60
+ function isAgentUser(publicKey) {
61
+ return activeAgents.value.some((a) => a.publicKey === publicKey);
62
+ }
63
+ function getAgentStatus(publicKey) {
64
+ const a = activeAgents.value.find((x) => x.publicKey === publicKey);
65
+ if (!a) return void 0;
66
+ return {
67
+ status: a.status ?? void 0,
68
+ statusContext: a.statusContext,
69
+ turnId: a.turnId,
70
+ activeToolCall: a.activeToolCall,
71
+ toolHistory: a.toolHistory
72
+ };
73
+ }
74
+ return {
75
+ onlineUsers,
76
+ getUserAppearance,
77
+ activeAgents,
78
+ agentsForChannel,
79
+ isAgentUser,
80
+ getAgentStatus
81
+ };
42
82
  }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * useDocPermissions
3
+ *
4
+ * Server-backed per-document permissions + public-access engine. This is the
5
+ * piece that makes `<ADocPanelSettings>` / `<ANodeSettingsPanel managePermissions>`
6
+ * actually *work* — the panel only emits `grant-permission` / `change-role` /
7
+ * `revoke-permission` / `set-public-access`; something has to fulfil them.
8
+ *
9
+ * It wraps the SDK permission surface
10
+ * (`listEffectivePermissions` / `setPermission` / `removePermission` /
11
+ * `getDocumentAccess` / `setDocumentAccess`) and re-shapes the server's
12
+ * snake_case rows into the camelCase `PermissionEntry` the panel renders.
13
+ *
14
+ * On grant, if the doc is E2E it rewraps the granter's DocKey for the new
15
+ * member's x25519 pubkey so they can read+write immediately (a soft failure
16
+ * surfaces on `warning`, it never rolls the grant back).
17
+ *
18
+ * Presentation-free by design: hard failures land on `error`, soft E2E
19
+ * warnings on `warning`. Toast them in your composer if you want — the
20
+ * composable never imports `useToast`.
21
+ *
22
+ * Usage (engine only):
23
+ * const perms = useDocPermissions(() => docId.value, { provider, users })
24
+ * await perms.refresh()
25
+ * // feed perms.permissions / perms.isOwner / … into <ADocPanelSettings>
26
+ *
27
+ * Or let `<ANodeSettingsPanel managePermissions />` wire it for you.
28
+ */
29
+ import { type MaybeRefOrGetter, type Ref } from 'vue';
30
+ import { type AbracadabraProvider } from '@abraca/dabra';
31
+ export type DocRole = 'owner' | 'editor' | 'viewer' | 'observer';
32
+ /** Camel-cased to match `<ADocPanelSettings>`'s `PermissionEntry` exactly. */
33
+ export interface DocPermissionEntry {
34
+ userId: string;
35
+ username: string;
36
+ displayName: string | null;
37
+ role: DocRole;
38
+ source: 'direct' | 'inherited';
39
+ inheritedFromDocId?: string;
40
+ }
41
+ /** Minimal online-user shape (matches `<ADocPanelSettings>`'s `OnlineUser`). */
42
+ export interface DocPermsOnlineUser {
43
+ publicKey: string;
44
+ name: string;
45
+ color?: string;
46
+ }
47
+ export interface DocPermsLabels {
48
+ publicAccessInherit: string;
49
+ publicAccessInheritDesc: string;
50
+ publicAccessNone: string;
51
+ publicAccessNoneDesc: string;
52
+ publicAccessViewer: string;
53
+ publicAccessViewerDesc: string;
54
+ publicAccessEditor: string;
55
+ publicAccessEditorDesc: string;
56
+ roleOwner: string;
57
+ roleEditor: string;
58
+ roleViewer: string;
59
+ roleObserver: string;
60
+ }
61
+ /** Returns the more-privileged of two role strings (mirrors `Role::max`). */
62
+ export declare function roleMax(a: string, b: string): string;
63
+ export declare function useDocPermissions(docId: MaybeRefOrGetter<string>, options?: {
64
+ /** Provider for THIS doc — used to read `effectiveRole` while the first fetch is in flight. */
65
+ provider?: Ref<AbracadabraProvider | null> | {
66
+ value: AbracadabraProvider | null;
67
+ };
68
+ /** Currently-online users — drives `onlineNotGranted` + avatar colors. */
69
+ users?: MaybeRefOrGetter<DocPermsOnlineUser[]>;
70
+ /** Locale overrides for the public-access + role labels this composable produces. */
71
+ labels?: Partial<DocPermsLabels>;
72
+ }): {
73
+ permissions: import("vue").ShallowRef<DocPermissionEntry[], DocPermissionEntry[]>;
74
+ directPermissions: import("vue").ComputedRef<DocPermissionEntry[]>;
75
+ inheritedPermissions: import("vue").ComputedRef<DocPermissionEntry[]>;
76
+ hasInheritedPermissions: import("vue").ComputedRef<boolean>;
77
+ inheritedFromDocId: import("vue").ComputedRef<string | null>;
78
+ inheritedFromLabel: import("vue").ComputedRef<string | null>;
79
+ loadingPermissions: Ref<boolean, boolean>;
80
+ error: Ref<string | null, string | null>;
81
+ warning: Ref<string | null, string | null>;
82
+ serverDefaultRole: Ref<string | null, string | null>;
83
+ docAccess: import("vue").ShallowRef<{
84
+ public_access: string | null;
85
+ effective_public_access: string | null;
86
+ } | null, {
87
+ public_access: string | null;
88
+ effective_public_access: string | null;
89
+ } | null>;
90
+ savingAccess: Ref<boolean, boolean>;
91
+ currentPublicAccessValue: import("vue").ComputedRef<string>;
92
+ publicAccessOptions: import("vue").ComputedRef<{
93
+ label: string;
94
+ value: string;
95
+ description: string;
96
+ }[]>;
97
+ roleItems: import("vue").ComputedRef<({
98
+ label: string;
99
+ value: "owner";
100
+ } | {
101
+ label: string;
102
+ value: "editor";
103
+ } | {
104
+ label: string;
105
+ value: "viewer";
106
+ } | {
107
+ label: string;
108
+ value: "observer";
109
+ })[]>;
110
+ effectiveRole: import("vue").ComputedRef<string | null>;
111
+ isOwner: import("vue").ComputedRef<boolean>;
112
+ myPermission: import("vue").ComputedRef<DocPermissionEntry | null>;
113
+ providerRole: import("vue").ComputedRef<"observer" | "viewer" | "editor" | "owner" | "admin" | "service" | null>;
114
+ onlineNotGranted: import("vue").ComputedRef<DocPermsOnlineUser[]>;
115
+ fetchPermissions: () => Promise<void>;
116
+ fetchDocAccess: () => Promise<void>;
117
+ refresh: () => Promise<void>;
118
+ setPublicAccess: (value: string | null) => Promise<void>;
119
+ grantPermission: (userId: string, role: DocRole) => Promise<void>;
120
+ changeRole: (userId: string, role: DocRole) => Promise<void>;
121
+ revokePermission: (userId: string) => Promise<void>;
122
+ findOnlineUser: (perm: {
123
+ userId: string;
124
+ username: string;
125
+ displayName: string | null;
126
+ }) => DocPermsOnlineUser | undefined;
127
+ isPermOnline: (perm: {
128
+ userId: string;
129
+ username: string;
130
+ displayName: string | null;
131
+ }) => boolean;
132
+ permAvatarStyle: (perm: {
133
+ userId: string;
134
+ username: string;
135
+ displayName: string | null;
136
+ }) => string;
137
+ };
@@ -0,0 +1,258 @@
1
+ import { computed, ref, shallowRef, toValue } from "vue";
2
+ import {
3
+ DocKeyManager,
4
+ toPlain
5
+ } from "@abraca/dabra";
6
+ import { deriveColorFromPubKey } from "../types.js";
7
+ import { avatarBorderStyle } from "../utils/avatarStyle.js";
8
+ import { useAbracadabra } from "./useAbracadabra.js";
9
+ const DEFAULT_LABELS = {
10
+ publicAccessInherit: "Inherit from parent",
11
+ publicAccessInheritDesc: "Use whatever the parent document allows.",
12
+ publicAccessNone: "No public access",
13
+ publicAccessNoneDesc: "Only explicitly granted members can open this.",
14
+ publicAccessViewer: "Anyone can view",
15
+ publicAccessViewerDesc: "Anyone with the link can read.",
16
+ publicAccessEditor: "Anyone can edit",
17
+ publicAccessEditorDesc: "Anyone with the link can read and write.",
18
+ roleOwner: "Owner",
19
+ roleEditor: "Editor",
20
+ roleViewer: "Viewer",
21
+ roleObserver: "Observer"
22
+ };
23
+ const ROLE_RANK = { observer: 0, viewer: 1, editor: 2, owner: 3 };
24
+ export function roleMax(a, b) {
25
+ return (ROLE_RANK[a] ?? -1) >= (ROLE_RANK[b] ?? -1) ? a : b;
26
+ }
27
+ export function useDocPermissions(docId, options) {
28
+ const { client, provider: rootProvider, publicKeyB64, userName, keystore } = useAbracadabra();
29
+ const labels = { ...DEFAULT_LABELS, ...options?.labels ?? {} };
30
+ const id = () => toValue(docId);
31
+ const users = () => options?.users ? toValue(options.users) : [];
32
+ const permissions = shallowRef([]);
33
+ const serverDefaultRole = ref(null);
34
+ const loadingPermissions = ref(false);
35
+ const error = ref(null);
36
+ const warning = ref(null);
37
+ const docAccess = shallowRef(null);
38
+ const savingAccess = ref(false);
39
+ const providerRole = computed(() => options?.provider?.value?.effectiveRole ?? null);
40
+ const myPermission = computed(() => {
41
+ const pk = publicKeyB64.value;
42
+ const list = permissions.value;
43
+ if (pk) {
44
+ const byKey = list.find((p) => p.userId === pk);
45
+ if (byKey) return byKey;
46
+ }
47
+ return list.find((p) => p.displayName === userName.value || p.username === userName.value) ?? null;
48
+ });
49
+ const effectiveRole = computed(() => {
50
+ if (loadingPermissions.value && permissions.value.length === 0) {
51
+ return providerRole.value ?? null;
52
+ }
53
+ const explicit = myPermission.value?.role ?? null;
54
+ const pub = docAccess.value?.public_access ?? docAccess.value?.effective_public_access;
55
+ const publicFloor = pub && pub !== "none" ? pub : null;
56
+ const def = serverDefaultRole.value || null;
57
+ if (explicit && publicFloor) return roleMax(explicit, publicFloor);
58
+ if (explicit) return explicit;
59
+ if (publicFloor && def) return roleMax(publicFloor, def);
60
+ if (publicFloor) return publicFloor;
61
+ return def ?? providerRole.value ?? null;
62
+ });
63
+ const isOwner = computed(() => effectiveRole.value === "owner");
64
+ const directPermissions = computed(() => permissions.value.filter((p) => p.source === "direct"));
65
+ const inheritedPermissions = computed(() => permissions.value.filter((p) => p.source === "inherited"));
66
+ const hasInheritedPermissions = computed(() => inheritedPermissions.value.length > 0);
67
+ const inheritedFromDocId = computed(() => inheritedPermissions.value[0]?.inheritedFromDocId ?? null);
68
+ const inheritedFromLabel = computed(() => {
69
+ if (!inheritedFromDocId.value) return null;
70
+ try {
71
+ const rootDoc = rootProvider.value?.document;
72
+ if (!rootDoc) return null;
73
+ const treeMap = rootDoc.getMap("doc-tree");
74
+ const entry = toPlain(treeMap.get(inheritedFromDocId.value));
75
+ if (entry && typeof entry === "object" && "label" in entry) return entry.label || null;
76
+ } catch {
77
+ }
78
+ return null;
79
+ });
80
+ const currentPublicAccessValue = computed(() => docAccess.value?.public_access ?? "inherit");
81
+ const publicAccessOptions = computed(() => [
82
+ { label: labels.publicAccessInherit, value: "inherit", description: labels.publicAccessInheritDesc },
83
+ { label: labels.publicAccessNone, value: "none", description: labels.publicAccessNoneDesc },
84
+ { label: labels.publicAccessViewer, value: "viewer", description: labels.publicAccessViewerDesc },
85
+ { label: labels.publicAccessEditor, value: "editor", description: labels.publicAccessEditorDesc }
86
+ ]);
87
+ const roleItems = computed(() => [
88
+ { label: labels.roleOwner, value: "owner" },
89
+ { label: labels.roleEditor, value: "editor" },
90
+ { label: labels.roleViewer, value: "viewer" },
91
+ { label: labels.roleObserver, value: "observer" }
92
+ ]);
93
+ const onlineNotGranted = computed(
94
+ () => users().filter(
95
+ (u) => u.publicKey && u.publicKey !== publicKeyB64.value && !permissions.value.some((p) => p.userId === u.publicKey || (p.displayName || p.username) === u.name)
96
+ )
97
+ );
98
+ function findOnlineUser(perm) {
99
+ return users().find(
100
+ (u) => u.publicKey && u.publicKey === perm.userId || u.name === (perm.displayName || perm.username)
101
+ );
102
+ }
103
+ function isPermOnline(perm) {
104
+ return !!findOnlineUser(perm);
105
+ }
106
+ function permAvatarStyle(perm) {
107
+ const online = findOnlineUser(perm);
108
+ const { hsl, neutralName } = deriveColorFromPubKey(perm.userId);
109
+ return avatarBorderStyle(online?.color ?? hsl, neutralName);
110
+ }
111
+ async function fetchPermissions() {
112
+ const docIdValue = id();
113
+ if (!docIdValue) return;
114
+ if (!client.value) {
115
+ permissions.value = [];
116
+ return;
117
+ }
118
+ loadingPermissions.value = true;
119
+ error.value = null;
120
+ try {
121
+ const res = await client.value.listEffectivePermissions(docIdValue);
122
+ permissions.value = res.permissions.map((p) => ({
123
+ userId: p.user_id,
124
+ username: p.username,
125
+ displayName: p.display_name,
126
+ role: p.role,
127
+ source: p.source,
128
+ inheritedFromDocId: p.inherited_from_doc_id
129
+ }));
130
+ serverDefaultRole.value = res.default_role;
131
+ } catch (e) {
132
+ error.value = e.message;
133
+ } finally {
134
+ loadingPermissions.value = false;
135
+ }
136
+ }
137
+ async function fetchDocAccess() {
138
+ const docIdValue = id();
139
+ if (!client.value || !docIdValue) return;
140
+ try {
141
+ docAccess.value = await client.value.getDocumentAccess(docIdValue);
142
+ } catch {
143
+ }
144
+ }
145
+ async function refresh() {
146
+ await Promise.all([fetchPermissions(), fetchDocAccess()]);
147
+ }
148
+ async function setPublicAccess(value) {
149
+ const docIdValue = id();
150
+ if (!client.value || !docIdValue) return;
151
+ savingAccess.value = true;
152
+ error.value = null;
153
+ try {
154
+ await client.value.setDocumentAccess(docIdValue, value === "inherit" ? null : value);
155
+ docAccess.value = await client.value.getDocumentAccess(docIdValue);
156
+ } catch (e) {
157
+ error.value = e.message;
158
+ } finally {
159
+ savingAccess.value = false;
160
+ }
161
+ }
162
+ async function _maybeProvisionEnvelopeForGrantee(targetDocId, granteeUserId) {
163
+ if (!client.value || !keystore.value) return;
164
+ const enc = await client.value.getDocEncryption(targetDocId);
165
+ if (enc.effective_mode !== "e2e") return;
166
+ const granteeKeys = await client.value.listUserKeys(granteeUserId);
167
+ if (!granteeKeys.length) throw new Error("grantee has no registered keys");
168
+ const granteeKey = granteeKeys[0];
169
+ if (!granteeKey.x25519Key) throw new Error("grantee has no x25519 pubkey on their primary key");
170
+ const dkm = new DocKeyManager();
171
+ const docKey = await dkm.getDocKey(targetDocId, client.value, keystore.value);
172
+ if (!docKey) throw new Error("granter has no key envelope for this doc \u2014 cannot rewrap");
173
+ const x25519Pub = Uint8Array.from(
174
+ atob(granteeKey.x25519Key.replace(/-/g, "+").replace(/_/g, "/")),
175
+ (c) => c.charCodeAt(0)
176
+ );
177
+ const wrapped = await dkm.wrapKeyForRecipient(docKey, x25519Pub, targetDocId);
178
+ const b64 = btoa(String.fromCharCode(...wrapped));
179
+ await client.value.uploadKeyEnvelopes(targetDocId, {
180
+ key_epoch: 1,
181
+ envelopes: [{ recipient_key_id: granteeKey.id, encrypted_key: b64 }]
182
+ });
183
+ }
184
+ async function grantPermission(userId, role) {
185
+ const docIdValue = id();
186
+ if (!client.value || !userId || !docIdValue) return;
187
+ error.value = null;
188
+ warning.value = null;
189
+ try {
190
+ await client.value.setPermission(docIdValue, { user_id: userId, role });
191
+ try {
192
+ await _maybeProvisionEnvelopeForGrantee(docIdValue, userId);
193
+ } catch (e) {
194
+ warning.value = e?.message ?? "Granted access, but E2E key provisioning failed. Re-grant or rotate the channel key.";
195
+ }
196
+ await fetchPermissions();
197
+ } catch (e) {
198
+ error.value = e.message;
199
+ }
200
+ }
201
+ async function changeRole(userId, role) {
202
+ const docIdValue = id();
203
+ if (!client.value || !docIdValue) return;
204
+ error.value = null;
205
+ try {
206
+ await client.value.setPermission(docIdValue, { user_id: userId, role });
207
+ await fetchPermissions();
208
+ } catch (e) {
209
+ error.value = e.message;
210
+ }
211
+ }
212
+ async function revokePermission(userId) {
213
+ const docIdValue = id();
214
+ if (!client.value || !docIdValue) return;
215
+ error.value = null;
216
+ try {
217
+ await client.value.removePermission(docIdValue, { user_id: userId });
218
+ await fetchPermissions();
219
+ } catch (e) {
220
+ error.value = e.message;
221
+ }
222
+ }
223
+ return {
224
+ // State
225
+ permissions,
226
+ directPermissions,
227
+ inheritedPermissions,
228
+ hasInheritedPermissions,
229
+ inheritedFromDocId,
230
+ inheritedFromLabel,
231
+ loadingPermissions,
232
+ error,
233
+ warning,
234
+ serverDefaultRole,
235
+ docAccess,
236
+ savingAccess,
237
+ currentPublicAccessValue,
238
+ publicAccessOptions,
239
+ roleItems,
240
+ effectiveRole,
241
+ isOwner,
242
+ myPermission,
243
+ providerRole,
244
+ onlineNotGranted,
245
+ // Actions
246
+ fetchPermissions,
247
+ fetchDocAccess,
248
+ refresh,
249
+ setPublicAccess,
250
+ grantPermission,
251
+ changeRole,
252
+ revokePermission,
253
+ // Helpers
254
+ findOnlineUser,
255
+ isPermOnline,
256
+ permAvatarStyle
257
+ };
258
+ }
@@ -59,7 +59,7 @@ export declare function useIdentityDoc(): {
59
59
  userName: import("vue").Ref<string, string>;
60
60
  userColorName: import("vue").Ref<string, string>;
61
61
  neutralColorName: import("vue").Ref<string, string>;
62
- securityTier: import("vue").Ref<"relaxed" | "standard" | "paranoid", "relaxed" | "standard" | "paranoid">;
62
+ securityTier: import("vue").Ref<"standard" | "relaxed" | "paranoid", "standard" | "relaxed" | "paranoid">;
63
63
  init: typeof init;
64
64
  destroy: typeof destroy;
65
65
  setUserName: typeof setUserName;