@plotday/twister 0.47.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 (123) hide show
  1. package/bin/commands/generate.js +5 -5
  2. package/bin/commands/generate.js.map +1 -1
  3. package/bin/templates/AGENTS.template.md +8 -2
  4. package/bin/utils/bundle.js +14 -0
  5. package/bin/utils/bundle.js.map +1 -1
  6. package/cli/templates/AGENTS.template.md +8 -2
  7. package/dist/connector.d.ts +67 -7
  8. package/dist/connector.d.ts.map +1 -1
  9. package/dist/connector.js +15 -5
  10. package/dist/connector.js.map +1 -1
  11. package/dist/docs/assets/hierarchy.js +1 -1
  12. package/dist/docs/assets/navigation.js +1 -1
  13. package/dist/docs/assets/search.js +1 -1
  14. package/dist/docs/classes/index.Connector.html +58 -49
  15. package/dist/docs/classes/index.Imap.html +1 -1
  16. package/dist/docs/classes/index.Options.html +1 -1
  17. package/dist/docs/classes/index.Smtp.html +1 -1
  18. package/dist/docs/classes/tools_ai.AI.html +1 -1
  19. package/dist/docs/classes/tools_callbacks.Callbacks.html +1 -1
  20. package/dist/docs/classes/tools_integrations.Integrations.html +21 -5
  21. package/dist/docs/classes/tools_network.Network.html +1 -1
  22. package/dist/docs/classes/tools_plot.Plot.html +1 -1
  23. package/dist/docs/classes/tools_store.Store.html +1 -1
  24. package/dist/docs/classes/tools_tasks.Tasks.html +1 -1
  25. package/dist/docs/classes/tools_twists.Twists.html +1 -1
  26. package/dist/docs/classes/twist.Twist.html +28 -28
  27. package/dist/docs/documents/Building_Connectors.html +8 -1
  28. package/dist/docs/documents/CLI_Reference.html +6 -4
  29. package/dist/docs/enums/tag.Tag.html +11 -1
  30. package/dist/docs/enums/tools_integrations.AuthProvider.html +14 -12
  31. package/dist/docs/hierarchy.html +1 -1
  32. package/dist/docs/media/AGENTS.md +298 -775
  33. package/dist/docs/media/MULTI_USER_AUTH.md +6 -4
  34. package/dist/docs/media/SYNC_STRATEGIES.md +20 -14
  35. package/dist/docs/modules/index.html +1 -1
  36. package/dist/docs/types/index.CreateLinkDraft.html +7 -12
  37. package/dist/docs/types/index.NoteWriteBackResult.html +38 -0
  38. package/dist/docs/types/tools_integrations.ArchiveLinkFilter.html +5 -5
  39. package/dist/docs/types/tools_integrations.AuthToken.html +4 -4
  40. package/dist/docs/types/tools_integrations.Authorization.html +4 -4
  41. package/dist/llm-docs/connector.d.ts +1 -1
  42. package/dist/llm-docs/connector.d.ts.map +1 -1
  43. package/dist/llm-docs/connector.js +1 -1
  44. package/dist/llm-docs/connector.js.map +1 -1
  45. package/dist/llm-docs/tag.d.ts +1 -1
  46. package/dist/llm-docs/tag.d.ts.map +1 -1
  47. package/dist/llm-docs/tag.js +1 -1
  48. package/dist/llm-docs/tag.js.map +1 -1
  49. package/dist/llm-docs/tools/integrations.d.ts +1 -1
  50. package/dist/llm-docs/tools/integrations.d.ts.map +1 -1
  51. package/dist/llm-docs/tools/integrations.js +1 -1
  52. package/dist/llm-docs/tools/integrations.js.map +1 -1
  53. package/dist/llm-docs/twist-guide-template.d.ts +1 -1
  54. package/dist/llm-docs/twist-guide-template.d.ts.map +1 -1
  55. package/dist/llm-docs/twist-guide-template.js +1 -1
  56. package/dist/llm-docs/twist-guide-template.js.map +1 -1
  57. package/dist/llm-docs/twist.d.ts +1 -1
  58. package/dist/llm-docs/twist.d.ts.map +1 -1
  59. package/dist/llm-docs/twist.js +1 -1
  60. package/dist/llm-docs/twist.js.map +1 -1
  61. package/dist/tag.d.ts +11 -1
  62. package/dist/tag.d.ts.map +1 -1
  63. package/dist/tag.js +10 -0
  64. package/dist/tag.js.map +1 -1
  65. package/dist/tools/integrations.d.ts +25 -1
  66. package/dist/tools/integrations.d.ts.map +1 -1
  67. package/dist/tools/integrations.js +2 -0
  68. package/dist/tools/integrations.js.map +1 -1
  69. package/dist/twist-guide.d.ts +1 -1
  70. package/dist/twist-guide.d.ts.map +1 -1
  71. package/dist/twist.d.ts +2 -1
  72. package/dist/twist.d.ts.map +1 -1
  73. package/dist/twist.js.map +1 -1
  74. package/dist/utils/markdown.d.ts +27 -0
  75. package/dist/utils/markdown.d.ts.map +1 -0
  76. package/dist/utils/markdown.js +82 -0
  77. package/dist/utils/markdown.js.map +1 -0
  78. package/package.json +7 -1
  79. package/src/connector.ts +427 -0
  80. package/src/creator-docs.ts +29 -0
  81. package/src/index.ts +10 -0
  82. package/src/llm-docs/connector.ts +8 -0
  83. package/src/llm-docs/index.ts +48 -0
  84. package/src/llm-docs/options.ts +8 -0
  85. package/src/llm-docs/plot.ts +8 -0
  86. package/src/llm-docs/schedule.ts +8 -0
  87. package/src/llm-docs/tag.ts +8 -0
  88. package/src/llm-docs/tool.ts +8 -0
  89. package/src/llm-docs/tools/ai.ts +8 -0
  90. package/src/llm-docs/tools/callbacks.ts +8 -0
  91. package/src/llm-docs/tools/imap.ts +8 -0
  92. package/src/llm-docs/tools/integrations.ts +8 -0
  93. package/src/llm-docs/tools/network.ts +8 -0
  94. package/src/llm-docs/tools/plot.ts +8 -0
  95. package/src/llm-docs/tools/smtp.ts +8 -0
  96. package/src/llm-docs/tools/store.ts +8 -0
  97. package/src/llm-docs/tools/tasks.ts +8 -0
  98. package/src/llm-docs/tools/twists.ts +8 -0
  99. package/src/llm-docs/twist-guide-template.ts +8 -0
  100. package/src/llm-docs/twist.ts +8 -0
  101. package/src/options.ts +115 -0
  102. package/src/plot.ts +1068 -0
  103. package/src/schedule.ts +203 -0
  104. package/src/tag.ts +54 -0
  105. package/src/tool.ts +377 -0
  106. package/src/tools/ai.ts +845 -0
  107. package/src/tools/callbacks.ts +134 -0
  108. package/src/tools/imap.ts +266 -0
  109. package/src/tools/index.ts +10 -0
  110. package/src/tools/integrations.ts +352 -0
  111. package/src/tools/network.ts +240 -0
  112. package/src/tools/plot.ts +692 -0
  113. package/src/tools/smtp.ts +166 -0
  114. package/src/tools/store.ts +149 -0
  115. package/src/tools/tasks.ts +137 -0
  116. package/src/tools/twists.ts +228 -0
  117. package/src/twist-guide.ts +9 -0
  118. package/src/twist.ts +436 -0
  119. package/src/utils/hash.ts +8 -0
  120. package/src/utils/markdown.ts +94 -0
  121. package/src/utils/serializable.ts +54 -0
  122. package/src/utils/types.ts +130 -0
  123. package/src/utils/uuid.ts +9 -0
