alchemy 0.2.3 → 0.2.4

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 (138) hide show
  1. package/lib/ai/ark.d.ts +11 -0
  2. package/lib/ai/ark.js +86 -0
  3. package/lib/ai/client.d.ts +51 -0
  4. package/lib/ai/client.js +29 -0
  5. package/lib/ai/document.d.ts +97 -0
  6. package/lib/ai/document.js +82 -0
  7. package/lib/{docs → ai}/index.d.ts +1 -0
  8. package/lib/{docs → ai}/index.js +1 -0
  9. package/lib/ai/object.d.ts +101 -0
  10. package/lib/ai/object.js +70 -0
  11. package/lib/alchemy.d.ts +83 -2
  12. package/lib/alchemy.js +31 -3
  13. package/lib/aws/bucket.d.ts +87 -1
  14. package/lib/aws/bucket.js +48 -1
  15. package/lib/aws/function.d.ts +186 -1
  16. package/lib/aws/function.js +62 -8
  17. package/lib/aws/oidc/github-oidc-provider.d.ts +81 -0
  18. package/lib/aws/oidc/github-oidc-provider.js +68 -0
  19. package/lib/aws/oidc/oidc-provider.d.ts +14 -6
  20. package/lib/aws/oidc/oidc-provider.js +26 -5
  21. package/lib/aws/policy-attachment.d.ts +44 -1
  22. package/lib/aws/policy-attachment.js +31 -0
  23. package/lib/aws/policy.d.ts +160 -1
  24. package/lib/aws/policy.js +78 -0
  25. package/lib/aws/queue.d.ts +83 -1
  26. package/lib/aws/queue.js +39 -0
  27. package/lib/aws/role.d.ts +162 -1
  28. package/lib/aws/role.js +114 -0
  29. package/lib/aws/ses.d.ts +57 -2
  30. package/lib/aws/ses.js +42 -1
  31. package/lib/aws/table.d.ts +96 -1
  32. package/lib/aws/table.js +36 -0
  33. package/lib/cloudflare/asset-manifest.js +0 -1
  34. package/lib/cloudflare/bound.js +0 -1
  35. package/lib/cloudflare/bucket.d.ts +37 -1
  36. package/lib/cloudflare/bucket.js +36 -0
  37. package/lib/cloudflare/durable-object-namespace.d.ts +25 -0
  38. package/lib/cloudflare/durable-object-namespace.js +22 -0
  39. package/lib/cloudflare/kv-namespace.d.ts +37 -1
  40. package/lib/cloudflare/kv-namespace.js +36 -0
  41. package/lib/cloudflare/static-site.d.ts +53 -1
  42. package/lib/cloudflare/static-site.js +53 -1
  43. package/lib/cloudflare/worker-metadata.js +0 -1
  44. package/lib/cloudflare/worker.d.ts +64 -1
  45. package/lib/cloudflare/worker.js +63 -0
  46. package/lib/cloudflare/wrangler.json.d.ts +1 -1
  47. package/lib/cloudflare/zone-settings.js +0 -1
  48. package/lib/cloudflare/zone.d.ts +56 -1
  49. package/lib/cloudflare/zone.js +55 -0
  50. package/lib/destroy.js +1 -1
  51. package/lib/esbuild/bundle.d.ts +43 -4
  52. package/lib/esbuild/bundle.js +16 -0
  53. package/lib/fs/file-collection.d.ts +16 -0
  54. package/lib/fs/file-collection.js +6 -0
  55. package/lib/fs/file-ref.d.ts +14 -0
  56. package/lib/fs/file-ref.js +6 -0
  57. package/lib/fs/file.d.ts +71 -25
  58. package/lib/fs/file.js +20 -44
  59. package/lib/fs/folder.d.ts +37 -5
  60. package/lib/fs/folder.js +26 -2
  61. package/lib/fs/index.d.ts +6 -0
  62. package/lib/fs/index.js +6 -0
  63. package/lib/fs/json-file.d.ts +16 -0
  64. package/lib/fs/json-file.js +7 -0
  65. package/lib/fs/text-file.d.ts +12 -0
  66. package/lib/fs/text-file.js +7 -0
  67. package/lib/fs/typescript-file.d.ts +19 -0
  68. package/lib/fs/typescript-file.js +14 -0
  69. package/lib/fs/yaml-file.d.ts +19 -0
  70. package/lib/fs/yaml-file.js +8 -0
  71. package/lib/github/secret.d.ts +63 -2
  72. package/lib/github/secret.js +61 -1
  73. package/lib/internal/docs.d.ts +5 -0
  74. package/lib/internal/docs.js +324 -0
  75. package/lib/resource.d.ts +1 -1
  76. package/lib/secret.d.ts +67 -0
  77. package/lib/secret.js +67 -0
  78. package/lib/shadcn/component.d.ts +1 -1
  79. package/lib/stripe/price.d.ts +51 -1
  80. package/lib/stripe/price.js +50 -0
  81. package/lib/stripe/product.d.ts +39 -1
  82. package/lib/stripe/product.js +38 -0
  83. package/lib/stripe/webhook.d.ts +46 -1
  84. package/lib/stripe/webhook.js +45 -0
  85. package/lib/test/bun.d.ts +64 -0
  86. package/lib/test/bun.js +35 -3
  87. package/lib/util/serde.js +14 -0
  88. package/lib/vite/vite.d.ts +1 -1
  89. package/lib/vitepress/dependencies.d.ts +2 -6
  90. package/lib/vitepress/vitepress.d.ts +12 -1
  91. package/lib/vitepress/vitepress.js +29 -23
  92. package/package.json +8 -3
  93. package/src/ai/ark.ts +118 -0
  94. package/src/ai/client.ts +78 -0
  95. package/src/ai/document.ts +160 -0
  96. package/src/{docs → ai}/index.ts +1 -0
  97. package/src/ai/object.ts +149 -0
  98. package/src/alchemy.ts +88 -5
  99. package/src/aws/bucket.ts +111 -7
  100. package/src/aws/function.ts +231 -10
  101. package/src/aws/oidc/github-oidc-provider.ts +83 -0
  102. package/src/aws/oidc/oidc-provider.ts +39 -7
  103. package/src/aws/policy-attachment.ts +44 -1
  104. package/src/aws/policy.ts +177 -2
  105. package/src/aws/queue.ts +89 -0
  106. package/src/aws/role.ts +174 -2
  107. package/src/aws/ses.ts +56 -1
  108. package/src/aws/table.ts +103 -0
  109. package/src/cloudflare/bucket.ts +36 -0
  110. package/src/cloudflare/durable-object-namespace.ts +25 -0
  111. package/src/cloudflare/kv-namespace.ts +36 -0
  112. package/src/cloudflare/static-site.ts +53 -1
  113. package/src/cloudflare/worker.ts +63 -0
  114. package/src/cloudflare/zone.ts +55 -0
  115. package/src/destroy.ts +1 -1
  116. package/src/esbuild/bundle.ts +53 -3
  117. package/src/fs/file-collection.ts +24 -0
  118. package/src/fs/file-ref.ts +22 -0
  119. package/src/fs/file.ts +70 -77
  120. package/src/fs/folder.ts +44 -5
  121. package/src/fs/index.ts +6 -0
  122. package/src/fs/json-file.ts +23 -0
  123. package/src/fs/text-file.ts +19 -0
  124. package/src/fs/typescript-file.ts +36 -0
  125. package/src/fs/yaml-file.ts +26 -0
  126. package/src/github/secret.ts +65 -2
  127. package/src/internal/docs.ts +369 -0
  128. package/src/resource.ts +1 -1
  129. package/src/secret.ts +67 -0
  130. package/src/stripe/price.ts +50 -0
  131. package/src/stripe/product.ts +38 -0
  132. package/src/stripe/webhook.ts +45 -0
  133. package/src/test/bun.ts +83 -3
  134. package/src/util/serde.ts +17 -0
  135. package/src/vitepress/vitepress.ts +47 -26
  136. package/lib/docs/document.d.ts +0 -123
  137. package/lib/docs/document.js +0 -67
  138. package/src/docs/document.ts +0 -225
@@ -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
- );