@abraca/nuxt 2.74.0 → 2.76.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.
package/dist/module.d.mts CHANGED
@@ -5,6 +5,7 @@ import { AbracadabraLocale } from '../dist/runtime/locale.js';
5
5
  export { AbracadabraLocale } from '../dist/runtime/locale.js';
6
6
  export { DocTreeReturn } from '../dist/runtime/composables/useDocTree.js';
7
7
  export { DocSeoOptions } from '../dist/runtime/composables/useDocSeo.js';
8
+ export { AppNotification, NotificationType } from '../dist/runtime/composables/useNotifications.js';
8
9
  export { DocDragState } from '../dist/runtime/composables/useDocDragBus.js';
9
10
  export { ParsedMessage, TextSegment, parseMessageContent, previewMessageContent, renderMessageSegments } from '../dist/runtime/utils/chatContent.js';
10
11
  export { DupEntry, duplicateDocContent, duplicateDocTree } from '../dist/runtime/utils/duplicateDocContent.js';
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "2.74.0",
7
+ "version": "2.76.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -18,7 +18,11 @@ declare var __VLS_1: {
18
18
  name?: string | undefined;
19
19
  color?: string | undefined;
20
20
  avatar?: string | undefined;
21
+ statusIcon?: string | undefined;
22
+ statusText?: string | undefined;
23
+ publicKey?: string | undefined;
21
24
  } | undefined;
25
+ docId?: string | undefined;
22
26
  } | null;
23
27
  avatarStyle: typeof userAvatarStyle;
24
28
  }, __VLS_3: {
@@ -18,7 +18,11 @@ declare var __VLS_1: {
18
18
  name?: string | undefined;
19
19
  color?: string | undefined;
20
20
  avatar?: string | undefined;
21
+ statusIcon?: string | undefined;
22
+ statusText?: string | undefined;
23
+ publicKey?: string | undefined;
21
24
  } | undefined;
25
+ docId?: string | undefined;
22
26
  } | null;
23
27
  avatarStyle: typeof userAvatarStyle;
