@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
package/dist/twist.d.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { type Priority } from "./plot";
|
|
2
|
+
import { type ITool } from "./tool";
|
|
3
|
+
import type { Callback } from "./tools/callbacks";
|
|
4
|
+
import type { InferTools, ToolBuilder, ToolShed } from "./utils/types";
|
|
5
|
+
/**
|
|
6
|
+
* Base class for all twists.
|
|
7
|
+
*
|
|
8
|
+
* Twists are activated in a Plot priority and have access to that priority and all
|
|
9
|
+
* its descendants.
|
|
10
|
+
*
|
|
11
|
+
* Override build() to declare tool dependencies and lifecycle methods to handle events.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* class FlatteringTwist extends Twist<FlatteringTwist> {
|
|
16
|
+
* build(build: ToolBuilder) {
|
|
17
|
+
* return {
|
|
18
|
+
* plot: build(Plot),
|
|
19
|
+
* };
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* async activate(priority: Pick<Priority, "id">) {
|
|
23
|
+
* // Initialize twist for the given priority
|
|
24
|
+
* await this.tools.plot.createActivity({
|
|
25
|
+
* type: ActivityType.Note,
|
|
26
|
+
* note: "Hello, good looking!",
|
|
27
|
+
* });
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare abstract class Twist<TSelf> {
|
|
33
|
+
protected id: string;
|
|
34
|
+
private toolShed;
|
|
35
|
+
constructor(id: string, toolShed: ToolShed);
|
|
36
|
+
/**
|
|
37
|
+
* Gets the initialized tools for this twist.
|
|
38
|
+
* @throws Error if called before initialization is complete
|
|
39
|
+
*/
|
|
40
|
+
protected get tools(): InferTools<TSelf>;
|
|
41
|
+
/**
|
|
42
|
+
* Declares tool dependencies for this twist.
|
|
43
|
+
* Return an object mapping tool names to build() promises.
|
|
44
|
+
*
|
|
45
|
+
* @param build - The build function to use for declaring dependencies
|
|
46
|
+
* @returns Object mapping tool names to tool promises
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* build(build: ToolBuilder) {
|
|
51
|
+
* return {
|
|
52
|
+
* plot: build(Plot),
|
|
53
|
+
* calendar: build(GoogleCalendar, { apiKey: "..." }),
|
|
54
|
+
* };
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
abstract build(build: ToolBuilder): Record<string, Promise<ITool>>;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a persistent callback to a method on this twist.
|
|
61
|
+
*
|
|
62
|
+
* ExtraArgs are strongly typed to match the method's signature after the first argument.
|
|
63
|
+
*
|
|
64
|
+
* @param fn - The method to callback
|
|
65
|
+
* @param extraArgs - Additional arguments to pass (type-checked, must be serializable)
|
|
66
|
+
* @returns Promise resolving to a persistent callback token
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const callback = await this.callback(this.onWebhook, "calendar", 123);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
protected callback(fn: Function, ...extraArgs: any[]): Promise<Callback>;
|
|
74
|
+
/**
|
|
75
|
+
* Deletes a specific callback by its token.
|
|
76
|
+
*
|
|
77
|
+
* @param token - The callback token to delete
|
|
78
|
+
* @returns Promise that resolves when the callback is deleted
|
|
79
|
+
*/
|
|
80
|
+
protected deleteCallback(token: Callback): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Deletes all callbacks for this twist.
|
|
83
|
+
*
|
|
84
|
+
* @returns Promise that resolves when all callbacks are deleted
|
|
85
|
+
*/
|
|
86
|
+
protected deleteAllCallbacks(): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Executes a callback by its token.
|
|
89
|
+
*
|
|
90
|
+
* @param token - The callback token to execute
|
|
91
|
+
* @param args - Optional arguments to pass to the callback
|
|
92
|
+
* @returns Promise resolving to the callback result
|
|
93
|
+
*/
|
|
94
|
+
protected run(token: Callback, ...args: []): Promise<any>;
|
|
95
|
+
/**
|
|
96
|
+
* Retrieves a value from persistent storage by key.
|
|
97
|
+
*
|
|
98
|
+
* @template T - The expected type of the stored value
|
|
99
|
+
* @param key - The storage key to retrieve
|
|
100
|
+
* @returns Promise resolving to the stored value or null
|
|
101
|
+
*/
|
|
102
|
+
protected get<T>(key: string): Promise<T | null>;
|
|
103
|
+
/**
|
|
104
|
+
* Stores a value in persistent storage.
|
|
105
|
+
*
|
|
106
|
+
* **Important**: Values must be JSON-serializable. Functions, Symbols, and undefined values
|
|
107
|
+
* cannot be stored directly.
|
|
108
|
+
*
|
|
109
|
+
* **For function references**: Use callbacks instead of storing functions directly.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // ❌ WRONG: Cannot store functions directly
|
|
114
|
+
* await this.set("handler", this.myHandler);
|
|
115
|
+
*
|
|
116
|
+
* // ✅ CORRECT: Create a callback token first
|
|
117
|
+
* const token = await this.callback(this.myHandler, "arg1", "arg2");
|
|
118
|
+
* await this.set("handler_token", token);
|
|
119
|
+
*
|
|
120
|
+
* // Later, execute the callback
|
|
121
|
+
* const token = await this.get<string>("handler_token");
|
|
122
|
+
* await this.run(token, args);
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @template T - The type of value being stored
|
|
126
|
+
* @param key - The storage key to use
|
|
127
|
+
* @param value - The value to store (must be JSON-serializable)
|
|
128
|
+
* @returns Promise that resolves when the value is stored
|
|
129
|
+
*/
|
|
130
|
+
protected set<T>(key: string, value: T): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Removes a specific key from persistent storage.
|
|
133
|
+
*
|
|
134
|
+
* @param key - The storage key to remove
|
|
135
|
+
* @returns Promise that resolves when the key is removed
|
|
136
|
+
*/
|
|
137
|
+
protected clear(key: string): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Removes all keys from this twist's storage.
|
|
140
|
+
*
|
|
141
|
+
* @returns Promise that resolves when all keys are removed
|
|
142
|
+
*/
|
|
143
|
+
protected clearAll(): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Queues a callback to execute in a separate worker context.
|
|
146
|
+
*
|
|
147
|
+
* @param callback - The callback token created with `this.callback()`
|
|
148
|
+
* @param options - Optional configuration for the execution
|
|
149
|
+
* @param options.runAt - If provided, schedules execution at this time; otherwise runs immediately
|
|
150
|
+
* @returns Promise resolving to a cancellation token (only for scheduled executions)
|
|
151
|
+
*/
|
|
152
|
+
protected runTask(callback: Callback, options?: {
|
|
153
|
+
runAt?: Date;
|
|
154
|
+
}): Promise<string | void>;
|
|
155
|
+
/**
|
|
156
|
+
* Cancels a previously scheduled execution.
|
|
157
|
+
*
|
|
158
|
+
* @param token - The cancellation token returned by runTask() with runAt option
|
|
159
|
+
* @returns Promise that resolves when the cancellation is processed
|
|
160
|
+
*/
|
|
161
|
+
protected cancelTask(token: string): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Cancels all scheduled executions for this twist.
|
|
164
|
+
*
|
|
165
|
+
* @returns Promise that resolves when all cancellations are processed
|
|
166
|
+
*/
|
|
167
|
+
protected cancelAllTasks(): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Called when the twist is activated for a specific priority.
|
|
170
|
+
*
|
|
171
|
+
* This method should contain initialization logic such as setting up
|
|
172
|
+
* initial activities, configuring webhooks, or establishing external connections.
|
|
173
|
+
*
|
|
174
|
+
* @param priority - The priority context containing the priority ID
|
|
175
|
+
* @returns Promise that resolves when activation is complete
|
|
176
|
+
*/
|
|
177
|
+
activate(priority: Pick<Priority, "id">): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* Called when a new version of the twist is deployed to an existing priority.
|
|
180
|
+
*
|
|
181
|
+
* This method should contain migration logic for updating old data structures
|
|
182
|
+
* or setting up new resources that weren't needed by the previous version.
|
|
183
|
+
* It is called with the new version for each active priorityTwist.
|
|
184
|
+
*
|
|
185
|
+
* @returns Promise that resolves when upgrade is complete
|
|
186
|
+
*/
|
|
187
|
+
upgrade(): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Called when the twist is removed from a priority.
|
|
190
|
+
*
|
|
191
|
+
* This method should contain cleanup logic such as removing webhooks,
|
|
192
|
+
* cleaning up external resources, or performing final data operations.
|
|
193
|
+
*
|
|
194
|
+
* @returns Promise that resolves when deactivation is complete
|
|
195
|
+
*/
|
|
196
|
+
deactivate(): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Waits for tool initialization to complete.
|
|
199
|
+
* Called automatically by the entrypoint before lifecycle methods.
|
|
200
|
+
* @internal
|
|
201
|
+
*/
|
|
202
|
+
waitForReady(): Promise<void>;
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=twist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twist.d.ts","sourceRoot":"","sources":["../src/twist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,8BAAs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,EAAE,IAAI,CAAA;KAAE,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIzB;;;;;OAKG;cACa,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD;;;;OAIG;cACa,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/C;;;;;;;;OAQG;IAEH,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD;;;;;;;;OAQG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB;;;;;;;OAOG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
|
package/dist/twist.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all twists.
|
|
3
|
+
*
|
|
4
|
+
* Twists are activated in a Plot priority and have access to that priority and all
|
|
5
|
+
* its descendants.
|
|
6
|
+
*
|
|
7
|
+
* Override build() to declare tool dependencies and lifecycle methods to handle events.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* class FlatteringTwist extends Twist<FlatteringTwist> {
|
|
12
|
+
* build(build: ToolBuilder) {
|
|
13
|
+
* return {
|
|
14
|
+
* plot: build(Plot),
|
|
15
|
+
* };
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* async activate(priority: Pick<Priority, "id">) {
|
|
19
|
+
* // Initialize twist for the given priority
|
|
20
|
+
* await this.tools.plot.createActivity({
|
|
21
|
+
* type: ActivityType.Note,
|
|
22
|
+
* note: "Hello, good looking!",
|
|
23
|
+
* });
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export class Twist {
|
|
29
|
+
id;
|
|
30
|
+
toolShed;
|
|
31
|
+
constructor(id, toolShed) {
|
|
32
|
+
this.id = id;
|
|
33
|
+
this.toolShed = toolShed;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the initialized tools for this twist.
|
|
37
|
+
* @throws Error if called before initialization is complete
|
|
38
|
+
*/
|
|
39
|
+
get tools() {
|
|
40
|
+
return this.toolShed.getTools();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a persistent callback to a method on this twist.
|
|
44
|
+
*
|
|
45
|
+
* ExtraArgs are strongly typed to match the method's signature after the first argument.
|
|
46
|
+
*
|
|
47
|
+
* @param fn - The method to callback
|
|
48
|
+
* @param extraArgs - Additional arguments to pass (type-checked, must be serializable)
|
|
49
|
+
* @returns Promise resolving to a persistent callback token
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const callback = await this.callback(this.onWebhook, "calendar", 123);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async callback(fn, ...extraArgs) {
|
|
57
|
+
return this.tools.callbacks.create(fn, ...extraArgs);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Deletes a specific callback by its token.
|
|
61
|
+
*
|
|
62
|
+
* @param token - The callback token to delete
|
|
63
|
+
* @returns Promise that resolves when the callback is deleted
|
|
64
|
+
*/
|
|
65
|
+
async deleteCallback(token) {
|
|
66
|
+
return this.tools.callbacks.delete(token);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Deletes all callbacks for this twist.
|
|
70
|
+
*
|
|
71
|
+
* @returns Promise that resolves when all callbacks are deleted
|
|
72
|
+
*/
|
|
73
|
+
async deleteAllCallbacks() {
|
|
74
|
+
return this.tools.callbacks.deleteAll();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Executes a callback by its token.
|
|
78
|
+
*
|
|
79
|
+
* @param token - The callback token to execute
|
|
80
|
+
* @param args - Optional arguments to pass to the callback
|
|
81
|
+
* @returns Promise resolving to the callback result
|
|
82
|
+
*/
|
|
83
|
+
async run(token, ...args) {
|
|
84
|
+
return this.tools.callbacks.run(token, ...args);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Retrieves a value from persistent storage by key.
|
|
88
|
+
*
|
|
89
|
+
* @template T - The expected type of the stored value
|
|
90
|
+
* @param key - The storage key to retrieve
|
|
91
|
+
* @returns Promise resolving to the stored value or null
|
|
92
|
+
*/
|
|
93
|
+
async get(key) {
|
|
94
|
+
return this.tools.store.get(key);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Stores a value in persistent storage.
|
|
98
|
+
*
|
|
99
|
+
* **Important**: Values must be JSON-serializable. Functions, Symbols, and undefined values
|
|
100
|
+
* cannot be stored directly.
|
|
101
|
+
*
|
|
102
|
+
* **For function references**: Use callbacks instead of storing functions directly.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* // ❌ WRONG: Cannot store functions directly
|
|
107
|
+
* await this.set("handler", this.myHandler);
|
|
108
|
+
*
|
|
109
|
+
* // ✅ CORRECT: Create a callback token first
|
|
110
|
+
* const token = await this.callback(this.myHandler, "arg1", "arg2");
|
|
111
|
+
* await this.set("handler_token", token);
|
|
112
|
+
*
|
|
113
|
+
* // Later, execute the callback
|
|
114
|
+
* const token = await this.get<string>("handler_token");
|
|
115
|
+
* await this.run(token, args);
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @template T - The type of value being stored
|
|
119
|
+
* @param key - The storage key to use
|
|
120
|
+
* @param value - The value to store (must be JSON-serializable)
|
|
121
|
+
* @returns Promise that resolves when the value is stored
|
|
122
|
+
*/
|
|
123
|
+
async set(key, value) {
|
|
124
|
+
return this.tools.store.set(key, value);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Removes a specific key from persistent storage.
|
|
128
|
+
*
|
|
129
|
+
* @param key - The storage key to remove
|
|
130
|
+
* @returns Promise that resolves when the key is removed
|
|
131
|
+
*/
|
|
132
|
+
async clear(key) {
|
|
133
|
+
return this.tools.store.clear(key);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Removes all keys from this twist's storage.
|
|
137
|
+
*
|
|
138
|
+
* @returns Promise that resolves when all keys are removed
|
|
139
|
+
*/
|
|
140
|
+
async clearAll() {
|
|
141
|
+
return this.tools.store.clearAll();
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Queues a callback to execute in a separate worker context.
|
|
145
|
+
*
|
|
146
|
+
* @param callback - The callback token created with `this.callback()`
|
|
147
|
+
* @param options - Optional configuration for the execution
|
|
148
|
+
* @param options.runAt - If provided, schedules execution at this time; otherwise runs immediately
|
|
149
|
+
* @returns Promise resolving to a cancellation token (only for scheduled executions)
|
|
150
|
+
*/
|
|
151
|
+
async runTask(callback, options) {
|
|
152
|
+
return this.tools.tasks.runTask(callback, options);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Cancels a previously scheduled execution.
|
|
156
|
+
*
|
|
157
|
+
* @param token - The cancellation token returned by runTask() with runAt option
|
|
158
|
+
* @returns Promise that resolves when the cancellation is processed
|
|
159
|
+
*/
|
|
160
|
+
async cancelTask(token) {
|
|
161
|
+
return this.tools.tasks.cancelTask(token);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Cancels all scheduled executions for this twist.
|
|
165
|
+
*
|
|
166
|
+
* @returns Promise that resolves when all cancellations are processed
|
|
167
|
+
*/
|
|
168
|
+
async cancelAllTasks() {
|
|
169
|
+
return this.tools.tasks.cancelAllTasks();
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Called when the twist is activated for a specific priority.
|
|
173
|
+
*
|
|
174
|
+
* This method should contain initialization logic such as setting up
|
|
175
|
+
* initial activities, configuring webhooks, or establishing external connections.
|
|
176
|
+
*
|
|
177
|
+
* @param priority - The priority context containing the priority ID
|
|
178
|
+
* @returns Promise that resolves when activation is complete
|
|
179
|
+
*/
|
|
180
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
181
|
+
activate(priority) {
|
|
182
|
+
return Promise.resolve();
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Called when a new version of the twist is deployed to an existing priority.
|
|
186
|
+
*
|
|
187
|
+
* This method should contain migration logic for updating old data structures
|
|
188
|
+
* or setting up new resources that weren't needed by the previous version.
|
|
189
|
+
* It is called with the new version for each active priorityTwist.
|
|
190
|
+
*
|
|
191
|
+
* @returns Promise that resolves when upgrade is complete
|
|
192
|
+
*/
|
|
193
|
+
upgrade() {
|
|
194
|
+
return Promise.resolve();
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Called when the twist is removed from a priority.
|
|
198
|
+
*
|
|
199
|
+
* This method should contain cleanup logic such as removing webhooks,
|
|
200
|
+
* cleaning up external resources, or performing final data operations.
|
|
201
|
+
*
|
|
202
|
+
* @returns Promise that resolves when deactivation is complete
|
|
203
|
+
*/
|
|
204
|
+
deactivate() {
|
|
205
|
+
return Promise.resolve();
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Waits for tool initialization to complete.
|
|
209
|
+
* Called automatically by the entrypoint before lifecycle methods.
|
|
210
|
+
* @internal
|
|
211
|
+
*/
|
|
212
|
+
async waitForReady() {
|
|
213
|
+
await this.toolShed.waitForReady();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=twist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twist.js","sourceRoot":"","sources":["../src/twist.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAgB,KAAK;IACH;IAAoB;IAA1C,YAAsB,EAAU,EAAU,QAAkB;QAAtC,OAAE,GAAF,EAAE,CAAQ;QAAU,aAAQ,GAAR,QAAQ,CAAU;IAAG,CAAC;IAEhE;;;O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CAAC,QAAQ;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IACrC,CAAC;IAED;;;;;;;OAOG;IACO,KAAK,CAAC,OAAO,CACrB,QAAkB,EAClB,OAA0B;QAE1B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,UAAU,CAAC,KAAa;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACO,KAAK,CAAC,cAAc;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;IAC3C,CAAC;IAED;;;;;;;;OAQG;IACH,6DAA6D;IAC7D,QAAQ,CAAC,QAA8B;QACrC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;;;;;;;OAQG;IACH,OAAO;QACL,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;;;;;;OAOG;IACH,UAAU;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal type utilities for SDK implementation.
|
|
3
|
+
*
|
|
4
|
+
* This file contains advanced TypeScript type utilities used internally
|
|
5
|
+
* by the SDK to provide type-safe APIs. Most developers don't need to
|
|
6
|
+
* reference these types directly - they work behind the scenes to power
|
|
7
|
+
* the Twist and Tool APIs.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
import type { Callbacks } from "../tools/callbacks";
|
|
12
|
+
import type { Store } from "../tools/store";
|
|
13
|
+
import type { Tasks } from "../tools/tasks";
|
|
14
|
+
/**
|
|
15
|
+
* Unwraps Promise types to their resolved values.
|
|
16
|
+
* Converts { foo: Promise<string> } to { foo: string }
|
|
17
|
+
*/
|
|
18
|
+
export type PromiseValues<T> = {
|
|
19
|
+
[K in keyof T]: T[K] extends Promise<infer U> ? U : T[K];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Extracts the return type from an instance build method.
|
|
23
|
+
*/
|
|
24
|
+
export type ExtractBuildReturn<T> = T extends {
|
|
25
|
+
build: (...args: any[]) => infer R;
|
|
26
|
+
} ? R : {};
|
|
27
|
+
/**
|
|
28
|
+
* Built-in tools available to all twists and tools.
|
|
29
|
+
*/
|
|
30
|
+
export type BuiltInTools = {
|
|
31
|
+
callbacks: Callbacks;
|
|
32
|
+
store: Store;
|
|
33
|
+
tasks: Tasks;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Infers the complete set of tools available to an twist or tool,
|
|
37
|
+
* combining tools declared in build with built-in tools.
|
|
38
|
+
*/
|
|
39
|
+
export type InferTools<T> = PromiseValues<ExtractBuildReturn<T>> & BuiltInTools;
|
|
40
|
+
/**
|
|
41
|
+
* Infers the options type from a constructor's second parameter.
|
|
42
|
+
*/
|
|
43
|
+
export type InferOptions<T> = T extends {
|
|
44
|
+
Options: infer O;
|
|
45
|
+
} ? O : unknown;
|
|
46
|
+
/**
|
|
47
|
+
* Function type for building tool dependencies.
|
|
48
|
+
* Used in build methods to request tool instances.
|
|
49
|
+
*/
|
|
50
|
+
export type ToolBuilder = <TC extends abstract new (...args: any) => any>(ToolClass: TC, options?: InferOptions<TC>) => Promise<InstanceType<TC>>;
|
|
51
|
+
/**
|
|
52
|
+
* Interface for managing tool initialization and lifecycle.
|
|
53
|
+
* Implemented by the twist runtime to provide tools to twists and tools.
|
|
54
|
+
*/
|
|
55
|
+
export interface ToolShed {
|
|
56
|
+
/**
|
|
57
|
+
* Build function for requesting tool dependencies
|
|
58
|
+
*/
|
|
59
|
+
build: ToolBuilder;
|
|
60
|
+
/**
|
|
61
|
+
* Whether tools are ready (all promises resolved)
|
|
62
|
+
*/
|
|
63
|
+
readonly ready: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Wait for all tool promises to resolve
|
|
66
|
+
*/
|
|
67
|
+
waitForReady(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Get resolved tools (throws if not ready)
|
|
70
|
+
*/
|
|
71
|
+
getTools<T>(): T;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Represents any non-function type.
|
|
75
|
+
*/
|
|
76
|
+
export type NonFunction = Exclude<unknown, (...args: any[]) => any>;
|
|
77
|
+
/**
|
|
78
|
+
* Filters out function properties from a type, keeping only data properties.
|
|
79
|
+
* For arrays, keeps the array structure while filtering functions from elements.
|
|
80
|
+
*/
|
|
81
|
+
export type NoFunctions<T> = T extends (...args: any[]) => any ? never : T extends object ? {
|
|
82
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? never : T[K];
|
|
83
|
+
} : T;
|
|
84
|
+
/**
|
|
85
|
+
* Extracts method names from a type that are functions.
|
|
86
|
+
* Used to type-check callback method references.
|
|
87
|
+
*/
|
|
88
|
+
export type CallbackMethods<T> = {
|
|
89
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
|
|
90
|
+
}[keyof T];
|
|
91
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAM5C;;;G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