alchemy 0.2.3 → 0.2.5
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/lib/ai/ark.d.ts +11 -0
- package/lib/ai/ark.js +86 -0
- package/lib/ai/client.d.ts +51 -0
- package/lib/ai/client.js +29 -0
- package/lib/ai/data.d.ts +101 -0
- package/lib/ai/data.js +70 -0
- package/lib/ai/document.d.ts +101 -0
- package/lib/ai/document.js +82 -0
- package/lib/ai/index.d.ts +3 -0
- package/lib/ai/index.js +3 -0
- package/lib/alchemy.d.ts +83 -2
- package/lib/alchemy.js +31 -3
- package/lib/aws/bucket.d.ts +87 -1
- package/lib/aws/bucket.js +48 -1
- package/lib/aws/function.d.ts +186 -1
- package/lib/aws/function.js +62 -8
- package/lib/aws/oidc/github-oidc-provider.d.ts +81 -0
- package/lib/aws/oidc/github-oidc-provider.js +68 -0
- package/lib/aws/oidc/oidc-provider.d.ts +14 -6
- package/lib/aws/oidc/oidc-provider.js +26 -5
- package/lib/aws/policy-attachment.d.ts +44 -1
- package/lib/aws/policy-attachment.js +31 -0
- package/lib/aws/policy.d.ts +160 -1
- package/lib/aws/policy.js +78 -0
- package/lib/aws/queue.d.ts +83 -1
- package/lib/aws/queue.js +39 -0
- package/lib/aws/role.d.ts +162 -1
- package/lib/aws/role.js +114 -0
- package/lib/aws/ses.d.ts +57 -2
- package/lib/aws/ses.js +42 -1
- package/lib/aws/table.d.ts +96 -1
- package/lib/aws/table.js +36 -0
- package/lib/cloudflare/asset-manifest.js +0 -1
- package/lib/cloudflare/bound.js +0 -1
- package/lib/cloudflare/bucket.d.ts +37 -1
- package/lib/cloudflare/bucket.js +36 -0
- package/lib/cloudflare/durable-object-namespace.d.ts +25 -0
- package/lib/cloudflare/durable-object-namespace.js +22 -0
- package/lib/cloudflare/kv-namespace.d.ts +37 -1
- package/lib/cloudflare/kv-namespace.js +36 -0
- package/lib/cloudflare/static-site.d.ts +53 -1
- package/lib/cloudflare/static-site.js +53 -1
- package/lib/cloudflare/worker-metadata.js +0 -1
- package/lib/cloudflare/worker.d.ts +64 -1
- package/lib/cloudflare/worker.js +63 -0
- package/lib/cloudflare/wrangler.json.d.ts +1 -1
- package/lib/cloudflare/zone-settings.js +0 -1
- package/lib/cloudflare/zone.d.ts +56 -1
- package/lib/cloudflare/zone.js +55 -0
- package/lib/destroy.js +1 -1
- package/lib/esbuild/bundle.d.ts +43 -4
- package/lib/esbuild/bundle.js +16 -0
- package/lib/fs/file-collection.d.ts +16 -0
- package/lib/fs/file-collection.js +6 -0
- package/lib/fs/file-ref.d.ts +14 -0
- package/lib/fs/file-ref.js +6 -0
- package/lib/fs/file.d.ts +71 -25
- package/lib/fs/file.js +20 -44
- package/lib/fs/folder.d.ts +37 -5
- package/lib/fs/folder.js +26 -2
- package/lib/fs/index.d.ts +6 -0
- package/lib/fs/index.js +6 -0
- package/lib/fs/json-file.d.ts +16 -0
- package/lib/fs/json-file.js +7 -0
- package/lib/fs/text-file.d.ts +12 -0
- package/lib/fs/text-file.js +7 -0
- package/lib/fs/typescript-file.d.ts +19 -0
- package/lib/fs/typescript-file.js +14 -0
- package/lib/fs/yaml-file.d.ts +19 -0
- package/lib/fs/yaml-file.js +8 -0
- package/lib/github/secret.d.ts +63 -2
- package/lib/github/secret.js +61 -1
- package/lib/internal/docs.d.ts +5 -0
- package/lib/internal/docs.js +287 -0
- package/lib/resource.d.ts +1 -1
- package/lib/secret.d.ts +67 -0
- package/lib/secret.js +67 -0
- package/lib/shadcn/component.d.ts +1 -1
- package/lib/stripe/price.d.ts +51 -1
- package/lib/stripe/price.js +50 -0
- package/lib/stripe/product.d.ts +39 -1
- package/lib/stripe/product.js +38 -0
- package/lib/stripe/webhook.d.ts +46 -1
- package/lib/stripe/webhook.js +45 -0
- package/lib/test/bun.d.ts +64 -0
- package/lib/test/bun.js +35 -3
- package/lib/util/serde.js +14 -0
- package/lib/vite/vite.d.ts +1 -1
- package/lib/vitepress/dependencies.d.ts +2 -6
- package/lib/vitepress/vitepress.d.ts +12 -1
- package/lib/vitepress/vitepress.js +29 -23
- package/package.json +8 -3
- package/src/ai/ark.ts +118 -0
- package/src/ai/client.ts +78 -0
- package/src/ai/data.ts +149 -0
- package/src/ai/document.ts +165 -0
- package/src/ai/index.ts +3 -0
- package/src/alchemy.ts +88 -5
- package/src/aws/bucket.ts +111 -7
- package/src/aws/function.ts +231 -10
- package/src/aws/oidc/github-oidc-provider.ts +83 -0
- package/src/aws/oidc/oidc-provider.ts +39 -7
- package/src/aws/policy-attachment.ts +44 -1
- package/src/aws/policy.ts +177 -2
- package/src/aws/queue.ts +89 -0
- package/src/aws/role.ts +174 -2
- package/src/aws/ses.ts +56 -1
- package/src/aws/table.ts +103 -0
- package/src/cloudflare/bucket.ts +36 -0
- package/src/cloudflare/durable-object-namespace.ts +25 -0
- package/src/cloudflare/kv-namespace.ts +36 -0
- package/src/cloudflare/static-site.ts +53 -1
- package/src/cloudflare/worker.ts +63 -0
- package/src/cloudflare/zone.ts +55 -0
- package/src/destroy.ts +1 -1
- package/src/esbuild/bundle.ts +53 -3
- package/src/fs/file-collection.ts +24 -0
- package/src/fs/file-ref.ts +22 -0
- package/src/fs/file.ts +70 -77
- package/src/fs/folder.ts +44 -5
- package/src/fs/index.ts +6 -0
- package/src/fs/json-file.ts +23 -0
- package/src/fs/text-file.ts +19 -0
- package/src/fs/typescript-file.ts +36 -0
- package/src/fs/yaml-file.ts +26 -0
- package/src/github/secret.ts +65 -2
- package/src/internal/docs.ts +338 -0
- package/src/resource.ts +1 -1
- package/src/secret.ts +67 -0
- package/src/stripe/price.ts +50 -0
- package/src/stripe/product.ts +38 -0
- package/src/stripe/webhook.ts +45 -0
- package/src/test/bun.ts +83 -3
- package/src/util/serde.ts +17 -0
- package/src/vitepress/vitepress.ts +47 -26
- package/lib/docs/document.d.ts +0 -123
- package/lib/docs/document.js +0 -67
- package/lib/docs/index.d.ts +0 -1
- package/lib/docs/index.js +0 -1
- package/src/docs/document.ts +0 -225
- package/src/docs/index.ts +0 -1
package/src/docs/document.ts
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
2
|
-
import { generateText } from "ai";
|
|
3
|
-
import fs from "node:fs/promises";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import type { Context } from "../context";
|
|
6
|
-
import { Resource } from "../resource";
|
|
7
|
-
import type { Secret } from "../secret";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Base properties for a Document
|
|
11
|
-
*/
|
|
12
|
-
interface BaseDocumentProps {
|
|
13
|
-
/**
|
|
14
|
-
* Path to the markdown document
|
|
15
|
-
*/
|
|
16
|
-
path: string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Base URL for the OpenAI API
|
|
20
|
-
* @default 'https://api.openai.com/v1'
|
|
21
|
-
*/
|
|
22
|
-
baseURL?: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Properties for creating a document with static content
|
|
27
|
-
*/
|
|
28
|
-
interface StaticDocumentProps extends BaseDocumentProps {
|
|
29
|
-
/**
|
|
30
|
-
* Static content of the document
|
|
31
|
-
*/
|
|
32
|
-
content: string;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Prompt for generating content
|
|
36
|
-
* @internal This is marked as never to ensure content and prompt are mutually exclusive
|
|
37
|
-
*/
|
|
38
|
-
prompt?: never;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* OpenAI API key
|
|
42
|
-
* @internal This is marked as never since it's not needed for static content
|
|
43
|
-
*/
|
|
44
|
-
apiKey?: never;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Model configuration
|
|
48
|
-
* @internal This is marked as never since it's not needed for static content
|
|
49
|
-
*/
|
|
50
|
-
model?: never;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Context files
|
|
54
|
-
* @internal This is marked as never since it's not needed for static content
|
|
55
|
-
*/
|
|
56
|
-
context?: never;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Properties for creating a document with AI-generated content
|
|
61
|
-
*/
|
|
62
|
-
interface GeneratedDocumentProps extends BaseDocumentProps {
|
|
63
|
-
/**
|
|
64
|
-
* Static content of the document
|
|
65
|
-
* @internal This is marked as never to ensure content and prompt are mutually exclusive
|
|
66
|
-
*/
|
|
67
|
-
content?: never;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Prompt for generating content
|
|
71
|
-
* Can be either a single string or an array of strings that will be joined with newlines
|
|
72
|
-
*/
|
|
73
|
-
prompt: string | string[];
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Optional context files to include in the prompt
|
|
77
|
-
* Key is the relative path to the file
|
|
78
|
-
* Value can be either the content string or another Document resource
|
|
79
|
-
*/
|
|
80
|
-
context?: {
|
|
81
|
-
[relativePath: string]:
|
|
82
|
-
| string
|
|
83
|
-
| Document
|
|
84
|
-
| {
|
|
85
|
-
path: string;
|
|
86
|
-
content: string;
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* OpenAI API key to use for generating content
|
|
92
|
-
* If not provided, will use OPENAI_API_KEY environment variable
|
|
93
|
-
*/
|
|
94
|
-
apiKey?: Secret;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Model configuration
|
|
98
|
-
*/
|
|
99
|
-
model?: {
|
|
100
|
-
/**
|
|
101
|
-
* Model ID to use
|
|
102
|
-
* @default 'gpt-4o'
|
|
103
|
-
*/
|
|
104
|
-
id?: string;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Model provider name
|
|
108
|
-
* @default 'openai'
|
|
109
|
-
*/
|
|
110
|
-
provider?: string;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Model-specific options
|
|
114
|
-
*/
|
|
115
|
-
options?: Record<string, unknown>;
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Properties for creating or updating a Document
|
|
121
|
-
* Must provide either static content or a prompt for AI generation
|
|
122
|
-
*/
|
|
123
|
-
export type DocumentProps = StaticDocumentProps | GeneratedDocumentProps;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* A markdown document that can be created, updated, and deleted
|
|
127
|
-
*/
|
|
128
|
-
export interface Document
|
|
129
|
-
extends Omit<DocumentProps, "content" | "prompt" | "context">,
|
|
130
|
-
Resource<"docs::Document"> {
|
|
131
|
-
/**
|
|
132
|
-
* Content of the document
|
|
133
|
-
*/
|
|
134
|
-
content: string;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Time at which the document was created
|
|
138
|
-
*/
|
|
139
|
-
createdAt: number;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Time at which the document was last updated
|
|
143
|
-
*/
|
|
144
|
-
updatedAt: number;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Resource for managing markdown documents using the Vercel AI SDK
|
|
149
|
-
*/
|
|
150
|
-
export const Document = Resource(
|
|
151
|
-
"docs::Document",
|
|
152
|
-
async function (
|
|
153
|
-
this: Context<Document, DocumentProps>,
|
|
154
|
-
id: string,
|
|
155
|
-
props: DocumentProps,
|
|
156
|
-
): Promise<Document> {
|
|
157
|
-
// Ensure directory exists
|
|
158
|
-
await fs.mkdir(path.dirname(props.path), { recursive: true });
|
|
159
|
-
|
|
160
|
-
if (this.phase === "delete") {
|
|
161
|
-
try {
|
|
162
|
-
await fs.unlink(props.path);
|
|
163
|
-
} catch (error: any) {
|
|
164
|
-
// Ignore if file doesn't exist
|
|
165
|
-
if (error.code !== "ENOENT") {
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return this.destroy();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
let content: string;
|
|
173
|
-
|
|
174
|
-
console.log("Generating content for", props.path);
|
|
175
|
-
|
|
176
|
-
// Generate content if prompt is provided
|
|
177
|
-
if ("prompt" in props) {
|
|
178
|
-
// Get API key from props or environment
|
|
179
|
-
const apiKey = props.apiKey?.unencrypted || process.env.OPENAI_API_KEY;
|
|
180
|
-
if (!apiKey) {
|
|
181
|
-
throw new Error("OpenAI API key is required for content generation");
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Initialize OpenAI compatible provider
|
|
185
|
-
const provider = createOpenAICompatible({
|
|
186
|
-
name: props.model?.provider || "openai",
|
|
187
|
-
apiKey,
|
|
188
|
-
baseURL: props.baseURL || "https://api.openai.com/v1",
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// Build the full prompt with context if provided
|
|
192
|
-
const fullPrompt = Array.isArray(props.prompt)
|
|
193
|
-
? props.prompt.join("\n")
|
|
194
|
-
: props.prompt!;
|
|
195
|
-
|
|
196
|
-
// console.log(fullPrompt);
|
|
197
|
-
|
|
198
|
-
const { text } = await generateText({
|
|
199
|
-
model: provider(props.model?.id || "gpt-4o"),
|
|
200
|
-
prompt: fullPrompt,
|
|
201
|
-
...(props.model?.options || {}),
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
content = text;
|
|
205
|
-
} else {
|
|
206
|
-
// Use static content
|
|
207
|
-
content = props.content;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Write content to file
|
|
211
|
-
await fs.writeFile(props.path, content);
|
|
212
|
-
|
|
213
|
-
// Get file stats for timestamps
|
|
214
|
-
const stats = await fs.stat(props.path);
|
|
215
|
-
|
|
216
|
-
// Return the resource
|
|
217
|
-
return this({
|
|
218
|
-
path: props.path,
|
|
219
|
-
baseURL: props.baseURL,
|
|
220
|
-
content,
|
|
221
|
-
createdAt: stats.birthtimeMs,
|
|
222
|
-
updatedAt: stats.mtimeMs,
|
|
223
|
-
});
|
|
224
|
-
},
|
|
225
|
-
);
|
package/src/docs/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./document";
|