24
28
  }, __VLS_3: {
@@ -12,8 +12,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
12
12
  awareness: boolean;
13
13
  tag: "video" | "audio";
14
14
  live: boolean;
15
- total: boolean;
16
15
  controls: boolean;
16
+ total: boolean;
17
17
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
18
  declare const _default: typeof __VLS_export;
19
19
  export default _default;
@@ -12,8 +12,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
12
12
  awareness: boolean;
13
13
  tag: "video" | "audio";
14
14
  live: boolean;
15
- total: boolean;
16
15
  controls: boolean;
16
+ total: boolean;
17
17
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
18
  declare const _default: typeof __VLS_export;
19
19
  export default _default;
@@ -1,5 +1,5 @@
1
1
  import type { MaybeRef } from 'vue';
2
- import type { AwarenessPeer } from '../types.js';
2
+ import type { AwarenessPeer, AwarenessUser } from '../types.js';
3
3
  /**
4
4
  * Reactive awareness peer list with idle detection and doc-scoped filtering.
5
5
  *
@@ -19,15 +19,23 @@ export declare function useAwarenessPeers(): {
19
19
  name?: string | undefined;
20
20
  color?: string | undefined;
21
21
  avatar?: string | undefined;
22
+ statusIcon?: string | undefined;
23
+ statusText?: string | undefined;
24
+ publicKey?: string | undefined;
22
25
  } | undefined;
23
- } | null, import("./useYDoc.js").AwarenessUser | {
26
+ docId?: string | undefined;
27
+ } | null, AwarenessUser | {
24
28
  [x: string]: any;
25
29
  clientId: number;
26
30
  user?: {
27
31
  name?: string | undefined;
28
32
  color?: string | undefined;
29
33
  avatar?: string | undefined;
34
+ statusIcon?: string | undefined;
35
+ statusText?: string | undefined;
36
+ publicKey?: string | undefined;
30
37
  } | undefined;
38
+ docId?: string | undefined;
31
39
  } | null>;
32
40
  isIdle: (clientId: number, thresholdMs?: number) => boolean;
33
41
  peersInDoc: (docId: MaybeRef<string>) => import("vue").ComputedRef<AwarenessPeer[]>;
@@ -26,7 +26,34 @@ export interface ChatChannel {
26
26
  lastMessage?: ChatMessage;
27
27
  unreadCount: number;
28
28
  }
29
+ /**
30
+ * Deterministic doc id of the DM between two pubkeys — a real `kind = "dm"`
31
+ * document at the server root, derived from the sorted pair so both sides
32
+ * compute the same target without coordinating.
33
+ *
34
+ * ⚠️ This REPLACES the old synthetic `dm:<a>:<b>` key. That key was never a
35
+ * doc, and since the server unified chat + notifications onto the document
36
+ * tree it rejects it outright:
37
+ *
38
+ * WARN abracadabra::messages: Messages: handler error for messages:send:
39
+ * not found: document dm:<a>:<b> not found
40
+ *
41
+ * The symptom is nasty because the send is fire-and-forget: the message
42
+ * appears locally via the optimistic echo and is simply never persisted or
43
+ * delivered. (Found in abracadabra-atrium — every DM silently vanished.)
44
+ *
45
+ * The doc must EXIST before the first send. Call `ensureDmChannel()` once when
46
+ * opening a conversation; this function is the cheap synchronous derivation
47
+ * for keying reactive state.
48
+ */
29
49
  export declare function buildDmChannelId(a: string, b: string): string;
50
+ /**
51
+ * Find-or-create the backing DM doc (`kind = "dm"`, `public_access = "none"`,
52
+ * explicit Editor rows for both participants) and return its id. Idempotent
53
+ * and race-tolerant — both sides derive the same id, so a concurrent create
54
+ * resolves to the same doc. Await this before the conversation's first send.
55
+ */
56
+ export declare function ensureDmChannel(otherPubkey: string): Promise<string | null>;
30
57
  declare function setMuted(id: string, on: boolean): void;
31
58
  declare function setPinned(id: string, on: boolean): void;
32
59
  declare function setHidden(id: string, on: boolean): void;
@@ -71,6 +98,7 @@ export declare function useChat(): {
71
98
  sendTyping: typeof sendTyping;
72
99
  setActiveChannel: typeof setActiveChannel;
73
100
  buildDmChannelId: typeof buildDmChannelId;
101
+ ensureDmChannel: typeof ensureDmChannel;
74
102
  mutedChannels: import("vue").Ref<Set<string> & Omit<Set<string>, keyof Set<any>>, Set<string> | (Set<string> & Omit<Set<string>, keyof Set<any>>)>;
75
103
  pinnedChannels: import("vue").Ref<Set<string> & Omit<Set<string>, keyof Set<any>>, Set<string> | (Set<string> & Omit<Set<string>, keyof Set<any>>)>;
76
104
  hiddenChannels: import("vue").Ref<Set<string> & Omit<Set<string>, keyof Set<any>>, Set<string> | (Set<string> & Omit<Set<string>, keyof Set<any>>)>;
@@ -5,6 +5,7 @@ import {
5
5
  ChannelKeyResolver,
6
6
  DocKeyManager,
7
7
  decryptChatContent,
8
+ deriveDmDocId,
8
9
  foldRecords,
9
10
  isEncryptedContent,
10
11
  recordFromYAny
@@ -22,7 +23,18 @@ function _resolveChannelKey(client) {
22
23
  return resolver;
23
24
  }
24
25
  export function buildDmChannelId(a, b) {
25
- return `dm:${[a, b].sort().join(":")}`;
26
+ return deriveDmDocId(a, b);
27
+ }
28
+ export async function ensureDmChannel(otherPubkey) {
29
+ const { client } = useAbracadabra();
30
+ const c = client.value;
31
+ if (!c?.findOrCreateDmDoc) return null;
32
+ try {
33
+ return await c.findOrCreateDmDoc(otherPubkey);
34
+ } catch (e) {
35
+ console.error("[abracadabra] ensureDmChannel failed:", e);
36
+ return null;
37
+ }
26
38
  }
27
39
  function normalizeChannel(channelId) {
28
40
  if (typeof channelId !== "string" || !channelId) return "";
@@ -199,7 +211,12 @@ export function _handleStatelessChat(payload) {
199
211
  // human-readable name from awareness so peers don't all show as
200
212
  // the placeholder "User" — that visual collapse was being read
201
213
  // as "chat is broken / messages aren't syncing".
202
- senderName: rec.sender_name ?? resolveSenderName(senderId),
214
+ //
215
+ // Falsy test, NOT `??`: the server round-trips `sender_name` as an
216
+ // EMPTY STRING rather than null, which `??` happily passes through —
217
+ // so every received message rendered with a blank byline (observed on
218
+ // abracadabra-atrium's DMs) while the resolver sat right there unused.
219
+ senderName: rec.sender_name || resolveSenderName(senderId),
203
220
  content: rec.content ?? "",
204
221
  createdAt: tsMs,
205
222
  ...rec.reply_to ? { replyTo: rec.reply_to } : {}
@@ -435,6 +452,7 @@ export function useChat() {
435
452
  sendTyping,
436
453
  setActiveChannel,
437
454
  buildDmChannelId,
455
+ ensureDmChannel,
438
456
  // Channel preferences
439
457
  mutedChannels,
440
458
  pinnedChannels,
@@ -20,10 +20,11 @@ export declare function useChildTree(rootDoc: ShallowRef<Y.Doc | null>, parentDo
20
20
  childrenOf: (parentId: string | null) => TreeEntry[];
21
21
  descendantsOf: (id: string) => TreeEntry[];
22
22
  createChild: (parentId: string | null, label: string, type?: string) => string;
23
+ createChildRegistered: (parentId: string | null, label: string, type?: string) => Promise<string>;
23
24
  registerDoc: (id: string, parentId: string, opts?: {
24
25
  label?: string;
25
26
  type?: string;
26
- }) => void;
27
+ }) => Promise<void>;
27
28
  moveEntry: (id: string, newParentId: string | null, newOrder: number) => void;
28
29
  deleteEntry: (id: string) => void;
29
30
  renameEntry: (id: string, label: string) => void;
@@ -62,18 +62,16 @@ export function useChildTree(rootDoc, parentDocId, options) {
62
62
  }
63
63
  function registerDoc(id, parentId, opts) {
64
64
  const client = abraState?.client?.value;
65
- if (import.meta.server || !client?.createChild) return;
66
- client.createChild(parentId, {
65
+ if (import.meta.server || !client?.createChild) return Promise.resolve();
66
+ return client.createChild(parentId, {
67
67
  child_id: id,
68
68
  label: opts?.label,
69
69
  doc_type: opts?.type
70
- }).catch(() => {
70
+ }).then(() => void 0).catch(() => {
71
71
  });
72
72
  }
73
- function createChild(parentId, label, type) {
74
- const id = crypto.randomUUID();
73
+ function writeTreeEntry(id, resolvedParent, label, type) {
75
74
  const now = Date.now();
76
- const resolvedParent = parentId === null ? parentDocId : parentId;
77
75
  treeMap.set(id, {
78
76
  label,
79
77
  parentId: resolvedParent,
@@ -82,7 +80,19 @@ export function useChildTree(rootDoc, parentDocId, options) {
82
80
  createdAt: now,
83
81
  updatedAt: now
84
82
  });
85
- registerDoc(id, resolvedParent, { label, type });
83
+ }
84
+ function createChild(parentId, label, type) {
85
+ const id = crypto.randomUUID();
86
+ const resolvedParent = parentId === null ? parentDocId : parentId;
87
+ void registerDoc(id, resolvedParent, { label, type });
88
+ writeTreeEntry(id, resolvedParent, label, type);
89
+ return id;
90
+ }
91
+ async function createChildRegistered(parentId, label, type) {
92
+ const id = crypto.randomUUID();
93
+ const resolvedParent = parentId === null ? parentDocId : parentId;
94
+ await registerDoc(id, resolvedParent, { label, type });
95
+ writeTreeEntry(id, resolvedParent, label, type);
86
96
  return id;
87
97
  }
88
98
  function moveEntry(id, newParentId, newOrder) {
@@ -133,6 +143,7 @@ export function useChildTree(rootDoc, parentDocId, options) {
133
143
  childrenOf,
134
144
  descendantsOf,
135
145
  createChild,
146
+ createChildRegistered,
136
147
  registerDoc,
137
148
  moveEntry,
138
149
  deleteEntry,
@@ -7,6 +7,30 @@
7
7
  *
8
8
  * Usage:
9
9
  * const { notifications, unreadCount, fetchNotifications, markRead } = useNotifications()
10
+ *
11
+ * ## Wire protocol — `messages:inbox_*` (NOT the old `notify:*`)
12
+ *
13
+ * abracadabra-rs collapsed the `chat:*` and `notify:*` stateless dialects into
14
+ * one unified `messages:*` subsystem (`crates/abracadabra/src/messages.rs`:
15
+ * "Replaces the old chat:* and notify:* dispatchers"). Nothing in the server
16
+ * answers `notify:fetch` / `notify:mark_read` / `notify:create` any more, and
17
+ * `sendStateless` is fire-and-forget — so this composable sat there sending
18
+ * into the void and reporting "all caught up" forever. Found while auditing
19
+ * abracadabra-atrium, whose inbox was permanently empty.
20
+ *
21
+ * A notification is now an `InboxEntry` on the caller's own `kind = "inbox"`
22
+ * doc, which the server writes as a side effect of `messages:send` fan-out
23
+ * (mentions + DM participants, consent-gated on read access). Requests:
24
+ *
25
+ * → `messages:inbox_fetch` { before?, limit?, unread_only? }
26
+ * ← `messages:inbox_history` { inbox_doc_id, entries: InboxEntry[] }
27
+ * → `messages:inbox_mark_read` { id | ids | source_id | all }
28
+ * ← `messages:ok` { source: "messages:inbox_mark_read" }
29
+ *
30
+ * There is no longer any "create a notification for an arbitrary user" call —
31
+ * `createNotification()` below emits a `messages:send` carrying the recipient
32
+ * in `mentions`, which is the supported path (service-role senders skip the
33
+ * channel role check, so a Nitro runner can fan out on a forum's behalf).
10
34
  */
11
35
  export type NotificationType = 'chat' | 'agent' | 'mention' | 'system';
12
36
  export interface AppNotification {
@@ -31,8 +55,25 @@ declare function fetchNotifications(opts?: {
31
55
  }): void;
32
56
  declare function markRead(id: string): void;
33
57
  declare function markAllRead(): void;
58
+ /**
59
+ * Deliver a notification to `recipientId`.
60
+ *
61
+ * There is no "write an arbitrary notification" server API any more. Inbox
62
+ * entries are produced by `messages:send` fan-out, so this posts a message on
63
+ * `channelDocId` naming the recipient in `mentions` — the server then resolves
64
+ * the recipient's read access to that channel (consent gate) and writes the
65
+ * inbox entry itself.
66
+ *
67
+ * `channelDocId` is REQUIRED: without a channel there is nothing to fan out
68
+ * from. Pass the doc the notification is *about* (a forum, a thread, a space) —
69
+ * any doc the caller can write becomes a chat container server-side.
70
+ *
71
+ * `title` is not carried on the wire (the inbox stores who/where/when +
72
+ * preview and the UI synthesises a title), so it's folded into the body.
73
+ */
34
74
  declare function createNotification(opts: {
35
75
  recipientId: string;
76
+ channelDocId: string;
36
77
  type?: NotificationType;
37
78
  title: string;
38
79
  body: string;
@@ -33,14 +33,49 @@ function parseNotification(data) {
33
33
  createdAt: data.created_at ? new Date(data.created_at).getTime() : Date.now()
34
34
  };
35
35
  }
36
+ const INBOX_KIND_TO_TYPE = {
37
+ mention: "mention",
38
+ reply: "mention",
39
+ dm: "chat",
40
+ system: "system"
41
+ };
42
+ function inboxEntryToNotification(e) {
43
+ const who = typeof e.sender_name === "string" && e.sender_name ? e.sender_name : null;
44
+ const title = e.kind === "dm" ? who ? `Message from ${who}` : "New message" : e.kind === "mention" ? who ? `${who} mentioned you` : "You were mentioned" : e.kind === "reply" ? who ? `${who} replied` : "New reply" : "Notification";
45
+ return {
46
+ id: String(e.id),
47
+ type: INBOX_KIND_TO_TYPE[e.kind] ?? "system",
48
+ title,
49
+ body: e.preview ?? "",
50
+ icon: e.kind === "dm" ? "i-lucide-mail" : void 0,
51
+ // The channel doc the entry came from — enough for a consumer to route to
52
+ // it. Consumers wanting richer links resolve `channel_doc_id` themselves.
53
+ link: void 0,
54
+ sourceId: e.channel_doc_id ?? void 0,
55
+ read: e.read === true,
56
+ createdAt: typeof e.ts === "number" ? e.ts : Date.now()
57
+ };
58
+ }
36
59
  function isForMe(recipientId) {
37
60
  if (!recipientId) return true;
38
61
  return recipientId === _publicKeyB64.value;
39
62
  }
40
63
  export function _handleStatelessNotification(payload) {
41
- if (!payload.includes('"notify:')) return;
64
+ const isInbox = payload.includes('"messages:inbox_history"');
65
+ if (!isInbox && !payload.includes('"notify:')) return;
42
66
  try {
43
67
  const data = JSON.parse(payload);
68
+ if (data.type === "messages:inbox_history") {
69
+ lastError.value = null;
70
+ const incoming = (data.entries || []).map(inboxEntryToNotification);
71
+ const existingIds = new Set(notifications.value.map((n) => n.id));
72
+ const fresh = incoming.filter((n) => !existingIds.has(n.id));
73
+ notifications.value = [...notifications.value, ...fresh].sort((a, b) => b.createdAt - a.createdAt);
74
+ if (existingIds.size > 0) {
75
+ for (const n of fresh) if (!n.read) _scheduleToast(n);
76
+ }
77
+ return;
78
+ }
44
79
  if (!data.type?.startsWith("notify:")) return;
45
80
  lastError.value = null;
46
81
  switch (data.type) {
@@ -130,7 +165,7 @@ function fetchNotifications(opts) {
130
165
  const { provider } = useAbracadabra();
131
166
  if (!provider.value) return;
132
167
  provider.value.sendStateless(JSON.stringify({
133
- type: "notify:fetch",
168
+ type: "messages:inbox_fetch",
134
169
  before: opts?.before,
135
170
  limit: opts?.limit ?? 50,
136
171
  unread_only: opts?.unreadOnly ?? false
@@ -139,29 +174,32 @@ function fetchNotifications(opts) {
139
174
  function markRead(id) {
140
175
  const { provider } = useAbracadabra();
141
176
  if (provider.value) {
142
- provider.value.sendStateless(JSON.stringify({ type: "notify:mark_read", id }));
177
+ provider.value.sendStateless(JSON.stringify({ type: "messages:inbox_mark_read", id }));
143
178
  }
144
179
  notifications.value = notifications.value.map((n) => n.id === id ? { ...n, read: true } : n);
145
180
  }
146
181
  function markAllRead() {
147
182
  const { provider } = useAbracadabra();
148
183
  if (provider.value) {
149
- provider.value.sendStateless(JSON.stringify({ type: "notify:mark_all_read" }));
184
+ provider.value.sendStateless(JSON.stringify({ type: "messages:inbox_mark_read", all: true }));
150
185
  }
151
186
  notifications.value = notifications.value.map((n) => ({ ...n, read: true }));
152
187
  }
153
188
  function createNotification(opts) {
154
189
  const { provider } = useAbracadabra();
155
190
  if (!provider.value) return;
191
+ if (!opts.channelDocId) {
192
+ console.warn("[abracadabra] createNotification: channelDocId is required \u2014 inbox entries are produced by messages:send fan-out");
193
+ return;
194
+ }
195
+ const content = opts.title && opts.body ? `${opts.title} \u2014 ${opts.body}` : opts.body || opts.title;
156
196
  provider.value.sendStateless(JSON.stringify({
157
- type: "notify:create",
158
- recipient_id: opts.recipientId,
159
- notification_type: opts.type ?? "system",
160
- title: opts.title,
161
- body: opts.body,
162
- icon: opts.icon,
163
- link: opts.link,
164
- source_id: opts.sourceId
197
+ type: "messages:send",
198
+ id: crypto.randomUUID(),
199
+ channel_doc_id: opts.channelDocId,
200
+ content,
201
+ mentions: [opts.recipientId],
202
+ ts: Date.now()
165
203
  }));
166
204
  }
167
205
  export function useNotifications() {
@@ -33,7 +33,11 @@ export declare function useRendererBase(props: RendererBaseProps): {
33
33
  name?: string | undefined;
34
34
  color?: string | undefined;
35
35
  avatar?: string | undefined;
36
+ statusIcon?: string | undefined;
37
+ statusText?: string | undefined;
38
+ publicKey?: string | undefined;
36
39
  } | undefined;
40
+ docId?: string | undefined;
37
41
  };
38
42
  }[], {
39
43
  clientId: number;
@@ -51,7 +55,11 @@ export declare function useRendererBase(props: RendererBaseProps): {
51
55
  name?: string | undefined;
52
56
  color?: string | undefined;
53
57
  avatar?: string | undefined;
58
+ statusIcon?: string | undefined;
59
+ statusText?: string | undefined;
60
+ publicKey?: string | undefined;
54
61
  } | undefined;
62
+ docId?: string | undefined;
55
63
  };
56
64
  }[]>;
57
65
  states: import("vue").Ref<{
@@ -61,7 +69,11 @@ export declare function useRendererBase(props: RendererBaseProps): {
61
69
  name?: string | undefined;
62
70
  color?: string | undefined;
63
71
  avatar?: string | undefined;
72
+ statusIcon?: string | undefined;
73
+ statusText?: string | undefined;
74
+ publicKey?: string | undefined;
64
75
  } | undefined;
76
+ docId?: string | undefined;
65
77
  }[], import("./useYDoc.js").AwarenessUser[] | {
66
78
  [x: string]: any;
67
79
  clientId: number;
@@ -69,7 +81,11 @@ export declare function useRendererBase(props: RendererBaseProps): {
69
81
  name?: string | undefined;
70
82
  color?: string | undefined;
71
83
  avatar?: string | undefined;
84
+ statusIcon?: string | undefined;
85
+ statusText?: string | undefined;
86
+ publicKey?: string | undefined;
72
87
  } | undefined;
88
+ docId?: string | undefined;
73
89
  }[]>;
74
90
  setLocalState: (state: any) => void;
75
91
  tree: {
@@ -77,10 +93,11 @@ export declare function useRendererBase(props: RendererBaseProps): {
77
93
  childrenOf: (parentId: string | null) => import("./useChildTree.js").TreeEntry[];
78
94
  descendantsOf: (id: string) => import("./useChildTree.js").TreeEntry[];
79
95
  createChild: (parentId: string | null, label: string, type?: string) => string;
96
+ createChildRegistered: (parentId: string | null, label: string, type?: string) => Promise<string>;
80
97
  registerDoc: (id: string, parentId: string, opts?: {
81
98
  label?: string;
82
99
  type?: string;
83
- }) => void;
100
+ }) => Promise<void>;
84
101
  moveEntry: (id: string, newParentId: string | null, newOrder: number) => void;
85
102
  deleteEntry: (id: string) => void;
86
103
  renameEntry: (id: string, label: string) => void;
@@ -10,15 +10,8 @@
10
10
  */
11
11
  import { type Ref, type ShallowRef } from 'vue';
12
12
  import type * as Y from 'yjs';
13
- export interface AwarenessUser {
14
- clientId: number;
15
- user?: {
16
- name?: string;
17
- color?: string;
18
- avatar?: string;
19
- };
20
- [key: string]: any;
21
- }
13
+ import type { AwarenessUser } from '../types.js';
14
+ export type { AwarenessUser } from '../types.js';
22
15
  export declare function useSyncedMap<T = any>(doc: ShallowRef<Y.Doc | null>, mapName: string): {
23
16
  data: Record<string, T>;
24
17
  lastUpdateLocal: ShallowRef<boolean, boolean>;
@@ -57,7 +50,11 @@ export declare function useAwarenessOf(provider: ShallowRef<{
57
50
  name?: string | undefined;
58
51
  color?: string | undefined;
59
52
  avatar?: string | undefined;
53
+ statusIcon?: string | undefined;
54
+ statusText?: string | undefined;
55
+ publicKey?: string | undefined;
60
56
  } | undefined;
57
+ docId?: string | undefined;
61
58
  }[], AwarenessUser[] | {
62
59
  [x: string]: any;
63
60
  clientId: number;
@@ -65,7 +62,11 @@ export declare function useAwarenessOf(provider: ShallowRef<{
65
62
  name?: string | undefined;
66
63
  color?: string | undefined;
67
64
  avatar?: string | undefined;
65
+ statusIcon?: string | undefined;
66
+ statusText?: string | undefined;
67
+ publicKey?: string | undefined;
68
68
  } | undefined;
69
+ docId?: string | undefined;
69
70
  }[]>;
70
71
  currentUser: Ref<{
71
72
  [x: string]: any;
@@ -74,7 +75,11 @@ export declare function useAwarenessOf(provider: ShallowRef<{
74
75
  name?: string | undefined;
75
76
  color?: string | undefined;
76
77
  avatar?: string | undefined;
78
+ statusIcon?: string | undefined;
79
+ statusText?: string | undefined;
80
+ publicKey?: string | undefined;
77
81
  } | undefined;
82
+ docId?: string | undefined;
78
83
  } | null, AwarenessUser | {
79
84
  [x: string]: any;
80
85
  clientId: number;
@@ -82,7 +87,11 @@ export declare function useAwarenessOf(provider: ShallowRef<{
82
87
  name?: string | undefined;
83
88
  color?: string | undefined;
84
89
  avatar?: string | undefined;
90
+ statusIcon?: string | undefined;
91
+ statusText?: string | undefined;
92
+ publicKey?: string | undefined;
85
93
  } | undefined;
94
+ docId?: string | undefined;
86
95
  } | null>;
87
96
  setLocalState: (state: any) => void;
88
97
  };
@@ -100,7 +109,11 @@ export declare function useSmoothedCursors(provider: ShallowRef<{
100
109
  name?: string | undefined;
101
110
  color?: string | undefined;
102
111
  avatar?: string | undefined;
112
+ statusIcon?: string | undefined;
113
+ statusText?: string | undefined;
114
+ publicKey?: string | undefined;
103
115
  } | undefined;
116
+ docId?: string | undefined;
104
117
  };
105
118
  }[], {
106
119
  clientId: number;
@@ -118,7 +131,11 @@ export declare function useSmoothedCursors(provider: ShallowRef<{
118
131
  name?: string | undefined;
119
132
  color?: string | undefined;
120
133
  avatar?: string | undefined;
134
+ statusIcon?: string | undefined;
135
+ statusText?: string | undefined;
136
+ publicKey?: string | undefined;
121
137
  } | undefined;
138
+ docId?: string | undefined;
122
139
  };
123
140
  }[]>;
124
141
  states: Ref<{
@@ -128,7 +145,11 @@ export declare function useSmoothedCursors(provider: ShallowRef<{
128
145
  name?: string | undefined;
129
146
  color?: string | undefined;
130
147
  avatar?: string | undefined;
148
+ statusIcon?: string | undefined;
149
+ statusText?: string | undefined;
150
+ publicKey?: string | undefined;
131
151
  } | undefined;
152
+ docId?: string | undefined;
132
153
  }[], AwarenessUser[] | {
133
154
  [x: string]: any;
134
155
  clientId: number;
@@ -136,7 +157,11 @@ export declare function useSmoothedCursors(provider: ShallowRef<{
136
157
  name?: string | undefined;
137
158
  color?: string | undefined;
138
159
  avatar?: string | undefined;
160
+ statusIcon?: string | undefined;
161
+ statusText?: string | undefined;
162
+ publicKey?: string | undefined;
139
163
  } | undefined;
164
+ docId?: string | undefined;
140
165
  }[]>;
141
166
  setLocalState: (state: any) => void;
142
167
  };
@@ -1445,7 +1445,7 @@ export default defineNuxtPlugin({
1445
1445
  }
1446
1446
  }
1447
1447
  try {
1448
- _provider.sendStateless?.(JSON.stringify({ type: "notify:fetch", limit: 20 }));
1448
+ _provider.sendStateless?.(JSON.stringify({ type: "messages:inbox_fetch", limit: 20 }));
1449
1449
  } catch {
1450
1450
  }
1451
1451
  try {
@@ -1,9 +1,9 @@
1
1
  declare const _default: import("h3").EventHandler<Omit<import("h3").EventHandlerRequest, "body">, Promise<{
2
2
  docId: string;
3
3
  html: string;
4
- title: any;
5
- type: any;
6
- meta: any;
4
+ title: string;
5
+ type: string;
6
+ meta: Record<string, any>;
7
7
  description: any;
8
8
  ogImage: any;
9
9
  source: "crdt-cache";
@@ -2,6 +2,7 @@ import { createError, getRouterParam, getHeader } from "h3";
2
2
  import { defineCachedEventHandler } from "nitropack/runtime";
3
3
  import { useRuntimeConfig } from "nitropack/runtime/config";
4
4
  import { useStorage } from "nitropack/runtime/storage";
5
+ import { getCachedTreeEntry, resolveRootDocIdFromConfig } from "../../../utils/docCache.js";
5
6
  function extractFirstParagraph(html) {
6
7
  if (!html) return "";
7
8
  const pMatch = html.match(/<p[^>]*>(.*?)<\/p>/is);
@@ -31,12 +32,12 @@ export default defineCachedEventHandler(async (event) => {
31
32
  throw createError({ statusCode: 400, message: "docId is required" });
32
33
  }
33
34
  const storage = useStorage();
34
- const [cachedHtml, cachedJson] = await Promise.all([
35
+ const rootDocId = resolveRootDocIdFromConfig(config);
36
+ const [cachedHtml, treeEntry] = await Promise.all([
35
37
  storage.getItem(`doc-cache:html:${docId}`),
36
- storage.getItem(`doc-cache:json:${docId}`)
38
+ getCachedTreeEntry(docId, rootDocId)
37
39
  ]);
38
40
  if (cachedHtml !== null) {
39
- const treeEntry = cachedJson?.["doc-tree"]?.[docId] ?? {};
40
41
  const html2 = cachedHtml ?? "";
41
42
  return {
42
43
  docId,
@@ -2,9 +2,9 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
2
2
  docId: string;
3
3
  slug: string;
4
4
  html: string;
5
- title: any;
6
- type: any;
7
- meta: any;
5
+ title: string;
6
+ type: string;
7
+ meta: Record<string, any>;
8
8
  description: any;
9
9
  ogImage: any;
10
10
  source: "none" | "crdt-cache";
@@ -1,6 +1,7 @@
1
1
  import { defineEventHandler, getRouterParam, createError } from "h3";
2
2
  import { getDocIdFromSlug } from "../../../utils/slugMap.js";
3
- import { getCachedHTML, getCachedJSON } from "../../../utils/docCache.js";
3
+ import { useRuntimeConfig } from "nitropack/runtime/config";
4
+ import { getCachedHTML, getCachedTreeEntry, resolveRootDocIdFromConfig } from "../../../utils/docCache.js";
4
5
  function extractFirstParagraph(html) {
5
6
  if (!html) return "";
6
7
  const pMatch = html.match(/<p[^>]*>(.*?)<\/p>/is);
@@ -24,12 +25,12 @@ export default defineEventHandler(async (event) => {
24
25
  if (!docId) {
25
26
  throw createError({ statusCode: 404, message: `Document not found for slug: ${slug}` });
26
27
  }
27
- const [cachedHtml, cachedJson] = await Promise.all([
28
+ const rootDocId = resolveRootDocIdFromConfig(useRuntimeConfig());
29
+ const [cachedHtml, treeEntry] = await Promise.all([
28
30
  getCachedHTML(docId),
29
- getCachedJSON(docId)
31
+ getCachedTreeEntry(docId, rootDocId)
30
32
  ]);
31
33
  const html = cachedHtml ?? "";
32
- const treeEntry = cachedJson?.["doc-tree"]?.[docId] ?? {};
33
34
  return {
34
35
  docId,
35
36
  slug,
@@ -17,6 +17,50 @@ export declare function initDocCache(storage: NitroStorage, extraExtensions?: An
17
17
  export declare function renderDocToHTML(ydoc: Y.Doc): Promise<string | null>;
18
18
  export declare function getCachedHTML(docId: string): Promise<string | null>;
19
19
  export declare function getCachedJSON(docId: string): Promise<Record<string, unknown> | null>;
20
+ /** A doc's `doc-tree` entry: label, page type and meta. */
21
+ export interface CachedTreeEntry {
22
+ label?: string;
23
+ type?: string;
24
+ parentId?: string | null;
25
+ meta?: Record<string, any>;
26
+ }
27
+ /**
28
+ * The `doc-tree` entry for `docId`, read out of the ROOT doc's cache.
29
+ *
30
+ * ⚠️ The tree lives ONLY on the root/space doc. A child doc's own Y.Doc has no
31
+ * `doc-tree` map, so `getCachedJSON(childId)['doc-tree']` is always `undefined` —
32
+ * which is what the render + resolve endpoints used to do, making them return
33
+ * `title: ""`, `type: "doc"`, `meta: {}` for EVERY child document no matter how
34
+ * warm the cache was. (Symptom in abracadabra-atrium: every route SSR'd a
35
+ * placeholder `<h1>Thread</h1>` / `<title>Forum · Atrium</title>` and the client
36
+ * replaced it on hydration, producing a mismatch warning on every navigation.)
37
+ *
38
+ * Falls back to the doc's own json so this still works when `docId` IS the root.
39
+ */
40
+ export declare function getCachedTreeEntry(docId: string, rootDocId?: string | null): Promise<CachedTreeEntry>;
41
+ /**
42
+ * The root/space doc id as seen from a Nitro request handler.
43
+ *
44
+ * `ServerRunnerContext.rootDocId` isn't reachable here, so resolve it the same
45
+ * way the service plugin does: the explicit `service.rootDocId` override wins,
46
+ * then the module's `entryDocId`.
47
+ */
48
+ export declare function resolveRootDocIdFromConfig(config: {
49
+ abracadabra?: {
50
+ entryDocId?: string;
51
+ service?: {
52
+ rootDocId?: string;
53
+ };
54
+ };
55
+ public?: {
56
+ abracadabra?: {
57
+ entryDocId?: string;
58
+ service?: {
59
+ rootDocId?: string;
60
+ };
61
+ };
62
+ };
63
+ }): string | null;
20
64
  export declare function invalidateDoc(docId: string, ydoc?: Y.Doc): Promise<void>;
21
65
  /**
22
66
  * Start observing a Y.Doc for changes with debounced re-rendering.
@@ -70,13 +70,35 @@ function htmlKey(docId) {
70
70
  function jsonKey(docId) {
71
71
  return `doc-cache:json:${docId}`;
72
72
  }
73
+ async function readStorage() {
74
+ if (_storage) return _storage;
75
+ try {
76
+ const { useStorage } = await import("nitropack/runtime/storage");
77
+ return useStorage();
78
+ } catch {
79
+ return null;
80
+ }
81
+ }
73
82
  export async function getCachedHTML(docId) {
74
- if (!_storage) return null;
75
- return await _storage.getItem(htmlKey(docId)) ?? null;
83
+ const storage = await readStorage();
84
+ if (!storage) return null;
85
+ return await storage.getItem(htmlKey(docId)) ?? null;
76
86
  }
77
87
  export async function getCachedJSON(docId) {
78
- if (!_storage) return null;
79
- return await _storage.getItem(jsonKey(docId)) ?? null;
88
+ const storage = await readStorage();
89
+ if (!storage) return null;
90
+ return await storage.getItem(jsonKey(docId)) ?? null;
91
+ }
92
+ export async function getCachedTreeEntry(docId, rootDocId) {
93
+ const fromRoot = rootDocId ? (await getCachedJSON(rootDocId))?.["doc-tree"] : void 0;
94
+ if (fromRoot?.[docId]) return fromRoot[docId];
95
+ const own = (await getCachedJSON(docId))?.["doc-tree"];
96
+ return own?.[docId] ?? {};
97
+ }
98
+ export function resolveRootDocIdFromConfig(config) {
99
+ const pub = config.public?.abracadabra;
100
+ const priv = config.abracadabra;
101
+ return priv?.service?.rootDocId ?? pub?.service?.rootDocId ?? priv?.entryDocId ?? pub?.entryDocId ?? null;
80
102
  }
81
103
  export async function invalidateDoc(docId, ydoc) {
82
104
  if (!_storage) return;
@@ -145,6 +145,13 @@ export interface DocTreeHelper {
145
145
  childrenOf: (parentId: string | null) => TreeEntry[];
146
146
  descendantsOf: (id: string) => TreeEntry[];
147
147
  createChild: (parentId: string | null, label: string, type?: string) => string;
148
+ /**
149
+ * Like `createChild`, but awaits the doc's REST registration before writing
150
+ * the tree entry — so the `documents` row carries the correct `parent_id` and
151
+ * the permission cascade gets a real ancestor chain. Prefer it for content
152
+ * docs; see the implementation notes in useChildTree.ts.
153
+ */
154
+ createChildRegistered: (parentId: string | null, label: string, type?: string) => Promise<string>;
148
155
  moveEntry: (id: string, newParentId: string | null, newOrder: number) => void;
149
156
  deleteEntry: (id: string) => void;
150
157
  renameEntry: (id: string, label: string) => void;
package/dist/types.d.mts CHANGED
@@ -6,6 +6,8 @@ export { type DocTreeReturn } from '../dist/runtime/composables/useDocTree.js'
6
6
 
7
7
  export { type DocSeoOptions } from '../dist/runtime/composables/useDocSeo.js'
8
8
 
9
+ export { type AppNotification, type NotificationType } from '../dist/runtime/composables/useNotifications.js'
10
+
9
11
  export { type DocDragState } from '../dist/runtime/composables/useDocDragBus.js'
10
12
 
11
13
  export { type ParsedMessage, type TextSegment, type parseMessageContent, type previewMessageContent, type renderMessageSegments } from '../dist/runtime/utils/chatContent.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/nuxt",
3
- "version": "2.74.0",
3
+ "version": "2.76.0",
4
4
  "description": "First-class Nuxt module for the Abracadabra CRDT collaboration platform",
5
5
  "repository": "abracadabra/abracadabra-nuxt",
6
6
  "license": "MIT",