alchemy 0.3.1 → 0.4.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 (104) 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/bucket.d.ts +118 -3
  22. package/lib/cloudflare/bucket.js +269 -89
  23. package/lib/cloudflare/custom-domain.d.ts +75 -0
  24. package/lib/cloudflare/custom-domain.js +154 -0
  25. package/lib/cloudflare/{dns.js → dns-records.js} +14 -1
  26. package/lib/cloudflare/index.d.ts +5 -1
  27. package/lib/cloudflare/index.js +5 -1
  28. package/lib/cloudflare/permission-groups.d.ts +78 -0
  29. package/lib/cloudflare/permission-groups.js +48 -0
  30. package/lib/cloudflare/r2-rest-state-store.d.ts +2 -1
  31. package/lib/cloudflare/r2-rest-state-store.js +3 -2
  32. package/lib/cloudflare/static-site.d.ts +17 -18
  33. package/lib/cloudflare/static-site.js +19 -10
  34. package/lib/{util/encrypt.d.ts → encrypt.d.ts} +1 -1
  35. package/lib/{util/encrypt.js → encrypt.js} +1 -1
  36. package/lib/fs/file-system-state-store.js +1 -1
  37. package/lib/fs/file.d.ts +18 -0
  38. package/lib/fs/file.js +6 -0
  39. package/lib/internal/{providers.d.ts → docs/providers.d.ts} +10 -4
  40. package/lib/internal/docs/providers.js +196 -0
  41. package/lib/secret.d.ts +3 -0
  42. package/lib/secret.js +13 -0
  43. package/lib/{util/serde.d.ts → serde.d.ts} +1 -1
  44. package/lib/{util/serde.js → serde.js} +12 -4
  45. package/lib/test/bun.js +3 -2
  46. package/lib/util/sha256.d.ts +1 -0
  47. package/lib/util/sha256.js +4 -0
  48. package/lib/web/vitepress/config.d.ts +2 -1
  49. package/lib/web/vitepress/config.js +1 -0
  50. package/lib/web/vitepress/index.d.ts +1 -0
  51. package/lib/web/vitepress/index.js +1 -0
  52. package/lib/web/vitepress/process-front-matter-files.d.ts +18 -0
  53. package/lib/web/vitepress/process-front-matter-files.js +68 -0
  54. package/lib/web/vitepress/vitepress.js +3 -2
  55. package/package.json +8 -4
  56. package/src/ai/document.ts +26 -2
  57. package/src/ai/index.ts +0 -2
  58. package/src/alchemy.ts +56 -2
  59. package/src/apply.ts +21 -20
  60. package/src/aws/account-id.ts +6 -2
  61. package/src/aws/credentials.ts +6 -0
  62. package/src/aws/oidc/oidc-provider.ts +17 -17
  63. package/src/aws/role.ts +68 -54
  64. package/src/cloudflare/account-api-token.ts +365 -0
  65. package/src/cloudflare/account-id.ts +0 -0
  66. package/src/cloudflare/api.ts +88 -17
  67. package/src/cloudflare/bucket.ts +493 -133
  68. package/src/cloudflare/custom-domain.ts +318 -0
  69. package/src/cloudflare/{dns.ts → dns-records.ts} +36 -22
  70. package/src/cloudflare/index.ts +5 -1
  71. package/src/cloudflare/permission-groups.ts +137 -0
  72. package/src/cloudflare/r2-rest-state-store.ts +14 -13
  73. package/src/cloudflare/static-site.ts +20 -32
  74. package/src/dns/import-dns.ts +4 -4
  75. package/src/{util/encrypt.ts → encrypt.ts} +7 -10
  76. package/src/fs/file-system-state-store.ts +5 -5
  77. package/src/fs/file.ts +29 -0
  78. package/src/internal/docs/providers.ts +281 -0
  79. package/src/secret.ts +16 -0
  80. package/src/{util/serde.ts → serde.ts} +16 -10
  81. package/src/test/bun.ts +8 -7
  82. package/src/util/sha256.ts +5 -0
  83. package/src/web/vitepress/config.ts +3 -1
  84. package/src/web/vitepress/index.ts +1 -0
  85. package/src/web/vitepress/process-front-matter-files.ts +98 -0
  86. package/src/web/vitepress/vitepress.ts +3 -2
  87. package/lib/ai/approve.d.ts +0 -99
  88. package/lib/ai/approve.js +0 -76
  89. package/lib/ai/review.d.ts +0 -122
  90. package/lib/ai/review.js +0 -101
  91. package/lib/internal/getting-started.d.ts +0 -21
  92. package/lib/internal/getting-started.js +0 -87
  93. package/lib/internal/index.d.ts +0 -3
  94. package/lib/internal/index.js +0 -3
  95. package/lib/internal/providers.js +0 -172
  96. package/lib/internal/tutorial.d.ts +0 -104
  97. package/lib/internal/tutorial.js +0 -251
  98. package/src/ai/approve.ts +0 -163
  99. package/src/ai/review.ts +0 -213
  100. package/src/internal/getting-started.ts +0 -115
  101. package/src/internal/index.ts +0 -3
  102. package/src/internal/providers.ts +0 -241
  103. package/src/internal/tutorial.ts +0 -392
  104. /package/lib/cloudflare/{dns.d.ts → dns-records.d.ts} +0 -0
