@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.
- package/LICENSE +21 -0
- package/README.md +261 -0
- package/bin/commands/build.js +108 -0
- package/bin/commands/build.js.map +1 -0
- package/bin/commands/create.js +230 -0
- package/bin/commands/create.js.map +1 -0
- package/bin/commands/deploy.js +292 -0
- package/bin/commands/deploy.js.map +1 -0
- package/bin/commands/generate.js +301 -0
- package/bin/commands/generate.js.map +1 -0
- package/bin/commands/lint.js +69 -0
- package/bin/commands/lint.js.map +1 -0
- package/bin/commands/login.js +140 -0
- package/bin/commands/login.js.map +1 -0
- package/bin/commands/priority-create.js +102 -0
- package/bin/commands/priority-create.js.map +1 -0
- package/bin/commands/priority-list.js +47 -0
- package/bin/commands/priority-list.js.map +1 -0
- package/bin/commands/twist-logs.js +187 -0
- package/bin/commands/twist-logs.js.map +1 -0
- package/bin/index.js +129 -0
- package/bin/index.js.map +1 -0
- package/bin/package.json +3 -0
- package/bin/plot.cjs +3 -0
- package/bin/templates/AGENTS.template.md +403 -0
- package/bin/templates/CLAUDE.template.md +1 -0
- package/bin/templates/README.template.md +189 -0
- package/bin/utils/bundle.js +106 -0
- package/bin/utils/bundle.js.map +1 -0
- package/bin/utils/output.js +133 -0
- package/bin/utils/output.js.map +1 -0
- package/bin/utils/packageManager.js +65 -0
- package/bin/utils/packageManager.js.map +1 -0
- package/bin/utils/sse.js +100 -0
- package/bin/utils/sse.js.map +1 -0
- package/bin/utils/token.js +75 -0
- package/bin/utils/token.js.map +1 -0
- package/cli/templates/AGENTS.template.md +403 -0
- package/cli/templates/CLAUDE.template.md +1 -0
- package/cli/templates/README.template.md +189 -0
- package/dist/common/calendar.d.ts +144 -0
- package/dist/common/calendar.d.ts.map +1 -0
- package/dist/common/calendar.js +2 -0
- package/dist/common/calendar.js.map +1 -0
- package/dist/common/messaging.d.ts +84 -0
- package/dist/common/messaging.d.ts.map +1 -0
- package/dist/common/messaging.js +2 -0
- package/dist/common/messaging.js.map +1 -0
- package/dist/creator-docs.d.ts +11 -0
- package/dist/creator-docs.d.ts.map +1 -0
- package/dist/creator-docs.js +27 -0
- package/dist/creator-docs.js.map +1 -0
- package/dist/docs/.nojekyll +1 -0
- package/dist/docs/assets/favicon.svg +8 -0
- package/dist/docs/assets/hierarchy.js +1 -0
- package/dist/docs/assets/highlight.css +134 -0
- package/dist/docs/assets/icons.js +18 -0
- package/dist/docs/assets/icons.svg +1 -0
- package/dist/docs/assets/main.js +60 -0
- package/dist/docs/assets/navigation.js +1 -0
- package/dist/docs/assets/search.js +1 -0
- package/dist/docs/assets/style.css +1633 -0
- package/dist/docs/classes/tool.ITool.html +4 -0
- package/dist/docs/classes/tool.Tool.html +116 -0
- package/dist/docs/classes/tools_ai.AI.html +27 -0
- package/dist/docs/classes/tools_callbacks.Callbacks.html +45 -0
- package/dist/docs/classes/tools_integrations.Integrations.html +26 -0
- package/dist/docs/classes/tools_network.Network.html +68 -0
- package/dist/docs/classes/tools_plot.Plot.html +82 -0
- package/dist/docs/classes/tools_store.Store.html +53 -0
- package/dist/docs/classes/tools_tasks.Tasks.html +39 -0
- package/dist/docs/classes/tools_twists.Twists.html +59 -0
- package/dist/docs/classes/twist.Twist.html +96 -0
- package/dist/docs/documents/Advanced.html +91 -0
- package/dist/docs/documents/Building_Custom_Tools.html +200 -0
- package/dist/docs/documents/Built-in_Tools.html +170 -0
- package/dist/docs/documents/CLI_Reference.html +193 -0
- package/dist/docs/documents/Core_Concepts.html +163 -0
- package/dist/docs/documents/Getting_Started.html +94 -0
- package/dist/docs/documents/Runtime_Environment.html +128 -0
- package/dist/docs/enums/plot.ActivityLinkType.html +12 -0
- package/dist/docs/enums/plot.ActivityType.html +10 -0
- package/dist/docs/enums/plot.ActorType.html +10 -0
- package/dist/docs/enums/plot.ConferencingProvider.html +14 -0
- package/dist/docs/enums/tag.Tag.html +45 -0
- package/dist/docs/enums/tools_ai.AIModel.html +31 -0
- package/dist/docs/enums/tools_integrations.AuthLevel.html +7 -0
- package/dist/docs/enums/tools_integrations.AuthProvider.html +24 -0
- package/dist/docs/enums/tools_plot.ActivityAccess.html +8 -0
- package/dist/docs/enums/tools_plot.ContactAccess.html +5 -0
- package/dist/docs/enums/tools_plot.PriorityAccess.html +8 -0
- package/dist/docs/hierarchy.html +1 -0
- package/dist/docs/index.html +100 -0
- package/dist/docs/interfaces/common_calendar.Calendar.html +13 -0
- package/dist/docs/interfaces/common_calendar.CalendarTool.html +49 -0
- package/dist/docs/interfaces/common_calendar.SyncOptions.html +8 -0
- package/dist/docs/interfaces/tools_ai.AIRequest.html +46 -0
- package/dist/docs/interfaces/tools_ai.AIResponse.html +19 -0
- package/dist/docs/interfaces/tools_ai.FilePart.html +14 -0
- package/dist/docs/interfaces/tools_ai.ImagePart.html +11 -0
- package/dist/docs/interfaces/tools_ai.ReasoningPart.html +7 -0
- package/dist/docs/interfaces/tools_ai.RedactedReasoningPart.html +5 -0
- package/dist/docs/interfaces/tools_ai.TextPart.html +5 -0
- package/dist/docs/interfaces/tools_ai.ToolCallPart.html +9 -0
- package/dist/docs/interfaces/tools_ai.ToolExecutionOptions.html +9 -0
- package/dist/docs/interfaces/tools_ai.ToolResultPart.html +9 -0
- package/dist/docs/interfaces/tools_twists.TwistSource.html +13 -0
- package/dist/docs/interfaces/utils_types.ToolShed.html +11 -0
- package/dist/docs/modules/common_calendar.html +1 -0
- package/dist/docs/modules/index.html +1 -0
- package/dist/docs/modules/plot.html +1 -0
- package/dist/docs/modules/tag.html +1 -0
- package/dist/docs/modules/tool.html +1 -0
- package/dist/docs/modules/tools_ai.html +1 -0
- package/dist/docs/modules/tools_callbacks.html +1 -0
- package/dist/docs/modules/tools_integrations.html +1 -0
- package/dist/docs/modules/tools_network.html +1 -0
- package/dist/docs/modules/tools_plot.html +1 -0
- package/dist/docs/modules/tools_store.html +1 -0
- package/dist/docs/modules/tools_tasks.html +1 -0
- package/dist/docs/modules/tools_twists.html +1 -0
- package/dist/docs/modules/twist.html +1 -0
- package/dist/docs/modules/utils_types.html +1 -0
- package/dist/docs/modules.html +1 -0
- package/dist/docs/types/common_calendar.CalendarAuth.html +7 -0
- package/dist/docs/types/plot.Activity.html +64 -0
- package/dist/docs/types/plot.ActivityLink.html +22 -0
- package/dist/docs/types/plot.ActivityMeta.html +11 -0
- package/dist/docs/types/plot.ActivityUpdate.html +13 -0
- package/dist/docs/types/plot.Actor.html +15 -0
- package/dist/docs/types/plot.ActorId.html +4 -0
- package/dist/docs/types/plot.NewActivity.html +16 -0
- package/dist/docs/types/plot.NewContact.html +13 -0
- package/dist/docs/types/plot.NewPriority.html +5 -0
- package/dist/docs/types/plot.NoteType.html +1 -0
- package/dist/docs/types/plot.PickPriorityConfig.html +22 -0
- package/dist/docs/types/plot.Priority.html +8 -0
- package/dist/docs/types/tools_ai.AIAssistantMessage.html +4 -0
- package/dist/docs/types/tools_ai.AIMessage.html +3 -0
- package/dist/docs/types/tools_ai.AISource.html +11 -0
- package/dist/docs/types/tools_ai.AISystemMessage.html +7 -0
- package/dist/docs/types/tools_ai.AITool.html +19 -0
- package/dist/docs/types/tools_ai.AIToolMessage.html +4 -0
- package/dist/docs/types/tools_ai.AIToolSet.html +1 -0
- package/dist/docs/types/tools_ai.AIUsage.html +10 -0
- package/dist/docs/types/tools_ai.AIUserMessage.html +4 -0
- package/dist/docs/types/tools_ai.DataContent.html +2 -0
- package/dist/docs/types/tools_ai.ModelPreferences.html +24 -0
- package/dist/docs/types/tools_callbacks.Callback.html +8 -0
- package/dist/docs/types/tools_integrations.AuthToken.html +16 -0
- package/dist/docs/types/tools_integrations.Authorization.html +10 -0
- package/dist/docs/types/tools_network.WebhookRequest.html +15 -0
- package/dist/docs/types/tools_plot.ActivityIntentHandler.html +9 -0
- package/dist/docs/types/tools_twists.Log.html +6 -0
- package/dist/docs/types/tools_twists.TwistPermissions.html +12 -0
- package/dist/docs/types/utils_types.BuiltInTools.html +5 -0
- package/dist/docs/types/utils_types.CallbackMethods.html +3 -0
- package/dist/docs/types/utils_types.ExtractBuildReturn.html +2 -0
- package/dist/docs/types/utils_types.InferOptions.html +2 -0
- package/dist/docs/types/utils_types.InferTools.html +3 -0
- package/dist/docs/types/utils_types.NoFunctions.html +3 -0
- package/dist/docs/types/utils_types.NonFunction.html +2 -0
- package/dist/docs/types/utils_types.PromiseValues.html +3 -0
- package/dist/docs/types/utils_types.ToolBuilder.html +3 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/llm-docs/common/calendar.d.ts +9 -0
- package/dist/llm-docs/common/calendar.d.ts.map +1 -0
- package/dist/llm-docs/common/calendar.js +8 -0
- package/dist/llm-docs/common/calendar.js.map +1 -0
- package/dist/llm-docs/common/messaging.d.ts +9 -0
- package/dist/llm-docs/common/messaging.d.ts.map +1 -0
- package/dist/llm-docs/common/messaging.js +8 -0
- package/dist/llm-docs/common/messaging.js.map +1 -0
- package/dist/llm-docs/creator-docs.d.ts +9 -0
- package/dist/llm-docs/creator-docs.d.ts.map +1 -0
- package/dist/llm-docs/creator-docs.js +8 -0
- package/dist/llm-docs/creator-docs.js.map +1 -0
- package/dist/llm-docs/index.d.ts +11 -0
- package/dist/llm-docs/index.d.ts.map +1 -0
- package/dist/llm-docs/index.js +42 -0
- package/dist/llm-docs/index.js.map +1 -0
- package/dist/llm-docs/plot.d.ts +9 -0
- package/dist/llm-docs/plot.d.ts.map +1 -0
- package/dist/llm-docs/plot.js +8 -0
- package/dist/llm-docs/plot.js.map +1 -0
- package/dist/llm-docs/tag.d.ts +9 -0
- package/dist/llm-docs/tag.d.ts.map +1 -0
- package/dist/llm-docs/tag.js +8 -0
- package/dist/llm-docs/tag.js.map +1 -0
- package/dist/llm-docs/tool.d.ts +9 -0
- package/dist/llm-docs/tool.d.ts.map +1 -0
- package/dist/llm-docs/tool.js +8 -0
- package/dist/llm-docs/tool.js.map +1 -0
- package/dist/llm-docs/tools/ai.d.ts +9 -0
- package/dist/llm-docs/tools/ai.d.ts.map +1 -0
- package/dist/llm-docs/tools/ai.js +8 -0
- package/dist/llm-docs/tools/ai.js.map +1 -0
- package/dist/llm-docs/tools/callbacks.d.ts +9 -0
- package/dist/llm-docs/tools/callbacks.d.ts.map +1 -0
- package/dist/llm-docs/tools/callbacks.js +8 -0
- package/dist/llm-docs/tools/callbacks.js.map +1 -0
- package/dist/llm-docs/tools/integrations.d.ts +9 -0
- package/dist/llm-docs/tools/integrations.d.ts.map +1 -0
- package/dist/llm-docs/tools/integrations.js +8 -0
- package/dist/llm-docs/tools/integrations.js.map +1 -0
- package/dist/llm-docs/tools/network.d.ts +9 -0
- package/dist/llm-docs/tools/network.d.ts.map +1 -0
- package/dist/llm-docs/tools/network.js +8 -0
- package/dist/llm-docs/tools/network.js.map +1 -0
- package/dist/llm-docs/tools/plot.d.ts +9 -0
- package/dist/llm-docs/tools/plot.d.ts.map +1 -0
- package/dist/llm-docs/tools/plot.js +8 -0
- package/dist/llm-docs/tools/plot.js.map +1 -0
- package/dist/llm-docs/tools/store.d.ts +9 -0
- package/dist/llm-docs/tools/store.d.ts.map +1 -0
- package/dist/llm-docs/tools/store.js +8 -0
- package/dist/llm-docs/tools/store.js.map +1 -0
- package/dist/llm-docs/tools/tasks.d.ts +9 -0
- package/dist/llm-docs/tools/tasks.d.ts.map +1 -0
- package/dist/llm-docs/tools/tasks.js +8 -0
- package/dist/llm-docs/tools/tasks.js.map +1 -0
- package/dist/llm-docs/tools/twists.d.ts +9 -0
- package/dist/llm-docs/tools/twists.d.ts.map +1 -0
- package/dist/llm-docs/tools/twists.js +8 -0
- package/dist/llm-docs/tools/twists.js.map +1 -0
- package/dist/llm-docs/twist-guide-template.d.ts +9 -0
- package/dist/llm-docs/twist-guide-template.d.ts.map +1 -0
- package/dist/llm-docs/twist-guide-template.js +8 -0
- package/dist/llm-docs/twist-guide-template.js.map +1 -0
- package/dist/llm-docs/twist.d.ts +9 -0
- package/dist/llm-docs/twist.d.ts.map +1 -0
- package/dist/llm-docs/twist.js +8 -0
- package/dist/llm-docs/twist.js.map +1 -0
- package/dist/plot.d.ts +463 -0
- package/dist/plot.d.ts.map +1 -0
- package/dist/plot.js +68 -0
- package/dist/plot.js.map +1 -0
- package/dist/tag.d.ts +47 -0
- package/dist/tag.d.ts.map +1 -0
- package/dist/tag.js +51 -0
- package/dist/tag.js.map +1 -0
- package/dist/tool.d.ts +242 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +283 -0
- package/dist/tool.js.map +1 -0
- package/dist/tools/ai.d.ts +697 -0
- package/dist/tools/ai.d.ts.map +1 -0
- package/dist/tools/ai.js +104 -0
- package/dist/tools/ai.js.map +1 -0
- package/dist/tools/callbacks.d.ts +96 -0
- package/dist/tools/callbacks.d.ts.map +1 -0
- package/dist/tools/callbacks.js +40 -0
- package/dist/tools/callbacks.js.map +1 -0
- package/dist/tools/index.d.ts +9 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +9 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/integrations.d.ts +142 -0
- package/dist/tools/integrations.d.ts.map +1 -0
- package/dist/tools/integrations.js +79 -0
- package/dist/tools/integrations.js.map +1 -0
- package/dist/tools/network.d.ts +188 -0
- package/dist/tools/network.d.ts.map +1 -0
- package/dist/tools/network.js +87 -0
- package/dist/tools/network.js.map +1 -0
- package/dist/tools/plot.d.ts +252 -0
- package/dist/tools/plot.d.ts.map +1 -0
- package/dist/tools/plot.js +72 -0
- package/dist/tools/plot.js.map +1 -0
- package/dist/tools/store.d.ts +90 -0
- package/dist/tools/store.d.ts.map +1 -0
- package/dist/tools/store.js +48 -0
- package/dist/tools/store.js.map +1 -0
- package/dist/tools/tasks.d.ts +93 -0
- package/dist/tools/tasks.d.ts.map +1 -0
- package/dist/tools/tasks.js +58 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/tools/twists.d.ts +213 -0
- package/dist/tools/twists.d.ts.map +1 -0
- package/dist/tools/twists.js +26 -0
- package/dist/tools/twists.js.map +1 -0
- package/dist/twist-guide.d.ts +2 -0
- package/dist/twist-guide.d.ts.map +1 -0
- package/dist/twist-guide.js +9 -0
- package/dist/twist-guide.js.map +1 -0
- package/dist/twist.d.ts +204 -0
- package/dist/twist.d.ts.map +1 -0
- package/dist/twist.js +216 -0
- package/dist/twist.js.map +1 -0
- package/dist/utils/types.d.ts +91 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +2 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +206 -0
- package/tsconfig.base.json +28 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ITool } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in tool for persistent key-value storage.
|
|
4
|
+
*
|
|
5
|
+
* The Store tool provides twists and tools with a simple, persistent storage
|
|
6
|
+
* mechanism that survives worker restarts and invocations. Each twist/tool
|
|
7
|
+
* instance gets its own isolated storage namespace.
|
|
8
|
+
*
|
|
9
|
+
* **Note:** Store methods are also available directly on Twist and Tool classes
|
|
10
|
+
* via `this.get()`, `this.set()`, `this.clear()`, and `this.clearAll()`.
|
|
11
|
+
* This is the recommended approach for most use cases.
|
|
12
|
+
*
|
|
13
|
+
* **Storage Characteristics:**
|
|
14
|
+
* - Persistent across worker restarts
|
|
15
|
+
* - Isolated per twist/tool instance
|
|
16
|
+
* - Supports any JSON-serializable data
|
|
17
|
+
* - Async operations for scalability
|
|
18
|
+
*
|
|
19
|
+
* **Use Cases:**
|
|
20
|
+
* - Storing authentication tokens
|
|
21
|
+
* - Caching configuration data
|
|
22
|
+
* - Maintaining sync state
|
|
23
|
+
* - Persisting user preferences
|
|
24
|
+
* - Tracking processing checkpoints
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* class CalendarTool extends Tool {
|
|
29
|
+
* async saveAuthToken(provider: string, token: string) {
|
|
30
|
+
* // Using built-in set method (recommended)
|
|
31
|
+
* await this.set(`auth_token_${provider}`, token);
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* async getAuthToken(provider: string): Promise<string | null> {
|
|
35
|
+
* // Using built-in get method (recommended)
|
|
36
|
+
* return await this.get<string>(`auth_token_${provider}`);
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* async clearAllTokens() {
|
|
40
|
+
* // Using built-in clearAll method (recommended)
|
|
41
|
+
* await this.clearAll();
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare abstract class Store extends ITool {
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves a value from storage by key.
|
|
49
|
+
*
|
|
50
|
+
* Returns the stored value deserialized to the specified type,
|
|
51
|
+
* or null if the key doesn't exist or the value is null.
|
|
52
|
+
*
|
|
53
|
+
* @template T - The expected type of the stored value
|
|
54
|
+
* @param key - The storage key to retrieve
|
|
55
|
+
* @returns Promise resolving to the stored value or null
|
|
56
|
+
*/
|
|
57
|
+
abstract get<T>(key: string): Promise<T | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Stores a value in persistent storage.
|
|
60
|
+
*
|
|
61
|
+
* The value will be JSON-serialized and stored persistently.
|
|
62
|
+
* Any existing value at the same key will be overwritten.
|
|
63
|
+
*
|
|
64
|
+
* @template T - The type of value being stored
|
|
65
|
+
* @param key - The storage key to use
|
|
66
|
+
* @param value - The value to store (must be JSON-serializable)
|
|
67
|
+
* @returns Promise that resolves when the value is stored
|
|
68
|
+
*/
|
|
69
|
+
abstract set<T>(key: string, value: T): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Removes a specific key from storage.
|
|
72
|
+
*
|
|
73
|
+
* After this operation, get() calls for this key will return null.
|
|
74
|
+
* No error is thrown if the key doesn't exist.
|
|
75
|
+
*
|
|
76
|
+
* @param key - The storage key to remove
|
|
77
|
+
* @returns Promise that resolves when the key is removed
|
|
78
|
+
*/
|
|
79
|
+
abstract clear(key: string): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Removes all keys from this storage instance.
|
|
82
|
+
*
|
|
83
|
+
* This operation clears all data stored by this twist/tool instance
|
|
84
|
+
* but does not affect storage for other twists or tools.
|
|
85
|
+
*
|
|
86
|
+
* @returns Promise that resolves when all keys are removed
|
|
87
|
+
*/
|
|
88
|
+
abstract clearAll(): Promise<void>;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/tools/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,8BAAsB,KAAM,SAAQ,KAAK;IACvC;;;;;;;;;OASG;IAEH,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAE/C;;;;;;;;;;OAUG;IAEH,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAErD;;;;;;;;OAQG;IAEH,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1C;;;;;;;OAOG;IACH,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CACnC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ITool } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in tool for persistent key-value storage.
|
|
4
|
+
*
|
|
5
|
+
* The Store tool provides twists and tools with a simple, persistent storage
|
|
6
|
+
* mechanism that survives worker restarts and invocations. Each twist/tool
|
|
7
|
+
* instance gets its own isolated storage namespace.
|
|
8
|
+
*
|
|
9
|
+
* **Note:** Store methods are also available directly on Twist and Tool classes
|
|
10
|
+
* via `this.get()`, `this.set()`, `this.clear()`, and `this.clearAll()`.
|
|
11
|
+
* This is the recommended approach for most use cases.
|
|
12
|
+
*
|
|
13
|
+
* **Storage Characteristics:**
|
|
14
|
+
* - Persistent across worker restarts
|
|
15
|
+
* - Isolated per twist/tool instance
|
|
16
|
+
* - Supports any JSON-serializable data
|
|
17
|
+
* - Async operations for scalability
|
|
18
|
+
*
|
|
19
|
+
* **Use Cases:**
|
|
20
|
+
* - Storing authentication tokens
|
|
21
|
+
* - Caching configuration data
|
|
22
|
+
* - Maintaining sync state
|
|
23
|
+
* - Persisting user preferences
|
|
24
|
+
* - Tracking processing checkpoints
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* class CalendarTool extends Tool {
|
|
29
|
+
* async saveAuthToken(provider: string, token: string) {
|
|
30
|
+
* // Using built-in set method (recommended)
|
|
31
|
+
* await this.set(`auth_token_${provider}`, token);
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* async getAuthToken(provider: string): Promise<string | null> {
|
|
35
|
+
* // Using built-in get method (recommended)
|
|
36
|
+
* return await this.get<string>(`auth_token_${provider}`);
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* async clearAllTokens() {
|
|
40
|
+
* // Using built-in clearAll method (recommended)
|
|
41
|
+
* await this.clearAll();
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export class Store extends ITool {
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/tools/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,OAAgB,KAAM,SAAQ,KAAK;CAiDxC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ITool } from "..";
|
|
2
|
+
import type { Callback } from "./callbacks";
|
|
3
|
+
/**
|
|
4
|
+
* Run background tasks and scheduled jobs.
|
|
5
|
+
*
|
|
6
|
+
* The Run tool enables twists and tools to queue callbacks. This is especially
|
|
7
|
+
* iportant for long-running operations and batch processing, since twists
|
|
8
|
+
* operate within runtime limits. Run callbacks also benefit from automatic
|
|
9
|
+
* retries on failure.
|
|
10
|
+
*
|
|
11
|
+
* **Note:** Run methods are also available directly on Twist and Tool classes
|
|
12
|
+
* via `this.runTask()`, `this.cancelTask()`, and `this.cancelAllTasks()`.
|
|
13
|
+
* This is the recommended approach for most use cases.
|
|
14
|
+
*
|
|
15
|
+
* **Best Practices:**
|
|
16
|
+
* - Break long operations into smaller batches
|
|
17
|
+
* - Create callbacks first using `this.callback()`
|
|
18
|
+
* - Store intermediate state using the Store tool
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* class SyncTool extends Tool {
|
|
23
|
+
* async startBatchSync(totalItems: number) {
|
|
24
|
+
* // Store initial state using built-in set method
|
|
25
|
+
* await this.set("sync_progress", { processed: 0, total: totalItems });
|
|
26
|
+
*
|
|
27
|
+
* // Create callback and queue first batch using built-in methods
|
|
28
|
+
* const callback = await this.callback("processBatch", { batchNumber: 1 });
|
|
29
|
+
* await this.runTask(callback);
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* async processBatch(args: any, context: { batchNumber: number }) {
|
|
33
|
+
* // Process one batch of items
|
|
34
|
+
* const progress = await this.get("sync_progress");
|
|
35
|
+
*
|
|
36
|
+
* // ... process items ...
|
|
37
|
+
*
|
|
38
|
+
* if (progress.processed < progress.total) {
|
|
39
|
+
* // Queue next batch using built-in methods
|
|
40
|
+
* const callback = await this.callback("processBatch", {
|
|
41
|
+
* batchNumber: context.batchNumber + 1
|
|
42
|
+
* });
|
|
43
|
+
* await this.runTask(callback);
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* async scheduleCleanup() {
|
|
48
|
+
* const tomorrow = new Date();
|
|
49
|
+
* tomorrow.setDate(tomorrow.getDate() + 1);
|
|
50
|
+
*
|
|
51
|
+
* const callback = await this.callback("cleanupOldData");
|
|
52
|
+
* return await this.run(callback, { runAt: tomorrow });
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare abstract class Tasks extends ITool {
|
|
58
|
+
/**
|
|
59
|
+
* Queues a callback to execute in a separate worker context.
|
|
60
|
+
*
|
|
61
|
+
* The callback will be invoked either immediately or at a scheduled time
|
|
62
|
+
* in an isolated execution environment with limited resources. Use this
|
|
63
|
+
* for breaking up long-running operations into manageable chunks.
|
|
64
|
+
*
|
|
65
|
+
* @param callback - Callback created with `this.callback()`
|
|
66
|
+
* @param options - Optional configuration for the execution
|
|
67
|
+
* @param options.runAt - If provided, schedules execution at this time; otherwise runs immediately
|
|
68
|
+
* @returns Promise resolving to a cancellation token (only for scheduled executions)
|
|
69
|
+
*/
|
|
70
|
+
abstract runTask(callback: Callback, options?: {
|
|
71
|
+
runAt?: Date;
|
|
72
|
+
}): Promise<string | void>;
|
|
73
|
+
/**
|
|
74
|
+
* Cancels a previously scheduled execution.
|
|
75
|
+
*
|
|
76
|
+
* Prevents a scheduled function from executing. No error is thrown
|
|
77
|
+
* if the token is invalid or the execution has already completed.
|
|
78
|
+
*
|
|
79
|
+
* @param token - The cancellation token returned by runTask() with runAt option
|
|
80
|
+
* @returns Promise that resolves when the cancellation is processed
|
|
81
|
+
*/
|
|
82
|
+
abstract cancelTask(token: string): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Cancels all scheduled executions for this tool/twist.
|
|
85
|
+
*
|
|
86
|
+
* Cancels all pending scheduled executions created by this tool or twist
|
|
87
|
+
* instance. Immediate executions cannot be cancelled.
|
|
88
|
+
*
|
|
89
|
+
* @returns Promise that resolves when all cancellations are processed
|
|
90
|
+
*/
|
|
91
|
+
abstract cancelAllTasks(): Promise<void>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=tasks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../../src/tools/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAC3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,8BAAsB,KAAM,SAAQ,KAAK;IACvC;;;;;;;;;;;OAWG;IAEH,QAAQ,CAAC,OAAO,CACd,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,IAAI,CAAA;KAAE,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAEzB;;;;;;;;OAQG;IAEH,QAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAEjD;;;;;;;OAOG;IACH,QAAQ,CAAC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CACzC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ITool } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* Run background tasks and scheduled jobs.
|
|
4
|
+
*
|
|
5
|
+
* The Run tool enables twists and tools to queue callbacks. This is especially
|
|
6
|
+
* iportant for long-running operations and batch processing, since twists
|
|
7
|
+
* operate within runtime limits. Run callbacks also benefit from automatic
|
|
8
|
+
* retries on failure.
|
|
9
|
+
*
|
|
10
|
+
* **Note:** Run methods are also available directly on Twist and Tool classes
|
|
11
|
+
* via `this.runTask()`, `this.cancelTask()`, and `this.cancelAllTasks()`.
|
|
12
|
+
* This is the recommended approach for most use cases.
|
|
13
|
+
*
|
|
14
|
+
* **Best Practices:**
|
|
15
|
+
* - Break long operations into smaller batches
|
|
16
|
+
* - Create callbacks first using `this.callback()`
|
|
17
|
+
* - Store intermediate state using the Store tool
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* class SyncTool extends Tool {
|
|
22
|
+
* async startBatchSync(totalItems: number) {
|
|
23
|
+
* // Store initial state using built-in set method
|
|
24
|
+
* await this.set("sync_progress", { processed: 0, total: totalItems });
|
|
25
|
+
*
|
|
26
|
+
* // Create callback and queue first batch using built-in methods
|
|
27
|
+
* const callback = await this.callback("processBatch", { batchNumber: 1 });
|
|
28
|
+
* await this.runTask(callback);
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* async processBatch(args: any, context: { batchNumber: number }) {
|
|
32
|
+
* // Process one batch of items
|
|
33
|
+
* const progress = await this.get("sync_progress");
|
|
34
|
+
*
|
|
35
|
+
* // ... process items ...
|
|
36
|
+
*
|
|
37
|
+
* if (progress.processed < progress.total) {
|
|
38
|
+
* // Queue next batch using built-in methods
|
|
39
|
+
* const callback = await this.callback("processBatch", {
|
|
40
|
+
* batchNumber: context.batchNumber + 1
|
|
41
|
+
* });
|
|
42
|
+
* await this.runTask(callback);
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* async scheduleCleanup() {
|
|
47
|
+
* const tomorrow = new Date();
|
|
48
|
+
* tomorrow.setDate(tomorrow.getDate() + 1);
|
|
49
|
+
*
|
|
50
|
+
* const callback = await this.callback("cleanupOldData");
|
|
51
|
+
* return await this.run(callback, { runAt: tomorrow });
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export class Tasks extends ITool {
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=tasks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/tools/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAG3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,OAAgB,KAAM,SAAQ,KAAK;CAwCxC"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { type Callback, ITool } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* Twist source code structure containing dependencies and source files.
|
|
4
|
+
*/
|
|
5
|
+
export interface TwistSource {
|
|
6
|
+
/**
|
|
7
|
+
* Package dependencies with version specifiers
|
|
8
|
+
* @example { "@plotday/sdk": "workspace:^", "@plotday/tool-google-calendar": "^1.0.0" }
|
|
9
|
+
*/
|
|
10
|
+
dependencies: Record<string, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Source files with their content
|
|
13
|
+
* Must include "index.ts" as the entry point
|
|
14
|
+
* @example { "index.ts": "export default class MyTwist extends Twist {...}" }
|
|
15
|
+
*/
|
|
16
|
+
files: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Represents a log entry from a twist execution.
|
|
20
|
+
*/
|
|
21
|
+
export type Log = {
|
|
22
|
+
timestamp: Date;
|
|
23
|
+
environment: "personal" | "private" | "review" | "public";
|
|
24
|
+
severity: "log" | "error" | "warn" | "info";
|
|
25
|
+
message: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Twist permissions returned after deployment.
|
|
29
|
+
* Nested structure mapping domains to entities to permission flags.
|
|
30
|
+
*
|
|
31
|
+
* Format: { domain: { entity: flags[] } }
|
|
32
|
+
* - domain: Tool name (e.g., "network", "plot")
|
|
33
|
+
* - entity: Domain-specific identifier (e.g., URL pattern, resource type)
|
|
34
|
+
* - flags: Array of permission flags ("read", "write", "update", "use")
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* {
|
|
39
|
+
* "network": {
|
|
40
|
+
* "https://api.example.com/*": ["use"],
|
|
41
|
+
* "https://googleapis.com/*": ["use"]
|
|
42
|
+
* },
|
|
43
|
+
* "plot": {
|
|
44
|
+
* "activity:mentioned": ["read", "write", "update"],
|
|
45
|
+
* "priority": ["read", "write", "update"]
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export type TwistPermissions = Record<string, Record<string, string[]>>;
|
|
51
|
+
/**
|
|
52
|
+
* Built-in tool for managing twists and deployments.
|
|
53
|
+
*
|
|
54
|
+
* The Twists tool provides twists with the ability to create twist IDs
|
|
55
|
+
* and programmatically deploy twists.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* class TwistBuilderTwist extends Twist {
|
|
60
|
+
* build(build: ToolBuilder) {
|
|
61
|
+
* return {
|
|
62
|
+
* twists: build.get(Twists)
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
*
|
|
66
|
+
* async activate() {
|
|
67
|
+
* const twistId = await this.tools.twists.create();
|
|
68
|
+
* // Display twist ID to user
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare abstract class Twists extends ITool {
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new twist ID and grants access to people in the current priority.
|
|
76
|
+
*
|
|
77
|
+
* @returns Promise resolving to the generated twist ID
|
|
78
|
+
* @throws When twist creation fails
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const twistId = await twist.create();
|
|
83
|
+
* console.log(`Your twist ID: ${twistId}`);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
abstract create(): Promise<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Generates twist source code from a specification using AI.
|
|
89
|
+
*
|
|
90
|
+
* This method uses Claude AI to generate TypeScript source code and dependencies
|
|
91
|
+
* from a markdown specification. The generated source is validated by attempting
|
|
92
|
+
* to build it, with iterative error correction (up to 3 attempts).
|
|
93
|
+
*
|
|
94
|
+
* @param spec - Markdown specification describing the twist functionality
|
|
95
|
+
* @returns Promise resolving to twist source (dependencies and files)
|
|
96
|
+
* @throws When generation fails after maximum attempts
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const source = await twist.generate(`
|
|
101
|
+
* # Calendar Sync Twist
|
|
102
|
+
*
|
|
103
|
+
* This twist syncs Google Calendar events to Plot activities.
|
|
104
|
+
*
|
|
105
|
+
* ## Features
|
|
106
|
+
* - Authenticate with Google
|
|
107
|
+
* - Sync calendar events
|
|
108
|
+
* - Create activities from events
|
|
109
|
+
* `);
|
|
110
|
+
*
|
|
111
|
+
* // source.dependencies: { "@plotday/sdk": "workspace:^", ... }
|
|
112
|
+
* // source.files: { "index.ts": "export default class..." }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
abstract generate(spec: string): Promise<TwistSource>;
|
|
116
|
+
/**
|
|
117
|
+
* Deploys a twist programmatically.
|
|
118
|
+
*
|
|
119
|
+
* This method provides the same functionality as the plot deploy CLI
|
|
120
|
+
* command, but can be called from within a twist. Accepts either:
|
|
121
|
+
* - A pre-bundled module (JavaScript code)
|
|
122
|
+
* - A source object (dependencies + files) which is built in a sandbox
|
|
123
|
+
*
|
|
124
|
+
* @param options - Deployment configuration
|
|
125
|
+
* @param options.twistId - Twist ID for deployment
|
|
126
|
+
* @param options.module - Pre-bundled twist module code (mutually exclusive with source)
|
|
127
|
+
* @param options.source - Twist source code with dependencies (mutually exclusive with module)
|
|
128
|
+
* @param options.environment - Target environment (defaults to "personal")
|
|
129
|
+
* @param options.name - Optional twist name (required for first deploy)
|
|
130
|
+
* @param options.description - Optional twist description (required for first deploy)
|
|
131
|
+
* @param options.dryRun - If true, validates without deploying (returns errors if any)
|
|
132
|
+
* @returns Promise resolving to deployment result with version and optional errors
|
|
133
|
+
* @throws When deployment fails or user lacks access
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* // Deploy with a module
|
|
138
|
+
* const result = await twist.deploy({
|
|
139
|
+
* twistId: 'abc-123-...',
|
|
140
|
+
* module: 'export default class MyTwist extends Twist {...}',
|
|
141
|
+
* environment: 'personal',
|
|
142
|
+
* name: 'My Twist',
|
|
143
|
+
* description: 'Does something cool'
|
|
144
|
+
* });
|
|
145
|
+
* console.log(`Deployed version ${result.version}`);
|
|
146
|
+
*
|
|
147
|
+
* // Deploy with source
|
|
148
|
+
* const source = await twist.generate(spec);
|
|
149
|
+
* const result = await twist.deploy({
|
|
150
|
+
* twistId: 'abc-123-...',
|
|
151
|
+
* source,
|
|
152
|
+
* environment: 'personal',
|
|
153
|
+
* name: 'My Twist',
|
|
154
|
+
* });
|
|
155
|
+
*
|
|
156
|
+
* // Validate with dryRun
|
|
157
|
+
* const result = await twist.deploy({
|
|
158
|
+
* twistId: 'abc-123-...',
|
|
159
|
+
* source,
|
|
160
|
+
* dryRun: true,
|
|
161
|
+
* });
|
|
162
|
+
* if (result.errors?.length) {
|
|
163
|
+
* console.error('Build errors:', result.errors);
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
abstract deploy(options: {
|
|
168
|
+
twistId: string;
|
|
169
|
+
environment?: "personal" | "private" | "review";
|
|
170
|
+
name?: string;
|
|
171
|
+
description?: string;
|
|
172
|
+
dryRun?: boolean;
|
|
173
|
+
} & ({
|
|
174
|
+
module: string;
|
|
175
|
+
} | {
|
|
176
|
+
source: TwistSource;
|
|
177
|
+
})): Promise<{
|
|
178
|
+
version: string;
|
|
179
|
+
permissions: TwistPermissions;
|
|
180
|
+
errors?: string[];
|
|
181
|
+
}>;
|
|
182
|
+
/**
|
|
183
|
+
* Subscribes to logs from a twist.
|
|
184
|
+
*
|
|
185
|
+
* This method registers a callback to receive batches of logs from twist executions.
|
|
186
|
+
* The callback will be invoked with an array of logs whenever new logs are captured
|
|
187
|
+
* from the twist's console output.
|
|
188
|
+
*
|
|
189
|
+
* @param twistId - Twist ID (root ID) to watch logs for
|
|
190
|
+
* @param callback - Callback token created via CallbackTool that will receive log batches
|
|
191
|
+
* @returns Promise that resolves when the subscription is created
|
|
192
|
+
* @throws When subscription fails
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* // Create twist and callback
|
|
197
|
+
* const twistId = await this.twist.create();
|
|
198
|
+
* const callback = await this.callback.create("onLogs");
|
|
199
|
+
*
|
|
200
|
+
* // Subscribe to logs
|
|
201
|
+
* await this.twist.watchLogs(twistId, callback);
|
|
202
|
+
*
|
|
203
|
+
* // Implement handler
|
|
204
|
+
* async onLogs(logs: Log[]) {
|
|
205
|
+
* for (const log of logs) {
|
|
206
|
+
* console.log(`[${log.environment}] ${log.severity}: ${log.message}`);
|
|
207
|
+
* }
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
abstract watchLogs(twistId: string, callback: Callback): Promise<void>;
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=twists.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twists.d.ts","sourceRoot":"","sources":["../../src/tools/twists.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAErC;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1D,QAAQ,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IAC5C,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,8BAAsB,MAAO,SAAQ,KAAK;IACxC;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IAEH,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkDG;IAEH,QAAQ,CAAC,MAAM,CACb,OAAO,EAAE;QACP,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;QAChD,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,GAAG,CACA;QACE,MAAM,EAAE,MAAM,CAAC;KAChB,GACD;QACE,MAAM,EAAE,WAAW,CAAC;KACrB,CACJ,GACA,OAAO,CAAC;QACT,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,gBAAgB,CAAC;QAC9B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IAEH,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CACvE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ITool } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in tool for managing twists and deployments.
|
|
4
|
+
*
|
|
5
|
+
* The Twists tool provides twists with the ability to create twist IDs
|
|
6
|
+
* and programmatically deploy twists.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* class TwistBuilderTwist extends Twist {
|
|
11
|
+
* build(build: ToolBuilder) {
|
|
12
|
+
* return {
|
|
13
|
+
* twists: build.get(Twists)
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* async activate() {
|
|
18
|
+
* const twistId = await this.tools.twists.create();
|
|
19
|
+
* // Display twist ID to user
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export class Twists extends ITool {
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=twists.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twists.js","sourceRoot":"","sources":["../../src/tools/twists.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,EAAE,MAAM,IAAI,CAAC;AAuD1C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAgB,MAAO,SAAQ,KAAK;CAsJzC"}
|
|
@@ -0,0 +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 CPU time**: Each execution has limited CPU time (typically 10 seconds) and memory (128MB)\n- **Use the Run tool**: Queue separate chunks of work with `run.now(functionName, context)`\n- **Break long operations**: Split large operations into smaller batches that can be processed independently\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## twist Structure Pattern\n\n```typescript\nimport {\n type Activity,\n twist,\n type Priority,\n type ToolBuilder,\n} from \"@plotday/twister\";\nimport { Plot } from \"@plotday/twister/tools/plot\";\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.Task,\n title: \"Connect your account\",\n links: [authLink],\n });\n}\n```\n\n**Store Parent Activity for Later:**\n\n```typescript\nconst activity = await this.tools.plot.createActivity({\n type: ActivityType.Task,\n title: \"Setup\",\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\nawait this.tools.plot.createActivity({\n type: ActivityType.Task,\n title: \"Task with links\",\n links: [urlLink, callbackLink],\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.Task,\n title: \"Connect Google account\",\n links: [authLink],\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\nPattern for syncing external data with callbacks:\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(activity: Activity, calendarId: string): Promise<void> {\n // Process incoming event from external service\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## 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 links,\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 execution time, you must break long operations into batches. Each batch runs independently in a new execution context.\n\n### Key Principles\n\n1. **Store state between batches**: Use the Store tool to persist progress\n2. **Queue next batch**: Use the Run tool to schedule the next chunk\n3. **Clean up when done**: Delete stored state after completion\n4. **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 });\n\n // Queue first batch using runTask method\n const callback = await this.callback(this.syncBatch, resourceId);\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 (keep under time limit)\n const result = await this.fetchBatch(state.nextPageToken);\n\n // Process results\n for (const item of result.items) {\n await this.tools.plot.createActivity(item);\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 });\n\n // Queue next batch (runs in new execution context)\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 note: `Sync complete: ${state.itemsProcessed + result.items.length} items processed`,\n });\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 note: `Failed to complete operation: ${error.message}`,\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- 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.\n- Tools are declared in the `build` method and accessed via `this.tools.toolName` in twist methods.\n- **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.\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\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
|
+
//# sourceMappingURL=twist-guide.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twist-guide.d.ts","sourceRoot":"","sources":["../src/twist-guide.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,WAAW,onZAAsB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twist Implementation Guide
|
|
3
|
+
*
|
|
4
|
+
* This guide is used by AI systems to generate Plot twists.
|
|
5
|
+
* Auto-generated from cli/templates/AGENTS.template.md during build.
|
|
6
|
+
*/
|
|
7
|
+
import twistsGuideTemplate from "./llm-docs/twist-guide-template.js";
|
|
8
|
+
export const TWIST_GUIDE = twistsGuideTemplate;
|
|
9
|
+
//# sourceMappingURL=twist-guide.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twist-guide.js","sourceRoot":"","sources":["../src/twist-guide.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,mBAAmB,MAAM,oCAAoC,CAAC;AAErE,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,CAAC"}
|