@plotday/twister 0.48.0 → 0.49.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 (82) hide show
  1. package/bin/templates/AGENTS.template.md +8 -2
  2. package/cli/templates/AGENTS.template.md +8 -2
  3. package/dist/connector.d.ts +67 -7
  4. package/dist/connector.d.ts.map +1 -1
  5. package/dist/connector.js +15 -5
  6. package/dist/connector.js.map +1 -1
  7. package/dist/docs/assets/hierarchy.js +1 -1
  8. package/dist/docs/assets/navigation.js +1 -1
  9. package/dist/docs/assets/search.js +1 -1
  10. package/dist/docs/classes/index.Connector.html +58 -49
  11. package/dist/docs/classes/index.Imap.html +1 -1
  12. package/dist/docs/classes/index.Options.html +1 -1
  13. package/dist/docs/classes/index.Smtp.html +1 -1
  14. package/dist/docs/classes/tools_ai.AI.html +1 -1
  15. package/dist/docs/classes/tools_callbacks.Callbacks.html +1 -1
  16. package/dist/docs/classes/tools_integrations.Integrations.html +21 -5
  17. package/dist/docs/classes/tools_network.Network.html +1 -1
  18. package/dist/docs/classes/tools_plot.Plot.html +1 -1
  19. package/dist/docs/classes/tools_store.Store.html +1 -1
  20. package/dist/docs/classes/tools_tasks.Tasks.html +1 -1
  21. package/dist/docs/classes/tools_twists.Twists.html +1 -1
  22. package/dist/docs/classes/twist.Twist.html +28 -28
  23. package/dist/docs/documents/Building_Connectors.html +8 -1
  24. package/dist/docs/enums/tag.Tag.html +11 -1
  25. package/dist/docs/enums/tools_integrations.AuthProvider.html +13 -13
  26. package/dist/docs/hierarchy.html +1 -1
  27. package/dist/docs/media/AGENTS.md +298 -775
  28. package/dist/docs/media/MULTI_USER_AUTH.md +6 -4
  29. package/dist/docs/media/SYNC_STRATEGIES.md +20 -14
  30. package/dist/docs/modules/index.html +1 -1
  31. package/dist/docs/types/index.CreateLinkDraft.html +7 -12
  32. package/dist/docs/types/index.NoteWriteBackResult.html +38 -0
  33. package/dist/docs/types/tools_integrations.ArchiveLinkFilter.html +5 -5
  34. package/dist/docs/types/tools_integrations.AuthToken.html +4 -4
  35. package/dist/docs/types/tools_integrations.Authorization.html +4 -4
  36. package/dist/llm-docs/connector.d.ts +1 -1
  37. package/dist/llm-docs/connector.d.ts.map +1 -1
  38. package/dist/llm-docs/connector.js +1 -1
  39. package/dist/llm-docs/connector.js.map +1 -1
  40. package/dist/llm-docs/tag.d.ts +1 -1
  41. package/dist/llm-docs/tag.d.ts.map +1 -1
  42. package/dist/llm-docs/tag.js +1 -1
  43. package/dist/llm-docs/tag.js.map +1 -1
  44. package/dist/llm-docs/tools/integrations.d.ts +1 -1
  45. package/dist/llm-docs/tools/integrations.d.ts.map +1 -1
  46. package/dist/llm-docs/tools/integrations.js +1 -1
  47. package/dist/llm-docs/tools/integrations.js.map +1 -1
  48. package/dist/llm-docs/twist-guide-template.d.ts +1 -1
  49. package/dist/llm-docs/twist-guide-template.d.ts.map +1 -1
  50. package/dist/llm-docs/twist-guide-template.js +1 -1
  51. package/dist/llm-docs/twist-guide-template.js.map +1 -1
  52. package/dist/llm-docs/twist.d.ts +1 -1
  53. package/dist/llm-docs/twist.d.ts.map +1 -1
  54. package/dist/llm-docs/twist.js +1 -1
  55. package/dist/llm-docs/twist.js.map +1 -1
  56. package/dist/tag.d.ts +11 -1
  57. package/dist/tag.d.ts.map +1 -1
  58. package/dist/tag.js +10 -0
  59. package/dist/tag.js.map +1 -1
  60. package/dist/tools/integrations.d.ts +22 -0
  61. package/dist/tools/integrations.d.ts.map +1 -1
  62. package/dist/tools/integrations.js.map +1 -1
  63. package/dist/twist-guide.d.ts +1 -1
  64. package/dist/twist-guide.d.ts.map +1 -1
  65. package/dist/twist.d.ts +2 -1
  66. package/dist/twist.d.ts.map +1 -1
  67. package/dist/twist.js.map +1 -1
  68. package/dist/utils/markdown.d.ts +27 -0
  69. package/dist/utils/markdown.d.ts.map +1 -0
  70. package/dist/utils/markdown.js +82 -0
  71. package/dist/utils/markdown.js.map +1 -0
  72. package/package.json +6 -1
  73. package/src/connector.ts +68 -7
  74. package/src/llm-docs/connector.ts +1 -1
  75. package/src/llm-docs/tag.ts +1 -1
  76. package/src/llm-docs/tools/integrations.ts +1 -1
  77. package/src/llm-docs/twist-guide-template.ts +1 -1
  78. package/src/llm-docs/twist.ts +1 -1
  79. package/src/tag.ts +10 -0
  80. package/src/tools/integrations.ts +24 -0
  81. package/src/twist.ts +2 -1
  82. package/src/utils/markdown.ts +94 -0
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Conversion helpers for connectors that bridge Plot markdown to external
3
+ * systems that store content as plain text (Google Drive comments, Todoist
4
+ * comments, Airtable cells, Attio notes, etc.).
5
+ *
6
+ * Both functions are pure and run in-process inside the connector's twist
7
+ * runtime — no RPC boundary is crossed, so they are cheap to call on every
8
+ * `onNoteCreated` / `onNoteUpdated`.
9
+ */
10
+
11
+ /**
12
+ * Render Markdown as plain text while preserving document structure.
13
+ *
14
+ * Numbered lists authored as `1. / 1. / 1.` in markdown are renumbered to
15
+ * `1. / 2. / 3.` so the plain-text reader sees real numbers. Bullet
16
+ * markers, headings content, blockquotes, and paragraph breaks survive;
17
+ * emphasis markers, code fences, and image syntax are dropped.
18
+ *
19
+ * Mentions `[Name](#@UUID)` render as `@Name`. Links `[text](url)`
20
+ * collapse to their label, falling back to the URL when the label is
21
+ * empty or identical to the URL.
22
+ *
23
+ * Use this when writing a Plot note to an external API that stores
24
+ * content verbatim as plain text. Pair the result with a matching
25
+ * `NoteWriteBackResult.externalContent` so the sync baseline round-trips.
26
+ */
27
+ export function markdownToPlainText(markdown: string): string {
28
+ let text = markdown;
29
+
30
+ text = text.replace(/```[a-zA-Z0-9]*\n([\s\S]*?)```/g, "$1");
31
+ text = text.replace(/`([^`]+)`/g, "$1");
32
+
33
+ text = text.replace(/!\[[^\]]*\]\([^)]*\)/g, "");
34
+
35
+ text = text.replace(/\[([^\]]+)\]\(#@[^)]+\)/g, "@$1");
36
+
37
+ text = text.replace(/\[([^\]]*)\]\(<?([^>)]+)>?\)/g, (_, label, url) => {
38
+ if (!label) return url;
39
+ if (label === url) return url;
40
+ return label;
41
+ });
42
+
43
+ text = text.replace(/^\s{0,3}#{1,6}\s+/gm, "");
44
+ text = text.replace(/^\s{0,3}>\s?/gm, "");
45
+
46
+ text = text.replace(/(\*\*|__)(.+?)\1/g, "$2");
47
+ text = text.replace(/(?<![*_])([*_])([^*_\n]+)\1(?![*_])/g, "$2");
48
+ text = text.replace(/~~(.+?)~~/g, "$1");
49
+
50
+ text = text.replace(/^\s{0,3}(?:-\s?){3,}\s*$/gm, "");
51
+ text = text.replace(/^\s{0,3}(?:\*\s?){3,}\s*$/gm, "");
52
+ text = text.replace(/^\s{0,3}(?:_\s?){3,}\s*$/gm, "");
53
+
54
+ text = renumberNumberedLists(text);
55
+
56
+ text = text
57
+ .replace(/&amp;/g, "&")
58
+ .replace(/&lt;/g, "<")
59
+ .replace(/&gt;/g, ">")
60
+ .replace(/&quot;/g, '"')
61
+ .replace(/&#39;/g, "'")
62
+ .replace(/&nbsp;/g, " ");
63
+
64
+ text = text.replace(/\n{3,}/g, "\n\n");
65
+
66
+ return text.trim();
67
+ }
68
+
69
+ function renumberNumberedLists(text: string): string {
70
+ const lines = text.split("\n");
71
+ const numberedRe = /^(\s*)(\d+)\.(\s+)(.*)$/;
72
+
73
+ let currentIndent: string | null = null;
74
+ let counter = 0;
75
+
76
+ for (let i = 0; i < lines.length; i++) {
77
+ const match = numberedRe.exec(lines[i]);
78
+ if (!match) {
79
+ currentIndent = null;
80
+ counter = 0;
81
+ continue;
82
+ }
83
+ const [, indent, , space, content] = match;
84
+ if (indent !== currentIndent) {
85
+ currentIndent = indent;
86
+ counter = 1;
87
+ } else {
88
+ counter += 1;
89
+ }
90
+ lines[i] = `${indent}${counter}.${space}${content}`;
91
+ }
92
+
93
+ return lines.join("\n");
94
+ }