alchemy 0.3.1 → 0.4.1

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 (113) hide show
  1. package/README.md +8 -3
  2. package/lib/ai/document.d.ts +12 -1
  3. package/lib/ai/document.js +10 -1
  4. package/lib/ai/index.d.ts +0 -2
  5. package/lib/ai/index.js +0 -2
  6. package/lib/alchemy.d.ts +5 -0
  7. package/lib/alchemy.js +44 -1
  8. package/lib/apply.js +17 -10
  9. package/lib/aws/account-id.d.ts +4 -1
  10. package/lib/aws/account-id.js +1 -1
  11. package/lib/aws/credentials.d.ts +5 -0
  12. package/lib/aws/credentials.js +0 -0
  13. package/lib/aws/oidc/oidc-provider.js +2 -2
  14. package/lib/aws/role.js +35 -23
  15. package/lib/cloudflare/account-api-token.d.ts +168 -0
  16. package/lib/cloudflare/account-api-token.js +179 -0
  17. package/lib/cloudflare/account-id.d.ts +1 -0
  18. package/lib/cloudflare/account-id.js +0 -0
  19. package/lib/cloudflare/api.d.ts +38 -1
  20. package/lib/cloudflare/api.js +55 -4
  21. package/lib/cloudflare/assets.d.ts +74 -0
  22. package/lib/cloudflare/assets.js +73 -0
  23. package/lib/cloudflare/bindings.d.ts +6 -1
  24. package/lib/cloudflare/bindings.js +6 -0
  25. package/lib/cloudflare/bucket.d.ts +118 -3
  26. package/lib/cloudflare/bucket.js +269 -89
  27. package/lib/cloudflare/custom-domain.d.ts +75 -0
  28. package/lib/cloudflare/custom-domain.js +154 -0
  29. package/lib/cloudflare/{dns.js → dns-records.js} +14 -1
  30. package/lib/cloudflare/index.d.ts +6 -1
  31. package/lib/cloudflare/index.js +6 -1
  32. package/lib/cloudflare/permission-groups.d.ts +78 -0
  33. package/lib/cloudflare/permission-groups.js +48 -0
  34. package/lib/cloudflare/r2-rest-state-store.d.ts +2 -1
  35. package/lib/cloudflare/r2-rest-state-store.js +55 -24
  36. package/lib/cloudflare/static-site.d.ts +17 -18
  37. package/lib/cloudflare/static-site.js +19 -10
  38. package/lib/cloudflare/worker.d.ts +14 -0
  39. package/lib/cloudflare/worker.js +150 -3
  40. package/lib/{util/encrypt.d.ts → encrypt.d.ts} +1 -1
  41. package/lib/{util/encrypt.js → encrypt.js} +1 -1
  42. package/lib/fs/file-system-state-store.js +1 -1
  43. package/lib/fs/file.d.ts +18 -0
  44. package/lib/fs/file.js +6 -0
  45. package/lib/internal/{providers.d.ts → docs/providers.d.ts} +10 -4
  46. package/lib/internal/docs/providers.js +196 -0
  47. package/lib/secret.d.ts +3 -0
  48. package/lib/secret.js +13 -0
  49. package/lib/{util/serde.d.ts → serde.d.ts} +1 -1
  50. package/lib/{util/serde.js → serde.js} +12 -4
  51. package/lib/test/bun.js +3 -2
  52. package/lib/util/sha256.d.ts +1 -0
  53. package/lib/util/sha256.js +4 -0
  54. package/lib/web/vitepress/config.d.ts +2 -1
  55. package/lib/web/vitepress/config.js +1 -0
  56. package/lib/web/vitepress/index.d.ts +1 -0
  57. package/lib/web/vitepress/index.js +1 -0
  58. package/lib/web/vitepress/process-front-matter-files.d.ts +18 -0
  59. package/lib/web/vitepress/process-front-matter-files.js +68 -0
  60. package/lib/web/vitepress/vitepress.js +3 -2
  61. package/package.json +8 -4
  62. package/src/ai/document.ts +26 -2
  63. package/src/ai/index.ts +0 -2
  64. package/src/alchemy.ts +56 -2
  65. package/src/apply.ts +21 -20
  66. package/src/aws/account-id.ts +6 -2
  67. package/src/aws/credentials.ts +6 -0
  68. package/src/aws/oidc/oidc-provider.ts +17 -17
  69. package/src/aws/role.ts +68 -54
  70. package/src/cloudflare/account-api-token.ts +365 -0
  71. package/src/cloudflare/account-id.ts +0 -0
  72. package/src/cloudflare/api.ts +88 -17
  73. package/src/cloudflare/assets.ts +155 -0
  74. package/src/cloudflare/bindings.ts +11 -2
  75. package/src/cloudflare/bucket.ts +493 -133
  76. package/src/cloudflare/custom-domain.ts +318 -0
  77. package/src/cloudflare/{dns.ts → dns-records.ts} +36 -22
  78. package/src/cloudflare/index.ts +6 -1
  79. package/src/cloudflare/permission-groups.ts +137 -0
  80. package/src/cloudflare/r2-rest-state-store.ts +87 -42
  81. package/src/cloudflare/static-site.ts +20 -32
  82. package/src/cloudflare/worker.ts +253 -5
  83. package/src/dns/import-dns.ts +4 -4
  84. package/src/{util/encrypt.ts → encrypt.ts} +7 -10
  85. package/src/fs/file-system-state-store.ts +5 -5
  86. package/src/fs/file.ts +29 -0
  87. package/src/internal/docs/providers.ts +281 -0
  88. package/src/secret.ts +16 -0
  89. package/src/{util/serde.ts → serde.ts} +16 -10
  90. package/src/test/bun.ts +8 -7
  91. package/src/util/sha256.ts +5 -0
  92. package/src/web/vitepress/config.ts +3 -1
  93. package/src/web/vitepress/index.ts +1 -0
  94. package/src/web/vitepress/process-front-matter-files.ts +98 -0
  95. package/src/web/vitepress/vitepress.ts +3 -2
  96. package/lib/ai/approve.d.ts +0 -99
  97. package/lib/ai/approve.js +0 -76
  98. package/lib/ai/review.d.ts +0 -122
  99. package/lib/ai/review.js +0 -101
  100. package/lib/internal/getting-started.d.ts +0 -21
  101. package/lib/internal/getting-started.js +0 -87
  102. package/lib/internal/index.d.ts +0 -3
  103. package/lib/internal/index.js +0 -3
  104. package/lib/internal/providers.js +0 -172
  105. package/lib/internal/tutorial.d.ts +0 -104
  106. package/lib/internal/tutorial.js +0 -251
  107. package/src/ai/approve.ts +0 -163
  108. package/src/ai/review.ts +0 -213
  109. package/src/internal/getting-started.ts +0 -115
  110. package/src/internal/index.ts +0 -3
  111. package/src/internal/providers.ts +0 -241
  112. package/src/internal/tutorial.ts +0 -392
  113. /package/lib/cloudflare/{dns.d.ts → dns-records.d.ts} +0 -0
