@plotday/twister 0.35.0 → 0.37.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 (262) hide show
  1. package/README.md +4 -2
  2. package/bin/commands/create.js +37 -3
  3. package/bin/commands/create.js.map +1 -1
  4. package/bin/commands/deploy.js +4 -0
  5. package/bin/commands/deploy.js.map +1 -1
  6. package/bin/index.js +1 -0
  7. package/bin/index.js.map +1 -1
  8. package/bin/templates/AGENTS.template.md +188 -271
  9. package/bin/templates/README.template.md +2 -23
  10. package/cli/templates/AGENTS.template.md +188 -271
  11. package/cli/templates/README.template.md +2 -23
  12. package/dist/docs/assets/hierarchy.js +1 -1
  13. package/dist/docs/assets/navigation.js +1 -1
  14. package/dist/docs/assets/search.js +1 -1
  15. package/dist/docs/classes/index.Options.html +10 -0
  16. package/dist/docs/classes/index.Source.html +184 -0
  17. package/dist/docs/classes/tool.ITool.html +1 -1
  18. package/dist/docs/classes/tool.Tool.html +21 -21
  19. package/dist/docs/classes/tools_ai.AI.html +1 -1
  20. package/dist/docs/classes/tools_callbacks.Callbacks.html +2 -2
  21. package/dist/docs/classes/tools_integrations.Integrations.html +38 -16
  22. package/dist/docs/classes/tools_network.Network.html +1 -1
  23. package/dist/docs/classes/tools_plot.Plot.html +86 -60
  24. package/dist/docs/classes/tools_store.Store.html +1 -1
  25. package/dist/docs/classes/tools_tasks.Tasks.html +1 -1
  26. package/dist/docs/classes/tools_twists.Twists.html +1 -1
  27. package/dist/docs/classes/twist.Twist.html +42 -10
  28. package/dist/docs/documents/Building_Sources.html +137 -0
  29. package/dist/docs/documents/Built-in_Tools.html +11 -2
  30. package/dist/docs/documents/Core_Concepts.html +5 -10
  31. package/dist/docs/documents/Getting_Started.html +1 -1
  32. package/dist/docs/enums/{plot.ActivityLinkType.html → plot.ActionType.html} +8 -8
  33. package/dist/docs/enums/plot.ActorType.html +7 -7
  34. package/dist/docs/enums/plot.ConferencingProvider.html +6 -6
  35. package/dist/docs/enums/plot.ThemeColor.html +9 -9
  36. package/dist/docs/enums/tag.Tag.html +3 -10
  37. package/dist/docs/enums/tools_integrations.AuthProvider.html +11 -11
  38. package/dist/docs/enums/tools_plot.ContactAccess.html +3 -3
  39. package/dist/docs/enums/tools_plot.PriorityAccess.html +3 -3
  40. package/dist/docs/enums/{tools_plot.ActivityAccess.html → tools_plot.ThreadAccess.html} +6 -6
  41. package/dist/docs/hierarchy.html +1 -1
  42. package/dist/docs/index.html +5 -6
  43. package/dist/docs/interfaces/utils_types.ToolShed.html +5 -5
  44. package/dist/docs/media/AGENTS.md +910 -0
  45. package/dist/docs/media/MULTI_USER_AUTH.md +111 -0
  46. package/dist/docs/media/SYNC_STRATEGIES.md +7 -7
  47. package/dist/docs/modules/index.html +1 -1
  48. package/dist/docs/modules/plot.html +1 -1
  49. package/dist/docs/modules/tool.html +1 -1
  50. package/dist/docs/modules/tools_integrations.html +1 -1
  51. package/dist/docs/modules/tools_plot.html +1 -1
  52. package/dist/docs/modules.html +1 -1
  53. package/dist/docs/types/index.BooleanDef.html +7 -0
  54. package/dist/docs/types/index.NewSchedule.html +33 -0
  55. package/dist/docs/types/index.NewScheduleContact.html +5 -0
  56. package/dist/docs/types/index.NewScheduleOccurrence.html +6 -0
  57. package/dist/docs/types/index.NumberDef.html +9 -0
  58. package/dist/docs/types/index.OptionDef.html +2 -0
  59. package/dist/docs/types/index.OptionsSchema.html +3 -0
  60. package/dist/docs/types/index.ResolvedOptions.html +4 -0
  61. package/dist/docs/types/index.Schedule.html +37 -0
  62. package/dist/docs/types/index.ScheduleContact.html +5 -0
  63. package/dist/docs/types/index.ScheduleContactRole.html +1 -0
  64. package/dist/docs/types/index.ScheduleContactStatus.html +1 -0
  65. package/dist/docs/types/index.ScheduleOccurrence.html +17 -0
  66. package/dist/docs/types/index.ScheduleOccurrenceUpdate.html +2 -0
  67. package/dist/docs/types/index.SelectDef.html +8 -0
  68. package/dist/docs/types/index.TextDef.html +8 -0
  69. package/dist/docs/types/plot.Action.html +26 -0
  70. package/dist/docs/types/plot.Actor.html +6 -6
  71. package/dist/docs/types/plot.ActorId.html +1 -1
  72. package/dist/docs/types/plot.ContentType.html +1 -1
  73. package/dist/docs/types/plot.Link.html +36 -0
  74. package/dist/docs/types/plot.NewActor.html +1 -1
  75. package/dist/docs/types/plot.NewContact.html +5 -5
  76. package/dist/docs/types/plot.NewLink.html +26 -0
  77. package/dist/docs/types/plot.NewLinkWithNotes.html +7 -0
  78. package/dist/docs/types/plot.NewNote.html +10 -10
  79. package/dist/docs/types/plot.NewPriority.html +1 -1
  80. package/dist/docs/types/plot.NewTags.html +1 -1
  81. package/dist/docs/types/plot.NewThread.html +27 -0
  82. package/dist/docs/types/plot.NewThreadWithNotes.html +1 -0
  83. package/dist/docs/types/plot.Note.html +9 -8
  84. package/dist/docs/types/plot.NoteUpdate.html +2 -2
  85. package/dist/docs/types/plot.PickPriorityConfig.html +8 -10
  86. package/dist/docs/types/plot.Priority.html +6 -6
  87. package/dist/docs/types/plot.PriorityUpdate.html +1 -1
  88. package/dist/docs/types/plot.Tags.html +1 -1
  89. package/dist/docs/types/plot.Thread.html +1 -0
  90. package/dist/docs/types/plot.ThreadCommon.html +17 -0
  91. package/dist/docs/types/plot.ThreadFilter.html +2 -0
  92. package/dist/docs/types/plot.ThreadMeta.html +11 -0
  93. package/dist/docs/types/plot.ThreadUpdate.html +3 -0
  94. package/dist/docs/types/plot.ThreadWithNotes.html +1 -0
  95. package/dist/docs/types/tools_integrations.ArchiveLinkFilter.html +11 -0
  96. package/dist/docs/types/tools_integrations.AuthToken.html +4 -4
  97. package/dist/docs/types/tools_integrations.Authorization.html +4 -4
  98. package/dist/docs/types/tools_integrations.Channel.html +11 -0
  99. package/dist/docs/types/tools_integrations.LinkTypeConfig.html +17 -0
  100. package/dist/docs/types/tools_plot.LinkFilter.html +10 -0
  101. package/dist/docs/types/tools_plot.NoteIntentHandler.html +6 -6
  102. package/dist/docs/types/tools_twists.TwistPermissions.html +1 -1
  103. package/dist/docs/types/utils_types.BuiltInTools.html +2 -2
  104. package/dist/docs/types/utils_types.ExtractBuildReturn.html +1 -1
  105. package/dist/docs/types/utils_types.InferOptions.html +1 -1
  106. package/dist/docs/types/utils_types.InferTools.html +1 -1
  107. package/dist/docs/types/utils_types.JSONValue.html +1 -1
  108. package/dist/docs/types/utils_types.PromiseValues.html +1 -1
  109. package/dist/docs/types/utils_types.ToolBuilder.html +2 -2
  110. package/dist/index.d.ts +3 -0
  111. package/dist/index.d.ts.map +1 -1
  112. package/dist/index.js +3 -0
  113. package/dist/index.js.map +1 -1
  114. package/dist/llm-docs/index.d.ts.map +1 -1
  115. package/dist/llm-docs/index.js +6 -8
  116. package/dist/llm-docs/index.js.map +1 -1
  117. package/dist/llm-docs/options.d.ts +9 -0
  118. package/dist/llm-docs/options.d.ts.map +1 -0
  119. package/dist/llm-docs/options.js +8 -0
  120. package/dist/llm-docs/options.js.map +1 -0
  121. package/dist/llm-docs/plot.d.ts +1 -1
  122. package/dist/llm-docs/plot.d.ts.map +1 -1
  123. package/dist/llm-docs/plot.js +1 -1
  124. package/dist/llm-docs/plot.js.map +1 -1
  125. package/dist/llm-docs/schedule.d.ts +9 -0
  126. package/dist/llm-docs/schedule.d.ts.map +1 -0
  127. package/dist/llm-docs/schedule.js +8 -0
  128. package/dist/llm-docs/schedule.js.map +1 -0
  129. package/dist/llm-docs/source.d.ts +9 -0
  130. package/dist/llm-docs/source.d.ts.map +1 -0
  131. package/dist/llm-docs/source.js +8 -0
  132. package/dist/llm-docs/source.js.map +1 -0
  133. package/dist/llm-docs/tag.d.ts +1 -1
  134. package/dist/llm-docs/tag.d.ts.map +1 -1
  135. package/dist/llm-docs/tag.js +1 -1
  136. package/dist/llm-docs/tag.js.map +1 -1
  137. package/dist/llm-docs/tool.d.ts +1 -1
  138. package/dist/llm-docs/tool.d.ts.map +1 -1
  139. package/dist/llm-docs/tool.js +1 -1
  140. package/dist/llm-docs/tool.js.map +1 -1
  141. package/dist/llm-docs/tools/callbacks.d.ts +1 -1
  142. package/dist/llm-docs/tools/callbacks.d.ts.map +1 -1
  143. package/dist/llm-docs/tools/callbacks.js +1 -1
  144. package/dist/llm-docs/tools/callbacks.js.map +1 -1
  145. package/dist/llm-docs/tools/integrations.d.ts +1 -1
  146. package/dist/llm-docs/tools/integrations.d.ts.map +1 -1
  147. package/dist/llm-docs/tools/integrations.js +1 -1
  148. package/dist/llm-docs/tools/integrations.js.map +1 -1
  149. package/dist/llm-docs/tools/plot.d.ts +1 -1
  150. package/dist/llm-docs/tools/plot.d.ts.map +1 -1
  151. package/dist/llm-docs/tools/plot.js +1 -1
  152. package/dist/llm-docs/tools/plot.js.map +1 -1
  153. package/dist/llm-docs/tools/twists.d.ts +1 -1
  154. package/dist/llm-docs/tools/twists.d.ts.map +1 -1
  155. package/dist/llm-docs/tools/twists.js +1 -1
  156. package/dist/llm-docs/tools/twists.js.map +1 -1
  157. package/dist/llm-docs/twist-guide-template.d.ts +1 -1
  158. package/dist/llm-docs/twist-guide-template.d.ts.map +1 -1
  159. package/dist/llm-docs/twist-guide-template.js +1 -1
  160. package/dist/llm-docs/twist-guide-template.js.map +1 -1
  161. package/dist/llm-docs/twist.d.ts +1 -1
  162. package/dist/llm-docs/twist.d.ts.map +1 -1
  163. package/dist/llm-docs/twist.js +1 -1
  164. package/dist/llm-docs/twist.js.map +1 -1
  165. package/dist/options.d.ts +104 -0
  166. package/dist/options.d.ts.map +1 -0
  167. package/dist/options.js +40 -0
  168. package/dist/options.js.map +1 -0
  169. package/dist/plot.d.ts +254 -588
  170. package/dist/plot.d.ts.map +1 -1
  171. package/dist/plot.js +16 -49
  172. package/dist/plot.js.map +1 -1
  173. package/dist/schedule.d.ts +172 -0
  174. package/dist/schedule.d.ts.map +1 -0
  175. package/dist/schedule.js +2 -0
  176. package/dist/schedule.js.map +1 -0
  177. package/dist/source.d.ts +133 -0
  178. package/dist/source.d.ts.map +1 -0
  179. package/dist/source.js +116 -0
  180. package/dist/source.js.map +1 -0
  181. package/dist/tag.d.ts +3 -10
  182. package/dist/tag.d.ts.map +1 -1
  183. package/dist/tag.js +2 -11
  184. package/dist/tag.js.map +1 -1
  185. package/dist/tool.d.ts +1 -15
  186. package/dist/tool.d.ts.map +1 -1
  187. package/dist/tool.js.map +1 -1
  188. package/dist/tools/callbacks.d.ts +1 -1
  189. package/dist/tools/callbacks.js +1 -1
  190. package/dist/tools/integrations.d.ts +107 -50
  191. package/dist/tools/integrations.d.ts.map +1 -1
  192. package/dist/tools/integrations.js +23 -22
  193. package/dist/tools/integrations.js.map +1 -1
  194. package/dist/tools/plot.d.ts +133 -117
  195. package/dist/tools/plot.d.ts.map +1 -1
  196. package/dist/tools/plot.js +19 -21
  197. package/dist/tools/plot.js.map +1 -1
  198. package/dist/tools/twists.d.ts +1 -1
  199. package/dist/twist-guide.d.ts +1 -1
  200. package/dist/twist-guide.d.ts.map +1 -1
  201. package/dist/twist.d.ts +66 -11
  202. package/dist/twist.d.ts.map +1 -1
  203. package/dist/twist.js +79 -10
  204. package/dist/twist.js.map +1 -1
  205. package/dist/utils/types.d.ts +5 -1
  206. package/dist/utils/types.d.ts.map +1 -1
  207. package/package.json +16 -41
  208. package/dist/common/calendar.d.ts +0 -135
  209. package/dist/common/calendar.d.ts.map +0 -1
  210. package/dist/common/calendar.js +0 -2
  211. package/dist/common/calendar.js.map +0 -1
  212. package/dist/common/documents.d.ts +0 -122
  213. package/dist/common/documents.d.ts.map +0 -1
  214. package/dist/common/documents.js +0 -2
  215. package/dist/common/documents.js.map +0 -1
  216. package/dist/common/messaging.d.ts +0 -84
  217. package/dist/common/messaging.d.ts.map +0 -1
  218. package/dist/common/messaging.js +0 -2
  219. package/dist/common/messaging.js.map +0 -1
  220. package/dist/common/projects.d.ts +0 -112
  221. package/dist/common/projects.d.ts.map +0 -1
  222. package/dist/common/projects.js +0 -2
  223. package/dist/common/projects.js.map +0 -1
  224. package/dist/docs/documents/Building_Custom_Tools.html +0 -215
  225. package/dist/docs/enums/plot.ActivityKind.html +0 -14
  226. package/dist/docs/enums/plot.ActivityType.html +0 -10
  227. package/dist/docs/modules/common_calendar.html +0 -1
  228. package/dist/docs/types/common_calendar.Calendar.html +0 -13
  229. package/dist/docs/types/common_calendar.CalendarTool.html +0 -81
  230. package/dist/docs/types/common_calendar.SyncOptions.html +0 -24
  231. package/dist/docs/types/plot.Activity.html +0 -2
  232. package/dist/docs/types/plot.ActivityCommon.html +0 -20
  233. package/dist/docs/types/plot.ActivityFilter.html +0 -3
  234. package/dist/docs/types/plot.ActivityLink.html +0 -26
  235. package/dist/docs/types/plot.ActivityMeta.html +0 -11
  236. package/dist/docs/types/plot.ActivityOccurrence.html +0 -22
  237. package/dist/docs/types/plot.ActivityOccurrenceUpdate.html +0 -3
  238. package/dist/docs/types/plot.ActivityUpdate.html +0 -3
  239. package/dist/docs/types/plot.ActivityWithNotes.html +0 -1
  240. package/dist/docs/types/plot.NewActivity.html +0 -81
  241. package/dist/docs/types/plot.NewActivityOccurrence.html +0 -24
  242. package/dist/docs/types/plot.NewActivityWithNotes.html +0 -1
  243. package/dist/docs/types/tool.SyncToolOptions.html +0 -9
  244. package/dist/docs/types/tools_integrations.IntegrationOptions.html +0 -4
  245. package/dist/docs/types/tools_integrations.IntegrationProviderConfig.html +0 -13
  246. package/dist/docs/types/tools_integrations.Syncable.html +0 -7
  247. package/dist/llm-docs/common/calendar.d.ts +0 -9
  248. package/dist/llm-docs/common/calendar.d.ts.map +0 -1
  249. package/dist/llm-docs/common/calendar.js +0 -8
  250. package/dist/llm-docs/common/calendar.js.map +0 -1
  251. package/dist/llm-docs/common/documents.d.ts +0 -9
  252. package/dist/llm-docs/common/documents.d.ts.map +0 -1
  253. package/dist/llm-docs/common/documents.js +0 -8
  254. package/dist/llm-docs/common/documents.js.map +0 -1
  255. package/dist/llm-docs/common/messaging.d.ts +0 -9
  256. package/dist/llm-docs/common/messaging.d.ts.map +0 -1
  257. package/dist/llm-docs/common/messaging.js +0 -8
  258. package/dist/llm-docs/common/messaging.js.map +0 -1
  259. package/dist/llm-docs/common/projects.d.ts +0 -9
  260. package/dist/llm-docs/common/projects.d.ts.map +0 -1
  261. package/dist/llm-docs/common/projects.js +0 -8
  262. package/dist/llm-docs/common/projects.js.map +0 -1
