@plotday/twister 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +261 -0
  3. package/bin/commands/build.js +108 -0
  4. package/bin/commands/build.js.map +1 -0
  5. package/bin/commands/create.js +230 -0
  6. package/bin/commands/create.js.map +1 -0
  7. package/bin/commands/deploy.js +292 -0
  8. package/bin/commands/deploy.js.map +1 -0
  9. package/bin/commands/generate.js +301 -0
  10. package/bin/commands/generate.js.map +1 -0
  11. package/bin/commands/lint.js +69 -0
  12. package/bin/commands/lint.js.map +1 -0
  13. package/bin/commands/login.js +140 -0
  14. package/bin/commands/login.js.map +1 -0
  15. package/bin/commands/priority-create.js +102 -0
  16. package/bin/commands/priority-create.js.map +1 -0
  17. package/bin/commands/priority-list.js +47 -0
  18. package/bin/commands/priority-list.js.map +1 -0
  19. package/bin/commands/twist-logs.js +187 -0
  20. package/bin/commands/twist-logs.js.map +1 -0
  21. package/bin/index.js +129 -0
  22. package/bin/index.js.map +1 -0
  23. package/bin/package.json +3 -0
  24. package/bin/plot.cjs +3 -0
  25. package/bin/templates/AGENTS.template.md +403 -0
  26. package/bin/templates/CLAUDE.template.md +1 -0
  27. package/bin/templates/README.template.md +189 -0
  28. package/bin/utils/bundle.js +106 -0
  29. package/bin/utils/bundle.js.map +1 -0
  30. package/bin/utils/output.js +133 -0
  31. package/bin/utils/output.js.map +1 -0
  32. package/bin/utils/packageManager.js +65 -0
  33. package/bin/utils/packageManager.js.map +1 -0
  34. package/bin/utils/sse.js +100 -0
  35. package/bin/utils/sse.js.map +1 -0
  36. package/bin/utils/token.js +75 -0
  37. package/bin/utils/token.js.map +1 -0
  38. package/cli/templates/AGENTS.template.md +403 -0
  39. package/cli/templates/CLAUDE.template.md +1 -0
  40. package/cli/templates/README.template.md +189 -0
  41. package/dist/common/calendar.d.ts +144 -0
  42. package/dist/common/calendar.d.ts.map +1 -0
  43. package/dist/common/calendar.js +2 -0
  44. package/dist/common/calendar.js.map +1 -0
  45. package/dist/common/messaging.d.ts +84 -0
  46. package/dist/common/messaging.d.ts.map +1 -0
  47. package/dist/common/messaging.js +2 -0
  48. package/dist/common/messaging.js.map +1 -0
  49. package/dist/creator-docs.d.ts +11 -0
  50. package/dist/creator-docs.d.ts.map +1 -0
  51. package/dist/creator-docs.js +27 -0
  52. package/dist/creator-docs.js.map +1 -0
  53. package/dist/docs/.nojekyll +1 -0
  54. package/dist/docs/assets/favicon.svg +8 -0
  55. package/dist/docs/assets/hierarchy.js +1 -0
  56. package/dist/docs/assets/highlight.css +134 -0
  57. package/dist/docs/assets/icons.js +18 -0
  58. package/dist/docs/assets/icons.svg +1 -0
  59. package/dist/docs/assets/main.js +60 -0
  60. package/dist/docs/assets/navigation.js +1 -0
  61. package/dist/docs/assets/search.js +1 -0
  62. package/dist/docs/assets/style.css +1633 -0
  63. package/dist/docs/classes/tool.ITool.html +4 -0
  64. package/dist/docs/classes/tool.Tool.html +116 -0
  65. package/dist/docs/classes/tools_ai.AI.html +27 -0
  66. package/dist/docs/classes/tools_callbacks.Callbacks.html +45 -0
  67. package/dist/docs/classes/tools_integrations.Integrations.html +26 -0
  68. package/dist/docs/classes/tools_network.Network.html +68 -0
  69. package/dist/docs/classes/tools_plot.Plot.html +82 -0
  70. package/dist/docs/classes/tools_store.Store.html +53 -0
  71. package/dist/docs/classes/tools_tasks.Tasks.html +39 -0
  72. package/dist/docs/classes/tools_twists.Twists.html +59 -0
  73. package/dist/docs/classes/twist.Twist.html +96 -0
  74. package/dist/docs/documents/Advanced.html +91 -0
  75. package/dist/docs/documents/Building_Custom_Tools.html +200 -0
  76. package/dist/docs/documents/Built-in_Tools.html +170 -0
  77. package/dist/docs/documents/CLI_Reference.html +193 -0
  78. package/dist/docs/documents/Core_Concepts.html +163 -0
  79. package/dist/docs/documents/Getting_Started.html +94 -0
  80. package/dist/docs/documents/Runtime_Environment.html +128 -0
  81. package/dist/docs/enums/plot.ActivityLinkType.html +12 -0
  82. package/dist/docs/enums/plot.ActivityType.html +10 -0
  83. package/dist/docs/enums/plot.ActorType.html +10 -0
  84. package/dist/docs/enums/plot.ConferencingProvider.html +14 -0
  85. package/dist/docs/enums/tag.Tag.html +45 -0
  86. package/dist/docs/enums/tools_ai.AIModel.html +31 -0
  87. package/dist/docs/enums/tools_integrations.AuthLevel.html +7 -0
  88. package/dist/docs/enums/tools_integrations.AuthProvider.html +24 -0
  89. package/dist/docs/enums/tools_plot.ActivityAccess.html +8 -0
  90. package/dist/docs/enums/tools_plot.ContactAccess.html +5 -0
  91. package/dist/docs/enums/tools_plot.PriorityAccess.html +8 -0
  92. package/dist/docs/hierarchy.html +1 -0
  93. package/dist/docs/index.html +100 -0
  94. package/dist/docs/interfaces/common_calendar.Calendar.html +13 -0
  95. package/dist/docs/interfaces/common_calendar.CalendarTool.html +49 -0
  96. package/dist/docs/interfaces/common_calendar.SyncOptions.html +8 -0
  97. package/dist/docs/interfaces/tools_ai.AIRequest.html +46 -0
  98. package/dist/docs/interfaces/tools_ai.AIResponse.html +19 -0
  99. package/dist/docs/interfaces/tools_ai.FilePart.html +14 -0
  100. package/dist/docs/interfaces/tools_ai.ImagePart.html +11 -0
  101. package/dist/docs/interfaces/tools_ai.ReasoningPart.html +7 -0
  102. package/dist/docs/interfaces/tools_ai.RedactedReasoningPart.html +5 -0
  103. package/dist/docs/interfaces/tools_ai.TextPart.html +5 -0
  104. package/dist/docs/interfaces/tools_ai.ToolCallPart.html +9 -0
  105. package/dist/docs/interfaces/tools_ai.ToolExecutionOptions.html +9 -0
  106. package/dist/docs/interfaces/tools_ai.ToolResultPart.html +9 -0
  107. package/dist/docs/interfaces/tools_twists.TwistSource.html +13 -0
  108. package/dist/docs/interfaces/utils_types.ToolShed.html +11 -0
  109. package/dist/docs/modules/common_calendar.html +1 -0
  110. package/dist/docs/modules/index.html +1 -0
  111. package/dist/docs/modules/plot.html +1 -0
  112. package/dist/docs/modules/tag.html +1 -0
  113. package/dist/docs/modules/tool.html +1 -0
  114. package/dist/docs/modules/tools_ai.html +1 -0
  115. package/dist/docs/modules/tools_callbacks.html +1 -0
  116. package/dist/docs/modules/tools_integrations.html +1 -0
  117. package/dist/docs/modules/tools_network.html +1 -0
  118. package/dist/docs/modules/tools_plot.html +1 -0
  119. package/dist/docs/modules/tools_store.html +1 -0
  120. package/dist/docs/modules/tools_tasks.html +1 -0
  121. package/dist/docs/modules/tools_twists.html +1 -0
  122. package/dist/docs/modules/twist.html +1 -0
  123. package/dist/docs/modules/utils_types.html +1 -0
  124. package/dist/docs/modules.html +1 -0
  125. package/dist/docs/types/common_calendar.CalendarAuth.html +7 -0
  126. package/dist/docs/types/plot.Activity.html +64 -0
  127. package/dist/docs/types/plot.ActivityLink.html +22 -0
  128. package/dist/docs/types/plot.ActivityMeta.html +11 -0
  129. package/dist/docs/types/plot.ActivityUpdate.html +13 -0
  130. package/dist/docs/types/plot.Actor.html +15 -0
  131. package/dist/docs/types/plot.ActorId.html +4 -0
  132. package/dist/docs/types/plot.NewActivity.html +16 -0
  133. package/dist/docs/types/plot.NewContact.html +13 -0
  134. package/dist/docs/types/plot.NewPriority.html +5 -0
  135. package/dist/docs/types/plot.NoteType.html +1 -0
  136. package/dist/docs/types/plot.PickPriorityConfig.html +22 -0
  137. package/dist/docs/types/plot.Priority.html +8 -0
  138. package/dist/docs/types/tools_ai.AIAssistantMessage.html +4 -0
  139. package/dist/docs/types/tools_ai.AIMessage.html +3 -0
  140. package/dist/docs/types/tools_ai.AISource.html +11 -0
  141. package/dist/docs/types/tools_ai.AISystemMessage.html +7 -0
  142. package/dist/docs/types/tools_ai.AITool.html +19 -0
  143. package/dist/docs/types/tools_ai.AIToolMessage.html +4 -0
  144. package/dist/docs/types/tools_ai.AIToolSet.html +1 -0
  145. package/dist/docs/types/tools_ai.AIUsage.html +10 -0
  146. package/dist/docs/types/tools_ai.AIUserMessage.html +4 -0
  147. package/dist/docs/types/tools_ai.DataContent.html +2 -0
  148. package/dist/docs/types/tools_ai.ModelPreferences.html +24 -0
  149. package/dist/docs/types/tools_callbacks.Callback.html +8 -0
  150. package/dist/docs/types/tools_integrations.AuthToken.html +16 -0
  151. package/dist/docs/types/tools_integrations.Authorization.html +10 -0
  152. package/dist/docs/types/tools_network.WebhookRequest.html +15 -0
  153. package/dist/docs/types/tools_plot.ActivityIntentHandler.html +9 -0
  154. package/dist/docs/types/tools_twists.Log.html +6 -0
  155. package/dist/docs/types/tools_twists.TwistPermissions.html +12 -0
  156. package/dist/docs/types/utils_types.BuiltInTools.html +5 -0
  157. package/dist/docs/types/utils_types.CallbackMethods.html +3 -0
  158. package/dist/docs/types/utils_types.ExtractBuildReturn.html +2 -0
  159. package/dist/docs/types/utils_types.InferOptions.html +2 -0
  160. package/dist/docs/types/utils_types.InferTools.html +3 -0
  161. package/dist/docs/types/utils_types.NoFunctions.html +3 -0
  162. package/dist/docs/types/utils_types.NonFunction.html +2 -0
  163. package/dist/docs/types/utils_types.PromiseValues.html +3 -0
  164. package/dist/docs/types/utils_types.ToolBuilder.html +3 -0
  165. package/dist/index.d.ts +7 -0
  166. package/dist/index.d.ts.map +1 -0
  167. package/dist/index.js +7 -0
  168. package/dist/index.js.map +1 -0
  169. package/dist/llm-docs/common/calendar.d.ts +9 -0
  170. package/dist/llm-docs/common/calendar.d.ts.map +1 -0
  171. package/dist/llm-docs/common/calendar.js +8 -0
  172. package/dist/llm-docs/common/calendar.js.map +1 -0
  173. package/dist/llm-docs/common/messaging.d.ts +9 -0
  174. package/dist/llm-docs/common/messaging.d.ts.map +1 -0
  175. package/dist/llm-docs/common/messaging.js +8 -0
  176. package/dist/llm-docs/common/messaging.js.map +1 -0
  177. package/dist/llm-docs/creator-docs.d.ts +9 -0
  178. package/dist/llm-docs/creator-docs.d.ts.map +1 -0
  179. package/dist/llm-docs/creator-docs.js +8 -0
  180. package/dist/llm-docs/creator-docs.js.map +1 -0
  181. package/dist/llm-docs/index.d.ts +11 -0
  182. package/dist/llm-docs/index.d.ts.map +1 -0
  183. package/dist/llm-docs/index.js +42 -0
  184. package/dist/llm-docs/index.js.map +1 -0
  185. package/dist/llm-docs/plot.d.ts +9 -0
  186. package/dist/llm-docs/plot.d.ts.map +1 -0
  187. package/dist/llm-docs/plot.js +8 -0
  188. package/dist/llm-docs/plot.js.map +1 -0
  189. package/dist/llm-docs/tag.d.ts +9 -0
  190. package/dist/llm-docs/tag.d.ts.map +1 -0
  191. package/dist/llm-docs/tag.js +8 -0
  192. package/dist/llm-docs/tag.js.map +1 -0
  193. package/dist/llm-docs/tool.d.ts +9 -0
  194. package/dist/llm-docs/tool.d.ts.map +1 -0
  195. package/dist/llm-docs/tool.js +8 -0
  196. package/dist/llm-docs/tool.js.map +1 -0
  197. package/dist/llm-docs/tools/ai.d.ts +9 -0
  198. package/dist/llm-docs/tools/ai.d.ts.map +1 -0
  199. package/dist/llm-docs/tools/ai.js +8 -0
  200. package/dist/llm-docs/tools/ai.js.map +1 -0
  201. package/dist/llm-docs/tools/callbacks.d.ts +9 -0
  202. package/dist/llm-docs/tools/callbacks.d.ts.map +1 -0
  203. package/dist/llm-docs/tools/callbacks.js +8 -0
  204. package/dist/llm-docs/tools/callbacks.js.map +1 -0
  205. package/dist/llm-docs/tools/integrations.d.ts +9 -0
  206. package/dist/llm-docs/tools/integrations.d.ts.map +1 -0
  207. package/dist/llm-docs/tools/integrations.js +8 -0
  208. package/dist/llm-docs/tools/integrations.js.map +1 -0
  209. package/dist/llm-docs/tools/network.d.ts +9 -0
  210. package/dist/llm-docs/tools/network.d.ts.map +1 -0
  211. package/dist/llm-docs/tools/network.js +8 -0
  212. package/dist/llm-docs/tools/network.js.map +1 -0
  213. package/dist/llm-docs/tools/plot.d.ts +9 -0
  214. package/dist/llm-docs/tools/plot.d.ts.map +1 -0
  215. package/dist/llm-docs/tools/plot.js +8 -0
  216. package/dist/llm-docs/tools/plot.js.map +1 -0
  217. package/dist/llm-docs/tools/store.d.ts +9 -0
  218. package/dist/llm-docs/tools/store.d.ts.map +1 -0
  219. package/dist/llm-docs/tools/store.js +8 -0
  220. package/dist/llm-docs/tools/store.js.map +1 -0
  221. package/dist/llm-docs/tools/tasks.d.ts +9 -0
  222. package/dist/llm-docs/tools/tasks.d.ts.map +1 -0
  223. package/dist/llm-docs/tools/tasks.js +8 -0
  224. package/dist/llm-docs/tools/tasks.js.map +1 -0
  225. package/dist/llm-docs/tools/twists.d.ts +9 -0
  226. package/dist/llm-docs/tools/twists.d.ts.map +1 -0
  227. package/dist/llm-docs/tools/twists.js +8 -0
  228. package/dist/llm-docs/tools/twists.js.map +1 -0
  229. package/dist/llm-docs/twist-guide-template.d.ts +9 -0
  230. package/dist/llm-docs/twist-guide-template.d.ts.map +1 -0
  231. package/dist/llm-docs/twist-guide-template.js +8 -0
  232. package/dist/llm-docs/twist-guide-template.js.map +1 -0
  233. package/dist/llm-docs/twist.d.ts +9 -0
  234. package/dist/llm-docs/twist.d.ts.map +1 -0
  235. package/dist/llm-docs/twist.js +8 -0
  236. package/dist/llm-docs/twist.js.map +1 -0
  237. package/dist/plot.d.ts +463 -0
  238. package/dist/plot.d.ts.map +1 -0
  239. package/dist/plot.js +68 -0
  240. package/dist/plot.js.map +1 -0
  241. package/dist/tag.d.ts +47 -0
  242. package/dist/tag.d.ts.map +1 -0
  243. package/dist/tag.js +51 -0
  244. package/dist/tag.js.map +1 -0
  245. package/dist/tool.d.ts +242 -0
  246. package/dist/tool.d.ts.map +1 -0
  247. package/dist/tool.js +283 -0
  248. package/dist/tool.js.map +1 -0
  249. package/dist/tools/ai.d.ts +697 -0
  250. package/dist/tools/ai.d.ts.map +1 -0
  251. package/dist/tools/ai.js +104 -0
  252. package/dist/tools/ai.js.map +1 -0
  253. package/dist/tools/callbacks.d.ts +96 -0
  254. package/dist/tools/callbacks.d.ts.map +1 -0
  255. package/dist/tools/callbacks.js +40 -0
  256. package/dist/tools/callbacks.js.map +1 -0
  257. package/dist/tools/index.d.ts +9 -0
  258. package/dist/tools/index.d.ts.map +1 -0
  259. package/dist/tools/index.js +9 -0
  260. package/dist/tools/index.js.map +1 -0
  261. package/dist/tools/integrations.d.ts +142 -0
  262. package/dist/tools/integrations.d.ts.map +1 -0
  263. package/dist/tools/integrations.js +79 -0
  264. package/dist/tools/integrations.js.map +1 -0
  265. package/dist/tools/network.d.ts +188 -0
  266. package/dist/tools/network.d.ts.map +1 -0
  267. package/dist/tools/network.js +87 -0
  268. package/dist/tools/network.js.map +1 -0
  269. package/dist/tools/plot.d.ts +252 -0
  270. package/dist/tools/plot.d.ts.map +1 -0
  271. package/dist/tools/plot.js +72 -0
  272. package/dist/tools/plot.js.map +1 -0
  273. package/dist/tools/store.d.ts +90 -0
  274. package/dist/tools/store.d.ts.map +1 -0
  275. package/dist/tools/store.js +48 -0
  276. package/dist/tools/store.js.map +1 -0
  277. package/dist/tools/tasks.d.ts +93 -0
  278. package/dist/tools/tasks.d.ts.map +1 -0
  279. package/dist/tools/tasks.js +58 -0
  280. package/dist/tools/tasks.js.map +1 -0
  281. package/dist/tools/twists.d.ts +213 -0
  282. package/dist/tools/twists.d.ts.map +1 -0
  283. package/dist/tools/twists.js +26 -0
  284. package/dist/tools/twists.js.map +1 -0
  285. package/dist/twist-guide.d.ts +2 -0
  286. package/dist/twist-guide.d.ts.map +1 -0
  287. package/dist/twist-guide.js +9 -0
  288. package/dist/twist-guide.js.map +1 -0
  289. package/dist/twist.d.ts +204 -0
  290. package/dist/twist.d.ts.map +1 -0
  291. package/dist/twist.js +216 -0
  292. package/dist/twist.js.map +1 -0
  293. package/dist/utils/types.d.ts +91 -0
  294. package/dist/utils/types.d.ts.map +1 -0
  295. package/dist/utils/types.js +2 -0
  296. package/dist/utils/types.js.map +1 -0
  297. package/package.json +206 -0
  298. package/tsconfig.base.json +28 -0
