@plotday/twister 0.20.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 (298) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +261 -0
  3. package/bin/commands/build.js +108 -0
  4. package/bin/commands/build.js.map +1 -0
  5. package/bin/commands/create.js +230 -0
  6. package/bin/commands/create.js.map +1 -0
  7. package/bin/commands/deploy.js +292 -0
  8. package/bin/commands/deploy.js.map +1 -0
  9. package/bin/commands/generate.js +301 -0
  10. package/bin/commands/generate.js.map +1 -0
  11. package/bin/commands/lint.js +69 -0
  12. package/bin/commands/lint.js.map +1 -0
  13. package/bin/commands/login.js +140 -0
  14. package/bin/commands/login.js.map +1 -0
  15. package/bin/commands/priority-create.js +102 -0
  16. package/bin/commands/priority-create.js.map +1 -0
  17. package/bin/commands/priority-list.js +47 -0
  18. package/bin/commands/priority-list.js.map +1 -0
  19. package/bin/commands/twist-logs.js +187 -0
  20. package/bin/commands/twist-logs.js.map +1 -0
  21. package/bin/index.js +129 -0
  22. package/bin/index.js.map +1 -0
  23. package/bin/package.json +3 -0
  24. package/bin/plot.cjs +3 -0
  25. package/bin/templates/AGENTS.template.md +403 -0
  26. package/bin/templates/CLAUDE.template.md +1 -0
  27. package/bin/templates/README.template.md +189 -0
  28. package/bin/utils/bundle.js +106 -0
  29. package/bin/utils/bundle.js.map +1 -0
  30. package/bin/utils/output.js +133 -0
  31. package/bin/utils/output.js.map +1 -0
  32. package/bin/utils/packageManager.js +65 -0
  33. package/bin/utils/packageManager.js.map +1 -0
  34. package/bin/utils/sse.js +100 -0
  35. package/bin/utils/sse.js.map +1 -0
  36. package/bin/utils/token.js +75 -0
  37. package/bin/utils/token.js.map +1 -0
  38. package/cli/templates/AGENTS.template.md +403 -0
  39. package/cli/templates/CLAUDE.template.md +1 -0
  40. package/cli/templates/README.template.md +189 -0
  41. package/dist/common/calendar.d.ts +144 -0
  42. package/dist/common/calendar.d.ts.map +1 -0
  43. package/dist/common/calendar.js +2 -0
  44. package/dist/common/calendar.js.map +1 -0
  45. package/dist/common/messaging.d.ts +84 -0
  46. package/dist/common/messaging.d.ts.map +1 -0
  47. package/dist/common/messaging.js +2 -0
  48. package/dist/common/messaging.js.map +1 -0
  49. package/dist/creator-docs.d.ts +11 -0
  50. package/dist/creator-docs.d.ts.map +1 -0
  51. package/dist/creator-docs.js +27 -0
  52. package/dist/creator-docs.js.map +1 -0
  53. package/dist/docs/.nojekyll +1 -0
  54. package/dist/docs/assets/favicon.svg +8 -0
  55. package/dist/docs/assets/hierarchy.js +1 -0
  56. package/dist/docs/assets/highlight.css +134 -0
  57. package/dist/docs/assets/icons.js +18 -0
  58. package/dist/docs/assets/icons.svg +1 -0
  59. package/dist/docs/assets/main.js +60 -0
  60. package/dist/docs/assets/navigation.js +1 -0
  61. package/dist/docs/assets/search.js +1 -0
  62. package/dist/docs/assets/style.css +1633 -0
  63. package/dist/docs/classes/tool.ITool.html +4 -0
  64. package/dist/docs/classes/tool.Tool.html +116 -0
  65. package/dist/docs/classes/tools_ai.AI.html +27 -0
  66. package/dist/docs/classes/tools_callbacks.Callbacks.html +45 -0
  67. package/dist/docs/classes/tools_integrations.Integrations.html +26 -0
  68. package/dist/docs/classes/tools_network.Network.html +68 -0
  69. package/dist/docs/classes/tools_plot.Plot.html +82 -0
  70. package/dist/docs/classes/tools_store.Store.html +53 -0
  71. package/dist/docs/classes/tools_tasks.Tasks.html +39 -0
  72. package/dist/docs/classes/tools_twists.Twists.html +59 -0
  73. package/dist/docs/classes/twist.Twist.html +96 -0
  74. package/dist/docs/documents/Advanced.html +91 -0
  75. package/dist/docs/documents/Building_Custom_Tools.html +200 -0
  76. package/dist/docs/documents/Built-in_Tools.html +170 -0
  77. package/dist/docs/documents/CLI_Reference.html +193 -0
  78. package/dist/docs/documents/Core_Concepts.html +163 -0
  79. package/dist/docs/documents/Getting_Started.html +94 -0
  80. package/dist/docs/documents/Runtime_Environment.html +128 -0
  81. package/dist/docs/enums/plot.ActivityLinkType.html +12 -0
  82. package/dist/docs/enums/plot.ActivityType.html +10 -0
  83. package/dist/docs/enums/plot.ActorType.html +10 -0
  84. package/dist/docs/enums/plot.ConferencingProvider.html +14 -0
  85. package/dist/docs/enums/tag.Tag.html +45 -0
  86. package/dist/docs/enums/tools_ai.AIModel.html +31 -0
  87. package/dist/docs/enums/tools_integrations.AuthLevel.html +7 -0
  88. package/dist/docs/enums/tools_integrations.AuthProvider.html +24 -0
  89. package/dist/docs/enums/tools_plot.ActivityAccess.html +8 -0
  90. package/dist/docs/enums/tools_plot.ContactAccess.html +5 -0
  91. package/dist/docs/enums/tools_plot.PriorityAccess.html +8 -0
  92. package/dist/docs/hierarchy.html +1 -0
  93. package/dist/docs/index.html +100 -0
  94. package/dist/docs/interfaces/common_calendar.Calendar.html +13 -0
  95. package/dist/docs/interfaces/common_calendar.CalendarTool.html +49 -0
  96. package/dist/docs/interfaces/common_calendar.SyncOptions.html +8 -0
  97. package/dist/docs/interfaces/tools_ai.AIRequest.html +46 -0
  98. package/dist/docs/interfaces/tools_ai.AIResponse.html +19 -0
  99. package/dist/docs/interfaces/tools_ai.FilePart.html +14 -0
  100. package/dist/docs/interfaces/tools_ai.ImagePart.html +11 -0
  101. package/dist/docs/interfaces/tools_ai.ReasoningPart.html +7 -0
  102. package/dist/docs/interfaces/tools_ai.RedactedReasoningPart.html +5 -0
  103. package/dist/docs/interfaces/tools_ai.TextPart.html +5 -0
  104. package/dist/docs/interfaces/tools_ai.ToolCallPart.html +9 -0
  105. package/dist/docs/interfaces/tools_ai.ToolExecutionOptions.html +9 -0
  106. package/dist/docs/interfaces/tools_ai.ToolResultPart.html +9 -0
  107. package/dist/docs/interfaces/tools_twists.TwistSource.html +13 -0
  108. package/dist/docs/interfaces/utils_types.ToolShed.html +11 -0
  109. package/dist/docs/modules/common_calendar.html +1 -0
  110. package/dist/docs/modules/index.html +1 -0
  111. package/dist/docs/modules/plot.html +1 -0
  112. package/dist/docs/modules/tag.html +1 -0
  113. package/dist/docs/modules/tool.html +1 -0
  114. package/dist/docs/modules/tools_ai.html +1 -0
  115. package/dist/docs/modules/tools_callbacks.html +1 -0
  116. package/dist/docs/modules/tools_integrations.html +1 -0
  117. package/dist/docs/modules/tools_network.html +1 -0
  118. package/dist/docs/modules/tools_plot.html +1 -0
  119. package/dist/docs/modules/tools_store.html +1 -0
  120. package/dist/docs/modules/tools_tasks.html +1 -0
  121. package/dist/docs/modules/tools_twists.html +1 -0
  122. package/dist/docs/modules/twist.html +1 -0
  123. package/dist/docs/modules/utils_types.html +1 -0
  124. package/dist/docs/modules.html +1 -0
  125. package/dist/docs/types/common_calendar.CalendarAuth.html +7 -0
  126. package/dist/docs/types/plot.Activity.html +64 -0
  127. package/dist/docs/types/plot.ActivityLink.html +22 -0
  128. package/dist/docs/types/plot.ActivityMeta.html +11 -0
  129. package/dist/docs/types/plot.ActivityUpdate.html +13 -0
  130. package/dist/docs/types/plot.Actor.html +15 -0
  131. package/dist/docs/types/plot.ActorId.html +4 -0
  132. package/dist/docs/types/plot.NewActivity.html +16 -0
  133. package/dist/docs/types/plot.NewContact.html +13 -0
  134. package/dist/docs/types/plot.NewPriority.html +5 -0
  135. package/dist/docs/types/plot.NoteType.html +1 -0
  136. package/dist/docs/types/plot.PickPriorityConfig.html +22 -0
  137. package/dist/docs/types/plot.Priority.html +8 -0
  138. package/dist/docs/types/tools_ai.AIAssistantMessage.html +4 -0
  139. package/dist/docs/types/tools_ai.AIMessage.html +3 -0
  140. package/dist/docs/types/tools_ai.AISource.html +11 -0
  141. package/dist/docs/types/tools_ai.AISystemMessage.html +7 -0
  142. package/dist/docs/types/tools_ai.AITool.html +19 -0
  143. package/dist/docs/types/tools_ai.AIToolMessage.html +4 -0
  144. package/dist/docs/types/tools_ai.AIToolSet.html +1 -0
  145. package/dist/docs/types/tools_ai.AIUsage.html +10 -0
  146. package/dist/docs/types/tools_ai.AIUserMessage.html +4 -0
  147. package/dist/docs/types/tools_ai.DataContent.html +2 -0
  148. package/dist/docs/types/tools_ai.ModelPreferences.html +24 -0
  149. package/dist/docs/types/tools_callbacks.Callback.html +8 -0
  150. package/dist/docs/types/tools_integrations.AuthToken.html +16 -0
  151. package/dist/docs/types/tools_integrations.Authorization.html +10 -0
  152. package/dist/docs/types/tools_network.WebhookRequest.html +15 -0
  153. package/dist/docs/types/tools_plot.ActivityIntentHandler.html +9 -0
  154. package/dist/docs/types/tools_twists.Log.html +6 -0
  155. package/dist/docs/types/tools_twists.TwistPermissions.html +12 -0
  156. package/dist/docs/types/utils_types.BuiltInTools.html +5 -0
  157. package/dist/docs/types/utils_types.CallbackMethods.html +3 -0
  158. package/dist/docs/types/utils_types.ExtractBuildReturn.html +2 -0
  159. package/dist/docs/types/utils_types.InferOptions.html +2 -0
  160. package/dist/docs/types/utils_types.InferTools.html +3 -0
  161. package/dist/docs/types/utils_types.NoFunctions.html +3 -0
  162. package/dist/docs/types/utils_types.NonFunction.html +2 -0
  163. package/dist/docs/types/utils_types.PromiseValues.html +3 -0
  164. package/dist/docs/types/utils_types.ToolBuilder.html +3 -0
  165. package/dist/index.d.ts +7 -0
  166. package/dist/index.d.ts.map +1 -0
  167. package/dist/index.js +7 -0
  168. package/dist/index.js.map +1 -0
  169. package/dist/llm-docs/common/calendar.d.ts +9 -0
  170. package/dist/llm-docs/common/calendar.d.ts.map +1 -0
  171. package/dist/llm-docs/common/calendar.js +8 -0
  172. package/dist/llm-docs/common/calendar.js.map +1 -0
  173. package/dist/llm-docs/common/messaging.d.ts +9 -0
  174. package/dist/llm-docs/common/messaging.d.ts.map +1 -0
  175. package/dist/llm-docs/common/messaging.js +8 -0
  176. package/dist/llm-docs/common/messaging.js.map +1 -0
  177. package/dist/llm-docs/creator-docs.d.ts +9 -0
  178. package/dist/llm-docs/creator-docs.d.ts.map +1 -0
  179. package/dist/llm-docs/creator-docs.js +8 -0
  180. package/dist/llm-docs/creator-docs.js.map +1 -0
  181. package/dist/llm-docs/index.d.ts +11 -0
  182. package/dist/llm-docs/index.d.ts.map +1 -0
  183. package/dist/llm-docs/index.js +42 -0
  184. package/dist/llm-docs/index.js.map +1 -0
  185. package/dist/llm-docs/plot.d.ts +9 -0
  186. package/dist/llm-docs/plot.d.ts.map +1 -0
  187. package/dist/llm-docs/plot.js +8 -0
  188. package/dist/llm-docs/plot.js.map +1 -0
  189. package/dist/llm-docs/tag.d.ts +9 -0
  190. package/dist/llm-docs/tag.d.ts.map +1 -0
  191. package/dist/llm-docs/tag.js +8 -0
  192. package/dist/llm-docs/tag.js.map +1 -0
  193. package/dist/llm-docs/tool.d.ts +9 -0
  194. package/dist/llm-docs/tool.d.ts.map +1 -0
  195. package/dist/llm-docs/tool.js +8 -0
  196. package/dist/llm-docs/tool.js.map +1 -0
  197. package/dist/llm-docs/tools/ai.d.ts +9 -0
  198. package/dist/llm-docs/tools/ai.d.ts.map +1 -0
  199. package/dist/llm-docs/tools/ai.js +8 -0
  200. package/dist/llm-docs/tools/ai.js.map +1 -0
  201. package/dist/llm-docs/tools/callbacks.d.ts +9 -0
  202. package/dist/llm-docs/tools/callbacks.d.ts.map +1 -0
  203. package/dist/llm-docs/tools/callbacks.js +8 -0
  204. package/dist/llm-docs/tools/callbacks.js.map +1 -0
  205. package/dist/llm-docs/tools/integrations.d.ts +9 -0
  206. package/dist/llm-docs/tools/integrations.d.ts.map +1 -0
  207. package/dist/llm-docs/tools/integrations.js +8 -0
  208. package/dist/llm-docs/tools/integrations.js.map +1 -0
  209. package/dist/llm-docs/tools/network.d.ts +9 -0
  210. package/dist/llm-docs/tools/network.d.ts.map +1 -0
  211. package/dist/llm-docs/tools/network.js +8 -0
  212. package/dist/llm-docs/tools/network.js.map +1 -0
  213. package/dist/llm-docs/tools/plot.d.ts +9 -0
  214. package/dist/llm-docs/tools/plot.d.ts.map +1 -0
  215. package/dist/llm-docs/tools/plot.js +8 -0
  216. package/dist/llm-docs/tools/plot.js.map +1 -0
  217. package/dist/llm-docs/tools/store.d.ts +9 -0
  218. package/dist/llm-docs/tools/store.d.ts.map +1 -0
  219. package/dist/llm-docs/tools/store.js +8 -0
  220. package/dist/llm-docs/tools/store.js.map +1 -0
  221. package/dist/llm-docs/tools/tasks.d.ts +9 -0
  222. package/dist/llm-docs/tools/tasks.d.ts.map +1 -0
  223. package/dist/llm-docs/tools/tasks.js +8 -0
  224. package/dist/llm-docs/tools/tasks.js.map +1 -0
  225. package/dist/llm-docs/tools/twists.d.ts +9 -0
  226. package/dist/llm-docs/tools/twists.d.ts.map +1 -0
  227. package/dist/llm-docs/tools/twists.js +8 -0
  228. package/dist/llm-docs/tools/twists.js.map +1 -0
  229. package/dist/llm-docs/twist-guide-template.d.ts +9 -0
  230. package/dist/llm-docs/twist-guide-template.d.ts.map +1 -0
  231. package/dist/llm-docs/twist-guide-template.js +8 -0
  232. package/dist/llm-docs/twist-guide-template.js.map +1 -0
  233. package/dist/llm-docs/twist.d.ts +9 -0
  234. package/dist/llm-docs/twist.d.ts.map +1 -0
  235. package/dist/llm-docs/twist.js +8 -0
  236. package/dist/llm-docs/twist.js.map +1 -0
  237. package/dist/plot.d.ts +463 -0
  238. package/dist/plot.d.ts.map +1 -0
  239. package/dist/plot.js +68 -0
  240. package/dist/plot.js.map +1 -0
  241. package/dist/tag.d.ts +47 -0
  242. package/dist/tag.d.ts.map +1 -0
  243. package/dist/tag.js +51 -0
  244. package/dist/tag.js.map +1 -0
  245. package/dist/tool.d.ts +242 -0
  246. package/dist/tool.d.ts.map +1 -0
  247. package/dist/tool.js +283 -0
  248. package/dist/tool.js.map +1 -0
  249. package/dist/tools/ai.d.ts +697 -0
  250. package/dist/tools/ai.d.ts.map +1 -0
  251. package/dist/tools/ai.js +104 -0
  252. package/dist/tools/ai.js.map +1 -0
  253. package/dist/tools/callbacks.d.ts +96 -0
  254. package/dist/tools/callbacks.d.ts.map +1 -0
  255. package/dist/tools/callbacks.js +40 -0
  256. package/dist/tools/callbacks.js.map +1 -0
  257. package/dist/tools/index.d.ts +9 -0
  258. package/dist/tools/index.d.ts.map +1 -0
  259. package/dist/tools/index.js +9 -0
  260. package/dist/tools/index.js.map +1 -0
  261. package/dist/tools/integrations.d.ts +142 -0
  262. package/dist/tools/integrations.d.ts.map +1 -0
  263. package/dist/tools/integrations.js +79 -0
  264. package/dist/tools/integrations.js.map +1 -0
  265. package/dist/tools/network.d.ts +188 -0
  266. package/dist/tools/network.d.ts.map +1 -0
  267. package/dist/tools/network.js +87 -0
  268. package/dist/tools/network.js.map +1 -0
  269. package/dist/tools/plot.d.ts +252 -0
  270. package/dist/tools/plot.d.ts.map +1 -0
  271. package/dist/tools/plot.js +72 -0
  272. package/dist/tools/plot.js.map +1 -0
  273. package/dist/tools/store.d.ts +90 -0
  274. package/dist/tools/store.d.ts.map +1 -0
  275. package/dist/tools/store.js +48 -0
  276. package/dist/tools/store.js.map +1 -0
  277. package/dist/tools/tasks.d.ts +93 -0
  278. package/dist/tools/tasks.d.ts.map +1 -0
  279. package/dist/tools/tasks.js +58 -0
  280. package/dist/tools/tasks.js.map +1 -0
  281. package/dist/tools/twists.d.ts +213 -0
  282. package/dist/tools/twists.d.ts.map +1 -0
  283. package/dist/tools/twists.js +26 -0
  284. package/dist/tools/twists.js.map +1 -0
  285. package/dist/twist-guide.d.ts +2 -0
  286. package/dist/twist-guide.d.ts.map +1 -0
  287. package/dist/twist-guide.js +9 -0
  288. package/dist/twist-guide.js.map +1 -0
  289. package/dist/twist.d.ts +204 -0
  290. package/dist/twist.d.ts.map +1 -0
  291. package/dist/twist.js +216 -0
  292. package/dist/twist.js.map +1 -0
  293. package/dist/utils/types.d.ts +91 -0
  294. package/dist/utils/types.d.ts.map +1 -0
  295. package/dist/utils/types.js +2 -0
  296. package/dist/utils/types.js.map +1 -0
  297. package/package.json +206 -0
  298. package/tsconfig.base.json +28 -0
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getGlobalTokenPath = getGlobalTokenPath;
37
+ exports.getToken = getToken;
38
+ const fs = __importStar(require("fs"));
39
+ const os = __importStar(require("os"));
40
+ const path = __importStar(require("path"));
41
+ /**
42
+ * Get the path to the global token file.
43
+ *
44
+ * @returns The path to the global token file
45
+ */
46
+ function getGlobalTokenPath() {
47
+ const homeDir = os.homedir();
48
+ if (process.platform === "win32") {
49
+ // Windows: Use APPDATA
50
+ const appData = process.env.APPDATA || path.join(homeDir, "AppData", "Roaming");
51
+ return path.join(appData, "plot", "token");
52
+ }
53
+ else {
54
+ // Unix-like: Use ~/.config/plot/token
55
+ return path.join(homeDir, ".config", "plot", "token");
56
+ }
57
+ }
58
+ /**
59
+ * Read the authentication token from the global token file.
60
+ *
61
+ * @returns The token string if found, null otherwise
62
+ */
63
+ async function getToken() {
64
+ const globalTokenPath = getGlobalTokenPath();
65
+ if (fs.existsSync(globalTokenPath)) {
66
+ try {
67
+ return fs.readFileSync(globalTokenPath, "utf-8").trim();
68
+ }
69
+ catch (error) {
70
+ console.warn(`Warning: Failed to read global token file: ${globalTokenPath}`);
71
+ }
72
+ }
73
+ return null;
74
+ }
75
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../../cli/utils/token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,gDAUC;AAOD,4BAYC;AAtCD,uCAAyB;AACzB,uCAAyB;AACzB,2CAA6B;AAE7B;;;;GAIG;AACH,SAAgB,kBAAkB;IAChC,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC7B,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,uBAAuB;QACvB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QAChF,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;SAAM,CAAC;QACN,sCAAsC;QACtC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;AACH,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,QAAQ;IAC5B,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAC;IAC7C,IAAI,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,OAAO,EAAE,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CACV,8CAA8C,eAAe,EAAE,CAChE,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,403 @@
1
+ # Twist Implementation Guide for LLMs
2
+
3
+ This document provides context for AI assistants generating or modifying twists.
4
+
5
+ ## Architecture Overview
6
+
7
+ Plot 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.
8
+
9
+ ### Runtime Environment
10
+
11
+ **Critical**: All Twists and tool functions are executed in a sandboxed, ephemeral environment with limited resources:
12
+
13
+ - **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.
14
+ - **Limited CPU time**: Each execution has limited CPU time (typically 10 seconds) and memory (128MB)
15
+ - **Use the Run tool**: Queue separate chunks of work with `run.now(functionName, context)`
16
+ - **Break long operations**: Split large operations into smaller batches that can be processed independently
17
+ - **Store intermediate state**: Use the Store tool to persist state between batches
18
+ - **Examples**: Syncing large datasets, processing many API calls, or performing batch operations
19
+
20
+ ## twist Structure Pattern
21
+
22
+ ```typescript
23
+ import {
24
+ type Activity,
25
+ twist,
26
+ type Priority,
27
+ type ToolBuilder,
28
+ } from "@plotday/twister";
29
+ import { Plot } from "@plotday/twister/tools/plot";
30
+
31
+ export default class MyTwist extends twist<MyTwist> {
32
+ build(build: ToolBuilder) {
33
+ return {
34
+ plot: build(Plot),
35
+ };
36
+ }
37
+
38
+ async activate(priority: Pick<Priority, "id">) {
39
+ // Called when twist is enabled for a priority
40
+ // Common actions: request auth, create setup activities
41
+ }
42
+
43
+ async activity(activity: Activity) {
44
+ // Called when an activity is routed to this twist
45
+ // Common actions: process external events, update activities
46
+ }
47
+ }
48
+ ```
49
+
50
+ ## Tool System
51
+
52
+ ### Accessing Tools
53
+
54
+ All tools are declared in the `build` method:
55
+
56
+ ```typescript
57
+ build(build: ToolBuilder) {
58
+ return {
59
+ toolName: build(ToolClass),
60
+ };
61
+ }
62
+ ```
63
+
64
+ All `build()` calls must occur in the `build` method as they are used for dependency analysis.
65
+
66
+ IMPORTANT: 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.
67
+
68
+ ### Built-in Tools (Always Available)
69
+
70
+ For 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.
71
+
72
+ **Quick reference - Available tools:**
73
+
74
+ - `@plotday/twister/tools/plot` - Core data layer (create/update activities, priorities, contacts)
75
+ - `@plotday/twister/tools/ai` - LLM integration (text generation, structured output, reasoning)
76
+ - Use ModelPreferences to specify `speed` (fast/balanced/capable) and `cost` (low/medium/high)
77
+ - `@plotday/twister/tools/store` - Persistent key-value storage (also via `this.set()`, `this.get()`)
78
+ - `@plotday/twister/tools/tasks` - Queue batched work (also via `this.run()`)
79
+ - `@plotday/twister/tools/callbacks` - Persistent function references (also via `this.callback()`)
80
+ - `@plotday/twister/tools/integrations` - OAuth2 authentication flows
81
+ - `@plotday/twister/tools/network` - HTTP access permissions and webhook management
82
+ - `@plotday/twister/tools/twists` - Manage other Twists
83
+
84
+ **Critical**: Never use instance variables for state. They are lost after function execution. Always use Store methods.
85
+
86
+ ### External Tools (Add to package.json)
87
+
88
+ Add tool dependencies to `package.json`:
89
+
90
+ ```json
91
+ {
92
+ "dependencies": {
93
+ "@plotday/twister": "workspace:^",
94
+ "@plotday/tool-google-calendar": "workspace:^"
95
+ }
96
+ }
97
+ ```
98
+
99
+ #### Common External Tools
100
+
101
+ - `@plotday/tool-google-calendar`: Google Calendar integration
102
+ - `@plotday/tool-outlook-calendar`: Outlook Calendar integration
103
+ - `@plotday/tool-google-contacts`: Google Contacts integration
104
+
105
+ ## Lifecycle Methods
106
+
107
+ ### activate(priority: Pick<Priority, "id">)
108
+
109
+ Called when the twist is enabled for a priority. Common patterns:
110
+
111
+ **Request Authentication:**
112
+
113
+ ```typescript
114
+ async activate(_priority: Pick<Priority, "id">) {
115
+ const authLink = await this.tools.externalTool.requestAuth(
116
+ this.onAuthComplete,
117
+ "google"
118
+ );
119
+
120
+ await this.tools.plot.createActivity({
121
+ type: ActivityType.Task,
122
+ title: "Connect your account",
123
+ links: [authLink],
124
+ });
125
+ }
126
+ ```
127
+
128
+ **Store Parent Activity for Later:**
129
+
130
+ ```typescript
131
+ const activity = await this.tools.plot.createActivity({
132
+ type: ActivityType.Task,
133
+ title: "Setup",
134
+ });
135
+
136
+ await this.set("setup_activity_id", activity.id);
137
+ ```
138
+
139
+ ### activity(activity: Activity)
140
+
141
+ Called when an activity is routed to the twist. Common patterns:
142
+
143
+ **Create Activities from External Events:**
144
+
145
+ ```typescript
146
+ async activity(activity: Activity) {
147
+ await this.tools.plot.createActivity(activity);
148
+ }
149
+ ```
150
+
151
+ **Update Based on User Action:**
152
+
153
+ ```typescript
154
+ async activity(activity: Activity) {
155
+ if (activity.completed) {
156
+ await this.handleCompletion(activity);
157
+ }
158
+ }
159
+ ```
160
+
161
+ ## Activity Links
162
+
163
+ Activity links enable user interaction:
164
+
165
+ ```typescript
166
+ import { type ActivityLink, ActivityLinkType } from "@plotday/twister";
167
+
168
+ // URL link
169
+ const urlLink: ActivityLink = {
170
+ title: "Open website",
171
+ type: ActivityLinkType.url,
172
+ url: "https://example.com",
173
+ };
174
+
175
+ // Callback link (uses Callbacks tool)
176
+ const token = await this.callback(this.onLinkClicked, "context");
177
+ const callbackLink: ActivityLink = {
178
+ title: "Click me",
179
+ type: ActivityLinkType.callback,
180
+ token: token,
181
+ };
182
+
183
+ // Add to activity
184
+ await this.tools.plot.createActivity({
185
+ type: ActivityType.Task,
186
+ title: "Task with links",
187
+ links: [urlLink, callbackLink],
188
+ });
189
+ ```
190
+
191
+ ## Authentication Pattern
192
+
193
+ Common pattern for OAuth authentication:
194
+
195
+ ```typescript
196
+ async activate(_priority: Pick<Priority, "id">) {
197
+ // Request auth link from tool with callback
198
+ const authLink = await this.tools.googleTool.requestAuth(
199
+ this.onAuthComplete,
200
+ "google"
201
+ );
202
+
203
+ // Create activity with auth link
204
+ const activity = await this.tools.plot.createActivity({
205
+ type: ActivityType.Task,
206
+ title: "Connect Google account",
207
+ links: [authLink],
208
+ });
209
+
210
+ // Store for later use
211
+ await this.set("auth_activity_id", activity.id);
212
+ }
213
+
214
+ async onAuthComplete(authResult: { authToken: string }, provider: string) {
215
+ // Store auth token
216
+ await this.set(`${provider}_auth`, authResult.authToken);
217
+
218
+ // Continue setup flow
219
+ await this.setupSyncOptions(authResult.authToken);
220
+ }
221
+ ```
222
+
223
+ ## Sync Pattern
224
+
225
+ Pattern for syncing external data with callbacks:
226
+
227
+ ```typescript
228
+ async startSync(calendarId: string): Promise<void> {
229
+ const authToken = await this.get<string>("auth_token");
230
+
231
+ await this.tools.calendarTool.startSync(
232
+ authToken,
233
+ calendarId,
234
+ this.handleEvent,
235
+ calendarId
236
+ );
237
+ }
238
+
239
+ async handleEvent(activity: Activity, calendarId: string): Promise<void> {
240
+ // Process incoming event from external service
241
+ await this.tools.plot.createActivity(activity);
242
+ }
243
+
244
+ async stopSync(calendarId: string): Promise<void> {
245
+ const authToken = await this.get<string>("auth_token");
246
+ await this.tools.calendarTool.stopSync(authToken, calendarId);
247
+ }
248
+ ```
249
+
250
+ ## Calendar Selection Pattern
251
+
252
+ Pattern for letting users select from multiple calendars/accounts:
253
+
254
+ ```typescript
255
+ private async createCalendarSelectionActivity(
256
+ provider: string,
257
+ calendars: Calendar[],
258
+ authToken: string
259
+ ): Promise<void> {
260
+ const links: ActivityLink[] = [];
261
+
262
+ for (const calendar of calendars) {
263
+ const token = await this.callback(
264
+ this.onCalendarSelected,
265
+ provider,
266
+ calendar.id,
267
+ calendar.name,
268
+ authToken
269
+ );
270
+
271
+ links.push({
272
+ title: `📅 ${calendar.name}${calendar.primary ? " (Primary)" : ""}`,
273
+ type: ActivityLinkType.callback,
274
+ token: token,
275
+ });
276
+ }
277
+
278
+ await this.tools.plot.createActivity({
279
+ type: ActivityType.Note,
280
+ title: "Which calendars would you like to connect?",
281
+ links,
282
+ });
283
+ }
284
+
285
+ async onCalendarSelected(
286
+ link: ActivityLink,
287
+ provider: string,
288
+ calendarId: string,
289
+ calendarName: string,
290
+ authToken: string
291
+ ): Promise<void> {
292
+ // Start sync for selected calendar
293
+ await this.tools.tool.startSync(
294
+ authToken,
295
+ calendarId,
296
+ this.handleEvent,
297
+ provider,
298
+ calendarId
299
+ );
300
+ }
301
+ ```
302
+
303
+ ## Batch Processing Pattern
304
+
305
+ **Important**: Because Twists run in an ephemeral environment with limited execution time, you must break long operations into batches. Each batch runs independently in a new execution context.
306
+
307
+ ### Key Principles
308
+
309
+ 1. **Store state between batches**: Use the Store tool to persist progress
310
+ 2. **Queue next batch**: Use the Run tool to schedule the next chunk
311
+ 3. **Clean up when done**: Delete stored state after completion
312
+ 4. **Handle failures**: Store enough state to resume if a batch fails
313
+
314
+ ### Example Implementation
315
+
316
+ ```typescript
317
+ async startSync(resourceId: string): Promise<void> {
318
+ // Initialize state in Store (persists between executions)
319
+ await this.set(`sync_state_${resourceId}`, {
320
+ nextPageToken: null,
321
+ batchNumber: 1,
322
+ itemsProcessed: 0,
323
+ });
324
+
325
+ // Queue first batch using runTask method
326
+ const callback = await this.callback(this.syncBatch, resourceId);
327
+ await this.runTask(callback);
328
+ }
329
+
330
+ async syncBatch(args: any, resourceId: string): Promise<void> {
331
+ // Load state from Store (set by previous execution)
332
+ const state = await this.get(`sync_state_${resourceId}`);
333
+
334
+ // Process one batch (keep under time limit)
335
+ const result = await this.fetchBatch(state.nextPageToken);
336
+
337
+ // Process results
338
+ for (const item of result.items) {
339
+ await this.tools.plot.createActivity(item);
340
+ }
341
+
342
+ if (result.nextPageToken) {
343
+ // Update state in Store for next batch
344
+ await this.set(`sync_state_${resourceId}`, {
345
+ nextPageToken: result.nextPageToken,
346
+ batchNumber: state.batchNumber + 1,
347
+ itemsProcessed: state.itemsProcessed + result.items.length,
348
+ });
349
+
350
+ // Queue next batch (runs in new execution context)
351
+ const nextCallback = await this.callback(this.syncBatch, resourceId);
352
+ await this.runTask(nextCallback);
353
+ } else {
354
+ // Cleanup when complete
355
+ await this.clear(`sync_state_${resourceId}`);
356
+
357
+ // Optionally notify user of completion
358
+ await this.tools.plot.createActivity({
359
+ type: ActivityType.Note,
360
+ note: `Sync complete: ${state.itemsProcessed + result.items.length} items processed`,
361
+ });
362
+ }
363
+ }
364
+ ```
365
+
366
+ ## Error Handling
367
+
368
+ Always handle errors gracefully and communicate them to users:
369
+
370
+ ```typescript
371
+ try {
372
+ await this.externalOperation();
373
+ } catch (error) {
374
+ console.error("Operation failed:", error);
375
+
376
+ await this.tools.plot.createActivity({
377
+ type: ActivityType.Note,
378
+ note: `Failed to complete operation: ${error.message}`,
379
+ });
380
+ }
381
+ ```
382
+
383
+ ## Common Pitfalls
384
+
385
+ - **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.
386
+ - **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.
387
+ - Most activity should be `type = ActivityType.Note` with a `title` and `note`, and no `start` or `end`. This represents a typical message. `start` and `end` should only be used for a note if it should be displayed for a specific date or time, such as a birthday.
388
+ - Tools are declared in the `build` method and accessed via `this.tools.toolName` in twist methods.
389
+ - **Don't forget runtime limits** - Each execution has ~10 seconds. Break long operations into batches with the Tasks tool. Process enough items per batch to be efficient, but few enough to stay under time limits.
390
+ - **Always use Callbacks tool for persistent references** - Direct function references don't survive worker restarts.
391
+ - **Store auth tokens** - Don't re-request authentication unnecessarily.
392
+ - **Clean up callbacks and stored state** - Delete callbacks and Store entries when no longer needed.
393
+ - **Handle missing auth gracefully** - Check for stored auth before operations.
394
+
395
+ ## Testing
396
+
397
+ Before deploying, verify:
398
+
399
+ 1. Linting passes: `{{packageManager}} lint`
400
+ 2. All dependencies are in package.json
401
+ 3. Authentication flow works end-to-end
402
+ 4. Batch operations handle pagination correctly
403
+ 5. Error cases are handled gracefully
@@ -0,0 +1 @@
1
+ @AGENTS.md
@@ -0,0 +1,189 @@
1
+ # {{displayName}} twist
2
+
3
+ A Plot twist that [describe what your twist does].
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Install dependencies
9
+ {{packageManager}} install
10
+
11
+ # Lint your code
12
+ {{packageManager}} lint
13
+
14
+ # Deploy to Plot
15
+ {{packageManager}} deploy
16
+ ```
17
+
18
+ ## Development
19
+
20
+ ### Project Structure
21
+
22
+ ```
23
+ .
24
+ ├── src/
25
+ │ └── index.ts # Main twist implementation
26
+ ├── package.json # twist metadata and dependencies
27
+ ├── tsconfig.json # TypeScript configuration
28
+ └── README.md # This file
29
+ ```
30
+
31
+ ### twist Lifecycle
32
+
33
+ Your twist implements two key lifecycle methods:
34
+
35
+ #### `activate(priority: Pick<Priority, "id">)`
36
+
37
+ Called when the twist is enabled for a priority. This is where you typically:
38
+ - Request authentication from external services
39
+ - Create initial setup activities
40
+ - Initialize twist state
41
+
42
+ #### `activity(activity: Activity)`
43
+
44
+ Called when an activity is routed to this twist. Use this to:
45
+ - Process incoming activities
46
+ - Create new activities based on external events
47
+ - Update existing activities
48
+
49
+ ### Using Tools
50
+
51
+ Twists access functionality through tools. Declare tools in the `build` method:
52
+
53
+ ```typescript
54
+ build(build: ToolBuilder) {
55
+ return {
56
+ plot: build(Plot),
57
+ };
58
+ }
59
+ // Store, Tasks, and Callbacks methods are available directly via this
60
+ ```
61
+
62
+ #### Built-in Tools
63
+
64
+ - **Plot**: Create, update, and delete activities
65
+ - **Store**: Persist data across twist invocations
66
+ - **Integrations**: Request OAuth authentication from external services
67
+ - **Tasks**: Queue background tasks and batch operations
68
+ - **Callbacks**: Create persistent function references for webhooks
69
+ - **Network**: HTTP access permissions and webhook management
70
+
71
+ #### External Tools
72
+
73
+ Add external tool dependencies to `package.json`:
74
+
75
+ ```json
76
+ {
77
+ "dependencies": {
78
+ "@plotday/twister": "workspace:^",
79
+ "@plotday/tool-google-calendar": "workspace:^"
80
+ }
81
+ }
82
+ ```
83
+
84
+ Then use them in your twist:
85
+
86
+ ```typescript
87
+ import GoogleCalendarTool from "@plotday/tool-google-calendar";
88
+
89
+ build(build: ToolBuilder) {
90
+ return {
91
+ googleCalendar: build(GoogleCalendarTool),
92
+ };
93
+ }
94
+ ```
95
+
96
+ ### Activity Types
97
+
98
+ Plot supports three activity types:
99
+
100
+ - **ActivityType.Note**: Information without actionable requirements
101
+ - **ActivityType.Task**: Actionable items that can be completed
102
+ - **ActivityType.Event**: Scheduled occurrences with start/end times
103
+
104
+ ### State Management
105
+
106
+ Use Store methods (available directly on twist and Tool classes) to persist data across twist invocations:
107
+
108
+ ```typescript
109
+ // Save state
110
+ await this.set("sync_token", token);
111
+
112
+ // Load state
113
+ const token = await this.get<string>("sync_token");
114
+ ```
115
+
116
+ **Important**: twist instances are ephemeral. Always use Store methods for data that needs to persist.
117
+
118
+ ### Runtime Limitations
119
+
120
+ **Important**: All twist and tool functions are executed in a sandboxed, ephemeral environment with limited resources:
121
+
122
+ - **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.
123
+ - **Limited CPU time**: Each execution has limited CPU time (typically 10 seconds) and memory (128MB)
124
+ - **Use the Tasks tool**: Queue separate chunks of work with `this.run(callback)`
125
+ - **Break long operations**: Split large operations into smaller batches that can be processed independently
126
+ - **Store intermediate state**: Use the Store tool to persist state between batches
127
+ - **Examples**: Syncing large datasets, processing many API calls, or performing batch operations
128
+
129
+ #### Pattern for Long-Running Operations
130
+
131
+ ```typescript
132
+ async startSync(calendarId: string): Promise<void> {
133
+ // Initialize state in Store (persists between executions)
134
+ await this.set(`sync_state_${calendarId}`, {
135
+ nextPageToken: null,
136
+ batchNumber: 1,
137
+ });
138
+
139
+ // Queue first batch using run method
140
+ const callback = await this.callback("syncBatch", { calendarId });
141
+ await this.run(callback);
142
+ }
143
+
144
+ async syncBatch(args: any, context: { calendarId: string }): Promise<void> {
145
+ // Load state from Store
146
+ const state = await this.get(`sync_state_${calendarId}`);
147
+
148
+ // Process one batch
149
+ const result = await processBatch(state.nextPageToken);
150
+
151
+ if (result.hasMore) {
152
+ // Update state and queue next batch
153
+ await this.set(`sync_state_${context.calendarId}`, {
154
+ nextPageToken: result.nextPageToken,
155
+ batchNumber: state.batchNumber + 1,
156
+ });
157
+
158
+ const nextCallback = await this.callback("syncBatch", context);
159
+ await this.run(nextCallback);
160
+ } else {
161
+ // Cleanup when done
162
+ await this.clear(`sync_state_${context.calendarId}`);
163
+ }
164
+ }
165
+ ```
166
+
167
+ ## Testing
168
+
169
+ Test your twist locally before deploying:
170
+
171
+ ```bash
172
+ # Run linter
173
+ {{packageManager}} lint
174
+
175
+ # Deploy to your Plot account
176
+ {{packageManager}} deploy
177
+ ```
178
+
179
+ ## Resources
180
+
181
+ - [Plot twist Builder Documentation](https://github.com/plotday/plot)
182
+ - [twist Examples](https://github.com/plotday/plot/tree/main/libs/twist/examples)
183
+ - [Tool Documentation](https://github.com/plotday/plot/tree/main/libs/twist/tools)
184
+
185
+ ## Support
186
+
187
+ For help or questions:
188
+ - Open an issue on GitHub
189
+ - Contact support@plot.day