@@ -1,392 +0,0 @@
1
- import type { CoreMessage } from "ai";
2
- import { Approve, Document, Review } from "../ai";
3
- import type { ModelConfig } from "../ai/client";
4
- import { alchemy } from "../alchemy";
5
- import type { Context } from "../context";
6
- import type { Folder } from "../fs";
7
- import { Resource } from "../resource";
8
-
9
- /**
10
- * Properties for creating or updating a Tutorial
11
- */
12
- export interface TutorialProps {
13
- /**
14
- * The output directory for the tutorial document.
15
- */
16
- path: string | Folder;
17
-
18
- /**
19
- * The title of the tutorial.
20
- */
21
- title: string;
22
-
23
- /**
24
- * The prompt to use for generating the tutorial.
25
- * This should include specific details about the tool or framework.
26
- */
27
- prompt: string;
28
-
29
- /**
30
- * Optional difficulty level for the tutorial.
31
- * Defaults to "beginner".
32
- */
33
- difficulty?: "beginner" | "intermediate" | "advanced";
34
-
35
- /**
36
- * Optional estimated time to complete the tutorial in minutes.
37
- * Defaults to 30.
38
- */
39
- estimatedTime?: number;
40
-
41
- /**
42
- * Optional model configuration for generating the tutorial.
43
- * Defaults to Claude 3.5 Sonnet.
44
- */
45
- model?: ModelConfig;
46
-
47
- /**
48
- * Maximum number of review iterations.
49
- * Defaults to 3.
50
- */
51
- maxIterations?: number;
52
-
53
- /**
54
- * Initial message history for the conversation.
55
- * If not provided, a new conversation will be started.
56
- */
57
- messages?: CoreMessage[];
58
- }
59
-
60
- /**
61
- * Output returned after Tutorial creation/update
62
- */
63
- export interface Tutorial extends TutorialProps, Resource<"docs::Tutorial"> {
64
- /**
65
- * The Document resource
66
- */
67
- document: Document;
68
-
69
- /**
70
- * The content of the tutorial
71
- */
72
- content: string;
73
-
74
- /**
75
- * Message history from the conversation.
76
- */
77
- messages: CoreMessage[];
78
-
79
- /**
80
- * Time at which the tutorial was created
81
- */
82
- createdAt: number;
83
-
84
- /**
85
- * Time at which the tutorial was last updated
86
- */
87
- updatedAt: number;
88
- }
89
-
90
- /**
91
- * Creates a tutorial document with iterative review and improvement
92
- *
93
- * @example
94
- * // Create a basic tutorial
95
- * const tutorial = await Tutorial("getting-started", {
96
- * path: "docs/tutorials/getting-started",
97
- * title: "Getting Started with Alchemy",
98
- * prompt: "Create a tutorial for getting started with the Alchemy framework",
99
- * difficulty: "beginner",
100
- * estimatedTime: 30
101
- * });
102
- *
103
- * @example
104
- * // Create an advanced tutorial with custom model and continue from existing messages
105
- * const advancedTutorial = await Tutorial("advanced-features", {
106
- * path: "docs/tutorials/advanced-features",
107
- * title: "Advanced Alchemy Features",
108
- * prompt: "Create a tutorial covering advanced features of the Alchemy framework",
109
- * difficulty: "advanced",
110
- * estimatedTime: 60,
111
- * model: {
112
- * id: "claude-3-7-sonnet-latest",
113
- * provider: "anthropic"
114
- * },
115
- * maxIterations: 5,
116
- * messages: basicTutorial.messages
117
- * });
118
- */
119
- export const Tutorial = Resource(
120
- "docs::Tutorial",
121
- async function (
122
- this: Context<Tutorial>,
123
- id: string,
124
- props: TutorialProps
125
- ): Promise<Tutorial> {
126
- const {
127
- path: outFile,
128
- title,
129
- prompt,
130
- difficulty = "beginner",
131
- estimatedTime = 30,
132
- model = {
133
- id: "claude-3-5-sonnet-latest",
134
- provider: "anthropic",
135
- },
136
- maxIterations = 3,
137
- messages: initialMessages = [],
138
- } = props;
139
-
140
- console.log(`Tutorial: Starting creation of "${title}" (ID: ${id})`);
141
-
142
- // Handle deletion phase
143
- if (this.phase === "delete") {
144
- console.log(`Tutorial: Deleting tutorial "${title}" (ID: ${id})`);
145
- return this.destroy();
146
- }
147
-
148
- // System prompts
149
- const docSystemPrompt = `You are a technical writer creating a comprehensive tutorial.
150
-
151
- Your task is to create a detailed tutorial about ${title} with difficulty level: ${difficulty} and estimated time to complete: ${estimatedTime} minutes.
152
-
153
- The tutorial should take users from zero knowledge to a working understanding of the tool or framework.
154
-
155
- The tutorial should be structured as follows:
156
-
157
- # ${title}
158
-
159
- ## Overview
160
-
161
- (Provide a brief introduction to the tool/framework, its purpose, and what users will learn in this tutorial)
162
-
163
- ## Prerequisites
164
-
165
- (List any prerequisites, tools, or knowledge required before starting the tutorial)
166
-
167
- ## Setup
168
-
169
- ### Installation
170
-
171
- \`\`\`bash
172
- # Installation commands
173
- \`\`\`
174
-
175
- ### Configuration
176
-
177
- (Explain any necessary configuration steps)
178
-
179
- \`\`\`bash
180
- # Configuration commands or code
181
- \`\`\`
182
-
183
- ## Step 1: [First Step Title]
184
-
185
- (Explain the first step in detail)
186
-
187
- \`\`\`bash
188
- # Commands or code for the first step
189
- \`\`\`
190
-
191
- (Explain what the code does and why it's important)
192
-
193
- ## Step 2: [Second Step Title]
194
-
195
- (Explain the second step in detail)
196
-
197
- \`\`\`bash
198
- # Commands or code for the second step
199
- \`\`\`
200
-
201
- (Explain what the code does and why it's important)
202
-
203
- ## Step 3: [Third Step Title]
204
-
205
- (Explain the third step in detail)
206
-
207
- \`\`\`bash
208
- # Commands or code for the third step
209
- \`\`\`
210
-
211
- (Explain what the code does and why it's important)
212
-
213
- ## Step 4: [Fourth Step Title]
214
-
215
- (Explain the fourth step in detail)
216
-
217
- \`\`\`bash
218
- # Commands or code for the fourth step
219
- \`\`\`
220
-
221
- (Explain what the code does and why it's important)
222
-
223
- ## Step 5: [Fifth Step Title]
224
-
225
- (Explain the fifth step in detail)
226
-
227
- \`\`\`bash
228
- # Commands or code for the fifth step
229
- \`\`\`
230
-
231
- (Explain what the code does and why it's important)
232
-
233
- ## Testing Your Work
234
-
235
- (Explain how to verify that everything is working correctly)
236
-
237
- \`\`\`bash
238
- # Testing commands or code
239
- \`\`\`
240
-
241
- ## Troubleshooting
242
-
243
- (Common issues users might encounter and how to resolve them)
244
-
245
- ## Next Steps
246
-
247
- (Suggest additional resources, advanced topics, or projects to try next)
248
-
249
- ## Additional Resources
250
-
251
- (Links to documentation, community resources, or related tutorials)`;
252
-
253
- // Initial message if none provided
254
- const startingMessages =
255
- initialMessages.length > 0
256
- ? initialMessages
257
- : [
258
- {
259
- role: "user" as const,
260
- content: `Create a comprehensive tutorial about ${title}.\n\n${prompt}\n\nDifficulty level: ${difficulty}\nEstimated time to complete: ${estimatedTime} minutes`,
261
- },
262
- ];
263
-
264
- // Generate the initial tutorial
265
- console.log(`Tutorial: Generating initial tutorial for "${title}"`);
266
- let tutorial = await Document(`document`, {
267
- title: title,
268
- path: typeof outFile === "string" ? outFile : outFile.path,
269
- model,
270
- messages: startingMessages,
271
- system: docSystemPrompt,
272
- });
273
- console.log(
274
- `Tutorial: Initial tutorial generated for "${title}" (${tutorial.content.length} chars)`
275
- );
276
-
277
- // Review and improve the tutorial in a loop
278
- let iteration = 0;
279
- let approved = false;
280
- let finalMessages = tutorial.messages;
281
-
282
- while (!approved && iteration < maxIterations) {
283
- iteration++;
284
- console.log(
285
- `Tutorial: Starting review iteration ${iteration}/${maxIterations} for "${title}"`
286
- );
287
-
288
- // Review the tutorial using system prompt
289
- console.log(`Tutorial: Requesting review for iteration ${iteration}`);
290
- const review = await Review(`review-${iteration}`, {
291
- messages: finalMessages,
292
- system:
293
- await alchemy`Please review this tutorial for correctness, conciseness, logical flow, and accurateness.
294
-
295
- The tutorial should:
296
- 1. Be technically accurate and free of errors
297
- 2. Be concise without over-explaining
298
- 3. Have a logical flow from basic to advanced concepts
299
- 4. Be accurate in its descriptions and instructions
300
- 5. Be appropriate for the ${difficulty} difficulty level
301
- 6. Be completable within approximately ${estimatedTime} minutes
302
-
303
- Provide specific feedback on areas that need improvement.`,
304
- model,
305
- });
306
-
307
- // Extract the actual review content from the last assistant message
308
- const reviewContent =
309
- review.messages[review.messages.length - 1]?.content || "";
310
- console.log(
311
- `Tutorial: Review received for iteration ${iteration} (${reviewContent.length} chars)`
312
- );
313
-
314
- // Check if the tutorial is approved using system prompt
315
- console.log(`Tutorial: Evaluating approval for iteration ${iteration}`);
316
- const approvalResult = await Approve(`approval-${iteration}`, {
317
- messages: review.messages,
318
- system:
319
- await alchemy`Based on the review above, determine if the tutorial meets the quality standards.
320
- The tutorial should be approved if:
321
- 1. It is technically accurate and free of errors
322
- 2. It is concise without over-explaining
323
- 3. It has a logical flow from basic to advanced concepts
324
- 4. It is accurate in its descriptions and instructions
325
- 5. It is appropriate for the ${difficulty} difficulty level
326
- 6. It is completable within approximately ${estimatedTime} minutes
327
-
328
- Respond with APPROVED or DENIED, followed by your explanation.`,
329
- });
330
- console.log(
331
- `Tutorial: Approval result for iteration ${iteration}: ${approvalResult.approved ? "APPROVED" : "DENIED"}`
332
- );
333
-
334
- // Log approval status
335
- if (approvalResult.approved) {
336
- console.log(
337
- `Tutorial: Final tutorial approved: ${approvalResult.explanation}`
338
- );
339
- approved = true;
340
- finalMessages = approvalResult.messages;
341
- } else {
342
- console.log(
343
- `Tutorial: Tutorial needs improvement: ${approvalResult.explanation}`
344
- );
345
-
346
- // Add improvement request and generate an improved tutorial
347
- const improvementMessages = [
348
- ...approvalResult.messages,
349
- {
350
- role: "user" as const,
351
- content: `Please create an improved version of the tutorial that addresses the issues identified in the review: ${approvalResult.explanation}`,
352
- },
353
- ];
354
-
355
- console.log(
356
- `Tutorial: Regenerating tutorial based on feedback for iteration ${iteration}`
357
- );
358
-
359
- tutorial = await Document(`tutorial-${iteration}`, {
360
- title: title,
361
- path: typeof outFile === "string" ? outFile : outFile.path,
362
- model,
363
- messages: improvementMessages,
364
- system: docSystemPrompt,
365
- });
366
- console.log(
367
- `Tutorial: Improved tutorial generated for iteration ${iteration} (${tutorial.content.length} chars)`
368
- );
369
-
370
- finalMessages = tutorial.messages;
371
- }
372
- }
373
-
374
- if (!approved) {
375
- console.log(
376
- `Tutorial: Tutorial not approved after ${maxIterations} iterations. Using the best version available.`
377
- );
378
- }
379
-
380
- console.log(`Tutorial: Completed creation of "${title}" (ID: ${id})`);
381
-
382
- // Return the tutorial resource
383
- return this({
384
- ...props,
385
- document: tutorial,
386
- content: tutorial.content,
387
- messages: finalMessages,
388
- createdAt: Date.now(),
389
- updatedAt: Date.now(),
390
- });
391
- }
392
- );
File without changes