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.
- package/README.md +8 -3
- package/lib/ai/document.d.ts +12 -1
- package/lib/ai/document.js +10 -1
- package/lib/ai/index.d.ts +0 -2
- package/lib/ai/index.js +0 -2
- package/lib/alchemy.d.ts +5 -0
- package/lib/alchemy.js +44 -1
- package/lib/apply.js +17 -10
- package/lib/aws/account-id.d.ts +4 -1
- package/lib/aws/account-id.js +1 -1
- package/lib/aws/credentials.d.ts +5 -0
- package/lib/aws/credentials.js +0 -0
- package/lib/aws/oidc/oidc-provider.js +2 -2
- package/lib/aws/role.js +35 -23
- package/lib/cloudflare/account-api-token.d.ts +168 -0
- package/lib/cloudflare/account-api-token.js +179 -0
- package/lib/cloudflare/account-id.d.ts +1 -0
- package/lib/cloudflare/account-id.js +0 -0
- package/lib/cloudflare/api.d.ts +38 -1
- package/lib/cloudflare/api.js +55 -4
- package/lib/cloudflare/assets.d.ts +74 -0
- package/lib/cloudflare/assets.js +73 -0
- package/lib/cloudflare/bindings.d.ts +6 -1
- package/lib/cloudflare/bindings.js +6 -0
- package/lib/cloudflare/bucket.d.ts +118 -3
- package/lib/cloudflare/bucket.js +269 -89
- package/lib/cloudflare/custom-domain.d.ts +75 -0
- package/lib/cloudflare/custom-domain.js +154 -0
- package/lib/cloudflare/{dns.js → dns-records.js} +14 -1
- package/lib/cloudflare/index.d.ts +6 -1
- package/lib/cloudflare/index.js +6 -1
- package/lib/cloudflare/permission-groups.d.ts +78 -0
- package/lib/cloudflare/permission-groups.js +48 -0
- package/lib/cloudflare/r2-rest-state-store.d.ts +2 -1
- package/lib/cloudflare/r2-rest-state-store.js +55 -24
- package/lib/cloudflare/static-site.d.ts +17 -18
- package/lib/cloudflare/static-site.js +19 -10
- package/lib/cloudflare/worker.d.ts +14 -0
- package/lib/cloudflare/worker.js +150 -3
- package/lib/{util/encrypt.d.ts → encrypt.d.ts} +1 -1
- package/lib/{util/encrypt.js → encrypt.js} +1 -1
- package/lib/fs/file-system-state-store.js +1 -1
- package/lib/fs/file.d.ts +18 -0
- package/lib/fs/file.js +6 -0
- package/lib/internal/{providers.d.ts → docs/providers.d.ts} +10 -4
- package/lib/internal/docs/providers.js +196 -0
- package/lib/secret.d.ts +3 -0
- package/lib/secret.js +13 -0
- package/lib/{util/serde.d.ts → serde.d.ts} +1 -1
- package/lib/{util/serde.js → serde.js} +12 -4
- package/lib/test/bun.js +3 -2
- package/lib/util/sha256.d.ts +1 -0
- package/lib/util/sha256.js +4 -0
- package/lib/web/vitepress/config.d.ts +2 -1
- package/lib/web/vitepress/config.js +1 -0
- package/lib/web/vitepress/index.d.ts +1 -0
- package/lib/web/vitepress/index.js +1 -0
- package/lib/web/vitepress/process-front-matter-files.d.ts +18 -0
- package/lib/web/vitepress/process-front-matter-files.js +68 -0
- package/lib/web/vitepress/vitepress.js +3 -2
- package/package.json +8 -4
- package/src/ai/document.ts +26 -2
- package/src/ai/index.ts +0 -2
- package/src/alchemy.ts +56 -2
- package/src/apply.ts +21 -20
- package/src/aws/account-id.ts +6 -2
- package/src/aws/credentials.ts +6 -0
- package/src/aws/oidc/oidc-provider.ts +17 -17
- package/src/aws/role.ts +68 -54
- package/src/cloudflare/account-api-token.ts +365 -0
- package/src/cloudflare/account-id.ts +0 -0
- package/src/cloudflare/api.ts +88 -17
- package/src/cloudflare/assets.ts +155 -0
- package/src/cloudflare/bindings.ts +11 -2
- package/src/cloudflare/bucket.ts +493 -133
- package/src/cloudflare/custom-domain.ts +318 -0
- package/src/cloudflare/{dns.ts → dns-records.ts} +36 -22
- package/src/cloudflare/index.ts +6 -1
- package/src/cloudflare/permission-groups.ts +137 -0
- package/src/cloudflare/r2-rest-state-store.ts +87 -42
- package/src/cloudflare/static-site.ts +20 -32
- package/src/cloudflare/worker.ts +253 -5
- package/src/dns/import-dns.ts +4 -4
- package/src/{util/encrypt.ts → encrypt.ts} +7 -10
- package/src/fs/file-system-state-store.ts +5 -5
- package/src/fs/file.ts +29 -0
- package/src/internal/docs/providers.ts +281 -0
- package/src/secret.ts +16 -0
- package/src/{util/serde.ts → serde.ts} +16 -10
- package/src/test/bun.ts +8 -7
- package/src/util/sha256.ts +5 -0
- package/src/web/vitepress/config.ts +3 -1
- package/src/web/vitepress/index.ts +1 -0
- package/src/web/vitepress/process-front-matter-files.ts +98 -0
- package/src/web/vitepress/vitepress.ts +3 -2
- package/lib/ai/approve.d.ts +0 -99
- package/lib/ai/approve.js +0 -76
- package/lib/ai/review.d.ts +0 -122
- package/lib/ai/review.js +0 -101
- package/lib/internal/getting-started.d.ts +0 -21
- package/lib/internal/getting-started.js +0 -87
- package/lib/internal/index.d.ts +0 -3
- package/lib/internal/index.js +0 -3
- package/lib/internal/providers.js +0 -172
- package/lib/internal/tutorial.d.ts +0 -104
- package/lib/internal/tutorial.js +0 -251
- package/src/ai/approve.ts +0 -163
- package/src/ai/review.ts +0 -213
- package/src/internal/getting-started.ts +0 -115
- package/src/internal/index.ts +0 -3
- package/src/internal/providers.ts +0 -241
- package/src/internal/tutorial.ts +0 -392
- /package/lib/cloudflare/{dns.d.ts → dns-records.d.ts} +0 -0
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { type } from "arktype";
|
|
2
|
-
import fs from "fs/promises";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { Data, Document } from "../ai";
|
|
5
|
-
import { alchemy } from "../alchemy";
|
|
6
|
-
import { Folder } from "../fs";
|
|
7
|
-
export async function AlchemyProviderDocs({ srcDir, outDir, filter, }) {
|
|
8
|
-
outDir = typeof outDir === "string" ? outDir : outDir.path;
|
|
9
|
-
const exclude = [
|
|
10
|
-
"util",
|
|
11
|
-
"test",
|
|
12
|
-
"vitepress",
|
|
13
|
-
"vite",
|
|
14
|
-
"shadcn",
|
|
15
|
-
"internal",
|
|
16
|
-
"web",
|
|
17
|
-
];
|
|
18
|
-
// Get all folders in the alchemy/src directory
|
|
19
|
-
let providers = (await fs.readdir(srcDir, {
|
|
20
|
-
withFileTypes: true,
|
|
21
|
-
}))
|
|
22
|
-
.filter((dirent) => dirent.isDirectory() && !exclude.includes(dirent.name))
|
|
23
|
-
.map((dirent) => path.join(dirent.parentPath, dirent.name));
|
|
24
|
-
// For each provider, list all files
|
|
25
|
-
if (filter === false) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
else if (typeof filter === "number") {
|
|
29
|
-
providers = providers.slice(0, filter);
|
|
30
|
-
}
|
|
31
|
-
return await Promise.all(providers.map(async (provider) => {
|
|
32
|
-
const providerName = path.basename(provider);
|
|
33
|
-
const files = (await fs.readdir(path.resolve(provider), {
|
|
34
|
-
withFileTypes: true,
|
|
35
|
-
}))
|
|
36
|
-
.filter((dirent) => dirent.isFile())
|
|
37
|
-
.map((dirent) => path.relative(process.cwd(), path.resolve(provider, dirent.name)))
|
|
38
|
-
.filter((file) => file.endsWith(".ts") && !file.endsWith("index.ts"));
|
|
39
|
-
const { object: { groups }, } = await Data(`docs/${providerName}`, {
|
|
40
|
-
model: {
|
|
41
|
-
id: "o3-mini",
|
|
42
|
-
provider: "openai",
|
|
43
|
-
options: {
|
|
44
|
-
reasoningEffort: "high",
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
temperature: 0.1,
|
|
48
|
-
schema: type({
|
|
49
|
-
groups: type({
|
|
50
|
-
title: type("string").describe("The title of the group, should be the Resource Name exactly as it's defined in code (const ResourceName translates to 'Resource Name') without spaces, e.g. Bucket or Static Site."),
|
|
51
|
-
filename: type("string").describe("The filename of the Resource's Document, e.g. bucket.md or static-site.md"),
|
|
52
|
-
category: type("'Resource'|'Client'|'Utility'|'Types'").describe("The classification of the Resource's Document, one of: Resource, Client, Utility, or Types."),
|
|
53
|
-
}).array(),
|
|
54
|
-
}),
|
|
55
|
-
system: await alchemy `
|
|
56
|
-
You are a technical writer tasked with identifying the distinct documents that need to be written for a document group (folder) in a documentation site.
|
|
57
|
-
You will be provided with a list of documents and instructions on how to classify them.
|
|
58
|
-
Each document has a title, file name, and category.
|
|
59
|
-
`,
|
|
60
|
-
prompt: await alchemy `
|
|
61
|
-
Identify and classify the documents that need to be written for the '${provider}' Service's Alchemy Resources.
|
|
62
|
-
For background knowledge on Alchemy, see ${alchemy.file("./README.md")}.
|
|
63
|
-
For background knowledge on the structure of an Alchemy Resource, see ${alchemy.file("./.cursorrules")}.
|
|
64
|
-
|
|
65
|
-
The ${provider} Service has the following resources:
|
|
66
|
-
${alchemy.files(files)}
|
|
67
|
-
|
|
68
|
-
A file is considered a "Resource" if it contains a const <ResourceName> = Resource(...) call or if it is a function that calls a Resource function, e.g. const TypeScriptFile = () => File(...).
|
|
69
|
-
A file is considered a "Client" if it exposes a wrapper around creating a SDK client or fetch.
|
|
70
|
-
A file is considered a "Utility" if it contains utility functions that are not resources or clients.
|
|
71
|
-
A file is considered a "Types" if it contains just type definitions and maybe helpers around working with those types.
|
|
72
|
-
|
|
73
|
-
The title should be simply the name of the resource's const in code (with spaces added in between each word), e.g. "Bucket" or "Function", except with spaces, e.g. "Static Site" for "const StaticSite". Maintain all other casing.
|
|
74
|
-
|
|
75
|
-
// "Resource Name"
|
|
76
|
-
const ResourceName = Resource(...)
|
|
77
|
-
`,
|
|
78
|
-
});
|
|
79
|
-
// console.log(groups);
|
|
80
|
-
const providerDocsDir = (await Folder(path.join(outDir, providerName)))
|
|
81
|
-
.path;
|
|
82
|
-
const documents = await Promise.allSettled(groups
|
|
83
|
-
.filter((g) => g.category === "Resource")
|
|
84
|
-
.map(async (g) => Document(`docs/${providerName}/${g.title}`, {
|
|
85
|
-
title: g.title,
|
|
86
|
-
path: path.join(providerDocsDir, `${g.filename.replace(".ts", "").replace(".md", "")}.md`),
|
|
87
|
-
model: {
|
|
88
|
-
id: "claude-3-5-sonnet-latest",
|
|
89
|
-
provider: "anthropic",
|
|
90
|
-
// options: {
|
|
91
|
-
// reasoningEffort: "high",
|
|
92
|
-
// },
|
|
93
|
-
},
|
|
94
|
-
prompt: await alchemy `
|
|
95
|
-
You are a technical writer writing API documentation for an Alchemy IaC Resource.
|
|
96
|
-
See ${alchemy.file("./README.md")} to understand the overview of Alchemy.
|
|
97
|
-
See ${alchemy.file("./.cursorrules")} to better understand the structure and convention of an Alchemy Resource.
|
|
98
|
-
|
|
99
|
-
Relevant files for the ${providerName} Service:
|
|
100
|
-
${alchemy.files(files)}
|
|
101
|
-
|
|
102
|
-
Write concise documentation for the "${g.title}" Resource.
|
|
103
|
-
|
|
104
|
-
> [!CAUTION]
|
|
105
|
-
> Avoid the temptation to over explain or over describe. Focus on concise, simple, high value snippets. One heading and 0-1 descriptions per snippet.
|
|
106
|
-
|
|
107
|
-
> [!TIP]
|
|
108
|
-
> Make sure the examples follow a natural progression from the minimal example to logical next steps of how the Resource might be used.
|
|
109
|
-
|
|
110
|
-
Each document must follow the following format:
|
|
111
|
-
|
|
112
|
-
# ${g.title}
|
|
113
|
-
|
|
114
|
-
(simple description with an external link to the provider's website)
|
|
115
|
-
e.g.
|
|
116
|
-
The Efs component lets you add [Amazon Elastic File System (EFS)](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html) to your app.
|
|
117
|
-
|
|
118
|
-
# Minimal Example
|
|
119
|
-
|
|
120
|
-
(brief 1-2 sentences of what it does)
|
|
121
|
-
|
|
122
|
-
\`\`\`ts
|
|
123
|
-
import { ${g.title.replaceAll(" ", "")} } from "alchemy/${providerName}";
|
|
124
|
-
|
|
125
|
-
(example)
|
|
126
|
-
\`\`\`
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# Create the ${g.title}
|
|
130
|
-
|
|
131
|
-
\`\`\`ts
|
|
132
|
-
import { ${g.title.replaceAll(" ", "")} } from "alchemy/${providerName}";
|
|
133
|
-
|
|
134
|
-
(example)
|
|
135
|
-
\`\`\`
|
|
136
|
-
|
|
137
|
-
${providerName === "cloudflare"
|
|
138
|
-
? await alchemy `# Bind to a Worker
|
|
139
|
-
(if it is a Cloudflare Resource)
|
|
140
|
-
|
|
141
|
-
\`\`\`ts
|
|
142
|
-
import { Worker, ${g.title.replaceAll(" ", "")} } from "alchemy/${providerName}";
|
|
143
|
-
|
|
144
|
-
const myResource = await ${g.title.replaceAll(" ", "")}("my-resource", {
|
|
145
|
-
// ...
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
await Worker("my-worker", {
|
|
149
|
-
name: "my-worker",
|
|
150
|
-
script: "console.log('Hello, world!')",
|
|
151
|
-
bindings: {
|
|
152
|
-
myResource,
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
\`\`\``
|
|
156
|
-
: ""}
|
|
157
|
-
`,
|
|
158
|
-
})));
|
|
159
|
-
// Unwrap all documents, fail if any rejected
|
|
160
|
-
const results = await Promise.all(documents.map((r) => {
|
|
161
|
-
if (r.status === "rejected") {
|
|
162
|
-
throw r.reason;
|
|
163
|
-
}
|
|
164
|
-
return r.value;
|
|
165
|
-
}));
|
|
166
|
-
return {
|
|
167
|
-
dir: providerDocsDir,
|
|
168
|
-
provider: providerName,
|
|
169
|
-
documents: results,
|
|
170
|
-
};
|
|
171
|
-
}));
|
|
172
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import type { CoreMessage } from "ai";
|
|
2
|
-
import { Document } from "../ai";
|
|
3
|
-
import type { ModelConfig } from "../ai/client";
|
|
4
|
-
import type { Context } from "../context";
|
|
5
|
-
import type { Folder } from "../fs";
|
|
6
|
-
import { Resource } from "../resource";
|
|
7
|
-
/**
|
|
8
|
-
* Properties for creating or updating a Tutorial
|
|
9
|
-
*/
|
|
10
|
-
export interface TutorialProps {
|
|
11
|
-
/**
|
|
12
|
-
* The output directory for the tutorial document.
|
|
13
|
-
*/
|
|
14
|
-
path: string | Folder;
|
|
15
|
-
/**
|
|
16
|
-
* The title of the tutorial.
|
|
17
|
-
*/
|
|
18
|
-
title: string;
|
|
19
|
-
/**
|
|
20
|
-
* The prompt to use for generating the tutorial.
|
|
21
|
-
* This should include specific details about the tool or framework.
|
|
22
|
-
*/
|
|
23
|
-
prompt: string;
|
|
24
|
-
/**
|
|
25
|
-
* Optional difficulty level for the tutorial.
|
|
26
|
-
* Defaults to "beginner".
|
|
27
|
-
*/
|
|
28
|
-
difficulty?: "beginner" | "intermediate" | "advanced";
|
|
29
|
-
/**
|
|
30
|
-
* Optional estimated time to complete the tutorial in minutes.
|
|
31
|
-
* Defaults to 30.
|
|
32
|
-
*/
|
|
33
|
-
estimatedTime?: number;
|
|
34
|
-
/**
|
|
35
|
-
* Optional model configuration for generating the tutorial.
|
|
36
|
-
* Defaults to Claude 3.5 Sonnet.
|
|
37
|
-
*/
|
|
38
|
-
model?: ModelConfig;
|
|
39
|
-
/**
|
|
40
|
-
* Maximum number of review iterations.
|
|
41
|
-
* Defaults to 3.
|
|
42
|
-
*/
|
|
43
|
-
maxIterations?: number;
|
|
44
|
-
/**
|
|
45
|
-
* Initial message history for the conversation.
|
|
46
|
-
* If not provided, a new conversation will be started.
|
|
47
|
-
*/
|
|
48
|
-
messages?: CoreMessage[];
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Output returned after Tutorial creation/update
|
|
52
|
-
*/
|
|
53
|
-
export interface Tutorial extends TutorialProps, Resource<"docs::Tutorial"> {
|
|
54
|
-
/**
|
|
55
|
-
* The Document resource
|
|
56
|
-
*/
|
|
57
|
-
document: Document;
|
|
58
|
-
/**
|
|
59
|
-
* The content of the tutorial
|
|
60
|
-
*/
|
|
61
|
-
content: string;
|
|
62
|
-
/**
|
|
63
|
-
* Message history from the conversation.
|
|
64
|
-
*/
|
|
65
|
-
messages: CoreMessage[];
|
|
66
|
-
/**
|
|
67
|
-
* Time at which the tutorial was created
|
|
68
|
-
*/
|
|
69
|
-
createdAt: number;
|
|
70
|
-
/**
|
|
71
|
-
* Time at which the tutorial was last updated
|
|
72
|
-
*/
|
|
73
|
-
updatedAt: number;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Creates a tutorial document with iterative review and improvement
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* // Create a basic tutorial
|
|
80
|
-
* const tutorial = await Tutorial("getting-started", {
|
|
81
|
-
* path: "docs/tutorials/getting-started",
|
|
82
|
-
* title: "Getting Started with Alchemy",
|
|
83
|
-
* prompt: "Create a tutorial for getting started with the Alchemy framework",
|
|
84
|
-
* difficulty: "beginner",
|
|
85
|
-
* estimatedTime: 30
|
|
86
|
-
* });
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* // Create an advanced tutorial with custom model and continue from existing messages
|
|
90
|
-
* const advancedTutorial = await Tutorial("advanced-features", {
|
|
91
|
-
* path: "docs/tutorials/advanced-features",
|
|
92
|
-
* title: "Advanced Alchemy Features",
|
|
93
|
-
* prompt: "Create a tutorial covering advanced features of the Alchemy framework",
|
|
94
|
-
* difficulty: "advanced",
|
|
95
|
-
* estimatedTime: 60,
|
|
96
|
-
* model: {
|
|
97
|
-
* id: "claude-3-7-sonnet-latest",
|
|
98
|
-
* provider: "anthropic"
|
|
99
|
-
* },
|
|
100
|
-
* maxIterations: 5,
|
|
101
|
-
* messages: basicTutorial.messages
|
|
102
|
-
* });
|
|
103
|
-
*/
|
|
104
|
-
export declare const Tutorial: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Tutorial>, id: string, props: TutorialProps) => Promise<Tutorial>);
|
package/lib/internal/tutorial.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import { Approve, Document, Review } from "../ai";
|
|
2
|
-
import { alchemy } from "../alchemy";
|
|
3
|
-
import { Resource } from "../resource";
|
|
4
|
-
/**
|
|
5
|
-
* Creates a tutorial document with iterative review and improvement
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* // Create a basic tutorial
|
|
9
|
-
* const tutorial = await Tutorial("getting-started", {
|
|
10
|
-
* path: "docs/tutorials/getting-started",
|
|
11
|
-
* title: "Getting Started with Alchemy",
|
|
12
|
-
* prompt: "Create a tutorial for getting started with the Alchemy framework",
|
|
13
|
-
* difficulty: "beginner",
|
|
14
|
-
* estimatedTime: 30
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* // Create an advanced tutorial with custom model and continue from existing messages
|
|
19
|
-
* const advancedTutorial = await Tutorial("advanced-features", {
|
|
20
|
-
* path: "docs/tutorials/advanced-features",
|
|
21
|
-
* title: "Advanced Alchemy Features",
|
|
22
|
-
* prompt: "Create a tutorial covering advanced features of the Alchemy framework",
|
|
23
|
-
* difficulty: "advanced",
|
|
24
|
-
* estimatedTime: 60,
|
|
25
|
-
* model: {
|
|
26
|
-
* id: "claude-3-7-sonnet-latest",
|
|
27
|
-
* provider: "anthropic"
|
|
28
|
-
* },
|
|
29
|
-
* maxIterations: 5,
|
|
30
|
-
* messages: basicTutorial.messages
|
|
31
|
-
* });
|
|
32
|
-
*/
|
|
33
|
-
export const Tutorial = Resource("docs::Tutorial", async function (id, props) {
|
|
34
|
-
const { path: outFile, title, prompt, difficulty = "beginner", estimatedTime = 30, model = {
|
|
35
|
-
id: "claude-3-5-sonnet-latest",
|
|
36
|
-
provider: "anthropic",
|
|
37
|
-
}, maxIterations = 3, messages: initialMessages = [], } = props;
|
|
38
|
-
console.log(`Tutorial: Starting creation of "${title}" (ID: ${id})`);
|
|
39
|
-
// Handle deletion phase
|
|
40
|
-
if (this.phase === "delete") {
|
|
41
|
-
console.log(`Tutorial: Deleting tutorial "${title}" (ID: ${id})`);
|
|
42
|
-
return this.destroy();
|
|
43
|
-
}
|
|
44
|
-
// System prompts
|
|
45
|
-
const docSystemPrompt = `You are a technical writer creating a comprehensive tutorial.
|
|
46
|
-
|
|
47
|
-
Your task is to create a detailed tutorial about ${title} with difficulty level: ${difficulty} and estimated time to complete: ${estimatedTime} minutes.
|
|
48
|
-
|
|
49
|
-
The tutorial should take users from zero knowledge to a working understanding of the tool or framework.
|
|
50
|
-
|
|
51
|
-
The tutorial should be structured as follows:
|
|
52
|
-
|
|
53
|
-
# ${title}
|
|
54
|
-
|
|
55
|
-
## Overview
|
|
56
|
-
|
|
57
|
-
(Provide a brief introduction to the tool/framework, its purpose, and what users will learn in this tutorial)
|
|
58
|
-
|
|
59
|
-
## Prerequisites
|
|
60
|
-
|
|
61
|
-
(List any prerequisites, tools, or knowledge required before starting the tutorial)
|
|
62
|
-
|
|
63
|
-
## Setup
|
|
64
|
-
|
|
65
|
-
### Installation
|
|
66
|
-
|
|
67
|
-
\`\`\`bash
|
|
68
|
-
# Installation commands
|
|
69
|
-
\`\`\`
|
|
70
|
-
|
|
71
|
-
### Configuration
|
|
72
|
-
|
|
73
|
-
(Explain any necessary configuration steps)
|
|
74
|
-
|
|
75
|
-
\`\`\`bash
|
|
76
|
-
# Configuration commands or code
|
|
77
|
-
\`\`\`
|
|
78
|
-
|
|
79
|
-
## Step 1: [First Step Title]
|
|
80
|
-
|
|
81
|
-
(Explain the first step in detail)
|
|
82
|
-
|
|
83
|
-
\`\`\`bash
|
|
84
|
-
# Commands or code for the first step
|
|
85
|
-
\`\`\`
|
|
86
|
-
|
|
87
|
-
(Explain what the code does and why it's important)
|
|
88
|
-
|
|
89
|
-
## Step 2: [Second Step Title]
|
|
90
|
-
|
|
91
|
-
(Explain the second step in detail)
|
|
92
|
-
|
|
93
|
-
\`\`\`bash
|
|
94
|
-
# Commands or code for the second step
|
|
95
|
-
\`\`\`
|
|
96
|
-
|
|
97
|
-
(Explain what the code does and why it's important)
|
|
98
|
-
|
|
99
|
-
## Step 3: [Third Step Title]
|
|
100
|
-
|
|
101
|
-
(Explain the third step in detail)
|
|
102
|
-
|
|
103
|
-
\`\`\`bash
|
|
104
|
-
# Commands or code for the third step
|
|
105
|
-
\`\`\`
|
|
106
|
-
|
|
107
|
-
(Explain what the code does and why it's important)
|
|
108
|
-
|
|
109
|
-
## Step 4: [Fourth Step Title]
|
|
110
|
-
|
|
111
|
-
(Explain the fourth step in detail)
|
|
112
|
-
|
|
113
|
-
\`\`\`bash
|
|
114
|
-
# Commands or code for the fourth step
|
|
115
|
-
\`\`\`
|
|
116
|
-
|
|
117
|
-
(Explain what the code does and why it's important)
|
|
118
|
-
|
|
119
|
-
## Step 5: [Fifth Step Title]
|
|
120
|
-
|
|
121
|
-
(Explain the fifth step in detail)
|
|
122
|
-
|
|
123
|
-
\`\`\`bash
|
|
124
|
-
# Commands or code for the fifth step
|
|
125
|
-
\`\`\`
|
|
126
|
-
|
|
127
|
-
(Explain what the code does and why it's important)
|
|
128
|
-
|
|
129
|
-
## Testing Your Work
|
|
130
|
-
|
|
131
|
-
(Explain how to verify that everything is working correctly)
|
|
132
|
-
|
|
133
|
-
\`\`\`bash
|
|
134
|
-
# Testing commands or code
|
|
135
|
-
\`\`\`
|
|
136
|
-
|
|
137
|
-
## Troubleshooting
|
|
138
|
-
|
|
139
|
-
(Common issues users might encounter and how to resolve them)
|
|
140
|
-
|
|
141
|
-
## Next Steps
|
|
142
|
-
|
|
143
|
-
(Suggest additional resources, advanced topics, or projects to try next)
|
|
144
|
-
|
|
145
|
-
## Additional Resources
|
|
146
|
-
|
|
147
|
-
(Links to documentation, community resources, or related tutorials)`;
|
|
148
|
-
// Initial message if none provided
|
|
149
|
-
const startingMessages = initialMessages.length > 0
|
|
150
|
-
? initialMessages
|
|
151
|
-
: [
|
|
152
|
-
{
|
|
153
|
-
role: "user",
|
|
154
|
-
content: `Create a comprehensive tutorial about ${title}.\n\n${prompt}\n\nDifficulty level: ${difficulty}\nEstimated time to complete: ${estimatedTime} minutes`,
|
|
155
|
-
},
|
|
156
|
-
];
|
|
157
|
-
// Generate the initial tutorial
|
|
158
|
-
console.log(`Tutorial: Generating initial tutorial for "${title}"`);
|
|
159
|
-
let tutorial = await Document(`document`, {
|
|
160
|
-
title: title,
|
|
161
|
-
path: typeof outFile === "string" ? outFile : outFile.path,
|
|
162
|
-
model,
|
|
163
|
-
messages: startingMessages,
|
|
164
|
-
system: docSystemPrompt,
|
|
165
|
-
});
|
|
166
|
-
console.log(`Tutorial: Initial tutorial generated for "${title}" (${tutorial.content.length} chars)`);
|
|
167
|
-
// Review and improve the tutorial in a loop
|
|
168
|
-
let iteration = 0;
|
|
169
|
-
let approved = false;
|
|
170
|
-
let finalMessages = tutorial.messages;
|
|
171
|
-
while (!approved && iteration < maxIterations) {
|
|
172
|
-
iteration++;
|
|
173
|
-
console.log(`Tutorial: Starting review iteration ${iteration}/${maxIterations} for "${title}"`);
|
|
174
|
-
// Review the tutorial using system prompt
|
|
175
|
-
console.log(`Tutorial: Requesting review for iteration ${iteration}`);
|
|
176
|
-
const review = await Review(`review-${iteration}`, {
|
|
177
|
-
messages: finalMessages,
|
|
178
|
-
system: await alchemy `Please review this tutorial for correctness, conciseness, logical flow, and accurateness.
|
|
179
|
-
|
|
180
|
-
The tutorial should:
|
|
181
|
-
1. Be technically accurate and free of errors
|
|
182
|
-
2. Be concise without over-explaining
|
|
183
|
-
3. Have a logical flow from basic to advanced concepts
|
|
184
|
-
4. Be accurate in its descriptions and instructions
|
|
185
|
-
5. Be appropriate for the ${difficulty} difficulty level
|
|
186
|
-
6. Be completable within approximately ${estimatedTime} minutes
|
|
187
|
-
|
|
188
|
-
Provide specific feedback on areas that need improvement.`,
|
|
189
|
-
model,
|
|
190
|
-
});
|
|
191
|
-
// Extract the actual review content from the last assistant message
|
|
192
|
-
const reviewContent = review.messages[review.messages.length - 1]?.content || "";
|
|
193
|
-
console.log(`Tutorial: Review received for iteration ${iteration} (${reviewContent.length} chars)`);
|
|
194
|
-
// Check if the tutorial is approved using system prompt
|
|
195
|
-
console.log(`Tutorial: Evaluating approval for iteration ${iteration}`);
|
|
196
|
-
const approvalResult = await Approve(`approval-${iteration}`, {
|
|
197
|
-
messages: review.messages,
|
|
198
|
-
system: await alchemy `Based on the review above, determine if the tutorial meets the quality standards.
|
|
199
|
-
The tutorial should be approved if:
|
|
200
|
-
1. It is technically accurate and free of errors
|
|
201
|
-
2. It is concise without over-explaining
|
|
202
|
-
3. It has a logical flow from basic to advanced concepts
|
|
203
|
-
4. It is accurate in its descriptions and instructions
|
|
204
|
-
5. It is appropriate for the ${difficulty} difficulty level
|
|
205
|
-
6. It is completable within approximately ${estimatedTime} minutes
|
|
206
|
-
|
|
207
|
-
Respond with APPROVED or DENIED, followed by your explanation.`,
|
|
208
|
-
});
|
|
209
|
-
console.log(`Tutorial: Approval result for iteration ${iteration}: ${approvalResult.approved ? "APPROVED" : "DENIED"}`);
|
|
210
|
-
// Log approval status
|
|
211
|
-
if (approvalResult.approved) {
|
|
212
|
-
console.log(`Tutorial: Final tutorial approved: ${approvalResult.explanation}`);
|
|
213
|
-
approved = true;
|
|
214
|
-
finalMessages = approvalResult.messages;
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
console.log(`Tutorial: Tutorial needs improvement: ${approvalResult.explanation}`);
|
|
218
|
-
// Add improvement request and generate an improved tutorial
|
|
219
|
-
const improvementMessages = [
|
|
220
|
-
...approvalResult.messages,
|
|
221
|
-
{
|
|
222
|
-
role: "user",
|
|
223
|
-
content: `Please create an improved version of the tutorial that addresses the issues identified in the review: ${approvalResult.explanation}`,
|
|
224
|
-
},
|
|
225
|
-
];
|
|
226
|
-
console.log(`Tutorial: Regenerating tutorial based on feedback for iteration ${iteration}`);
|
|
227
|
-
tutorial = await Document(`tutorial-${iteration}`, {
|
|
228
|
-
title: title,
|
|
229
|
-
path: typeof outFile === "string" ? outFile : outFile.path,
|
|
230
|
-
model,
|
|
231
|
-
messages: improvementMessages,
|
|
232
|
-
system: docSystemPrompt,
|
|
233
|
-
});
|
|
234
|
-
console.log(`Tutorial: Improved tutorial generated for iteration ${iteration} (${tutorial.content.length} chars)`);
|
|
235
|
-
finalMessages = tutorial.messages;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (!approved) {
|
|
239
|
-
console.log(`Tutorial: Tutorial not approved after ${maxIterations} iterations. Using the best version available.`);
|
|
240
|
-
}
|
|
241
|
-
console.log(`Tutorial: Completed creation of "${title}" (ID: ${id})`);
|
|
242
|
-
// Return the tutorial resource
|
|
243
|
-
return this({
|
|
244
|
-
...props,
|
|
245
|
-
document: tutorial,
|
|
246
|
-
content: tutorial.content,
|
|
247
|
-
messages: finalMessages,
|
|
248
|
-
createdAt: Date.now(),
|
|
249
|
-
updatedAt: Date.now(),
|
|
250
|
-
});
|
|
251
|
-
});
|
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
|
-
}
|