@@ -1,2 +1,2 @@
1
- export declare const TWIST_GUIDE = "# Twist Implementation Guide for LLMs\n\nThis document provides context for AI assistants generating or modifying twists.\n\n## Architecture Overview\n\nPlot Twists are TypeScript classes that extend the `Twist` base class. Twists interact with external services and Plot's core functionality through a tool-based architecture.\n\n### Runtime Environment\n\n**Critical**: All Twists and tool functions are executed in a sandboxed, ephemeral environment with limited resources:\n\n- **Memory is temporary**: Anything stored in memory (e.g. as a variable in the twist/tool object) is lost after the function completes. Use the Store tool instead. Only use memory for temporary caching.\n- **Limited requests per execution**: Each execution has ~1000 requests (HTTP requests, tool calls, database operations)\n- **Limited CPU time**: Each execution has limited CPU time (typically ~60 seconds) and memory (128MB)\n- **Use tasks to get fresh request limits**: `this.runTask()` creates a NEW execution with a fresh ~1000 request limit\n- **Calling callbacks continues same execution**: `this.run()` continues the same execution and shares the request count\n- **Break long loops**: Split large operations into batches that each stay under the ~1000 request limit\n- **Store intermediate state**: Use the Store tool to persist state between batches\n- **Examples**: Syncing large datasets, processing many API calls, or performing batch operations\n\n## Understanding Activities and Notes\n\n**CRITICAL CONCEPT**: An **Activity** represents something done or to be done (a task, event, or conversation), while **Notes** represent the updates and details on that activity.\n\n**Think of an Activity as a thread** on a messaging platform, and **Notes as the messages in that thread**.\n\n### Key Guidelines\n\n1. **Always create Activities with an initial Note** - The title is just a summary; detailed content goes in Notes\n2. **Add Notes to existing Activities for updates** - Don't create a new Activity for each related message\n3. **Use Activity.source and Note.key for automatic upserts (Recommended)** - Set Activity.source to the external item's URL for deduplication, and use Note.key for upsertable note content. No manual ID tracking needed.\n4. **For advanced cases, use generated UUIDs** - Only when you need multiple Plot activities per external item (see SYNC_STRATEGIES.md)\n5. **Most Activities should be `ActivityType.Note`** - Use `Action` only for tasks with `done`, use `Event` only for items with `start`/`end`\n\n### Recommended Decision Tree (Strategy 2: Upsert via Source/Key)\n\n```\nNew event/task/conversation from external system?\n \u251C\u2500 Has stable URL or ID?\n \u2502 \u2514\u2500 Yes \u2192 Set Activity.source to the canonical URL/ID\n \u2502 Create Activity (Plot handles deduplication automatically)\n \u2502 Use Note.key for different note types:\n \u2502 - \"description\" for main content\n \u2502 - \"metadata\" for status/priority/assignee\n \u2502 - \"comment-{id}\" for individual comments\n \u2502\n \u2514\u2500 No stable identifier OR need multiple Plot activities per external item?\n \u2514\u2500 Use Advanced Pattern (Strategy 3: Generate and Store IDs)\n See SYNC_STRATEGIES.md for details\n```\n\n### Advanced Decision Tree (Strategy 3: Generate and Store IDs)\n\nOnly use when source/key upserts aren't sufficient (e.g., creating multiple activities from one external item):\n\n```\nNew event/task/conversation?\n \u251C\u2500 Yes \u2192 Generate UUID with Uuid.Generate()\n \u2502 Create new Activity with that UUID\n \u2502 Store mapping: external_id \u2192 activity_uuid\n \u2502\n \u2514\u2500 No (update/reply/comment) \u2192 Look up mapping by external_id\n \u251C\u2500 Found \u2192 Add Note to existing Activity using stored UUID\n \u2514\u2500 Not found \u2192 Create new Activity with UUID + store mapping\n```\n\n## Twist Structure Pattern\n\n```typescript\nimport {\n type Activity,\n type Priority,\n type ToolBuilder,\n twist,\n} from \"@plotday/twister\";\nimport { Plot } from \"@plotday/twister/tools/plot\";\nimport { Uuid } from \"@plotday/twister/utils/uuid\";\n\nexport default class MyTwist extends Twist<MyTwist> {\n build(build: ToolBuilder) {\n return {\n plot: build(Plot),\n };\n }\n\n async activate(priority: Pick<Priority, \"id\">) {\n // Called when twist is enabled for a priority\n // Common actions: request auth, create setup activities\n }\n\n async activity(activity: Activity) {\n // Called when an activity is routed to this twist\n // Common actions: process external events, update activities\n }\n}\n```\n\n## Tool System\n\n### Accessing Tools\n\nAll tools are declared in the `build` method:\n\n```typescript\nbuild(build: ToolBuilder) {\n return {\n toolName: build(ToolClass),\n };\n}\n```\n\nAll `build()` calls must occur in the `build` method as they are used for dependency analysis.\n\nIMPORTANT: HTTP access is restricted to URLs requested via `build(Network, { urls: [url1, url2, ...] })` in the `build` method. Wildcards are supported. Use `build(Network, { urls: ['*'] })` if full access is needed.\n\n### Built-in Tools (Always Available)\n\nFor complete API documentation of built-in tools including all methods, types, and detailed examples, see the TypeScript definitions in your installed package at `node_modules/@plotday/twister/src/tools/*.ts`. Each tool file contains comprehensive JSDoc documentation.\n\n**Quick reference - Available tools:**\n\n- `@plotday/twister/tools/plot` - Core data layer (create/update activities, priorities, contacts)\n- `@plotday/twister/tools/ai` - LLM integration (text generation, structured output, reasoning)\n - Use ModelPreferences to specify `speed` (fast/balanced/capable) and `cost` (low/medium/high)\n- `@plotday/twister/tools/store` - Persistent key-value storage (also via `this.set()`, `this.get()`)\n- `@plotday/twister/tools/tasks` - Queue batched work (also via `this.run()`)\n- `@plotday/twister/tools/callbacks` - Persistent function references (also via `this.callback()`)\n- `@plotday/twister/tools/integrations` - OAuth2 authentication flows\n- `@plotday/twister/tools/network` - HTTP access permissions and webhook management\n- `@plotday/twister/tools/twists` - Manage other Twists\n\n**Critical**: Never use instance variables for state. They are lost after function execution. Always use Store methods.\n\n### External Tools (Add to package.json)\n\nAdd tool dependencies to `package.json`:\n\n```json\n{\n \"dependencies\": {\n \"@plotday/twister\": \"workspace:^\",\n \"@plotday/tool-google-calendar\": \"workspace:^\"\n }\n}\n```\n\n#### Common External Tools\n\n- `@plotday/tool-google-calendar`: Google Calendar integration\n- `@plotday/tool-outlook-calendar`: Outlook Calendar integration\n- `@plotday/tool-google-contacts`: Google Contacts integration\n\n## Lifecycle Methods\n\n### activate(priority: Pick<Priority, \"id\">)\n\nCalled when the twist is enabled for a priority. Common patterns:\n\n**Request Authentication:**\n\n```typescript\nasync activate(_priority: Pick<Priority, \"id\">) {\n const authLink = await this.tools.externalTool.requestAuth(\n this.onAuthComplete,\n \"google\"\n );\n\n await this.tools.plot.createActivity({\n type: ActivityType.Note,\n title: \"Connect your account\",\n notes: [\n {\n content: \"Click the link below to connect your account and start syncing.\",\n links: [authLink],\n },\n ],\n });\n}\n```\n\n**Store Parent Activity for Later:**\n\n```typescript\nconst activity = await this.tools.plot.createActivity({\n type: ActivityType.Note,\n title: \"Setup\",\n notes: [\n {\n content: \"Your twist is being set up. Configuration steps will appear here.\",\n },\n ],\n});\n\nawait this.set(\"setup_activity_id\", activity.id);\n```\n\n### activity(activity: Activity)\n\nCalled when an activity is routed to the twist. Common patterns:\n\n**Create Activities from External Events:**\n\n```typescript\nasync activity(activity: Activity) {\n await this.tools.plot.createActivity(activity);\n}\n```\n\n**Update Based on User Action:**\n\n```typescript\nasync activity(activity: Activity) {\n if (activity.completed) {\n await this.handleCompletion(activity);\n }\n}\n```\n\n## Activity Links\n\nActivity links enable user interaction:\n\n```typescript\nimport { type ActivityLink, ActivityLinkType } from \"@plotday/twister\";\n\n// URL link\nconst urlLink: ActivityLink = {\n title: \"Open website\",\n type: ActivityLinkType.url,\n url: \"https://example.com\",\n};\n\n// Callback link (uses Callbacks tool)\nconst token = await this.callback(this.onLinkClicked, \"context\");\nconst callbackLink: ActivityLink = {\n title: \"Click me\",\n type: ActivityLinkType.callback,\n token: token,\n};\n\n// Add to activity note\nawait this.tools.plot.createActivity({\n type: ActivityType.Note,\n title: \"Task with links\",\n notes: [\n {\n content: \"Click the links below to take action.\",\n links: [urlLink, callbackLink],\n },\n ],\n});\n```\n\n## Authentication Pattern\n\nCommon pattern for OAuth authentication:\n\n```typescript\nasync activate(_priority: Pick<Priority, \"id\">) {\n // Request auth link from tool with callback\n const authLink = await this.tools.googleTool.requestAuth(\n this.onAuthComplete,\n \"google\"\n );\n\n // Create activity with auth link\n const activity = await this.tools.plot.createActivity({\n type: ActivityType.Note,\n title: \"Connect Google account\",\n notes: [\n {\n content: \"Click below to connect your Google account and start syncing.\",\n links: [authLink],\n },\n ],\n });\n\n // Store for later use\n await this.set(\"auth_activity_id\", activity.id);\n}\n\nasync onAuthComplete(authResult: { authToken: string }, provider: string) {\n // Store auth token\n await this.set(`${provider}_auth`, authResult.authToken);\n\n // Continue setup flow\n await this.setupSyncOptions(authResult.authToken);\n}\n```\n\n## Sync Pattern\n\n### Recommended: Upsert via Source/Key (Strategy 2)\n\nPattern for syncing external data using automatic upserts - **no manual ID tracking needed**:\n\n```typescript\nasync startSync(calendarId: string): Promise<void> {\n const authToken = await this.get<string>(\"auth_token\");\n\n await this.tools.calendarTool.startSync(\n authToken,\n calendarId,\n this.handleEvent,\n calendarId\n );\n}\n\nasync handleEvent(\n event: ExternalEvent,\n calendarId: string\n): Promise<void> {\n // Use the event's canonical URL as the source for automatic deduplication\n const activity: NewActivityWithNotes = {\n source: event.htmlLink, // or event.url, depending on your external system\n type: ActivityType.Event,\n title: event.summary || \"(No title)\",\n start: event.start?.dateTime || event.start?.date || null,\n end: event.end?.dateTime || event.end?.date || null,\n notes: [],\n };\n\n // Add description as an upsertable note\n if (event.description) {\n activity.notes.push({\n activity: { source: event.htmlLink },\n key: \"description\", // This key enables upserts - same key updates the note\n content: event.description,\n });\n }\n\n // Add attendees as an upsertable note\n if (event.attendees?.length) {\n const attendeeList = event.attendees\n .map(a => `- ${a.email}${a.displayName ? ` (${a.displayName})` : ''}`)\n .join('\\n');\n\n activity.notes.push({\n activity: { source: event.htmlLink },\n key: \"attendees\", // Different key for different note types\n content: `## Attendees\\n${attendeeList}`,\n });\n }\n\n // Create or update - Plot automatically handles deduplication based on source\n await this.tools.plot.createActivity(activity);\n}\n\nasync stopSync(calendarId: string): Promise<void> {\n const authToken = await this.get<string>(\"auth_token\");\n await this.tools.calendarTool.stopSync(authToken, calendarId);\n}\n```\n\n### Advanced: Generate and Store IDs (Strategy 3)\n\nOnly use this pattern when you need to create multiple Plot activities from a single external item, or when the external system doesn't provide stable identifiers. See SYNC_STRATEGIES.md for details.\n\n```typescript\nasync handleEventAdvanced(\n incomingActivity: NewActivityWithNotes,\n calendarId: string\n): Promise<void> {\n // Extract external event ID from meta (adapt based on your tool's data)\n const externalId = incomingActivity.meta?.eventId;\n\n if (!externalId) {\n console.error(\"Event missing external ID\");\n return;\n }\n\n // Check if we've already synced this event\n const mappingKey = `event_mapping:${calendarId}:${externalId}`;\n const existingActivityId = await this.get<Uuid>(mappingKey);\n\n if (existingActivityId) {\n // Event already exists - add update as a Note (add message to thread)\n if (incomingActivity.notes?.[0]?.content) {\n await this.tools.plot.createNote({\n activity: { id: existingActivityId },\n content: incomingActivity.notes[0].content,\n });\n }\n return;\n }\n\n // New event - generate UUID and store mapping\n const activityId = Uuid.Generate();\n await this.set(mappingKey, activityId);\n\n // Create new Activity with initial Note (new thread with first message)\n await this.tools.plot.createActivity({\n ...incomingActivity,\n id: activityId,\n });\n}\n```\n\n## Calendar Selection Pattern\n\nPattern for letting users select from multiple calendars/accounts:\n\n```typescript\nprivate async createCalendarSelectionActivity(\n provider: string,\n calendars: Calendar[],\n authToken: string\n): Promise<void> {\n const links: ActivityLink[] = [];\n\n for (const calendar of calendars) {\n const token = await this.callback(\n this.onCalendarSelected,\n provider,\n calendar.id,\n calendar.name,\n authToken\n );\n\n links.push({\n title: `\uD83D\uDCC5 ${calendar.name}${calendar.primary ? \" (Primary)\" : \"\"}`,\n type: ActivityLinkType.callback,\n token: token,\n });\n }\n\n await this.tools.plot.createActivity({\n type: ActivityType.Note,\n title: \"Which calendars would you like to connect?\",\n notes: [\n {\n content: \"Select the calendars you want to sync:\",\n links,\n },\n ],\n });\n}\n\nasync onCalendarSelected(\n link: ActivityLink,\n provider: string,\n calendarId: string,\n calendarName: string,\n authToken: string\n): Promise<void> {\n // Start sync for selected calendar\n await this.tools.tool.startSync(\n authToken,\n calendarId,\n this.handleEvent,\n provider,\n calendarId\n );\n}\n```\n\n## Batch Processing Pattern\n\n**Important**: Because Twists run in an ephemeral environment with limited requests per execution (~1000 requests), you must break long operations into batches. Each batch runs independently in a new execution context with its own fresh request limit.\n\n### Key Principles\n\n1. **Stay under request limits**: Each execution has ~1000 requests. Size batches accordingly.\n2. **Use runTask() for fresh limits**: Each call to `this.runTask()` creates a NEW execution with fresh ~1000 requests\n3. **Store state between batches**: Use the Store tool to persist progress\n4. **Calculate safe batch sizes**: Determine requests per item to size batches (e.g., ~10 requests per item = ~100 items per batch)\n5. **Clean up when done**: Delete stored state after completion\n6. **Handle failures**: Store enough state to resume if a batch fails\n\n### Example Implementation\n\n```typescript\nasync startSync(resourceId: string): Promise<void> {\n // Initialize state in Store (persists between executions)\n await this.set(`sync_state_${resourceId}`, {\n nextPageToken: null,\n batchNumber: 1,\n itemsProcessed: 0,\n initialSync: true, // Track whether this is the first sync\n });\n\n // Queue first batch using runTask method\n const callback = await this.callback(this.syncBatch, resourceId);\n // runTask creates NEW execution with fresh ~1000 request limit\n await this.runTask(callback);\n}\n\nasync syncBatch(args: any, resourceId: string): Promise<void> {\n // Load state from Store (set by previous execution)\n const state = await this.get(`sync_state_${resourceId}`);\n\n // Process one batch (size to stay under ~1000 request limit)\n const result = await this.fetchBatch(state.nextPageToken);\n\n // Process results using source/key pattern (automatic upserts, no manual tracking)\n // If each item makes ~10 requests, keep batch size \u2264 100 items to stay under limit\n for (const item of result.items) {\n // Each createActivity may make ~5-10 requests depending on notes/links\n await this.tools.plot.createActivity({\n source: item.url, // Use item's canonical URL for automatic deduplication\n type: ActivityType.Note,\n title: item.title,\n notes: [{\n activity: { source: item.url },\n key: \"description\", // Use key for upsertable notes\n content: item.description,\n }],\n unread: !state.initialSync, // false for initial sync, true for incremental\n ...(state.initialSync ? { archived: false } : {}), // unarchive on initial only\n });\n }\n\n if (result.nextPageToken) {\n // Update state in Store for next batch\n await this.set(`sync_state_${resourceId}`, {\n nextPageToken: result.nextPageToken,\n batchNumber: state.batchNumber + 1,\n itemsProcessed: state.itemsProcessed + result.items.length,\n initialSync: state.initialSync, // Preserve initialSync flag across batches\n });\n\n // Queue next batch - creates NEW execution with fresh request limit\n const nextCallback = await this.callback(this.syncBatch, resourceId);\n await this.runTask(nextCallback);\n } else {\n // Cleanup when complete\n await this.clear(`sync_state_${resourceId}`);\n\n // Optionally notify user of completion\n await this.tools.plot.createActivity({\n type: ActivityType.Note,\n title: \"Sync complete\",\n notes: [\n {\n content: `Successfully processed ${state.itemsProcessed + result.items.length} items.`,\n },\n ],\n });\n }\n}\n```\n\n## Activity Sync Best Practices\n\nWhen syncing activities from external systems, follow these patterns for optimal user experience:\n\n### The `initialSync` Flag\n\nAll sync-based tools should distinguish between initial sync (first import) and incremental sync (ongoing updates):\n\n| Field | Initial Sync | Incremental Sync | Reason |\n|-------|--------------|------------------|---------|\n| `unread` | `false` | `true` | Avoid notification overload from historical items |\n| `archived` | `false` | *omit* | Unarchive on install, preserve user choice on updates |\n\n**Example:**\n```typescript\nconst activity: NewActivity = {\n type: ActivityType.Event,\n source: event.url,\n title: event.title,\n unread: !initialSync, // false for initial, true for incremental\n ...(initialSync ? { archived: false } : {}), // unarchive on initial only\n};\n```\n\n**Why this matters:**\n- **Initial sync**: Activities are unarchived and marked as read, preventing spam from bulk historical imports\n- **Incremental sync**: New activities appear as unread, and archived state is preserved (respects user's archiving decisions)\n- **Reinstall**: Acts as initial sync, so previously archived activities are unarchived (fresh start)\n\n### Two-Way Sync: Avoiding Race Conditions\n\nWhen implementing two-way sync where items created in Plot are pushed to an external system (e.g. Notes becoming comments), a race condition can occur: the external system may send a webhook for the newly created item before you've updated the Activity/Note with the external key. The webhook handler won't find the item by external key and may create a duplicate.\n\n**Solution:** Embed the Plot `Activity.id` / `Note.id` in the external item's metadata when creating it, and update `Activity.source` / `Note.key` after creation. When processing webhooks, check for the Plot ID in metadata first.\n\n```typescript\nasync pushNoteAsComment(note: Note, externalItemId: string): Promise<void> {\n // Create external item with Plot ID in metadata for webhook correlation\n const externalComment = await externalApi.createComment(externalItemId, {\n body: note.content,\n metadata: { plotNoteId: note.id },\n });\n\n // Update Note with external key AFTER creation\n // A webhook may arrive before this completes \u2014 that's OK (see onWebhook below)\n await this.tools.plot.updateNote({\n id: note.id,\n key: `comment-${externalComment.id}`,\n });\n}\n\nasync onWebhook(payload: WebhookPayload): Promise<void> {\n const comment = payload.comment;\n\n // Use Plot ID from metadata if present (handles race condition),\n // otherwise fall back to upserting by activity source and key\n await this.tools.plot.createNote({\n ...(comment.metadata?.plotNoteId\n ? { id: comment.metadata.plotNoteId }\n : { activity: { source: payload.itemUrl } }),\n key: `comment-${comment.id}`,\n content: comment.body,\n });\n}\n```\n\n## Error Handling\n\nAlways handle errors gracefully and communicate them to users:\n\n```typescript\ntry {\n await this.externalOperation();\n} catch (error) {\n console.error(\"Operation failed:\", error);\n\n await this.tools.plot.createActivity({\n type: ActivityType.Note,\n title: \"Operation failed\",\n notes: [\n {\n content: `Failed to complete operation: ${error.message}`,\n },\n ],\n });\n}\n```\n\n## Common Pitfalls\n\n- **Don't use instance variables for state** - Anything stored in memory is lost after function execution. Always use the Store tool for data that needs to persist.\n- **Processing self-created activities** - Other users may change an Activity created by the twist, resulting in an \\`activity\\` call. Be sure to check the \\`changes === null\\` and/or \\`activity.author.id !== this.id\\` to avoid re-processing.\n- **Always create Activities with Notes** - See \"Understanding Activities and Notes\" section above for the thread/message pattern and decision tree.\n- **Use correct Activity types** - Most should be `ActivityType.Note`. Only use `Action` for tasks with `done`, and `Event` for items with `start`/`end`.\n- **Use Activity.source and Note.key for automatic upserts (Recommended)** - Set Activity.source to the external item's URL for automatic deduplication. Only use UUID generation and storage for advanced cases (see SYNC_STRATEGIES.md).\n- **Add Notes to existing Activities** - For source/key pattern, reference activities by source. For UUID pattern, look up stored mappings before creating new Activities. Think thread replies, not new threads.\n- Tools are declared in the `build` method and accessed via `this.tools.toolName` in twist methods.\n- **Don't forget request limits** - Each execution has ~1000 requests (HTTP requests, tool calls). Break long loops into batches with `this.runTask()` to get fresh request limits. Calculate requests per item to determine safe batch size (e.g., if each item needs ~10 requests, batch size = ~100 items).\n- **Always use Callbacks tool for persistent references** - Direct function references don't survive worker restarts.\n- **Store auth tokens** - Don't re-request authentication unnecessarily.\n- **Clean up callbacks and stored state** - Delete callbacks and Store entries when no longer needed.\n- **Handle missing auth gracefully** - Check for stored auth before operations.\n- **CRITICAL: Maintain callback backward compatibility** - All callbacks (webhooks, tasks, batch operations) automatically upgrade to new twist versions. You **must** maintain backward compatibility in callback method signatures. Only add optional parameters at the end, never remove or reorder parameters. For breaking changes, implement migration logic in the `upgrade()` lifecycle method to recreate affected callbacks.\n\n## Testing\n\nBefore deploying, verify:\n\n1. Linting passes: `{{packageManager}} lint`\n2. All dependencies are in package.json\n3. Authentication flow works end-to-end\n4. Batch operations handle pagination correctly\n5. Error cases are handled gracefully\n";
1
+ export declare const TWIST_GUIDE = "# Twist Implementation Guide for LLMs\n\nThis document provides context for AI assistants generating or modifying twists.\n\n## Architecture Overview\n\nPlot Twists are TypeScript classes that extend the `Twist` base class. Twists interact with external services and Plot's core functionality through a tool-based architecture.\n\n### Runtime Environment\n\n**Critical**: All Twists and tool functions are executed in a sandboxed, ephemeral environment with limited resources:\n\n- **Memory is temporary**: Anything stored in memory (e.g. as a variable in the twist/tool object) is lost after the function completes. Use the Store tool instead. Only use memory for temporary caching.\n- **Limited requests per execution**: Each execution has ~1000 requests (HTTP requests, tool calls, database operations)\n- **Limited CPU time**: Each execution has limited CPU time (typically ~60 seconds) and memory (128MB)\n- **Use tasks to get fresh request limits**: `this.runTask()` creates a NEW execution with a fresh ~1000 request limit\n- **Calling callbacks continues same execution**: `this.run()` continues the same execution and shares the request count\n- **Break long loops**: Split large operations into batches that each stay under the ~1000 request limit\n- **Store intermediate state**: Use the Store tool to persist state between batches\n- **Examples**: Syncing large datasets, processing many API calls, or performing batch operations\n\n## Understanding Threads and Notes\n\n**CRITICAL CONCEPT**: A **Thread** represents something done or to be done (a task, event, or conversation), while **Notes** represent the updates and details on that thread.\n\n**Think of a Thread as a thread** on a messaging platform, and **Notes as the messages in that thread**.\n\n### Key Guidelines\n\n1. **Always create Threads with an initial Note** - The title is just a summary; detailed content goes in Notes\n2. **Add Notes to existing Threads for updates** - Don't create a new Thread for each related message\n3. **Use Thread.source and Note.key for automatic upserts (Recommended)** - Set Thread.source to the external item's URL for deduplication, and use Note.key for upsertable note content. No manual ID tracking needed.\n4. **For advanced cases, use generated UUIDs** - Only when you need multiple Plot threads per external item (see SYNC_STRATEGIES.md)\n5. **Most Threads should be `ThreadType.Note`** - Use `Action` only for tasks with `done`, use `Event` only for items with `start`/`end`\n\n### Recommended Decision Tree (Strategy 2: Upsert via Source/Key)\n\n```\nNew event/task/conversation from external system?\n \u251C\u2500 Has stable URL or ID?\n \u2502 \u2514\u2500 Yes \u2192 Set Thread.source to the canonical URL/ID\n \u2502 Create Thread (Plot handles deduplication automatically)\n \u2502 Use Note.key for different note types:\n \u2502 - \"description\" for main content\n \u2502 - \"metadata\" for status/priority/assignee\n \u2502 - \"comment-{id}\" for individual comments\n \u2502\n \u2514\u2500 No stable identifier OR need multiple Plot threads per external item?\n \u2514\u2500 Use Advanced Pattern (Strategy 3: Generate and Store IDs)\n See SYNC_STRATEGIES.md for details\n```\n\n### Advanced Decision Tree (Strategy 3: Generate and Store IDs)\n\nOnly use when source/key upserts aren't sufficient (e.g., creating multiple threads from one external item):\n\n```\nNew event/task/conversation?\n \u251C\u2500 Yes \u2192 Generate UUID with Uuid.Generate()\n \u2502 Create new Thread with that UUID\n \u2502 Store mapping: external_id \u2192 thread_uuid\n \u2502\n \u2514\u2500 No (update/reply/comment) \u2192 Look up mapping by external_id\n \u251C\u2500 Found \u2192 Add Note to existing Thread using stored UUID\n \u2514\u2500 Not found \u2192 Create new Thread with UUID + store mapping\n```\n\n## Twist Structure Pattern\n\n```typescript\nimport {\n type Thread,\n type NewThreadWithNotes,\n type ThreadFilter,\n type Priority,\n type ToolBuilder,\n Twist,\n ThreadType,\n} from \"@plotday/twister\";\nimport { ThreadAccess, Plot } from \"@plotday/twister/tools/plot\";\n// Import your sources or tools as needed\n\nexport default class MyTwist extends Twist<MyTwist> {\n build(build: ToolBuilder) {\n return {\n plot: build(Plot, {\n thread: { access: ThreadAccess.Create },\n }),\n };\n }\n\n async activate(_priority: Pick<Priority, \"id\">) {\n // Auth and resource selection handled in the twist edit modal.\n }\n}\n```\n\n## Tool System\n\n### Accessing Tools\n\nAll tools are declared in the `build` method:\n\n```typescript\nbuild(build: ToolBuilder) {\n return {\n toolName: build(ToolClass),\n };\n}\n```\n\nAll `build()` calls must occur in the `build` method as they are used for dependency analysis.\n\nIMPORTANT: HTTP access is restricted to URLs requested via `build(Network, { urls: [url1, url2, ...] })` in the `build` method. Wildcards are supported. Use `build(Network, { urls: ['*'] })` if full access is needed.\n\n### Built-in Tools (Always Available)\n\nFor complete API documentation of built-in tools including all methods, types, and detailed examples, see the TypeScript definitions in your installed package at `node_modules/@plotday/twister/src/tools/*.ts`. Each tool file contains comprehensive JSDoc documentation.\n\n**Quick reference - Available tools:**\n\n- `@plotday/twister/tools/plot` - Core data layer (create/update activities, priorities, contacts)\n- `@plotday/twister/tools/ai` - LLM integration (text generation, structured output, reasoning)\n - Use ModelPreferences to specify `speed` (fast/balanced/capable) and `cost` (low/medium/high)\n- `@plotday/twister/tools/store` - Persistent key-value storage (also via `this.set()`, `this.get()`)\n- `@plotday/twister/tools/tasks` - Queue batched work (also via `this.run()`)\n- `@plotday/twister/tools/callbacks` - Persistent function references (also via `this.callback()`)\n- `@plotday/twister/tools/integrations` - OAuth2 authentication flows\n- `@plotday/twister/tools/network` - HTTP access permissions and webhook management\n- `@plotday/twister/tools/twists` - Manage other Twists\n\n**Critical**: Never use instance variables for state. They are lost after function execution. Always use Store methods.\n\n## Lifecycle Methods\n\n### activate(priority: Pick<Priority, \"id\">)\n\nCalled when the twist is enabled for a priority. Auth and resource selection are handled automatically via the twist edit modal when using external tools with Integrations.\n\nMost twists have an empty or minimal `activate()`:\n\n```typescript\nasync activate(_priority: Pick<Priority, \"id\">) {\n // Auth and resource selection are handled in the twist edit modal.\n // Only add custom initialization here if needed.\n}\n```\n\n**Store Parent Thread for Later (optional):**\n\n```typescript\nasync activate(_priority: Pick<Priority, \"id\">) {\n const threadId = await this.tools.plot.createThread({\n type: ThreadType.Note,\n title: \"Setup complete\",\n notes: [{\n content: \"Your twist is ready. Threads will appear as they sync.\",\n }],\n });\n await this.set(\"setup_thread_id\", threadId);\n}\n```\n\n### Event Callbacks (via build options)\n\nTwists respond to events through callbacks declared in `build()`:\n\n**React to thread changes (for two-way sync):**\n\n```typescript\nplot: build(Plot, {\n thread: {\n access: ThreadAccess.Create,\n updated: this.onThreadUpdated,\n },\n note: {\n created: this.onNoteCreated,\n },\n}),\n\nasync onThreadUpdated(thread: Thread, changes: { tagsAdded, tagsRemoved }): Promise<void> {\n const tool = this.getToolForThread(thread);\n if (tool?.updateIssue) await tool.updateIssue(thread);\n}\n\nasync onNoteCreated(note: Note): Promise<void> {\n if (note.author.type === ActorType.Twist) return; // Prevent loops\n // Sync note to external service as a comment\n}\n```\n\n**Respond to mentions (AI twist pattern):**\n\n```typescript\nplot: build(Plot, {\n thread: { access: ThreadAccess.Respond },\n note: {\n intents: [{\n description: \"Respond to general questions\",\n examples: [\"What's the weather?\", \"Help me plan my week\"],\n handler: this.respond,\n }],\n },\n}),\n```\n\n## Actions\n\nActions enable user interaction:\n\n```typescript\nimport { type Action, ActionType } from \"@plotday/twister\";\n\n// External URL action\nconst urlAction: Action = {\n title: \"Open website\",\n type: ActionType.external,\n url: \"https://example.com\",\n};\n\n// Callback action (uses Callbacks tool \u2014 use linkCallback, not callback)\nconst token = await this.linkCallback(this.onActionClicked, \"context\");\nconst callbackAction: Action = {\n title: \"Click me\",\n type: ActionType.callback,\n callback: token,\n};\n\n// Add to thread note\nawait this.tools.plot.createThread({\n type: ThreadType.Note,\n title: \"Task with actions\",\n notes: [\n {\n content: \"Click the actions below to take action.\",\n actions: [urlAction, callbackAction],\n },\n ],\n});\n\n// Callback handler receives the Action as first argument\nasync onActionClicked(action: Action, context: string): Promise<void> {\n // Handle action click\n}\n```\n\n## Authentication Pattern\n\nAuth is handled automatically via the Integrations tool. Tools declare their OAuth provider in `build()`, and users connect in the twist edit modal. **You do not need to create auth activities manually.**\n\n```typescript\n// In your tool's build() method:\nbuild(build: ToolBuilder) {\n return {\n integrations: build(Integrations, {\n providers: [{\n provider: AuthProvider.Google,\n scopes: [\"https://www.googleapis.com/auth/calendar\"],\n getChannels: this.getChannels, // List available resources after auth\n onChannelEnabled: this.onChannelEnabled, // User enabled a resource\n onChannelDisabled: this.onChannelDisabled, // User disabled a resource\n }],\n }),\n // ...\n };\n}\n\n// Get a token for API calls:\nconst token = await this.tools.integrations.get(AuthProvider.Google, channelId);\nif (!token) throw new Error(\"No auth token available\");\nconst client = new ApiClient({ accessToken: token.token });\n```\n\nFor per-user write-backs (e.g., RSVP, comments attributed to the acting user):\n\n```typescript\nawait this.tools.integrations.actAs(\n AuthProvider.Google,\n actorId, // The user who performed the action\n threadId, // Thread to prompt for auth if needed\n this.performWriteBack,\n ...extraArgs\n);\n```\n\n## Sync Pattern\n\n### Upsert via Source/Key (Strategy 2)\n\nUse source/key for automatic upserts:\n\n```typescript\nasync handleEvent(event: ExternalEvent): Promise<void> {\n const thread: NewThreadWithNotes = {\n source: event.htmlLink, // Canonical URL for automatic deduplication\n type: ThreadType.Event,\n title: event.summary || \"(No title)\",\n notes: [],\n };\n\n if (event.description) {\n thread.notes.push({\n thread: { source: event.htmlLink },\n key: \"description\", // This key enables note-level upserts\n content: event.description,\n });\n }\n\n // Create or update \u2014 Plot handles deduplication automatically\n await this.tools.plot.createThread(thread);\n}\n```\n\n### Advanced: Generate and Store IDs (Strategy 3)\n\nOnly use this pattern when you need to create multiple Plot threads from a single external item, or when the external system doesn't provide stable identifiers. See SYNC_STRATEGIES.md for details.\n\n```typescript\nasync handleEventAdvanced(\n incomingThread: NewThreadWithNotes,\n calendarId: string\n): Promise<void> {\n // Extract external event ID from meta (adapt based on your tool's data)\n const externalId = incomingThread.meta?.eventId;\n\n if (!externalId) {\n console.error(\"Event missing external ID\");\n return;\n }\n\n // Check if we've already synced this event\n const mappingKey = `event_mapping:${calendarId}:${externalId}`;\n const existingThreadId = await this.get<Uuid>(mappingKey);\n\n if (existingThreadId) {\n // Event already exists - add update as a Note (add message to thread)\n if (incomingThread.notes?.[0]?.content) {\n await this.tools.plot.createNote({\n thread: { id: existingThreadId },\n content: incomingThread.notes[0].content,\n });\n }\n return;\n }\n\n // New event - generate UUID and store mapping\n const threadId = Uuid.Generate();\n await this.set(mappingKey, threadId);\n\n // Create new Thread with initial Note (new thread with first message)\n await this.tools.plot.createThread({\n ...incomingThread,\n id: threadId,\n });\n}\n```\n\n## Resource Selection\n\nResource selection (calendars, projects, channels) is handled automatically in the twist edit modal via the Integrations tool. Users see a list of available resources returned by your tool's `getChannels()` method and toggle them on/off. You do **not** need to build custom selection UI.\n\n```typescript\n// In your tool:\nasync getChannels(_auth: Authorization, token: AuthToken): Promise<Channel[]> {\n const client = new ApiClient({ accessToken: token.token });\n const calendars = await client.listCalendars();\n return calendars.map(c => ({\n id: c.id,\n title: c.name,\n children: c.subCalendars?.map(sc => ({ id: sc.id, title: sc.name })),\n }));\n}\n```\n\n## Batch Processing Pattern\n\n**Important**: Because Twists run in an ephemeral environment with limited requests per execution (~1000 requests), you must break long operations into batches. Each batch runs independently in a new execution context with its own fresh request limit.\n\n### Key Principles\n\n1. **Stay under request limits**: Each execution has ~1000 requests. Size batches accordingly.\n2. **Use runTask() for fresh limits**: Each call to `this.runTask()` creates a NEW execution with fresh ~1000 requests\n3. **Store state between batches**: Use the Store tool to persist progress\n4. **Calculate safe batch sizes**: Determine requests per item to size batches (e.g., ~10 requests per item = ~100 items per batch)\n5. **Clean up when done**: Delete stored state after completion\n6. **Handle failures**: Store enough state to resume if a batch fails\n\n### Example Implementation\n\n```typescript\nasync startSync(resourceId: string): Promise<void> {\n // Initialize state in Store (persists between executions)\n await this.set(`sync_state_${resourceId}`, {\n nextPageToken: null,\n batchNumber: 1,\n itemsProcessed: 0,\n initialSync: true, // Track whether this is the first sync\n });\n\n // Queue first batch using runTask method\n const callback = await this.callback(this.syncBatch, resourceId);\n // runTask creates NEW execution with fresh ~1000 request limit\n await this.runTask(callback);\n}\n\nasync syncBatch(resourceId: string): Promise<void> {\n // Load state from Store (set by previous execution)\n const state = await this.get(`sync_state_${resourceId}`);\n\n // Process one batch (size to stay under ~1000 request limit)\n const result = await this.fetchBatch(state.nextPageToken);\n\n // Process results using source/key pattern (automatic upserts, no manual tracking)\n // If each item makes ~10 requests, keep batch size \u2264 100 items to stay under limit\n for (const item of result.items) {\n // Each createThread may make ~5-10 requests depending on notes/links\n await this.tools.plot.createThread({\n source: item.url, // Use item's canonical URL for automatic deduplication\n type: ThreadType.Note,\n title: item.title,\n notes: [{\n activity: { source: item.url },\n key: \"description\", // Use key for upsertable notes\n content: item.description,\n }],\n ...(state.initialSync ? { unread: false } : {}), // false for initial, omit for incremental\n ...(state.initialSync ? { archived: false } : {}), // unarchive on initial only\n });\n }\n\n if (result.nextPageToken) {\n // Update state in Store for next batch\n await this.set(`sync_state_${resourceId}`, {\n nextPageToken: result.nextPageToken,\n batchNumber: state.batchNumber + 1,\n itemsProcessed: state.itemsProcessed + result.items.length,\n initialSync: state.initialSync, // Preserve initialSync flag across batches\n });\n\n // Queue next batch - creates NEW execution with fresh request limit\n const nextCallback = await this.callback(this.syncBatch, resourceId);\n await this.runTask(nextCallback);\n } else {\n // Cleanup when complete\n await this.clear(`sync_state_${resourceId}`);\n\n // Optionally notify user of completion\n await this.tools.plot.createThread({\n type: ThreadType.Note,\n title: \"Sync complete\",\n notes: [\n {\n content: `Successfully processed ${state.itemsProcessed + result.items.length} items.`,\n },\n ],\n });\n }\n}\n```\n\n## Thread Sync Best Practices\n\nWhen syncing threads from external systems, follow these patterns for optimal user experience:\n\n### The `initialSync` Flag\n\nAll sync-based tools should distinguish between initial sync (first import) and incremental sync (ongoing updates):\n\n| Field | Initial Sync | Incremental Sync | Reason |\n|-------|--------------|------------------|---------|\n| `unread` | `false` | *omit* | Initial: mark read for all. Incremental: auto-mark read for author only |\n| `archived` | `false` | *omit* | Unarchive on install, preserve user choice on updates |\n\n**Example:**\n```typescript\nconst thread: NewThread = {\n type: ThreadType.Event,\n source: event.url,\n title: event.title,\n ...(initialSync ? { unread: false } : {}), // false for initial, omit for incremental\n ...(initialSync ? { archived: false } : {}), // unarchive on initial only\n};\n```\n\n**Why this matters:**\n- **Initial sync**: Activities are unarchived and marked as read for all users, preventing spam from bulk historical imports\n- **Incremental sync**: Activities are auto-marked read for the author (twist owner), unread for everyone else. Archived state is preserved\n- **Reinstall**: Acts as initial sync, so previously archived activities are unarchived (fresh start)\n\n### Two-Way Sync: Avoiding Race Conditions\n\nWhen implementing two-way sync where items created in Plot are pushed to an external system (e.g. Notes becoming comments), a race condition can occur: the external system may send a webhook for the newly created item before you've updated the Thread/Note with the external key. The webhook handler won't find the item by external key and may create a duplicate.\n\n**Solution:** Embed the Plot `Thread.id` / `Note.id` in the external item's metadata when creating it, and update `Thread.source` / `Note.key` after creation. When processing webhooks, check for the Plot ID in metadata first.\n\n```typescript\nasync pushNoteAsComment(note: Note, externalItemId: string): Promise<void> {\n // Create external item with Plot ID in metadata for webhook correlation\n const externalComment = await externalApi.createComment(externalItemId, {\n body: note.content,\n metadata: { plotNoteId: note.id },\n });\n\n // Update Note with external key AFTER creation\n // A webhook may arrive before this completes \u2014 that's OK (see onWebhook below)\n await this.tools.plot.updateNote({\n id: note.id,\n key: `comment-${externalComment.id}`,\n });\n}\n\nasync onWebhook(payload: WebhookPayload): Promise<void> {\n const comment = payload.comment;\n\n // Use Plot ID from metadata if present (handles race condition),\n // otherwise fall back to upserting by activity source and key\n await this.tools.plot.createNote({\n ...(comment.metadata?.plotNoteId\n ? { id: comment.metadata.plotNoteId }\n : { activity: { source: payload.itemUrl } }),\n key: `comment-${comment.id}`,\n content: comment.body,\n });\n}\n```\n\n## Error Handling\n\nAlways handle errors gracefully and communicate them to users:\n\n```typescript\ntry {\n await this.externalOperation();\n} catch (error) {\n console.error(\"Operation failed:\", error);\n\n await this.tools.plot.createThread({\n type: ThreadType.Note,\n title: \"Operation failed\",\n notes: [\n {\n content: `Failed to complete operation: ${error.message}`,\n },\n ],\n });\n}\n```\n\n## Common Pitfalls\n\n- **Don't use instance variables for state** - Anything stored in memory is lost after function execution. Always use the Store tool for data that needs to persist.\n- **Processing self-created threads** - Other users may change a Thread created by the twist, resulting in a callback. Be sure to check the `changes === null` and/or `thread.author.id !== this.id` to avoid re-processing.\n- **Always create Threads with Notes** - See \"Understanding Threads and Notes\" section above for the thread/message pattern and decision tree.\n- **Use correct Thread types** - Most should be `ThreadType.Note`. Only use `Action` for tasks with `done`, and `Event` for items with `start`/`end`.\n- **Use Thread.source and Note.key for automatic upserts (Recommended)** - Set Thread.source to the external item's URL for automatic deduplication. Only use UUID generation and storage for advanced cases (see SYNC_STRATEGIES.md).\n- **Add Notes to existing Threads** - For source/key pattern, reference threads by source. For UUID pattern, look up stored mappings before creating new Threads. Think thread replies, not new threads.\n- Tools are declared in the `build` method and accessed via `this.tools.toolName` in twist methods.\n- **Don't forget request limits** - Each execution has ~1000 requests (HTTP requests, tool calls). Break long loops into batches with `this.runTask()` to get fresh request limits. Calculate requests per item to determine safe batch size (e.g., if each item needs ~10 requests, batch size = ~100 items).\n- **Always use Callbacks tool for persistent references** - Direct function references don't survive worker restarts.\n- **Store auth tokens** - Don't re-request authentication unnecessarily.\n- **Clean up callbacks and stored state** - Delete callbacks and Store entries when no longer needed.\n- **Handle missing auth gracefully** - Check for stored auth before operations.\n- **CRITICAL: Maintain callback backward compatibility** - All callbacks (webhooks, tasks, batch operations) automatically upgrade to new twist versions. You **must** maintain backward compatibility in callback method signatures. Only add optional parameters at the end, never remove or reorder parameters. For breaking changes, implement migration logic in the `upgrade()` lifecycle method to recreate affected callbacks.\n\n## Testing\n\nBefore deploying, verify:\n\n1. Linting passes: `{{packageManager}} lint`\n2. All dependencies are in package.json\n3. Authentication flow works end-to-end\n4. Batch operations handle pagination correctly\n5. Error cases are handled gracefully\n";
2
2
  //# sourceMappingURL=twist-guide.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"twist-guide.d.ts","sourceRoot":"","sources":["../src/twist-guide.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,WAAW,y8vBAAsB,CAAC"}