package/src/ai/approve.ts DELETED
@@ -1,163 +0,0 @@
1
- import type { CoreMessage } from "ai";
2
- import { type } from "arktype";
3
- import { Data } from "./data";
4
-
5
- /**
6
- * Properties for approving or denying content
7
- */
8
- export interface ApproveProps {
9
- /**
10
- * Content to be reviewed
11
- * Use alchemy template literals to include file context:
12
- * @example
13
- * content: await alchemy`
14
- * Review this code:
15
- * ${alchemy.file("src/api.ts")}
16
- * `
17
- *
18
- * Required unless messages are provided
19
- */
20
- content?: string;
21
-
22
- /**
23
- * Prompt for the approval decision
24
- * This should include specific criteria for approval or denial
25
- * @example
26
- * prompt: "Approve this code if it follows security best practices and has proper error handling."
27
- *
28
- * Required unless messages are provided
29
- */
30
- prompt?: string;
31
-
32
- /**
33
- * System prompt for the model
34
- * This is used to provide instructions to the model about how to make the decision
35
- */
36
- system?: string;
37
-
38
- /**
39
- * Message history for the conversation
40
- * If provided, this will be used instead of the prompt and content
41
- */
42
- messages?: CoreMessage[];
43
-
44
- /**
45
- * Temperature for controlling randomness in generation.
46
- * Higher values (e.g., 0.8) make output more random,
47
- * lower values (e.g., 0.2) make it more deterministic.
48
- * @default 0.2 (lower for more consistent decisions)
49
- */
50
- temperature?: number;
51
- }
52
-
53
- /**
54
- * Result of the approval process
55
- */
56
- export interface ApprovalResult {
57
- /**
58
- * Whether the content was approved
59
- */
60
- approved: boolean;
61
-
62
- /**
63
- * Explanation for the decision
64
- */
65
- explanation: string;
66
-
67
- /**
68
- * Suggestions for improvement if denied
69
- */
70
- suggestions?: string[];
71
-
72
- /**
73
- * Updated message history with the approval response appended
74
- */
75
- messages: CoreMessage[];
76
- }
77
-
78
- export type Approve = ApprovalResult;
79
-
80
- /**
81
- * Default system prompt for approval decisions
82
- */
83
- const DEFAULT_APPROVE_SYSTEM_PROMPT = `You are an expert content reviewer tasked with approving or denying content based on specific criteria.
84
-
85
- Your role is to:
86
- 1. Carefully evaluate the content against the provided criteria
87
- 2. Make a clear decision to approve or deny the content
88
- 3. Provide a detailed explanation for your decision
89
- 4. If denying, offer specific suggestions for improvement
90
-
91
- Be objective, thorough, and fair in your assessment.`;
92
-
93
- /**
94
- * Approves or denies content based on a prompt or message history
95
- *
96
- * @example
97
- * // Approve or deny a code file
98
- * const result = await Approve("code-approval", {
99
- * content: await alchemy`
100
- * Review this API implementation:
101
- * ${alchemy.file("src/api.ts")}
102
- * `,
103
- * prompt: "Approve this code if it follows security best practices and has proper error handling."
104
- * });
105
- *
106
- * if (result.approved) {
107
- * console.log("Content approved:", result.explanation);
108
- * } else {
109
- * console.log("Content denied:", result.explanation);
110
- * console.log("Suggestions:", result.suggestions);
111
- * }
112
- *
113
- * @example
114
- * // Approve or deny using message history
115
- * const result = await Approve("doc-approval-with-history", {
116
- * content: "This is the content to review",
117
- * prompt: "Approve this documentation if it is clear and accurate",
118
- * messages: [
119
- * { role: "user", content: "Can you review this documentation?" },
120
- * { role: "assistant", content: "Yes, I'd be happy to review it." },
121
- * { role: "user", content: "Please check for clarity and accuracy." }
122
- * ]
123
- * });
124
- */
125
- export async function Approve(
126
- id: string,
127
- props: ApproveProps
128
- ): Promise<ApprovalResult> {
129
- // Create messages array if not provided
130
- const messages =
131
- props.messages ||
132
- (props.content && props.prompt
133
- ? [
134
- {
135
- role: "user" as const,
136
- content: `${props.content}\n\n${props.prompt}`,
137
- },
138
- ]
139
- : []);
140
-
141
- if (messages.length === 0) {
142
- throw new Error(
143
- "Either messages or both content and prompt must be provided"
144
- );
145
- }
146
-
147
- const data = await Data(id, {
148
- schema: type({
149
- approved: "boolean",
150
- explanation: "string",
151
- suggestions: "string[]?",
152
- }),
153
- messages,
154
- system: props.system || DEFAULT_APPROVE_SYSTEM_PROMPT,
155
- temperature: props.temperature ?? 0.2,
156
- });
157
-
158
- // Return the result with updated messages from Data
159
- return {
160
- ...data.object,
161
- messages: data.messages,
162
- };
163
- }
package/src/ai/review.ts DELETED
@@ -1,213 +0,0 @@
1
- import { generateText, type CoreMessage } from "ai";
2
- import type { Context } from "../context";
3
- import { Resource } from "../resource";
4
- import type { Secret } from "../secret";
5
- import { createModel, withRateLimitRetry, type ModelConfig } from "./client";
6
-
7
- /**
8
- * Properties for creating or updating a Review
9
- */
10
- export interface ReviewProps {
11
- /**
12
- * Content to be reviewed
13
- * Use alchemy template literals to include file context:
14
- * @example
15
- * content: await alchemy`
16
- * Review this code:
17
- * ${alchemy.file("src/api.ts")}
18
- * `
19
- *
20
- * Required unless messages are provided
21
- */
22
- content?: string;
23
-
24
- /**
25
- * Prompt for the review
26
- * This should include specific instructions for the review
27
- * @example
28
- * prompt: "Review this code for security vulnerabilities, performance issues, and best practices."
29
- *
30
- * Required unless messages are provided
31
- */
32
- prompt?: string;
33
-
34
- /**
35
- * Message history for the conversation
36
- * If provided, this will be used instead of the prompt and content
37
- */
38
- messages?: CoreMessage[];
39
-
40
- /**
41
- * System prompt for the model
42
- * This is used to provide instructions to the model about how to format the response
43
- * The default system prompt instructs the model to act as a reviewer
44
- */
45
- system?: string;
46
-
47
- /**
48
- * AI API key to use for generating content
49
- * If not provided, will use OPENAI_API_KEY environment variable
50
- */
51
- apiKey?: Secret;
52
-
53
- /**
54
- * Model configuration
55
- */
56
- model?: ModelConfig;
57
-
58
- /**
59
- * Temperature for controlling randomness in generation.
60
- * Higher values (e.g., 0.8) make output more random,
61
- * lower values (e.g., 0.2) make it more deterministic.
62
- * @default 0.7
63
- */
64
- temperature?: number;
65
-
66
- /**
67
- * Maximum number of tokens to generate.
68
- * Higher values allow for longer documents but may increase cost and generation time.
69
- * @default 10000
70
- */
71
- maxTokens?: number;
72
- }
73
-
74
- /**
75
- * Output returned after Review creation/update
76
- */
77
- export interface Review extends ReviewProps, Resource<"ai::Review"> {
78
- /**
79
- * Content of the review
80
- */
81
- content: string;
82
-
83
- /**
84
- * Updated message history with the review response appended
85
- */
86
- messages: CoreMessage[];
87
-
88
- /**
89
- * Time at which the review was created
90
- */
91
- createdAt: number;
92
-
93
- /**
94
- * Time at which the review was last updated
95
- */
96
- updatedAt: number;
97
- }
98
-
99
- /**
100
- * Default system prompt for review generation
101
- */
102
- const DEFAULT_REVIEW_SYSTEM_PROMPT = `You are an expert code reviewer and technical writer. Your task is to provide a thorough review of the provided content. Your review should include:
103
-
104
- 1. A high-level summary of the content
105
- 2. Detailed feedback on the content's quality, accuracy, and completeness
106
- 3. Specific suggestions for improvement
107
- 4. Alternative approaches or solutions where applicable
108
- 5. Best practices that should be followed
109
- 6. Potential issues or concerns that should be addressed
110
-
111
- Provide your review in a clear, well-structured format.`;
112
-
113
- /**
114
- * Creates or updates a Review resource
115
- *
116
- * @example
117
- * // Create a review of a code file
118
- * const codeReview = await Review("api-review", {
119
- * content: await alchemy`
120
- * Review this API implementation:
121
- * ${alchemy.file("src/api.ts")}
122
- * `,
123
- * prompt: "Review this API implementation for security vulnerabilities, performance issues, and best practices. Suggest improvements and alternative approaches."
124
- * });
125
- *
126
- * @example
127
- * // Create a review of a document
128
- * const docReview = await Review("tutorial-review", {
129
- * content: await alchemy`
130
- * Review this tutorial:
131
- * ${alchemy.file("docs/tutorials/getting-started.md")}
132
- * `,
133
- * prompt: "Review this tutorial for clarity, accuracy, and completeness. Suggest improvements to make it more user-friendly."
134
- * });
135
- *
136
- * @example
137
- * // Create a review with message history
138
- * const reviewWithHistory = await Review("code-review-iteration-2", {
139
- * content: "Updated code implementation",
140
- * prompt: "Review this updated implementation",
141
- * messages: [
142
- * { role: "user", content: "Can you review my code?" },
143
- * { role: "assistant", content: "I'll review your code. Please share it." },
144
- * { role: "user", content: "Here's my implementation: [code]" },
145
- * { role: "assistant", content: "Here's my review of your code: [previous review]" }
146
- * ]
147
- * });
148
- */
149
- export const Review = Resource(
150
- "ai::Review",
151
- async function (
152
- this: Context<Review>,
153
- id: string,
154
- props: ReviewProps
155
- ): Promise<Review> {
156
- if (this.phase === "delete") {
157
- return this.destroy();
158
- }
159
-
160
- // Use provided system prompt or default
161
- const system = props.system || DEFAULT_REVIEW_SYSTEM_PROMPT;
162
-
163
- // Create messages array if not provided
164
- const messages =
165
- props.messages ||
166
- (props.content && props.prompt
167
- ? [
168
- {
169
- role: "user",
170
- content: `${props.content}\n\n${props.prompt}`,
171
- },
172
- ]
173
- : []);
174
-
175
- if (messages.length === 0) {
176
- throw new Error(
177
- "Either messages or both content and prompt must be provided"
178
- );
179
- }
180
-
181
- // Generate review content with rate limit retry
182
- const { text } = await withRateLimitRetry(async () => {
183
- return generateText({
184
- model: createModel(props),
185
- messages,
186
- system,
187
- maxTokens: props.maxTokens || 8192,
188
- providerOptions: props.model?.options,
189
- ...(props.temperature === undefined
190
- ? {}
191
- : { temperature: props.temperature }),
192
- });
193
- });
194
-
195
- // Create updated message history with the AI's response
196
- const updatedMessages = [
197
- ...messages,
198
- {
199
- role: "assistant" as const,
200
- content: text,
201
- },
202
- ];
203
-
204
- // Return the review with the direct text from the LLM and updated messages
205
- return this({
206
- ...props,
207
- content: text,
208
- messages: updatedMessages,
209
- createdAt: Date.now(),
210
- updatedAt: Date.now(),
211
- });
212
- }
213
- );
@@ -1,115 +0,0 @@
1
- import { Document } from "../ai";
2
- import type { ModelConfig } from "../ai/client";
3
- import { alchemy } from "../alchemy";
4
- import type { Folder } from "../fs";
5
-
6
- export interface GettingStartedProps {
7
- /**
8
- * The output directory for the getting started document.
9
- */
10
- path: string | Folder;
11
-
12
- /**
13
- * The prompt to use for generating the getting started guide.
14
- * This should include specific details about the product or framework.
15
- */
16
- prompt: string;
17
-
18
- /**
19
- * Optional model configuration for generating the getting started guide.
20
- * Defaults to Claude 3.5 Sonnet.
21
- */
22
- model?: ModelConfig;
23
- }
24
-
25
- export type GettingStarted = Document;
26
-
27
- export async function GettingStarted({
28
- path: outFile,
29
- prompt,
30
- model = {
31
- id: "claude-3-5-sonnet-latest",
32
- provider: "anthropic",
33
- },
34
- }: GettingStartedProps): Promise<Document> {
35
- return Document(`docs/getting-started`, {
36
- title: "Getting Started Guide",
37
- path: typeof outFile === "string" ? outFile : outFile.path,
38
- model,
39
- prompt: await alchemy`
40
- You are a technical writer creating a getting started guide.
41
-
42
- ${prompt}
43
-
44
- If you need a template structure to follow, use this format:
45
-
46
- # Getting Started with [Product/Framework Name]
47
-
48
- (Brief introduction to the product/framework)
49
-
50
- ## Installation
51
-
52
- \`\`\`bash
53
- # Installation command
54
- \`\`\`
55
-
56
- ## Creating Your First Project
57
-
58
- (Step-by-step guide to creating a basic project)
59
-
60
- \`\`\`ts
61
- // Example of a simple project
62
- \`\`\`
63
-
64
- ## Core Concepts
65
-
66
- ### [Concept 1]
67
-
68
- (Explanation of the first core concept)
69
-
70
- \`\`\`ts
71
- // Example of using the concept
72
- \`\`\`
73
-
74
- ### [Concept 2]
75
-
76
- (Explanation of the second core concept)
77
-
78
- \`\`\`ts
79
- // Example of using the concept
80
- \`\`\`
81
-
82
- ## Working with [Feature]
83
-
84
- (How to use a specific feature)
85
-
86
- \`\`\`ts
87
- // Example of using the feature
88
- \`\`\`
89
-
90
- ## Testing
91
-
92
- (How to test your project)
93
-
94
- \`\`\`ts
95
- // Example of testing
96
- \`\`\`
97
-
98
- ## Deployment
99
-
100
- (How to deploy your project)
101
-
102
- \`\`\`ts
103
- // Example of deployment
104
- \`\`\`
105
-
106
- ## Next Steps
107
-
108
- (Where to go next to learn more)
109
-
110
- > [!TIP]
111
- > Make sure the examples follow a natural progression from minimal examples to more complex use cases.
112
- > Keep explanations concise and focused on high-value information.
113
- `,
114
- });
115
- }
@@ -1,3 +0,0 @@
1
- export * from "./getting-started";
2
- export * from "./providers";
3
- export * from "./tutorial";