@@ -0,0 +1,697 @@
1
+ import type { Static, TSchema } from "typebox";
2
+ import { ITool } from "..";
3
+ /**
4
+ * Built-in tool for prompting Large Language Models (LLMs).
5
+ *
6
+ * The AI tool provides twists and tools with access to LLM capabilities
7
+ * for natural language processing, text generation, data extraction,
8
+ * and intelligent decision making within their workflows.
9
+ *
10
+ * **Features:**
11
+ * - Access to multiple AI providers (OpenAI, Anthropic, Google, Workers AI)
12
+ * - Multi-turn conversation support with `messages`
13
+ * - Tool calling with automatic execution
14
+ * - Structured output with Typebox schemas via `outputSchema`
15
+ * - Unified API across all models via Vercel AI SDK
16
+ * - Automatic response parsing and validation with full type inference
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { Type } from "typebox";
21
+ *
22
+ * class SmartEmailTool extends Tool {
23
+ * private ai: AI;
24
+ *
25
+ * constructor(id: string, tools: ToolBuilder) {
26
+ * super();
27
+ * this.ai = tools.get(AI);
28
+ * }
29
+ *
30
+ * async categorizeEmail(emailContent: string) {
31
+ * // Define the output schema using Typebox
32
+ * const schema = Type.Object({
33
+ * category: Type.Union([
34
+ * Type.Literal("work"),
35
+ * Type.Literal("personal"),
36
+ * Type.Literal("spam"),
37
+ * Type.Literal("promotional")
38
+ * ]),
39
+ * confidence: Type.Number({ minimum: 0, maximum: 1 }),
40
+ * reasoning: Type.Optional(Type.String())
41
+ * });
42
+ *
43
+ * const response = await this.ai.prompt({
44
+ * model: { speed: "fast", cost: "medium" },
45
+ * system: "Classify emails into categories: work, personal, spam, or promotional.",
46
+ * prompt: `Categorize this email: ${emailContent}`,
47
+ * outputSchema: schema
48
+ * });
49
+ *
50
+ * return response.output;
51
+ * }
52
+ *
53
+ * async generateResponse(emailContent: string) {
54
+ * const response = await this.ai.prompt({
55
+ * model: { speed: "fast", cost: "medium" },
56
+ * system: "Generate professional email responses that are helpful and concise.",
57
+ * prompt: `Write a response to: ${emailContent}`
58
+ * });
59
+ *
60
+ * return response.text;
61
+ * }
62
+ * }
63
+ * ```
64
+ */
65
+ export declare abstract class AI extends ITool {
66
+ /**
67
+ * Sends a request to an AI model and returns the response using the Vercel AI SDK.
68
+ *
69
+ * Supports text generation, multi-turn conversations, structured outputs,
70
+ * and tool calling across multiple AI providers via Cloudflare AI Gateway.
71
+ *
72
+ * @param request - AI request with model, prompt/messages, and optional configuration
73
+ * @returns Promise resolving to the AI response with generated text and metadata
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // Simple text generation
78
+ * const response = await ai.prompt({
79
+ * model: { speed: "fast", cost: "medium" },
80
+ * prompt: "Explain quantum computing in simple terms"
81
+ * });
82
+ * console.log(response.text);
83
+ *
84
+ * // Fast and cheap for simple tasks
85
+ * const response = await ai.prompt({
86
+ * model: { speed: "fast", cost: "low" },
87
+ * prompt: "Summarize this text..."
88
+ * });
89
+ * console.log(response.text);
90
+ *
91
+ * // With system instructions for complex reasoning
92
+ * const response = await ai.prompt({
93
+ * model: { speed: "capable", cost: "high" },
94
+ * system: "You are a helpful physics tutor.",
95
+ * prompt: "Explain quantum entanglement"
96
+ * });
97
+ * console.log(response.text);
98
+ *
99
+ * // Multi-turn conversation
100
+ * const response = await ai.prompt({
101
+ * model: { speed: "balanced", cost: "medium" },
102
+ * messages: [
103
+ * { role: "user", content: "What is 2+2?" },
104
+ * { role: "assistant", content: "2+2 equals 4." },
105
+ * { role: "user", content: "What about 3+3?" }
106
+ * ]
107
+ * });
108
+ * console.log(response.text);
109
+ *
110
+ * // Structured output with Typebox schema
111
+ * const response = await ai.prompt({
112
+ * model: { speed: "fast", cost: "medium" },
113
+ * prompt: "Extract information: John is 30 years old",
114
+ * outputSchema: Type.Object({
115
+ * name: Type.String(),
116
+ * age: Type.Number()
117
+ * })
118
+ * });
119
+ * console.log(response.output); // { name: "John", age: 30 }
120
+ *
121
+ * // Tool calling
122
+ * const response = await ai.prompt({
123
+ * model: { speed: "balanced", cost: "medium" },
124
+ * prompt: "What's the weather in San Francisco?",
125
+ * tools: {
126
+ * getWeather: {
127
+ * description: "Get weather for a city",
128
+ * parameters: Type.Object({
129
+ * city: Type.String()
130
+ * }),
131
+ * execute: async ({ city }) => {
132
+ * return { temp: 72, condition: "sunny" };
133
+ * }
134
+ * }
135
+ * }
136
+ * });
137
+ * console.log(response.text); // Model's response using tool results
138
+ * console.log(response.toolCalls); // Array of tool calls made
139
+ * ```
140
+ */
141
+ abstract prompt<TOOLS extends AIToolSet, SCHEMA extends TSchema = never>(request: AIRequest<TOOLS, SCHEMA>): Promise<AIResponse<TOOLS, SCHEMA>>;
142
+ }
143
+ /**
144
+ * Model preferences for selecting an AI model based on performance and cost requirements.
145
+ * This allows Plot to match those preferences with user preferences (such as preferred or
146
+ * disallowed providers), as well as availability of newer and better models.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * // Fast and cheap - uses Workers AI models like Llama 3.2 1B
151
+ * const response = await ai.prompt({
152
+ * model: { speed: "fast", cost: "low" },
153
+ * prompt: "Summarize this in one sentence: ..."
154
+ * });
155
+ *
156
+ * // Balanced performance - uses GPT-5 Mini or Gemini 2.5 Flash
157
+ * const response = await ai.prompt({
158
+ * model: { speed: "balanced", cost: "medium" },
159
+ * prompt: "Analyze this data..."
160
+ * });
161
+ *
162
+ * // Most capable - uses Claude Sonnet 4.5 or Opus 4.1
163
+ * const response = await ai.prompt({
164
+ * model: { speed: "capable", cost: "high" },
165
+ * prompt: "Solve this complex reasoning problem..."
166
+ * });
167
+ *
168
+ * // Request a specific model with a hint
169
+ * const response = await ai.prompt({
170
+ * model: { speed: "balanced", cost: "medium", hint: AIModel.CLAUDE_SONNET_45 },
171
+ * prompt: "..."
172
+ * });
173
+ * ```
174
+ */
175
+ export type ModelPreferences = {
176
+ /**
177
+ * Desired speed tier:
178
+ * - "fast": Optimized for low latency and quick responses
179
+ * - "balanced": Good balance of speed and capability
180
+ * - "capable": Maximum reasoning and problem-solving ability
181
+ */
182
+ speed: "fast" | "balanced" | "capable";
183
+ /**
184
+ * Desired cost tier:
185
+ * - "low": Minimal cost, often using Workers AI models (free/very cheap)
186
+ * - "medium": Moderate pricing for good performance
187
+ * - "high": Premium pricing for best-in-class models
188
+ */
189
+ cost: "low" | "medium" | "high";
190
+ /**
191
+ * Optional hint to suggest a specific model. The system will use this
192
+ * model if possible, but may override it based on user preferences.
193
+ */
194
+ hint?: AIModel;
195
+ };
196
+ /**
197
+ * Supported AI models available through Cloudflare AI Gateway and Workers AI.
198
+ *
199
+ * Models are organized by provider:
200
+ * - **OpenAI**: Latest GPT models via AI Gateway
201
+ * - **Anthropic**: Claude models via AI Gateway (prefix with "anthropic/")
202
+ * - **Google**: Gemini models via AI Gateway (prefix with "google-ai-studio/")
203
+ * - **Workers AI**: Models running on Cloudflare's network (free/low cost)
204
+ */
205
+ export declare enum AIModel {
206
+ GPT_5 = "openai/gpt-5",
207
+ GPT_5_PRO = "openai/gpt-5-pro",
208
+ GPT_5_MINI = "openai/gpt-5-mini",
209
+ GPT_5_NANO = "openai/gpt-5-nano",
210
+ GPT_4O = "openai/gpt-4o",
211
+ GPT_4O_MINI = "openai/gpt-4o-mini",
212
+ O3 = "openai/o3",
213
+ O3_MINI = "openai/o3-mini",
214
+ CLAUDE_SONNET_45 = "anthropic/claude-sonnet-4-5",
215
+ CLAUDE_HAIKU_45 = "anthropic/claude-haiku-4-5",
216
+ CLAUDE_OPUS_41 = "anthropic/claude-opus-4-1",
217
+ CLAUDE_37_SONNET = "anthropic/claude-3-7-sonnet-latest",
218
+ GEMINI_25_PRO = "google/gemini-2.5-pro",
219
+ GEMINI_25_FLASH = "google/gemini-2.5-flash",
220
+ GEMINI_25_FLASH_LITE = "google/gemini-2.5-flash-lite",
221
+ GEMINI_20_FLASH = "google/gemini-2.0-flash",
222
+ GEMINI_20_FLASH_LITE = "google/gemini-2.0-flash-lite",
223
+ LLAMA_4_SCOUT_17B = "meta/llama-4-scout-17b-16e-instruct",
224
+ LLAMA_33_70B = "meta/llama-3.3-70b-instruct-fp8-fast",
225
+ LLAMA_31_8B = "meta/llama-3.1-8b-instruct-fp8",
226
+ LLAMA_32_1B = "meta/llama-3.2-1b-instruct",
227
+ DEEPSEEK_R1_32B = "deepseek-ai/deepseek-r1-distill-qwen-32b"
228
+ }
229
+ /**
230
+ * Request parameters for AI text generation, matching Vercel AI SDK's generateText() function.
231
+ */
232
+ export interface AIRequest<TOOLS extends AIToolSet, SCHEMA extends TSchema = never> {
233
+ /**
234
+ * Model selection preferences based on desired speed and cost characteristics.
235
+ * Plot will automatically select the best available model matching these preferences.
236
+ *
237
+ * @example
238
+ * // Fast and cheap - good for simple tasks
239
+ * model: { speed: "fast", cost: "low" }
240
+ *
241
+ * @example
242
+ * // Balanced performance - general purpose
243
+ * model: { speed: "balanced", cost: "medium" }
244
+ *
245
+ * @example
246
+ * // Maximum capability - complex reasoning
247
+ * model: { speed: "capable", cost: "high" }
248
+ *
249
+ * @example
250
+ * // With a specific model hint
251
+ * model: { speed: "balanced", cost: "medium", hint: "anthropic/claude-sonnet-4-5" }
252
+ */
253
+ model: ModelPreferences;
254
+ /**
255
+ * System instructions to guide the model's behavior.
256
+ */
257
+ system?: string;
258
+ /**
259
+ * The user's input prompt. Can be a simple string or an array of messages for multi-turn conversations.
260
+ */
261
+ prompt?: string;
262
+ /**
263
+ * Conversation messages for multi-turn interactions.
264
+ * Replaces 'prompt' for more complex conversations.
265
+ */
266
+ messages?: AIMessage[];
267
+ /**
268
+ * Tools that the model can call during generation.
269
+ * Each tool definition includes a description, input schema, and optional execute function.
270
+ */
271
+ tools?: TOOLS;
272
+ /**
273
+ * Controls which tools the model can use.
274
+ * - "auto": Model decides whether to use tools
275
+ * - "none": Model cannot use tools
276
+ * - "required": Model must use at least one tool
277
+ * - { type: "tool", toolName: string }: Model must use specific tool
278
+ */
279
+ toolChoice?: ToolChoice<TOOLS>;
280
+ /**
281
+ * Structured output schema using Typebox.
282
+ * Typebox schemas are JSON Schema objects that provide full TypeScript type inference.
283
+ */
284
+ outputSchema?: SCHEMA;
285
+ /**
286
+ * Maximum number of tokens to generate.
287
+ */
288
+ maxOutputTokens?: number;
289
+ /**
290
+ * Temperature for controlling randomness (0-2).
291
+ * Higher values make output more random, lower values more deterministic.
292
+ */
293
+ temperature?: number;
294
+ /**
295
+ * Top P sampling parameter (0-1).
296
+ * Controls diversity by limiting to top probability tokens.
297
+ */
298
+ topP?: number;
299
+ }
300
+ /**
301
+ * Response from AI text generation, matching Vercel AI SDK's GenerateTextResult.
302
+ */
303
+ export interface AIResponse<TOOLS extends AIToolSet, SCHEMA extends TSchema = never> {
304
+ /**
305
+ * The generated text.
306
+ */
307
+ text: string;
308
+ /**
309
+ * Tool calls made by the model during generation.
310
+ */
311
+ toolCalls?: ToolCallArray<TOOLS>;
312
+ /**
313
+ * Results from tool executions.
314
+ */
315
+ toolResults?: ToolResultArray<TOOLS>;
316
+ /**
317
+ * Reason why the model stopped generating.
318
+ */
319
+ finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown";
320
+ /**
321
+ * Token usage information for this generation.
322
+ */
323
+ usage: AIUsage;
324
+ /**
325
+ * Sources used by the model (if supported).
326
+ */
327
+ sources?: Array<AISource>;
328
+ /**
329
+ * Structured output when using outputSchema.
330
+ * Type is automatically inferred from the Typebox schema.
331
+ */
332
+ output?: Static<SCHEMA>;
333
+ /**
334
+ * Response metadata including messages.
335
+ */
336
+ response?: {
337
+ id?: string;
338
+ timestamp?: Date;
339
+ modelId?: string;
340
+ messages?: AIMessage[];
341
+ };
342
+ }
343
+ /**
344
+ * A system message. It can contain system information.
345
+ *
346
+ * Note: using the "system" part of the prompt is strongly preferred
347
+ * to increase the resilience against prompt injection attacks,
348
+ * and because not all providers support several system messages.
349
+ */
350
+ export type AISystemMessage = {
351
+ role: "system";
352
+ content: string;
353
+ };
354
+ /**
355
+ * A user message. It can contain text or a combination of text and images.
356
+ */
357
+ export type AIUserMessage = {
358
+ role: "user";
359
+ content: string | Array<TextPart | ImagePart | FilePart>;
360
+ };
361
+ /**
362
+ * An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
363
+ */
364
+ export type AIAssistantMessage = {
365
+ role: "assistant";
366
+ content: string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart>;
367
+ };
368
+ /**
369
+ * A tool message. It contains the result of one or more tool calls.
370
+ */
371
+ export type AIToolMessage = {
372
+ role: "tool";
373
+ content: Array<ToolResultPart>;
374
+ };
375
+ /**
376
+ * A message that can be used in the `messages` field of a prompt.
377
+ * It can be a user message, an assistant message, or a tool message.
378
+ */
379
+ export type AIMessage = AISystemMessage | AIUserMessage | AIAssistantMessage | AIToolMessage;
380
+ /**
381
+ * Represents the number of tokens used in a prompt and completion.
382
+ */
383
+ export type AIUsage = {
384
+ /**
385
+ * The number of tokens used in the prompt.
386
+ */
387
+ inputTokens?: number;
388
+ /**
389
+ * The number of tokens used in the completion.
390
+ */
391
+ outputTokens?: number;
392
+ /**
393
+ * The total number of tokens used (promptTokens + completionTokens).
394
+ */
395
+ totalTokens?: number;
396
+ /**
397
+ * The number of reasoning tokens used in the completion.
398
+ */
399
+ reasoningTokens?: number;
400
+ };
401
+ /**
402
+ * A source that has been used as input to generate the response.
403
+ */
404
+ export type AISource = {
405
+ type: "source";
406
+ /**
407
+ * A URL source. This is returned by web search RAG models.
408
+ */
409
+ sourceType: "url";
410
+ /**
411
+ * The ID of the source.
412
+ */
413
+ id: string;
414
+ /**
415
+ * The URL of the source.
416
+ */
417
+ url: string;
418
+ /**
419
+ * The title of the source.
420
+ */
421
+ title?: string;
422
+ } | {
423
+ type: "source";
424
+ /**
425
+ * The type of source - document sources reference files/documents.
426
+ */
427
+ sourceType: "document";
428
+ /**
429
+ * The ID of the source.
430
+ */
431
+ id: string;
432
+ /**
433
+ * IANA media type of the document (e.g., 'application/pdf').
434
+ */
435
+ mediaType: string;
436
+ /**
437
+ * The title of the document.
438
+ */
439
+ title: string;
440
+ /**
441
+ * Optional filename of the document.
442
+ */
443
+ filename?: string;
444
+ };
445
+ /**
446
+ * Text content part of a prompt. It contains a string of text.
447
+ */
448
+ export interface TextPart {
449
+ type: "text";
450
+ /**
451
+ * The text content.
452
+ */
453
+ text: string;
454
+ }
455
+ /**
456
+ * Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
457
+ */
458
+ export type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
459
+ /**
460
+ * Image content part of a prompt. It contains an image.
461
+ */
462
+ export interface ImagePart {
463
+ type: "image";
464
+ /**
465
+ * Image data. Can either be:
466
+ *
467
+ * - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
468
+ * - URL: a URL that points to the image
469
+ */
470
+ image: DataContent | URL;
471
+ /**
472
+ * Optional mime type of the image.
473
+ */
474
+ mimeType?: string;
475
+ }
476
+ /**
477
+ * File content part of a prompt. It contains a file.
478
+ */
479
+ export interface FilePart {
480
+ type: "file";
481
+ /**
482
+ * File data. Can either be:
483
+ *
484
+ * - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
485
+ * - URL: a URL that points to the file
486
+ */
487
+ data: DataContent | URL;
488
+ /**
489
+ * Optional filename of the file.
490
+ */
491
+ filename?: string;
492
+ /**
493
+ * IANA media type of the file.
494
+ *
495
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
496
+ */
497
+ mediaType: string;
498
+ }
499
+ /**
500
+ * Reasoning content part of a prompt. It contains a reasoning.
501
+ */
502
+ export interface ReasoningPart {
503
+ type: "reasoning";
504
+ /**
505
+ * The reasoning text.
506
+ */
507
+ text: string;
508
+ /**
509
+ * An optional signature for verifying that the reasoning originated from the model.
510
+ */
511
+ signature?: string;
512
+ }
513
+ /**
514
+ * Redacted reasoning content part of a prompt.
515
+ */
516
+ export interface RedactedReasoningPart {
517
+ type: "redacted-reasoning";
518
+ /**
519
+ * Redacted reasoning data.
520
+ */
521
+ data: string;
522
+ }
523
+ /**
524
+ * Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
525
+ */
526
+ export interface ToolCallPart {
527
+ type: "tool-call";
528
+ /**
529
+ * ID of the tool call. This ID is used to match the tool call with the tool result.
530
+ */
531
+ toolCallId: string;
532
+ /**
533
+ * Name of the tool that is being called.
534
+ */
535
+ toolName: string;
536
+ /**
537
+ * Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
538
+ */
539
+ input: unknown;
540
+ }
541
+ type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
542
+ type JSONObject = {
543
+ [key: string]: JSONValue;
544
+ };
545
+ type JSONArray = JSONValue[];
546
+ /**
547
+ * Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
548
+ */
549
+ export interface ToolResultPart {
550
+ type: "tool-result";
551
+ /**
552
+ * ID of the tool call that this result is associated with.
553
+ */
554
+ toolCallId: string;
555
+ /**
556
+ * Name of the tool that generated this result.
557
+ */
558
+ toolName: string;
559
+ /**
560
+ * Result of the tool call. This is a JSON-serializable object.
561
+ */
562
+ output: {
563
+ type: "text";
564
+ value: string;
565
+ } | {
566
+ type: "json";
567
+ value: JSONValue;
568
+ } | {
569
+ type: "error-text";
570
+ value: string;
571
+ } | {
572
+ type: "error-json";
573
+ value: JSONValue;
574
+ } | {
575
+ type: "content";
576
+ value: Array<{
577
+ type: "text";
578
+ /**
579
+ Text content.
580
+ */
581
+ text: string;
582
+ } | {
583
+ type: "media";
584
+ /**
585
+ Base-64 encoded media data.
586
+ */
587
+ data: string;
588
+ /**
589
+ IANA media type.
590
+ @see https://www.iana.org/assignments/media-types/media-types.xhtml
591
+ */
592
+ mediaType: string;
593
+ }>;
594
+ };
595
+ }
596
+ type ToolParameters = TSchema;
597
+ type inferParameters<PARAMETERS extends ToolParameters> = Static<PARAMETERS>;
598
+ /**
599
+ * Options passed to tool execution functions.
600
+ */
601
+ export interface ToolExecutionOptions {
602
+ /**
603
+ * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
604
+ */
605
+ toolCallId: string;
606
+ /**
607
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
608
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
609
+ */
610
+ messages: AIMessage[];
611
+ /**
612
+ * An optional abort signal that indicates that the overall operation should be aborted.
613
+ */
614
+ abortSignal?: AbortSignal;
615
+ }
616
+ /**
617
+ * A tool contains the description and the schema of the input that the tool expects.
618
+ * This enables the language model to generate the input.
619
+ *
620
+ * The tool can also contain an optional execute function for the actual execution function of the tool.
621
+ */
622
+ export type AITool<PARAMETERS extends ToolParameters = any, RESULT = any> = {
623
+ /**
624
+ * The schema of the input that the tool expects. The language model will use this to generate the input.
625
+ * It is also used to validate the output of the language model.
626
+ * Use descriptions to make the input understandable for the language model.
627
+ */
628
+ parameters: PARAMETERS;
629
+ /**
630
+ * The schema of the input that the tool expects. The language model will use this to generate the input.
631
+ * It is also used to validate the output of the language model.
632
+ * Use descriptions to make the input understandable for the language model.
633
+ */
634
+ inputSchema: TSchema;
635
+ /**
636
+ * An optional description of what the tool does.
637
+ * Will be used by the language model to decide whether to use the tool.
638
+ * Not used for provider-defined tools.
639
+ */
640
+ description?: string;
641
+ /**
642
+ * An async function that is called with the arguments from the tool call and produces a result.
643
+ * If not provided, the tool will not be executed automatically.
644
+ *
645
+ * @param args - The input of the tool call
646
+ * @param options - Execution options including abort signal and messages
647
+ */
648
+ execute?: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
649
+ } & ({
650
+ /**
651
+ * Function tool.
652
+ */
653
+ type?: undefined | "function";
654
+ } | {
655
+ /**
656
+ * Provider-defined tool.
657
+ */
658
+ type: "provider-defined";
659
+ /**
660
+ * The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
661
+ */
662
+ id: `${string}.${string}`;
663
+ /**
664
+ * The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
665
+ */
666
+ args: Record<string, unknown>;
667
+ });
668
+ /**
669
+ * Tool choice for the generation. It supports the following settings:
670
+ *
671
+ * - `auto` (default): the model can choose whether and which tools to call.
672
+ * - `required`: the model must call a tool. It can choose which tool to call.
673
+ * - `none`: the model must not call tools
674
+ * - `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
675
+ */
676
+ type ToolChoice<TOOLS extends Record<string, unknown>> = "auto" | "none" | "required" | {
677
+ type: "tool";
678
+ toolName: Extract<keyof TOOLS, string>;
679
+ };
680
+ export type AIToolSet = Record<string, (AITool<never, never> | AITool<any, any> | AITool<any, never> | AITool<never, any>) & Pick<AITool<any, any>, "execute">>;
681
+ type ToolCallUnion<_TOOLS extends AIToolSet> = {
682
+ type: "tool-call";
683
+ toolCallId: string;
684
+ toolName: string;
685
+ args?: unknown;
686
+ };
687
+ type ToolCallArray<TOOLS extends AIToolSet> = Array<ToolCallUnion<TOOLS>>;
688
+ type ToolResultUnion<_TOOLS extends AIToolSet> = {
689
+ type: "tool-result";
690
+ toolCallId: string;
691
+ toolName: string;
692
+ args?: unknown;
693
+ result?: unknown;
694
+ };
695
+ type ToolResultArray<TOOLS extends AIToolSet> = Array<ToolResultUnion<TOOLS>>;
696
+ export {};
697
+ //# sourceMappingURL=ai.d.ts.map