1
+ {"version":3,"file":"twist-guide.d.ts","sourceRoot":"","sources":["../src/twist-guide.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,WAAW,yntBAAsB,CAAC"}
package/dist/twist.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { ActivityLink, type Actor, type Priority, Uuid } from "./plot";
1
+ import { type Action, type Actor, type ActorId, type Link, type Note, type Priority, type Thread, Uuid } from "./plot";
2
+ import type { Tag } from "./tag";
2
3
  import { type ITool } from "./tool";
3
4
  import type { Callback } from "./tools/callbacks";
4
5
  import type { Serializable } from "./utils/serializable";
@@ -22,9 +23,8 @@ import type { InferTools, ToolBuilder, ToolShed } from "./utils/types";
22
23
  *
23
24
  * async activate(priority: Pick<Priority, "id">) {
24
25
  * // Initialize twist for the given priority
25
- * await this.tools.plot.createActivity({
26
- * type: ActivityType.Note,
27
- * note: "Hello, good looking!",
26
+ * await this.tools.plot.createThread({
27
+ * title: "Hello, good looking!",
28
28
  * });
29
29
  * }
30
30
  * }
@@ -74,23 +74,23 @@ export declare abstract class Twist<TSelf> {
74
74
  protected callback<TArgs extends Serializable[], Fn extends (...args: TArgs) => any>(fn: Fn, ...extraArgs: TArgs): Promise<Callback>;
75
75
  protected callback<TArgs extends Serializable[], Fn extends (arg1: any, ...extraArgs: TArgs) => any>(fn: Fn, ...extraArgs: TArgs): Promise<Callback>;
76
76
  /**
77
- * Like callback(), but for an ActivityLink, which receives the link as the first argument.
77
+ * Like callback(), but for an Action, which receives the action as the first argument.
78
78
  *
79
79
  * @param fn - The method to callback
80
- * @param extraArgs - Additional arguments to pass after the link
80
+ * @param extraArgs - Additional arguments to pass after the action
81
81
  * @returns Promise resolving to a persistent callback token
82
82
  *
83
83
  * @example
84
84
  * ```typescript
85
- * const callback = await this.linkCallback(this.doSomething, 123);
86
- * const link: ActivityLink = {
87
- * type: ActivityLinkType.Callback,
85
+ * const callback = await this.actionCallback(this.doSomething, 123);
86
+ * const action: Action = {
87
+ * type: ActionType.callback,
88
88
  * title: "Do Something",
89
89
  * callback,
90
90
  * };
91
91
  * ```
92
92
  */
93
- protected linkCallback<TArgs extends Serializable[], Fn extends (link: ActivityLink, ...extraArgs: TArgs) => any>(fn: Fn, ...extraArgs: TArgs): Promise<Callback>;
93
+ protected actionCallback<TArgs extends Serializable[], Fn extends (action: Action, ...extraArgs: TArgs) => any>(fn: Fn, ...extraArgs: TArgs): Promise<Callback>;
94
94
  /**
95
95
  * Deletes a specific callback by its token.
96
96
  *
@@ -203,7 +203,7 @@ export declare abstract class Twist<TSelf> {
203
203
  * Called when the twist is activated for a specific priority.
204
204
  *
205
205
  * This method should contain initialization logic such as setting up
206
- * initial activities, configuring webhooks, or establishing external connections.
206
+ * initial threads, configuring webhooks, or establishing external connections.
207
207
  *
208
208
  * @param priority - The priority context containing the priority ID
209
209
  * @param context - Optional context containing the actor who triggered activation
@@ -222,6 +222,17 @@ export declare abstract class Twist<TSelf> {
222
222
  * @returns Promise that resolves when upgrade is complete
223
223
  */
224
224
  upgrade(): Promise<void>;
225
+ /**
226
+ * Called when the twist's options configuration changes.
227
+ *
228
+ * Override to react to option changes, e.g. archiving items when a sync
229
+ * type is toggled off, or starting sync when a type is toggled on.
230
+ *
231
+ * @param oldOptions - The previously resolved options
232
+ * @param newOptions - The newly resolved options
233
+ * @returns Promise that resolves when the change is handled
234
+ */
235
+ onOptionsChanged(oldOptions: Record<string, any>, newOptions: Record<string, any>): Promise<void>;
225
236
  /**
226
237
  * Called when the twist is removed from a priority.
227
238
  *
@@ -231,6 +242,50 @@ export declare abstract class Twist<TSelf> {
231
242
  * @returns Promise that resolves when deactivation is complete
232
243
  */
233
244
  deactivate(): Promise<void>;
245
+ /**
246
+ * Called when a thread created by this twist is updated.
247
+ * Override to implement two-way sync with an external system.
248
+ *
249
+ * @param thread - The updated thread
250
+ * @param changes - Tag additions and removals on the thread
251
+ */
252
+ onThreadUpdated(thread: Thread, changes: {
253
+ tagsAdded: Record<Tag, ActorId[]>;
254
+ tagsRemoved: Record<Tag, ActorId[]>;
255
+ }): Promise<void>;
256
+ /**
257
+ * Called when a note is created on a thread created by this twist.
258
+ * Override to implement two-way sync (e.g. syncing notes as comments).
259
+ *
260
+ * Notes created by the twist itself are filtered out to prevent loops.
261
+ *
262
+ * @param note - The newly created note
263
+ */
264
+ onNoteCreated(note: Note, ...args: any[]): Promise<void>;
265
+ /**
266
+ * Called when a link is created in a connected source channel.
267
+ * Requires `link: true` in Plot options.
268
+ *
269
+ * @param link - The newly created link
270
+ * @param notes - Notes on the link's thread
271
+ */
272
+ onLinkCreated(link: Link, notes: Note[]): Promise<void>;
273
+ /**
274
+ * Called when a link in a connected source channel is updated.
275
+ * Requires `link: true` in Plot options.
276
+ *
277
+ * @param link - The updated link
278
+ * @param notes - Notes on the link's thread (optional)
279
+ */
280
+ onLinkUpdated(link: Link, notes?: Note[]): Promise<void>;
281
+ /**
282
+ * Called when a note is created on a thread with a link from a connected channel.
283
+ * Requires `link: true` in Plot options.
284
+ *
285
+ * @param note - The newly created note
286
+ * @param link - The link associated with the thread
287
+ */
288
+ onLinkNoteCreated(note: Note, link: Link): Promise<void>;
234
289
  /**
235
290
  * Waits for tool initialization to complete.
236
291
  * Called automatically by the entrypoint before lifecycle methods.
@@ -1 +1 @@
1
- {"version":3,"file":"twist.d.ts","sourceRoot":"","sources":["../src/twist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACvE,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,Y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;;;OAMG;IAEH,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD;;;;;;OAMG;IAEH,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD;;;;;;OAMG;IAEH,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
package/dist/twist.js CHANGED
@@ -17,9 +17,8 @@
17
17
  *
18
18
  * async activate(priority: Pick<Priority, "id">) {
19
19
  * // Initialize twist for the given priority
20
- * await this.tools.plot.createActivity({
21
- * type: ActivityType.Note,
22
- * note: "Hello, good looking!",
20
+ * await this.tools.plot.createThread({
21
+ * title: "Hello, good looking!",
23
22
  * });
24
23
  * }
25
24
  * }
@@ -43,23 +42,23 @@ export class Twist {
43
42
  return this.tools.callbacks.create(fn, ...extraArgs);
44
43
  }
45
44
  /**
46
- * Like callback(), but for an ActivityLink, which receives the link as the first argument.
45
+ * Like callback(), but for an Action, which receives the action as the first argument.
47
46
  *
48
47
  * @param fn - The method to callback
49
- * @param extraArgs - Additional arguments to pass after the link
48
+ * @param extraArgs - Additional arguments to pass after the action
50
49
  * @returns Promise resolving to a persistent callback token
51
50
  *
52
51
  * @example
53
52
  * ```typescript
54
- * const callback = await this.linkCallback(this.doSomething, 123);
55
- * const link: ActivityLink = {
56
- * type: ActivityLinkType.Callback,
53
+ * const callback = await this.actionCallback(this.doSomething, 123);
54
+ * const action: Action = {
55
+ * type: ActionType.callback,
57
56
  * title: "Do Something",
58
57
  * callback,
59
58
  * };
60
59
  * ```
61
60
  */
62
- async linkCallback(fn, ...extraArgs) {
61
+ async actionCallback(fn, ...extraArgs) {
63
62
  return this.tools.callbacks.create(fn, ...extraArgs);
64
63
  }
65
64
  /**
@@ -192,7 +191,7 @@ export class Twist {
192
191
  * Called when the twist is activated for a specific priority.
193
192
  *
194
193
  * This method should contain initialization logic such as setting up
195
- * initial activities, configuring webhooks, or establishing external connections.
194
+ * initial threads, configuring webhooks, or establishing external connections.
196
195
  *
197
196
  * @param priority - The priority context containing the priority ID
198
197
  * @param context - Optional context containing the actor who triggered activation
@@ -214,6 +213,20 @@ export class Twist {
214
213
  upgrade() {
215
214
  return Promise.resolve();
216
215
  }
216
+ /**
217
+ * Called when the twist's options configuration changes.
218
+ *
219
+ * Override to react to option changes, e.g. archiving items when a sync
220
+ * type is toggled off, or starting sync when a type is toggled on.
221
+ *
222
+ * @param oldOptions - The previously resolved options
223
+ * @param newOptions - The newly resolved options
224
+ * @returns Promise that resolves when the change is handled
225
+ */
226
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
227
+ onOptionsChanged(oldOptions, newOptions) {
228
+ return Promise.resolve();
229
+ }
217
230
  /**
218
231
  * Called when the twist is removed from a priority.
219
232
  *
@@ -225,6 +238,62 @@ export class Twist {
225
238
  deactivate() {
226
239
  return Promise.resolve();
227
240
  }
241
+ /**
242
+ * Called when a thread created by this twist is updated.
243
+ * Override to implement two-way sync with an external system.
244
+ *
245
+ * @param thread - The updated thread
246
+ * @param changes - Tag additions and removals on the thread
247
+ */
248
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
249
+ onThreadUpdated(thread, changes) {
250
+ return Promise.resolve();
251
+ }
252
+ /**
253
+ * Called when a note is created on a thread created by this twist.
254
+ * Override to implement two-way sync (e.g. syncing notes as comments).
255
+ *
256
+ * Notes created by the twist itself are filtered out to prevent loops.
257
+ *
258
+ * @param note - The newly created note
259
+ */
260
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
261
+ onNoteCreated(note, ...args) {
262
+ return Promise.resolve();
263
+ }
264
+ /**
265
+ * Called when a link is created in a connected source channel.
266
+ * Requires `link: true` in Plot options.
267
+ *
268
+ * @param link - The newly created link
269
+ * @param notes - Notes on the link's thread
270
+ */
271
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
272
+ onLinkCreated(link, notes) {
273
+ return Promise.resolve();
274
+ }
275
+ /**
276
+ * Called when a link in a connected source channel is updated.
277
+ * Requires `link: true` in Plot options.
278
+ *
279
+ * @param link - The updated link
280
+ * @param notes - Notes on the link's thread (optional)
281
+ */
282
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
283
+ onLinkUpdated(link, notes) {
284
+ return Promise.resolve();
285
+ }
286
+ /**
287
+ * Called when a note is created on a thread with a link from a connected channel.
288
+ * Requires `link: true` in Plot options.
289
+ *
290
+ * @param note - The newly created note
291
+ * @param link - The link associated with the thread
292
+ */
293
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
294
+ onLinkNoteCreated(note, link) {
295
+ return Promise.resolve();
296
+ }
228
297
  /**
229
298
  * Waits for tool initialization to complete.
230
299
  * Called automatically by the entrypoint before lifecycle methods.
package/dist/twist.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"twist.js","sourceRoot":"","sources":["../src/twist.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAgB,KAAK;IACH;IAAkB;IAAxC,YAAsB,EAAQ,EAAU,QAAkB;QAApC,OAAE,GAAF,EAAE,CAAM;QAAU,aAAQ,GAAR,QAAQ,CAAU;IAAG,CAAC;IAE9D;;;OAGG;IACH,IAAc,KAAK;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAqB,CAAC;IACrD,CAAC;IA4CS,KAAK,CAAC,QAAQ,CAGtB,EAAM,EAAE,GAAG,SAAgB;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACO,KAAK,CAAC,YAAY,CAG1B,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A6D;IAC7D,aAAa,CAAC,IAAU,EAAE,KAAa;QACrC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,6DAA6D;IAC7D,aAAa,CAAC,IAAU,EAAE,KAAc;QACtC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,6DAA6D;IAC7D,iBAAiB,CAAC,IAAU,EAAE,IAAU;QACtC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC;IACrC,CAAC;CACF"}
@@ -8,6 +8,7 @@
8
8
  *
9
9
  * @internal
10
10
  */
11
+ import type { Options, OptionsSchema, ResolvedOptions } from "../options";
11
12
  import type { Callbacks } from "../tools/callbacks";
12
13
  import type { Store } from "../tools/store";
13
14
  import type { Tasks } from "../tools/tasks";
@@ -48,7 +49,10 @@ export type InferOptions<T> = T extends {
48
49
  * Function type for building tool dependencies.
49
50
  * Used in build methods to request tool instances.
50
51
  */
51
- export type ToolBuilder = <TC extends abstract new (...args: any) => any>(ToolClass: TC, options?: InferOptions<TC>) => Promise<InstanceType<TC>>;
52
+ export type ToolBuilder = {
53
+ <T extends OptionsSchema>(ToolClass: typeof Options, schema: T): Promise<ResolvedOptions<T>>;
54
+ <TC extends abstract new (...args: any) => any>(ToolClass: TC, options?: InferOptions<TC>): Promise<InstanceType<TC>>;
55
+ };
52
56
  /**
53
57
  * Interface for managing tool initialization and lifecycle.
54
58
  * Implemented by the twist runtime to provide tools to twists and tools.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,KA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"0.35.0",
3
+ "version": "0.37.0",
4
4
  "description": "Plot Twist Creator - Build intelligent extensions that integrate and automate",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,16 +24,31 @@
24
24
  "types": "./dist/tool.d.ts",
25
25
  "default": "./dist/tool.js"
26
26
  },
27
+ "./source": {
28
+ "@plotday/source": "./src/source.ts",
29
+ "types": "./dist/source.d.ts",
30
+ "default": "./dist/source.js"
31
+ },
27
32
  "./plot": {
28
33
  "@plotday/source": "./src/plot.ts",
29
34
  "types": "./dist/plot.d.ts",
30
35
  "default": "./dist/plot.js"
31
36
  },
37
+ "./schedule": {
38
+ "@plotday/source": "./src/schedule.ts",
39
+ "types": "./dist/schedule.d.ts",
40
+ "default": "./dist/schedule.js"
41
+ },
32
42
  "./tag": {
33
43
  "@plotday/source": "./src/tag.ts",
34
44
  "types": "./dist/tag.d.ts",
35
45
  "default": "./dist/tag.js"
36
46
  },
47
+ "./options": {
48
+ "@plotday/source": "./src/options.ts",
49
+ "types": "./dist/options.d.ts",
50
+ "default": "./dist/options.js"
51
+ },
37
52
  "./tools/twists": {
38
53
  "@plotday/source": "./src/tools/twists.ts",
39
54
  "types": "./dist/tools/twists.d.ts",
@@ -89,26 +104,6 @@
89
104
  "types": "./dist/utils/uuid.d.ts",
90
105
  "default": "./dist/utils/uuid.js"
91
106
  },
92
- "./common/calendar": {
93
- "@plotday/source": "./src/common/calendar.ts",
94
- "types": "./dist/common/calendar.d.ts",
95
- "default": "./dist/common/calendar.js"
96
- },
97
- "./common/messaging": {
98
- "@plotday/source": "./src/common/messaging.ts",
99
- "types": "./dist/common/messaging.d.ts",
100
- "default": "./dist/common/messaging.js"
101
- },
102
- "./common/projects": {
103
- "@plotday/source": "./src/common/projects.ts",
104
- "types": "./dist/common/projects.d.ts",
105
- "default": "./dist/common/projects.js"
106
- },
107
- "./common/documents": {
108
- "@plotday/source": "./src/common/documents.ts",
109
- "types": "./dist/common/documents.d.ts",
110
- "default": "./dist/common/documents.js"
111
- },
112
107
  "./twist-guide": {
113
108
  "@plotday/source": "./src/twist-guide.ts",
114
109
  "types": "./dist/twist-guide.d.ts",
@@ -184,26 +179,6 @@
184
179
  "types": "./dist/llm-docs/tools/store.d.ts",
185
180
  "default": "./dist/llm-docs/tools/store.js"
186
181
  },
187
- "./llm-docs/common/calendar": {
188
- "@plotday/source": "./src/llm-docs/common/calendar.ts",
189
- "types": "./dist/llm-docs/common/calendar.d.ts",
190
- "default": "./dist/llm-docs/common/calendar.js"
191
- },
192
- "./llm-docs/common/messaging": {
193
- "@plotday/source": "./src/llm-docs/common/messaging.ts",
194
- "types": "./dist/llm-docs/common/messaging.d.ts",
195
- "default": "./dist/llm-docs/common/messaging.js"
196
- },
197
- "./llm-docs/common/projects": {
198
- "@plotday/source": "./src/llm-docs/common/projects.ts",
199
- "types": "./dist/llm-docs/common/projects.d.ts",
200
- "default": "./dist/llm-docs/common/projects.js"
201
- },
202
- "./llm-docs/common/documents": {
203
- "@plotday/source": "./src/llm-docs/common/documents.ts",
204
- "types": "./dist/llm-docs/common/documents.d.ts",
205
- "default": "./dist/llm-docs/common/documents.js"
206
- },
207
182
  "./tsconfig.base.json": "./tsconfig.base.json"
208
183
  },
209
184
  "files": [