@@ -46,8 +46,8 @@ When a twist needs to write back to an external system (e.g., posting a comment
46
46
  The simplest approach passes the actor's ID as the `authToken` parameter. The tool's `getClient()` method will look it up via `integrations.get(provider, actorId)`:
47
47
 
48
48
  ```typescript
49
- private async onNoteCreated(note: Note): Promise<void> {
50
- const provider = activity.meta?.provider;
49
+ private async onNoteCreated(note: Note, thread: Thread): Promise<NoteWriteBackResult | void> {
50
+ const provider = thread.meta?.provider;
51
51
  const tool = this.getProviderTool(provider);
52
52
 
53
53
  // Try actor's credentials first, then installer's
@@ -63,8 +63,10 @@ private async onNoteCreated(note: Note): Promise<void> {
63
63
 
64
64
  for (const authToken of authTokensToTry) {
65
65
  try {
66
- await tool.addIssueComment(authToken, activity.meta, note.content, note.id);
67
- return; // Success
66
+ // addIssueComment returns { key, externalContent } — returning it
67
+ // directly lets the runtime set note.key AND record the sync
68
+ // baseline so future re-syncs preserve Plot's markdown.
69
+ return await tool.addIssueComment(authToken, thread.meta, note.content, note.id);
68
70
  } catch {
69
71
  continue; // Try next token
70
72
  }
@@ -764,29 +764,31 @@ When implementing two-way sync where items can be created in Plot and pushed to
764
764
 
765
765
  This eliminates a race condition where a webhook for an item you're creating arrives before you've updated the Activity/Note with the external key. Without this pattern, the webhook handler won't find the item by external key and may create a duplicate.
766
766
 
767
+ In a connector, return a `NoteWriteBackResult` from `onNoteCreated` — the runtime sets the key atomically and also records the external content as the sync baseline:
768
+
767
769
  ```typescript
768
- async pushNoteAsComment(note: Note, externalItemId: string): Promise<void> {
769
- // Create the comment in the external system, embedding the Note ID in metadata
770
- const externalComment = await externalApi.createComment(externalItemId, {
771
- body: note.content,
770
+ async onNoteCreated(note: Note, thread: Thread): Promise<NoteWriteBackResult | void> {
771
+ const externalComment = await externalApi.createComment(thread.meta.externalItemId, {
772
+ body: note.content ?? "",
772
773
  metadata: { plotNoteId: note.id }, // Embed Plot ID for webhook correlation
773
774
  });
774
-
775
- // Update the Note with the external key AFTER creation
776
- // A webhook may arrive between these two steps — that's OK because
777
- // the webhook handler checks metadata first (see below)
778
- await this.tools.plot.updateNote({
779
- id: note.id,
775
+ if (!externalComment?.id) return;
776
+ return {
780
777
  key: `comment-${externalComment.id}`,
781
- });
778
+ // What the external system NOW STORES — must match what your sync-in
779
+ // path emits as NewNote.content on re-ingest. The runtime hashes this
780
+ // so the next sync re-listing unchanged content preserves Plot's
781
+ // (possibly richer-markdown) version instead of clobbering it.
782
+ externalContent: externalComment.body,
783
+ };
782
784
  }
783
785
 
784
786
  async onWebhook(payload: WebhookPayload): Promise<void> {
785
787
  const comment = payload.comment;
786
788
 
787
- // Use the Plot ID from metadata if present (handles the race condition
788
- // where the webhook arrives before we've set the external key on the Note),
789
- // otherwise fall back to upserting by activity source and key
789
+ // Use the Plot ID from metadata if present (handles the race where the
790
+ // webhook arrives before onNoteCreated's return has been applied),
791
+ // otherwise fall back to upserting by activity source and key.
790
792
  await this.tools.plot.createNote({
791
793
  ...(comment.metadata?.plotNoteId
792
794
  ? { id: comment.metadata.plotNoteId }
@@ -797,6 +799,10 @@ async onWebhook(payload: WebhookPayload): Promise<void> {
797
799
  }
798
800
  ```
799
801
 
802
+ For twists that write notes outside the `onNoteCreated` dispatch path (explicit `pushNoteAsComment`-style methods), set `key` via `updateNote` after the external write — see the legacy pattern below. In that path the sync baseline is **not** established, so the next sync-in will overwrite Plot's content with the external version. Prefer the connector `onNoteCreated` flow when round-trip preservation matters.
803
+
804
+ See `connectors/AGENTS.md` → "Sync baseline preservation" for the full contract on what `externalContent` must equal.
805
+
800
806
  ## Summary
801
807
 
802
808
  - **Strategy 1** (Create Once): Simplest, no deduplication, use for one-time items