@liveblocks/node 3.18.5 → 3.19.1

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
@@ -156,7 +156,7 @@ type AiCopilotProviderSettings = {
156
156
  seed?: number;
157
157
  maxRetries?: number;
158
158
  };
159
- type OpenAiModel = "o1" | "o1-mini" | "o3" | "o3-mini" | "o4-mini" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini" | "gpt-4-turbo" | "gpt-4" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gpt-5-chat-latest" | "gpt-5.1" | "gpt-5.1-mini" | "gpt-5.1-chat-latest";
159
+ type OpenAiModel = "o1" | "o1-mini" | "o3" | "o3-mini" | "o4-mini" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini" | "gpt-4-turbo" | "gpt-4" | "gpt-5" | "gpt-5-pro" | "gpt-5-mini" | "gpt-5-nano" | "gpt-5-chat-latest" | "gpt-5.1" | "gpt-5.1-mini" | "gpt-5.1-chat-latest" | "gpt-5.2" | "gpt-5.2-pro" | "gpt-5.4" | "gpt-5.4-pro" | "gpt-5.4-mini" | "gpt-5.4-nano" | "gpt-5.5";
160
160
  type OpenAiProviderOptions = {
161
161
  openai: {
162
162
  reasoningEffort?: "low" | "medium" | "high";
@@ -165,7 +165,7 @@ type OpenAiProviderOptions = {
165
165
  };
166
166
  };
167
167
  };
168
- type AnthropicModel = "claude-sonnet-4-5-20250929" | "claude-haiku-4-5-20251001" | "claude-opus-4-1-20250805" | "claude-4-opus-20250514" | "claude-4-sonnet-20250514" | "claude-3-7-sonnet-20250219" | "claude-3-5-sonnet-latest" | "claude-3-5-haiku-latest" | "claude-3-opus-latest";
168
+ type AnthropicModel = "claude-opus-4-7" | "claude-sonnet-4-6" | "claude-opus-4-6" | "claude-opus-4-5-20251101" | "claude-sonnet-4-5-20250929" | "claude-haiku-4-5-20251001" | "claude-opus-4-1-20250805" | "claude-4-opus-20250514" | "claude-4-sonnet-20250514" | "claude-3-7-sonnet-20250219" | "claude-3-5-sonnet-latest" | "claude-3-5-haiku-latest" | "claude-3-opus-latest";
169
169
  type AnthropicProviderOptions = {
170
170
  anthropic: {
171
171
  thinking?: {
@@ -179,7 +179,7 @@ type AnthropicProviderOptions = {
179
179
  };
180
180
  };
181
181
  };
182
- type GoogleModel = "gemini-2.5-flash" | "gemini-2.5-pro" | "gemini-2.0-flash-001" | "gemini-1.5-flash" | "gemini-1.5-pro";
182
+ type GoogleModel = "gemini-3-flash-preview" | "gemini-3.1-pro-preview" | "gemini-2.5-flash" | "gemini-2.5-pro" | "gemini-2.0-flash-001" | "gemini-1.5-flash" | "gemini-1.5-pro";
183
183
  type GoogleProviderOptions = {
184
184
  google: {
185
185
  thinkingConfig?: {
@@ -1589,6 +1589,17 @@ declare class LiveblocksError extends Error {
1589
1589
  static from(res: Response): Promise<LiveblocksError>;
1590
1590
  }
1591
1591
 
1592
+ /**
1593
+ * Converts a Markdown string into a `CommentBody` object that can be used to write
1594
+ * comments with `createThread`, `createComment`, or `editComment`.
1595
+ *
1596
+ * This is a lossy conversion because `CommentBody` only supports paragraphs,
1597
+ * inline text formatting (bold, italic, strikethrough, code), links, and
1598
+ * `@mentions`. Unsupported features like headings, lists, tables, or blockquotes
1599
+ * are kept as plain text.
1600
+ */
1601
+ declare function markdownToCommentBody(markdown: string): CommentBody;
1602
+
1592
1603
  declare class WebhookHandler {
1593
1604
  #private;
1594
1605
  constructor(
@@ -1990,4 +2001,4 @@ declare function isTextMentionNotificationEvent(event: WebhookEvent): event is T
1990
2001
  */
1991
2002
  declare function isCustomNotificationEvent(event: WebhookEvent): event is CustomNotificationEvent;
1992
2003
 
1993
- export { type AiCopilot, type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CreateAiCopilotOptions, type CreateFeedMessageOptions, type CreateFeedOptions, type CreateFileKnowledgeSourceOptions, type CreateRoomOptions, type CreateWebKnowledgeSourceOptions, type CustomNotificationEvent, type GetAiCopilotsOptions, type GetInboxNotificationsOptions, type GetKnowledgeSourcesOptions, type GetRoomsOptions, type GetWebKnowledgeSourceLinksOptions, type InboxNotificationsQueryCriteria, type KnowledgeSource, Liveblocks, LiveblocksError, type LiveblocksOptions, type MassMutateStorageCallback, type MassMutateStorageOptions, type MutateStorageCallback, type MutateStorageOptions, type NotificationEvent, type Page, type PaginationOptions, type RoomAccesses, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomPermission, type RoomUser, type RoomsQueryCriteria, type SetPresenceOptions, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UpdateAiCopilotOptions, type UpdateFeedMessageOptions, type UpdateFeedOptions, type UpdateRoomOptions, type UpsertRoomOptions, type UserEnteredEvent, type UserLeftEvent, type WebKnowledgeSourceLink, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isCustomNotificationEvent, isTextMentionNotificationEvent, isThreadNotificationEvent };
2004
+ export { type AiCopilot, type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CreateAiCopilotOptions, type CreateFeedMessageOptions, type CreateFeedOptions, type CreateFileKnowledgeSourceOptions, type CreateRoomOptions, type CreateWebKnowledgeSourceOptions, type CustomNotificationEvent, type GetAiCopilotsOptions, type GetInboxNotificationsOptions, type GetKnowledgeSourcesOptions, type GetRoomsOptions, type GetWebKnowledgeSourceLinksOptions, type InboxNotificationsQueryCriteria, type KnowledgeSource, Liveblocks, LiveblocksError, type LiveblocksOptions, type MassMutateStorageCallback, type MassMutateStorageOptions, type MutateStorageCallback, type MutateStorageOptions, type NotificationEvent, type Page, type PaginationOptions, type RoomAccesses, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomPermission, type RoomUser, type RoomsQueryCriteria, type SetPresenceOptions, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UpdateAiCopilotOptions, type UpdateFeedMessageOptions, type UpdateFeedOptions, type UpdateRoomOptions, type UpsertRoomOptions, type UserEnteredEvent, type UserLeftEvent, type WebKnowledgeSourceLink, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isCustomNotificationEvent, isTextMentionNotificationEvent, isThreadNotificationEvent, markdownToCommentBody };
package/dist/index.d.ts CHANGED
@@ -156,7 +156,7 @@ type AiCopilotProviderSettings = {
156
156
  seed?: number;
157
157
  maxRetries?: number;
158
158
  };
159
- type OpenAiModel = "o1" | "o1-mini" | "o3" | "o3-mini" | "o4-mini" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini" | "gpt-4-turbo" | "gpt-4" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gpt-5-chat-latest" | "gpt-5.1" | "gpt-5.1-mini" | "gpt-5.1-chat-latest";
159
+ type OpenAiModel = "o1" | "o1-mini" | "o3" | "o3-mini" | "o4-mini" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini" | "gpt-4-turbo" | "gpt-4" | "gpt-5" | "gpt-5-pro" | "gpt-5-mini" | "gpt-5-nano" | "gpt-5-chat-latest" | "gpt-5.1" | "gpt-5.1-mini" | "gpt-5.1-chat-latest" | "gpt-5.2" | "gpt-5.2-pro" | "gpt-5.4" | "gpt-5.4-pro" | "gpt-5.4-mini" | "gpt-5.4-nano" | "gpt-5.5";
160
160
  type OpenAiProviderOptions = {
161
161
  openai: {
162
162
  reasoningEffort?: "low" | "medium" | "high";
@@ -165,7 +165,7 @@ type OpenAiProviderOptions = {
165
165
  };
166
166
  };
167
167
  };
168
- type AnthropicModel = "claude-sonnet-4-5-20250929" | "claude-haiku-4-5-20251001" | "claude-opus-4-1-20250805" | "claude-4-opus-20250514" | "claude-4-sonnet-20250514" | "claude-3-7-sonnet-20250219" | "claude-3-5-sonnet-latest" | "claude-3-5-haiku-latest" | "claude-3-opus-latest";
168
+ type AnthropicModel = "claude-opus-4-7" | "claude-sonnet-4-6" | "claude-opus-4-6" | "claude-opus-4-5-20251101" | "claude-sonnet-4-5-20250929" | "claude-haiku-4-5-20251001" | "claude-opus-4-1-20250805" | "claude-4-opus-20250514" | "claude-4-sonnet-20250514" | "claude-3-7-sonnet-20250219" | "claude-3-5-sonnet-latest" | "claude-3-5-haiku-latest" | "claude-3-opus-latest";
169
169
  type AnthropicProviderOptions = {
170
170
  anthropic: {
171
171
  thinking?: {
@@ -179,7 +179,7 @@ type AnthropicProviderOptions = {
179
179
  };
180
180
  };
181
181
  };
182
- type GoogleModel = "gemini-2.5-flash" | "gemini-2.5-pro" | "gemini-2.0-flash-001" | "gemini-1.5-flash" | "gemini-1.5-pro";
182
+ type GoogleModel = "gemini-3-flash-preview" | "gemini-3.1-pro-preview" | "gemini-2.5-flash" | "gemini-2.5-pro" | "gemini-2.0-flash-001" | "gemini-1.5-flash" | "gemini-1.5-pro";
183
183
  type GoogleProviderOptions = {
184
184
  google: {
185
185
  thinkingConfig?: {
@@ -1589,6 +1589,17 @@ declare class LiveblocksError extends Error {
1589
1589
  static from(res: Response): Promise<LiveblocksError>;
1590
1590
  }
1591
1591
 
1592
+ /**
1593
+ * Converts a Markdown string into a `CommentBody` object that can be used to write
1594
+ * comments with `createThread`, `createComment`, or `editComment`.
1595
+ *
1596
+ * This is a lossy conversion because `CommentBody` only supports paragraphs,
1597
+ * inline text formatting (bold, italic, strikethrough, code), links, and
1598
+ * `@mentions`. Unsupported features like headings, lists, tables, or blockquotes
1599
+ * are kept as plain text.
1600
+ */
1601
+ declare function markdownToCommentBody(markdown: string): CommentBody;
1602
+
1592
1603
  declare class WebhookHandler {
1593
1604
  #private;
1594
1605
  constructor(
@@ -1990,4 +2001,4 @@ declare function isTextMentionNotificationEvent(event: WebhookEvent): event is T
1990
2001
  */
1991
2002
  declare function isCustomNotificationEvent(event: WebhookEvent): event is CustomNotificationEvent;
1992
2003
 
1993
- export { type AiCopilot, type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CreateAiCopilotOptions, type CreateFeedMessageOptions, type CreateFeedOptions, type CreateFileKnowledgeSourceOptions, type CreateRoomOptions, type CreateWebKnowledgeSourceOptions, type CustomNotificationEvent, type GetAiCopilotsOptions, type GetInboxNotificationsOptions, type GetKnowledgeSourcesOptions, type GetRoomsOptions, type GetWebKnowledgeSourceLinksOptions, type InboxNotificationsQueryCriteria, type KnowledgeSource, Liveblocks, LiveblocksError, type LiveblocksOptions, type MassMutateStorageCallback, type MassMutateStorageOptions, type MutateStorageCallback, type MutateStorageOptions, type NotificationEvent, type Page, type PaginationOptions, type RoomAccesses, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomPermission, type RoomUser, type RoomsQueryCriteria, type SetPresenceOptions, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UpdateAiCopilotOptions, type UpdateFeedMessageOptions, type UpdateFeedOptions, type UpdateRoomOptions, type UpsertRoomOptions, type UserEnteredEvent, type UserLeftEvent, type WebKnowledgeSourceLink, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isCustomNotificationEvent, isTextMentionNotificationEvent, isThreadNotificationEvent };
2004
+ export { type AiCopilot, type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CreateAiCopilotOptions, type CreateFeedMessageOptions, type CreateFeedOptions, type CreateFileKnowledgeSourceOptions, type CreateRoomOptions, type CreateWebKnowledgeSourceOptions, type CustomNotificationEvent, type GetAiCopilotsOptions, type GetInboxNotificationsOptions, type GetKnowledgeSourcesOptions, type GetRoomsOptions, type GetWebKnowledgeSourceLinksOptions, type InboxNotificationsQueryCriteria, type KnowledgeSource, Liveblocks, LiveblocksError, type LiveblocksOptions, type MassMutateStorageCallback, type MassMutateStorageOptions, type MutateStorageCallback, type MutateStorageOptions, type NotificationEvent, type Page, type PaginationOptions, type RoomAccesses, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomPermission, type RoomUser, type RoomsQueryCriteria, type SetPresenceOptions, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UpdateAiCopilotOptions, type UpdateFeedMessageOptions, type UpdateFeedOptions, type UpdateRoomOptions, type UpsertRoomOptions, type UserEnteredEvent, type UserLeftEvent, type WebKnowledgeSourceLink, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isCustomNotificationEvent, isTextMentionNotificationEvent, isThreadNotificationEvent, markdownToCommentBody };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { detectDupes } from "@liveblocks/core";
3
3
 
4
4
  // src/version.ts
5
5
  var PKG_NAME = "@liveblocks/node";
6
- var PKG_VERSION = "3.18.5";
6
+ var PKG_VERSION = "3.19.1";
7
7
  var PKG_FORMAT = "esm";
8
8
 
9
9
  // src/client.ts
@@ -2457,6 +2457,385 @@ ${this.details}`;
2457
2457
  }
2458
2458
  };
2459
2459
 
2460
+ // src/comment-body.ts
2461
+ import {
2462
+ sanitizeUrl
2463
+ } from "@liveblocks/core";
2464
+ import {
2465
+ Lexer,
2466
+ Tokenizer
2467
+ } from "marked";
2468
+ var MENTION_REGEX = /(^|[^A-Za-z0-9_.-])@([A-Za-z0-9_][A-Za-z0-9_.@-]*)/g;
2469
+ var MENTION_TRAILING_PUNCTUATION_REGEX = /[.-]/;
2470
+ var WHITESPACE_REGEX = /\s/;
2471
+ var MarkedCustomTokenizer = class extends Tokenizer {
2472
+ url(src) {
2473
+ const token = super.url(src);
2474
+ if (token?.href.startsWith("mailto:")) {
2475
+ return void 0;
2476
+ }
2477
+ return token;
2478
+ }
2479
+ };
2480
+ function assertTokens(_) {
2481
+ }
2482
+ function tokenizeMarkdown(markdown) {
2483
+ return new Lexer({ gfm: true, tokenizer: new MarkedCustomTokenizer() }).lex(
2484
+ markdown
2485
+ );
2486
+ }
2487
+ function toCommentBodyText(text, formatting) {
2488
+ return {
2489
+ text,
2490
+ ...formatting
2491
+ };
2492
+ }
2493
+ function appendPlainText(inlines, text, formatting) {
2494
+ if (text.length === 0) {
2495
+ return;
2496
+ }
2497
+ inlines.push(toCommentBodyText(text, formatting));
2498
+ }
2499
+ function listIndent(listDepth) {
2500
+ return " ".repeat(listDepth);
2501
+ }
2502
+ function blockquotePrefix(blockquoteDepth) {
2503
+ return blockquoteDepth > 0 ? "> ".repeat(blockquoteDepth) : "";
2504
+ }
2505
+ function listMarker(ordered, start, index) {
2506
+ if (!ordered) {
2507
+ return "- ";
2508
+ }
2509
+ const firstItemNumber = start === "" ? 1 : start;
2510
+ return `${firstItemNumber + index}. `;
2511
+ }
2512
+ function taskListPrefix(item) {
2513
+ if (!item.task) {
2514
+ return "";
2515
+ }
2516
+ return item.checked ? "[x] " : "[ ] ";
2517
+ }
2518
+ function prependTextToParagraph(paragraph, textPrefix) {
2519
+ if (textPrefix.length === 0) {
2520
+ return paragraph;
2521
+ }
2522
+ return {
2523
+ ...paragraph,
2524
+ children: [{ text: textPrefix }, ...paragraph.children]
2525
+ };
2526
+ }
2527
+ function appendTextWithMentions(inlines, text, formatting) {
2528
+ let cursor = 0;
2529
+ for (const match of text.matchAll(MENTION_REGEX)) {
2530
+ const prefix = match[1] ?? "";
2531
+ const rawId = match[2];
2532
+ if (match.index === void 0 || rawId === void 0) {
2533
+ continue;
2534
+ }
2535
+ const atSignIndex = match.index + prefix.length;
2536
+ const idStart = atSignIndex + 1;
2537
+ let idEnd = idStart + rawId.length;
2538
+ while (idEnd > idStart && MENTION_TRAILING_PUNCTUATION_REGEX.test(text.charAt(idEnd - 1)) && (idEnd === text.length || WHITESPACE_REGEX.test(text.charAt(idEnd)))) {
2539
+ idEnd -= 1;
2540
+ }
2541
+ if (atSignIndex > cursor) {
2542
+ inlines.push(
2543
+ toCommentBodyText(text.slice(cursor, atSignIndex), formatting)
2544
+ );
2545
+ }
2546
+ inlines.push({
2547
+ type: "mention",
2548
+ kind: "user",
2549
+ id: text.slice(idStart, idEnd)
2550
+ });
2551
+ cursor = idEnd;
2552
+ }
2553
+ if (cursor < text.length) {
2554
+ inlines.push(toCommentBodyText(text.slice(cursor), formatting));
2555
+ }
2556
+ }
2557
+ function appendFormattedInlinesFromTokens(inlines, tokens, formatting) {
2558
+ inlines.push(...tokensToCommentBodyInlines(tokens, formatting));
2559
+ }
2560
+ function tableAlignmentMarker(alignment) {
2561
+ switch (alignment) {
2562
+ case "left":
2563
+ return ":---";
2564
+ case "center":
2565
+ return ":---:";
2566
+ case "right":
2567
+ return "---:";
2568
+ default:
2569
+ return "---";
2570
+ }
2571
+ }
2572
+ function tableToMarkdownRows(table) {
2573
+ const rows = [table.header, ...table.rows];
2574
+ const markdownRows = rows.map((row) => {
2575
+ const cells = row.map((cell) => tokensToPlainText(cell.tokens));
2576
+ return `| ${cells.join(" | ")} |`;
2577
+ });
2578
+ if (markdownRows.length === 0) {
2579
+ return [];
2580
+ }
2581
+ const separatorRow = `| ${table.align.map(tableAlignmentMarker).join(" | ")} |`;
2582
+ return [markdownRows[0], separatorRow, ...markdownRows.slice(1)].filter(
2583
+ (row) => row !== void 0
2584
+ );
2585
+ }
2586
+ function tokensToPlainText(tokens, listDepth = 0) {
2587
+ assertTokens(tokens);
2588
+ return tokens.map((t) => tokenToPlainText(t, listDepth)).join("");
2589
+ }
2590
+ function tokenToPlainText(token, listDepth = 0) {
2591
+ switch (token.type) {
2592
+ case "escape":
2593
+ case "html":
2594
+ case "codespan":
2595
+ case "text": {
2596
+ return token.text;
2597
+ }
2598
+ case "br": {
2599
+ return "\n";
2600
+ }
2601
+ case "strong":
2602
+ case "em":
2603
+ case "del":
2604
+ case "link": {
2605
+ return tokensToPlainText(token.tokens, 0);
2606
+ }
2607
+ case "image": {
2608
+ return token.text || token.href;
2609
+ }
2610
+ case "paragraph":
2611
+ case "heading": {
2612
+ return tokensToPlainText(token.tokens, listDepth);
2613
+ }
2614
+ case "blockquote": {
2615
+ return tokensToPlainText(token.tokens, listDepth);
2616
+ }
2617
+ case "list": {
2618
+ return token.items.map(
2619
+ (item, index) => listItemToText(item, token.ordered, token.start, index, listDepth)
2620
+ ).join("\n");
2621
+ }
2622
+ case "list_item": {
2623
+ return tokensToPlainText(token.tokens, listDepth);
2624
+ }
2625
+ case "code": {
2626
+ return token.text;
2627
+ }
2628
+ case "table": {
2629
+ return tableToMarkdownRows(token).join("\n");
2630
+ }
2631
+ case "space":
2632
+ case "hr": {
2633
+ return "";
2634
+ }
2635
+ default: {
2636
+ return "";
2637
+ }
2638
+ }
2639
+ }
2640
+ function listItemToText(item, ordered, start, index, listDepth) {
2641
+ const indent = listIndent(listDepth);
2642
+ const marker = listMarker(ordered, start, index);
2643
+ const prefix = indent + marker + taskListPrefix(item);
2644
+ return `${prefix}${tokensToPlainText(item.tokens, listDepth + 1)}`;
2645
+ }
2646
+ function tokensToCommentBodyInlines(tokens, formatting = {}) {
2647
+ assertTokens(tokens);
2648
+ const inlines = [];
2649
+ for (const token of tokens) {
2650
+ switch (token.type) {
2651
+ case "escape":
2652
+ case "html":
2653
+ case "text": {
2654
+ if (token.type === "text" && token.tokens?.length) {
2655
+ appendFormattedInlinesFromTokens(inlines, token.tokens, formatting);
2656
+ } else {
2657
+ appendTextWithMentions(inlines, token.text, formatting);
2658
+ }
2659
+ break;
2660
+ }
2661
+ case "br": {
2662
+ inlines.push(toCommentBodyText("\n", formatting));
2663
+ break;
2664
+ }
2665
+ case "strong": {
2666
+ appendFormattedInlinesFromTokens(inlines, token.tokens, {
2667
+ ...formatting,
2668
+ bold: true
2669
+ });
2670
+ break;
2671
+ }
2672
+ case "em": {
2673
+ appendFormattedInlinesFromTokens(inlines, token.tokens, {
2674
+ ...formatting,
2675
+ italic: true
2676
+ });
2677
+ break;
2678
+ }
2679
+ case "del": {
2680
+ appendFormattedInlinesFromTokens(inlines, token.tokens, {
2681
+ ...formatting,
2682
+ strikethrough: true
2683
+ });
2684
+ break;
2685
+ }
2686
+ case "codespan": {
2687
+ inlines.push(
2688
+ toCommentBodyText(token.text, {
2689
+ ...formatting,
2690
+ code: true
2691
+ })
2692
+ );
2693
+ break;
2694
+ }
2695
+ case "link": {
2696
+ const href = sanitizeUrl(token.href);
2697
+ const text = tokensToPlainText(token.tokens, 0);
2698
+ if (href === null) {
2699
+ appendPlainText(inlines, text, formatting);
2700
+ break;
2701
+ }
2702
+ inlines.push({
2703
+ type: "link",
2704
+ url: href,
2705
+ text
2706
+ });
2707
+ break;
2708
+ }
2709
+ case "image": {
2710
+ appendPlainText(inlines, token.raw, formatting);
2711
+ break;
2712
+ }
2713
+ default: {
2714
+ const text = tokenToPlainText(token, 0);
2715
+ if (text) {
2716
+ appendTextWithMentions(inlines, text, formatting);
2717
+ }
2718
+ break;
2719
+ }
2720
+ }
2721
+ }
2722
+ return inlines;
2723
+ }
2724
+ function tokenToCommentBodyParagraphs(token, listDepth = 0, blockquoteDepth = 0) {
2725
+ switch (token.type) {
2726
+ case "space":
2727
+ case "hr": {
2728
+ return [];
2729
+ }
2730
+ case "paragraph":
2731
+ case "heading": {
2732
+ const children = tokensToCommentBodyInlines(token.tokens);
2733
+ if (children.length === 0) {
2734
+ return [];
2735
+ }
2736
+ const headingPrefix = token.type === "heading" ? `${"#".repeat(token.depth)} ` : "";
2737
+ return [
2738
+ prependTextToParagraph(
2739
+ {
2740
+ type: "paragraph",
2741
+ children
2742
+ },
2743
+ blockquotePrefix(blockquoteDepth) + headingPrefix
2744
+ )
2745
+ ];
2746
+ }
2747
+ case "blockquote": {
2748
+ return tokensToCommentBodyParagraphs(
2749
+ token.tokens,
2750
+ listDepth,
2751
+ blockquoteDepth + 1
2752
+ );
2753
+ }
2754
+ case "list": {
2755
+ const indent = listIndent(listDepth);
2756
+ const quotePrefix = blockquotePrefix(blockquoteDepth);
2757
+ return token.items.flatMap((item, index) => {
2758
+ const marker = listMarker(token.ordered, token.start, index);
2759
+ const listPrefix = indent + marker + taskListPrefix(item);
2760
+ const paragraphs = tokensToCommentBodyParagraphs(
2761
+ item.tokens,
2762
+ listDepth + 1,
2763
+ 0
2764
+ );
2765
+ const [firstParagraph, ...remainingParagraphs] = paragraphs;
2766
+ if (!firstParagraph) {
2767
+ return [
2768
+ {
2769
+ type: "paragraph",
2770
+ children: [{ text: quotePrefix + listPrefix }]
2771
+ }
2772
+ ];
2773
+ }
2774
+ const firstParagraphWithPrefixes = prependTextToParagraph(
2775
+ firstParagraph,
2776
+ quotePrefix + listPrefix
2777
+ );
2778
+ const remainingParagraphsWithQuotePrefix = remainingParagraphs.map(
2779
+ (paragraph) => prependTextToParagraph(paragraph, quotePrefix)
2780
+ );
2781
+ return [
2782
+ firstParagraphWithPrefixes,
2783
+ ...remainingParagraphsWithQuotePrefix
2784
+ ];
2785
+ });
2786
+ }
2787
+ case "list_item": {
2788
+ return tokensToCommentBodyParagraphs(
2789
+ token.tokens,
2790
+ listDepth,
2791
+ blockquoteDepth
2792
+ );
2793
+ }
2794
+ case "code": {
2795
+ return [
2796
+ prependTextToParagraph(
2797
+ {
2798
+ type: "paragraph",
2799
+ children: [{ text: token.text }]
2800
+ },
2801
+ blockquotePrefix(blockquoteDepth)
2802
+ )
2803
+ ];
2804
+ }
2805
+ case "table": {
2806
+ const quotePrefix = blockquotePrefix(blockquoteDepth);
2807
+ return tableToMarkdownRows(token).map((row) => ({
2808
+ type: "paragraph",
2809
+ children: [{ text: quotePrefix + row }]
2810
+ }));
2811
+ }
2812
+ default: {
2813
+ const inlines = tokensToCommentBodyInlines([token]);
2814
+ return inlines.length > 0 ? [
2815
+ prependTextToParagraph(
2816
+ {
2817
+ type: "paragraph",
2818
+ children: inlines
2819
+ },
2820
+ blockquotePrefix(blockquoteDepth)
2821
+ )
2822
+ ] : [];
2823
+ }
2824
+ }
2825
+ }
2826
+ function tokensToCommentBodyParagraphs(tokens, listDepth = 0, blockquoteDepth = 0) {
2827
+ assertTokens(tokens);
2828
+ return tokens.flatMap(
2829
+ (token) => tokenToCommentBodyParagraphs(token, listDepth, blockquoteDepth)
2830
+ );
2831
+ }
2832
+ function markdownToCommentBody(markdown) {
2833
+ return {
2834
+ version: 1,
2835
+ content: tokensToCommentBodyParagraphs(tokenizeMarkdown(markdown))
2836
+ };
2837
+ }
2838
+
2460
2839
  // src/webhooks.ts
2461
2840
  import * as base64 from "@stablelib/base64";
2462
2841
  import * as sha256 from "fast-sha256";
@@ -2624,6 +3003,7 @@ export {
2624
3003
  isNotificationChannelEnabled,
2625
3004
  isTextMentionNotificationEvent,
2626
3005
  isThreadNotificationEvent,
3006
+ markdownToCommentBody,
2627
3007
  stringifyCommentBody
2628
3008
  };
2629
3009
  //# sourceMappingURL=index.js.map