alchemy 0.62.2 → 0.63.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.
- package/bin/alchemy.js +1518 -1204
- package/bin/commands/deploy.ts +2 -0
- package/bin/commands/dev.ts +2 -0
- package/bin/services/execute-alchemy.ts +11 -0
- package/bin/services/template-manager.ts +2 -0
- package/bin/types.ts +2 -1
- package/lib/alchemy.d.ts +6 -22
- package/lib/alchemy.d.ts.map +1 -1
- package/lib/alchemy.js +65 -169
- package/lib/alchemy.js.map +1 -1
- package/lib/apply.d.ts +0 -2
- package/lib/apply.d.ts.map +1 -1
- package/lib/apply.js +2 -16
- package/lib/apply.js.map +1 -1
- package/lib/aws/account-id.d.ts.map +1 -1
- package/lib/aws/account-id.js +3 -2
- package/lib/aws/account-id.js.map +1 -1
- package/lib/aws/bucket.d.ts +8 -2
- package/lib/aws/bucket.d.ts.map +1 -1
- package/lib/aws/bucket.js +21 -14
- package/lib/aws/bucket.js.map +1 -1
- package/lib/aws/ec2/security-group.d.ts +8 -2
- package/lib/aws/ec2/security-group.d.ts.map +1 -1
- package/lib/aws/ec2/security-group.js +7 -2
- package/lib/aws/ec2/security-group.js.map +1 -1
- package/lib/aws/function.d.ts +9 -3
- package/lib/aws/function.d.ts.map +1 -1
- package/lib/aws/function.js +35 -26
- package/lib/aws/function.js.map +1 -1
- package/lib/aws/policy-attachment.d.ts.map +1 -1
- package/lib/aws/policy-attachment.js +2 -1
- package/lib/aws/policy-attachment.js.map +1 -1
- package/lib/aws/policy.d.ts +8 -2
- package/lib/aws/policy.d.ts.map +1 -1
- package/lib/aws/policy.js +13 -4
- package/lib/aws/policy.js.map +1 -1
- package/lib/aws/queue.d.ts +8 -2
- package/lib/aws/queue.d.ts.map +1 -1
- package/lib/aws/queue.js +22 -14
- package/lib/aws/queue.js.map +1 -1
- package/lib/aws/role.d.ts +8 -2
- package/lib/aws/role.d.ts.map +1 -1
- package/lib/aws/role.js +10 -3
- package/lib/aws/role.js.map +1 -1
- package/lib/aws/ses.d.ts +1 -1
- package/lib/aws/ses.d.ts.map +1 -1
- package/lib/aws/ses.js +2 -1
- package/lib/aws/ses.js.map +1 -1
- package/lib/aws/ssm-parameter.d.ts +8 -2
- package/lib/aws/ssm-parameter.d.ts.map +1 -1
- package/lib/aws/ssm-parameter.js +15 -10
- package/lib/aws/ssm-parameter.js.map +1 -1
- package/lib/aws/table.d.ts +8 -2
- package/lib/aws/table.d.ts.map +1 -1
- package/lib/aws/table.js +17 -9
- package/lib/aws/table.js.map +1 -1
- package/lib/cloudflare/account-api-token.d.ts +2 -2
- package/lib/cloudflare/account-api-token.d.ts.map +1 -1
- package/lib/cloudflare/account-api-token.js +7 -6
- package/lib/cloudflare/account-api-token.js.map +1 -1
- package/lib/cloudflare/ai-gateway.d.ts +9 -4
- package/lib/cloudflare/ai-gateway.d.ts.map +1 -1
- package/lib/cloudflare/ai-gateway.js +20 -24
- package/lib/cloudflare/ai-gateway.js.map +1 -1
- package/lib/cloudflare/api-schema.d.ts +2 -2
- package/lib/cloudflare/api-schema.d.ts.map +1 -1
- package/lib/cloudflare/api-schema.js +6 -2
- package/lib/cloudflare/api-schema.js.map +1 -1
- package/lib/cloudflare/api-shield.d.ts +5 -1
- package/lib/cloudflare/api-shield.d.ts.map +1 -1
- package/lib/cloudflare/api-shield.js +6 -1
- package/lib/cloudflare/api-shield.js.map +1 -1
- package/lib/cloudflare/assets.d.ts +1 -1
- package/lib/cloudflare/assets.d.ts.map +1 -1
- package/lib/cloudflare/astro/astro.d.ts.map +1 -1
- package/lib/cloudflare/astro/astro.js +3 -1
- package/lib/cloudflare/astro/astro.js.map +1 -1
- package/lib/cloudflare/astro/plugin.d.ts +2 -1
- package/lib/cloudflare/astro/plugin.d.ts.map +1 -1
- package/lib/cloudflare/astro/plugin.js.map +1 -1
- package/lib/cloudflare/bindings.d.ts +2 -2
- package/lib/cloudflare/bindings.d.ts.map +1 -1
- package/lib/cloudflare/bound.d.ts +1 -1
- package/lib/cloudflare/bound.d.ts.map +1 -1
- package/lib/cloudflare/bucket.d.ts +120 -1
- package/lib/cloudflare/bucket.d.ts.map +1 -1
- package/lib/cloudflare/bucket.js +80 -2
- package/lib/cloudflare/bucket.js.map +1 -1
- package/lib/cloudflare/compatibility-date.gen.d.ts +1 -1
- package/lib/cloudflare/compatibility-date.gen.js +1 -1
- package/lib/cloudflare/container.d.ts +10 -4
- package/lib/cloudflare/container.d.ts.map +1 -1
- package/lib/cloudflare/container.js +12 -9
- package/lib/cloudflare/container.js.map +1 -1
- package/lib/cloudflare/custom-domain.js +2 -1
- package/lib/cloudflare/custom-domain.js.map +1 -1
- package/lib/cloudflare/d1-database.d.ts +1 -1
- package/lib/cloudflare/d1-database.d.ts.map +1 -1
- package/lib/cloudflare/d1-database.js +7 -3
- package/lib/cloudflare/d1-database.js.map +1 -1
- package/lib/cloudflare/dispatch-namespace.d.ts +2 -0
- package/lib/cloudflare/dispatch-namespace.d.ts.map +1 -1
- package/lib/cloudflare/dispatch-namespace.js +7 -5
- package/lib/cloudflare/dispatch-namespace.js.map +1 -1
- package/lib/cloudflare/hyperdrive.d.ts +7 -1
- package/lib/cloudflare/hyperdrive.d.ts.map +1 -1
- package/lib/cloudflare/hyperdrive.js +2 -1
- package/lib/cloudflare/hyperdrive.js.map +1 -1
- package/lib/cloudflare/kv-namespace.d.ts +3 -0
- package/lib/cloudflare/kv-namespace.d.ts.map +1 -1
- package/lib/cloudflare/kv-namespace.js +11 -2
- package/lib/cloudflare/kv-namespace.js.map +1 -1
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.js +3 -1
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.js.map +1 -1
- package/lib/cloudflare/miniflare/paths.d.ts +4 -0
- package/lib/cloudflare/miniflare/paths.d.ts.map +1 -1
- package/lib/cloudflare/miniflare/paths.js +11 -0
- package/lib/cloudflare/miniflare/paths.js.map +1 -1
- package/lib/cloudflare/pipeline.d.ts +14 -3
- package/lib/cloudflare/pipeline.d.ts.map +1 -1
- package/lib/cloudflare/pipeline.js +31 -2
- package/lib/cloudflare/pipeline.js.map +1 -1
- package/lib/cloudflare/queue-consumer.js +1 -1
- package/lib/cloudflare/queue-consumer.js.map +1 -1
- package/lib/cloudflare/queue.d.ts +6 -4
- package/lib/cloudflare/queue.d.ts.map +1 -1
- package/lib/cloudflare/queue.js +13 -9
- package/lib/cloudflare/queue.js.map +1 -1
- package/lib/cloudflare/react-router/plugin.d.ts +1 -1
- package/lib/cloudflare/react-router/plugin.d.ts.map +1 -1
- package/lib/cloudflare/react-router/react-router.d.ts.map +1 -1
- package/lib/cloudflare/react-router/react-router.js +32 -2
- package/lib/cloudflare/react-router/react-router.js.map +1 -1
- package/lib/cloudflare/redwood/plugin.d.ts +2 -1
- package/lib/cloudflare/redwood/plugin.d.ts.map +1 -1
- package/lib/cloudflare/redwood/plugin.js.map +1 -1
- package/lib/cloudflare/route.js +1 -1
- package/lib/cloudflare/route.js.map +1 -1
- package/lib/cloudflare/ruleset.d.ts +3 -1
- package/lib/cloudflare/ruleset.d.ts.map +1 -1
- package/lib/cloudflare/ruleset.js +3 -2
- package/lib/cloudflare/ruleset.js.map +1 -1
- package/lib/cloudflare/secret.d.ts +6 -23
- package/lib/cloudflare/secret.d.ts.map +1 -1
- package/lib/cloudflare/secret.js +8 -4
- package/lib/cloudflare/secret.js.map +1 -1
- package/lib/cloudflare/secrets-store.d.ts +1 -1
- package/lib/cloudflare/secrets-store.d.ts.map +1 -1
- package/lib/cloudflare/secrets-store.js +5 -2
- package/lib/cloudflare/secrets-store.js.map +1 -1
- package/lib/cloudflare/tunnel.d.ts +5 -1
- package/lib/cloudflare/tunnel.d.ts.map +1 -1
- package/lib/cloudflare/tunnel.js +5 -1
- package/lib/cloudflare/tunnel.js.map +1 -1
- package/lib/cloudflare/vectorize-index.d.ts +7 -1
- package/lib/cloudflare/vectorize-index.d.ts.map +1 -1
- package/lib/cloudflare/vectorize-index.js +5 -2
- package/lib/cloudflare/vectorize-index.js.map +1 -1
- package/lib/cloudflare/vite/plugin.d.ts +2 -1
- package/lib/cloudflare/vite/plugin.d.ts.map +1 -1
- package/lib/cloudflare/vite/plugin.js.map +1 -1
- package/lib/cloudflare/vite/vite.d.ts +1 -1
- package/lib/cloudflare/vite/vite.d.ts.map +1 -1
- package/lib/cloudflare/vite/vite.js +1 -1
- package/lib/cloudflare/vite/vite.js.map +1 -1
- package/lib/cloudflare/website.js +1 -1
- package/lib/cloudflare/website.js.map +1 -1
- package/lib/cloudflare/worker.d.ts +1 -1
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js +12 -7
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/cloudflare/wrangler.json.d.ts +1 -1
- package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
- package/lib/cloudflare/wrangler.json.js +5 -3
- package/lib/cloudflare/wrangler.json.js.map +1 -1
- package/lib/docker/container.d.ts +6 -0
- package/lib/docker/container.d.ts.map +1 -1
- package/lib/docker/container.js +5 -1
- package/lib/docker/container.js.map +1 -1
- package/lib/docker/network.d.ts +8 -2
- package/lib/docker/network.d.ts.map +1 -1
- package/lib/docker/network.js +7 -2
- package/lib/docker/network.js.map +1 -1
- package/lib/docker/volume.d.ts +8 -2
- package/lib/docker/volume.d.ts.map +1 -1
- package/lib/docker/volume.js +6 -4
- package/lib/docker/volume.js.map +1 -1
- package/lib/esbuild/bundle.d.ts +1 -1
- package/lib/fs/index.d.ts +0 -8
- package/lib/fs/index.d.ts.map +1 -1
- package/lib/fs/index.js +0 -8
- package/lib/fs/index.js.map +1 -1
- package/lib/github/client.d.ts +1 -1
- package/lib/github/client.d.ts.map +1 -1
- package/lib/github/client.js +2 -1
- package/lib/github/client.js.map +1 -1
- package/lib/github/repository-environment.d.ts +8 -2
- package/lib/github/repository-environment.d.ts.map +1 -1
- package/lib/github/repository-environment.js +16 -12
- package/lib/github/repository-environment.js.map +1 -1
- package/lib/neon/project.d.ts +7 -1
- package/lib/neon/project.d.ts.map +1 -1
- package/lib/neon/project.js +10 -6
- package/lib/neon/project.js.map +1 -1
- package/lib/planetscale/branch.d.ts +4 -2
- package/lib/planetscale/branch.d.ts.map +1 -1
- package/lib/planetscale/branch.js +18 -12
- package/lib/planetscale/branch.js.map +1 -1
- package/lib/planetscale/database.d.ts +8 -2
- package/lib/planetscale/database.d.ts.map +1 -1
- package/lib/planetscale/database.js +24 -16
- package/lib/planetscale/database.js.map +1 -1
- package/lib/planetscale/password.d.ts +8 -2
- package/lib/planetscale/password.d.ts.map +1 -1
- package/lib/planetscale/password.js +2 -2
- package/lib/planetscale/password.js.map +1 -1
- package/lib/resource.d.ts +0 -2
- package/lib/resource.d.ts.map +1 -1
- package/lib/resource.js +1 -9
- package/lib/resource.js.map +1 -1
- package/lib/scope.d.ts +9 -3
- package/lib/scope.d.ts.map +1 -1
- package/lib/scope.js +21 -34
- package/lib/scope.js.map +1 -1
- package/lib/sentry/client-key.d.ts +7 -1
- package/lib/sentry/client-key.d.ts.map +1 -1
- package/lib/sentry/client-key.js +45 -6
- package/lib/sentry/client-key.js.map +1 -1
- package/lib/sentry/project.d.ts +8 -2
- package/lib/sentry/project.d.ts.map +1 -1
- package/lib/sentry/project.js +35 -5
- package/lib/sentry/project.js.map +1 -1
- package/lib/sentry/team.d.ts +8 -2
- package/lib/sentry/team.d.ts.map +1 -1
- package/lib/sentry/team.js +36 -6
- package/lib/sentry/team.js.map +1 -1
- package/lib/serde.d.ts +0 -5
- package/lib/serde.d.ts.map +1 -1
- package/lib/serde.js +0 -28
- package/lib/serde.js.map +1 -1
- package/lib/state/d1-state-store.d.ts +1 -1
- package/lib/state/d1-state-store.d.ts.map +1 -1
- package/lib/state/d1-state-store.js +5 -5
- package/lib/state/d1-state-store.js.map +1 -1
- package/lib/state/sqlite-state-store.d.ts.map +1 -1
- package/lib/state/sqlite-state-store.js +7 -11
- package/lib/state/sqlite-state-store.js.map +1 -1
- package/lib/stripe/card.d.ts.map +1 -1
- package/lib/stripe/card.js +3 -2
- package/lib/stripe/card.js.map +1 -1
- package/lib/stripe/client.d.ts +2 -2
- package/lib/stripe/client.d.ts.map +1 -1
- package/lib/stripe/client.js +4 -3
- package/lib/stripe/client.js.map +1 -1
- package/lib/stripe/coupon.d.ts.map +1 -1
- package/lib/stripe/coupon.js +4 -3
- package/lib/stripe/coupon.js.map +1 -1
- package/lib/stripe/customer.js +2 -2
- package/lib/stripe/customer.js.map +1 -1
- package/lib/stripe/entitlements-feature.d.ts.map +1 -1
- package/lib/stripe/entitlements-feature.js +3 -2
- package/lib/stripe/entitlements-feature.js.map +1 -1
- package/lib/stripe/file.d.ts.map +1 -1
- package/lib/stripe/file.js +3 -2
- package/lib/stripe/file.js.map +1 -1
- package/lib/stripe/meter.js +2 -2
- package/lib/stripe/meter.js.map +1 -1
- package/lib/stripe/portal-configuration.d.ts.map +1 -1
- package/lib/stripe/portal-configuration.js +3 -2
- package/lib/stripe/portal-configuration.js.map +1 -1
- package/lib/stripe/price.d.ts.map +1 -1
- package/lib/stripe/price.js +3 -2
- package/lib/stripe/price.js.map +1 -1
- package/lib/stripe/product-feature.d.ts.map +1 -1
- package/lib/stripe/product-feature.js +3 -2
- package/lib/stripe/product-feature.js.map +1 -1
- package/lib/stripe/product.d.ts.map +1 -1
- package/lib/stripe/product.js +3 -2
- package/lib/stripe/product.js.map +1 -1
- package/lib/stripe/promotion-code.d.ts.map +1 -1
- package/lib/stripe/promotion-code.js +3 -2
- package/lib/stripe/promotion-code.js.map +1 -1
- package/lib/stripe/shipping-rate.d.ts.map +1 -1
- package/lib/stripe/shipping-rate.js +4 -3
- package/lib/stripe/shipping-rate.js.map +1 -1
- package/lib/stripe/tax-rate.d.ts.map +1 -1
- package/lib/stripe/tax-rate.js +3 -2
- package/lib/stripe/tax-rate.js.map +1 -1
- package/lib/stripe/webhook.d.ts.map +1 -1
- package/lib/stripe/webhook.js +4 -3
- package/lib/stripe/webhook.js.map +1 -1
- package/lib/test/vitest.d.ts.map +1 -1
- package/lib/test/vitest.js +1 -0
- package/lib/test/vitest.js.map +1 -1
- package/lib/upstash/redis.d.ts +8 -2
- package/lib/upstash/redis.d.ts.map +1 -1
- package/lib/upstash/redis.js +5 -4
- package/lib/upstash/redis.js.map +1 -1
- package/lib/util/ignore-matcher.d.ts.map +1 -1
- package/lib/util/ignore-matcher.js +3 -1
- package/lib/util/ignore-matcher.js.map +1 -1
- package/lib/util/peer.d.ts +10 -0
- package/lib/util/peer.d.ts.map +1 -0
- package/lib/util/peer.js +42 -0
- package/lib/util/peer.js.map +1 -0
- package/lib/util/telemetry/constants.d.ts.map +1 -1
- package/lib/util/telemetry/constants.js +2 -2
- package/lib/util/telemetry/constants.js.map +1 -1
- package/lib/vercel/project.d.ts +7 -1
- package/lib/vercel/project.d.ts.map +1 -1
- package/lib/vercel/project.js +28 -0
- package/lib/vercel/project.js.map +1 -1
- package/package.json +88 -74
- package/src/alchemy.ts +76 -222
- package/src/apply.ts +6 -19
- package/src/aws/account-id.ts +6 -3
- package/src/aws/bucket.ts +43 -32
- package/src/aws/ec2/security-group.ts +15 -3
- package/src/aws/function.ts +65 -39
- package/src/aws/policy-attachment.ts +10 -6
- package/src/aws/policy.ts +33 -15
- package/src/aws/queue.ts +50 -29
- package/src/aws/role.ts +37 -20
- package/src/aws/ses.ts +24 -20
- package/src/aws/ssm-parameter.ts +40 -20
- package/src/aws/table.ts +35 -17
- package/src/cloudflare/account-api-token.ts +9 -7
- package/src/cloudflare/ai-gateway.ts +37 -34
- package/src/cloudflare/api-schema.ts +33 -26
- package/src/cloudflare/api-shield.ts +15 -2
- package/src/cloudflare/astro/astro.ts +5 -1
- package/src/cloudflare/astro/plugin.ts +2 -1
- package/src/cloudflare/bindings.ts +2 -2
- package/src/cloudflare/bound.ts +1 -1
- package/src/cloudflare/bucket.ts +242 -3
- package/src/cloudflare/compatibility-date.gen.ts +1 -1
- package/src/cloudflare/container.ts +23 -12
- package/src/cloudflare/custom-domain.ts +2 -2
- package/src/cloudflare/d1-database.ts +11 -4
- package/src/cloudflare/dispatch-namespace.ts +10 -7
- package/src/cloudflare/hyperdrive.ts +13 -3
- package/src/cloudflare/kv-namespace.ts +25 -2
- package/src/cloudflare/miniflare/miniflare-worker-proxy.ts +3 -1
- package/src/cloudflare/miniflare/paths.ts +13 -0
- package/src/cloudflare/pipeline.ts +76 -28
- package/src/cloudflare/queue-consumer.ts +1 -1
- package/src/cloudflare/queue.ts +65 -54
- package/src/cloudflare/react-router/react-router.ts +28 -2
- package/src/cloudflare/redwood/plugin.ts +3 -2
- package/src/cloudflare/route.ts +1 -1
- package/src/cloudflare/ruleset.ts +7 -2
- package/src/cloudflare/secret.ts +20 -31
- package/src/cloudflare/secrets-store.ts +7 -3
- package/src/cloudflare/tunnel.ts +13 -2
- package/src/cloudflare/vectorize-index.ts +14 -3
- package/src/cloudflare/vite/plugin.ts +3 -2
- package/src/cloudflare/vite/vite.ts +2 -3
- package/src/cloudflare/website.ts +1 -1
- package/src/cloudflare/worker.ts +35 -23
- package/src/cloudflare/wrangler.json.ts +7 -4
- package/src/docker/container.ts +13 -1
- package/src/docker/network.ts +18 -3
- package/src/docker/volume.ts +17 -6
- package/src/fs/index.ts +0 -8
- package/src/github/client.ts +6 -2
- package/src/github/repository-environment.ts +27 -13
- package/src/neon/project.ts +20 -6
- package/src/planetscale/branch.ts +24 -13
- package/src/planetscale/database.ts +38 -17
- package/src/planetscale/password.ts +10 -3
- package/src/resource.ts +1 -10
- package/src/scope.ts +29 -38
- package/src/sentry/client-key.ts +74 -6
- package/src/sentry/project.ts +59 -6
- package/src/sentry/team.ts +55 -7
- package/src/serde.ts +0 -44
- package/src/state/d1-state-store.ts +13 -6
- package/src/state/sqlite-state-store.ts +16 -17
- package/src/stripe/card.ts +5 -2
- package/src/stripe/client.ts +10 -3
- package/src/stripe/coupon.ts +4 -3
- package/src/stripe/customer.ts +2 -2
- package/src/stripe/entitlements-feature.ts +5 -2
- package/src/stripe/file.ts +3 -2
- package/src/stripe/meter.ts +2 -2
- package/src/stripe/portal-configuration.ts +5 -2
- package/src/stripe/price.ts +3 -2
- package/src/stripe/product-feature.ts +5 -2
- package/src/stripe/product.ts +3 -2
- package/src/stripe/promotion-code.ts +3 -2
- package/src/stripe/shipping-rate.ts +4 -3
- package/src/stripe/tax-rate.ts +3 -2
- package/src/stripe/webhook.ts +4 -3
- package/src/test/vitest.ts +1 -0
- package/src/upstash/redis.ts +15 -5
- package/src/util/ignore-matcher.ts +3 -1
- package/src/util/peer.ts +53 -0
- package/src/util/telemetry/constants.ts +2 -2
- package/src/vercel/project.ts +46 -1
- package/templates/astro/_gitignore +2 -1
- package/templates/hono/README.md +19 -0
- package/templates/hono/_env +1 -0
- package/templates/hono/_env.example +1 -0
- package/templates/hono/_gitignore +34 -0
- package/templates/hono/alchemy.run.ts +22 -0
- package/templates/hono/package.json +18 -0
- package/templates/hono/src/index.ts +17 -0
- package/templates/hono/tsconfig.json +13 -0
- package/templates/hono/types/env.d.ts +16 -0
- package/templates/nuxt/_gitignore +2 -1
- package/templates/react-router/_gitignore +1 -0
- package/templates/react-router/vite.config.ts +5 -3
- package/templates/rwsdk/_gitignore +2 -3
- package/templates/sveltekit/_gitignore +2 -1
- package/templates/tanstack-start/_gitignore +2 -1
- package/templates/typescript/_gitignore +2 -1
- package/templates/vite/_gitignore +2 -1
- package/workers/cloudflare-state-store.js +69 -74
- package/workers/dofs-state-store.js +1 -1
- package/bin/bootstrap-s3.ts +0 -255
- package/lib/ai/ark.d.ts +0 -12
- package/lib/ai/ark.d.ts.map +0 -1
- package/lib/ai/ark.js +0 -87
- package/lib/ai/ark.js.map +0 -1
- package/lib/ai/astro-file.d.ts +0 -138
- package/lib/ai/astro-file.d.ts.map +0 -1
- package/lib/ai/astro-file.js +0 -158
- package/lib/ai/astro-file.js.map +0 -1
- package/lib/ai/client.d.ts +0 -51
- package/lib/ai/client.d.ts.map +0 -1
- package/lib/ai/client.js +0 -58
- package/lib/ai/client.js.map +0 -1
- package/lib/ai/css-file.d.ts +0 -132
- package/lib/ai/css-file.d.ts.map +0 -1
- package/lib/ai/css-file.js +0 -142
- package/lib/ai/css-file.js.map +0 -1
- package/lib/ai/data.d.ts +0 -152
- package/lib/ai/data.d.ts.map +0 -1
- package/lib/ai/data.js +0 -120
- package/lib/ai/data.js.map +0 -1
- package/lib/ai/document.d.ts +0 -208
- package/lib/ai/document.d.ts.map +0 -1
- package/lib/ai/document.js +0 -206
- package/lib/ai/document.js.map +0 -1
- package/lib/ai/html-file.d.ts +0 -129
- package/lib/ai/html-file.d.ts.map +0 -1
- package/lib/ai/html-file.js +0 -139
- package/lib/ai/html-file.js.map +0 -1
- package/lib/ai/index.d.ts +0 -11
- package/lib/ai/index.d.ts.map +0 -1
- package/lib/ai/index.js +0 -11
- package/lib/ai/index.js.map +0 -1
- package/lib/ai/json-file.d.ts +0 -161
- package/lib/ai/json-file.d.ts.map +0 -1
- package/lib/ai/json-file.js +0 -188
- package/lib/ai/json-file.js.map +0 -1
- package/lib/ai/typescript-file.d.ts +0 -140
- package/lib/ai/typescript-file.d.ts.map +0 -1
- package/lib/ai/typescript-file.js +0 -146
- package/lib/ai/typescript-file.js.map +0 -1
- package/lib/ai/vue-file.d.ts +0 -127
- package/lib/ai/vue-file.d.ts.map +0 -1
- package/lib/ai/vue-file.js +0 -137
- package/lib/ai/vue-file.js.map +0 -1
- package/lib/ai/yaml-file.d.ts +0 -170
- package/lib/ai/yaml-file.d.ts.map +0 -1
- package/lib/ai/yaml-file.js +0 -201
- package/lib/ai/yaml-file.js.map +0 -1
- package/lib/fs/static-astro-file.d.ts +0 -35
- package/lib/fs/static-astro-file.d.ts.map +0 -1
- package/lib/fs/static-astro-file.js +0 -40
- package/lib/fs/static-astro-file.js.map +0 -1
- package/lib/fs/static-css-file.d.ts +0 -25
- package/lib/fs/static-css-file.d.ts.map +0 -1
- package/lib/fs/static-css-file.js +0 -30
- package/lib/fs/static-css-file.js.map +0 -1
- package/lib/fs/static-html-file.d.ts +0 -32
- package/lib/fs/static-html-file.d.ts.map +0 -1
- package/lib/fs/static-html-file.js +0 -37
- package/lib/fs/static-html-file.js.map +0 -1
- package/lib/fs/static-json-file.d.ts +0 -18
- package/lib/fs/static-json-file.d.ts.map +0 -1
- package/lib/fs/static-json-file.js +0 -19
- package/lib/fs/static-json-file.js.map +0 -1
- package/lib/fs/static-text-file.d.ts +0 -13
- package/lib/fs/static-text-file.d.ts.map +0 -1
- package/lib/fs/static-text-file.js +0 -9
- package/lib/fs/static-text-file.js.map +0 -1
- package/lib/fs/static-typescript-file.d.ts +0 -20
- package/lib/fs/static-typescript-file.d.ts.map +0 -1
- package/lib/fs/static-typescript-file.js +0 -16
- package/lib/fs/static-typescript-file.js.map +0 -1
- package/lib/fs/static-vue-file.d.ts +0 -29
- package/lib/fs/static-vue-file.d.ts.map +0 -1
- package/lib/fs/static-vue-file.js +0 -34
- package/lib/fs/static-vue-file.js.map +0 -1
- package/lib/fs/static-yaml-file.d.ts +0 -23
- package/lib/fs/static-yaml-file.d.ts.map +0 -1
- package/lib/fs/static-yaml-file.js +0 -10
- package/lib/fs/static-yaml-file.js.map +0 -1
- package/lib/internal/docs/providers.d.ts +0 -34
- package/lib/internal/docs/providers.d.ts.map +0 -1
- package/lib/internal/docs/providers.js +0 -200
- package/lib/internal/docs/providers.js.map +0 -1
- package/lib/runtime/bind.d.ts +0 -25
- package/lib/runtime/bind.d.ts.map +0 -1
- package/lib/runtime/bind.js +0 -76
- package/lib/runtime/bind.js.map +0 -1
- package/lib/runtime/global.d.ts +0 -8
- package/lib/runtime/global.d.ts.map +0 -1
- package/lib/runtime/global.js +0 -3
- package/lib/runtime/global.js.map +0 -1
- package/lib/runtime/plugin.d.ts +0 -35
- package/lib/runtime/plugin.d.ts.map +0 -1
- package/lib/runtime/plugin.js +0 -134
- package/lib/runtime/plugin.js.map +0 -1
- package/lib/runtime/shims.d.ts +0 -6
- package/lib/runtime/shims.d.ts.map +0 -1
- package/lib/runtime/shims.js +0 -27
- package/lib/runtime/shims.js.map +0 -1
- package/lib/runtime/state.d.ts +0 -5
- package/lib/runtime/state.d.ts.map +0 -1
- package/lib/runtime/state.js +0 -4
- package/lib/runtime/state.js.map +0 -1
- package/lib/web/astro.d.ts +0 -148
- package/lib/web/astro.d.ts.map +0 -1
- package/lib/web/astro.js +0 -419
- package/lib/web/astro.js.map +0 -1
- package/lib/web/shadcn-component.d.ts +0 -30
- package/lib/web/shadcn-component.d.ts.map +0 -1
- package/lib/web/shadcn-component.js +0 -25
- package/lib/web/shadcn-component.js.map +0 -1
- package/lib/web/shadcn.d.ts +0 -98
- package/lib/web/shadcn.d.ts.map +0 -1
- package/lib/web/shadcn.js +0 -102
- package/lib/web/shadcn.js.map +0 -1
- package/lib/web/tailwind.d.ts +0 -65
- package/lib/web/tailwind.d.ts.map +0 -1
- package/lib/web/tailwind.js +0 -98
- package/lib/web/tailwind.js.map +0 -1
- package/lib/web/vite.d.ts +0 -96
- package/lib/web/vite.d.ts.map +0 -1
- package/lib/web/vite.js +0 -232
- package/lib/web/vite.js.map +0 -1
- package/lib/web/vitepress/config.d.ts +0 -12
- package/lib/web/vitepress/config.d.ts.map +0 -1
- package/lib/web/vitepress/config.js +0 -33
- package/lib/web/vitepress/config.js.map +0 -1
- package/lib/web/vitepress/custom-theme.d.ts +0 -174
- package/lib/web/vitepress/custom-theme.d.ts.map +0 -1
- package/lib/web/vitepress/custom-theme.js +0 -337
- package/lib/web/vitepress/custom-theme.js.map +0 -1
- package/lib/web/vitepress/dependencies.d.ts +0 -13
- package/lib/web/vitepress/dependencies.d.ts.map +0 -1
- package/lib/web/vitepress/dependencies.js +0 -37
- package/lib/web/vitepress/dependencies.js.map +0 -1
- package/lib/web/vitepress/home-page.d.ts +0 -247
- package/lib/web/vitepress/home-page.d.ts.map +0 -1
- package/lib/web/vitepress/home-page.js +0 -146
- package/lib/web/vitepress/home-page.js.map +0 -1
- package/lib/web/vitepress/index.d.ts +0 -6
- package/lib/web/vitepress/index.d.ts.map +0 -1
- package/lib/web/vitepress/index.js +0 -6
- package/lib/web/vitepress/index.js.map +0 -1
- package/lib/web/vitepress/process-front-matter-files.d.ts +0 -19
- package/lib/web/vitepress/process-front-matter-files.d.ts.map +0 -1
- package/lib/web/vitepress/process-front-matter-files.js +0 -73
- package/lib/web/vitepress/process-front-matter-files.js.map +0 -1
- package/lib/web/vitepress/vitepress.d.ts +0 -75
- package/lib/web/vitepress/vitepress.d.ts.map +0 -1
- package/lib/web/vitepress/vitepress.js +0 -254
- package/lib/web/vitepress/vitepress.js.map +0 -1
- package/src/ai/ark.ts +0 -118
- package/src/ai/astro-file.ts +0 -270
- package/src/ai/client.ts +0 -117
- package/src/ai/css-file.ts +0 -247
- package/src/ai/data.ts +0 -221
- package/src/ai/document.ts +0 -367
- package/src/ai/html-file.ts +0 -244
- package/src/ai/index.ts +0 -10
- package/src/ai/json-file.ts +0 -325
- package/src/ai/typescript-file.ts +0 -259
- package/src/ai/vue-file.ts +0 -242
- package/src/ai/yaml-file.ts +0 -328
- package/src/fs/static-astro-file.ts +0 -45
- package/src/fs/static-css-file.ts +0 -35
- package/src/fs/static-html-file.ts +0 -42
- package/src/fs/static-json-file.ts +0 -38
- package/src/fs/static-text-file.ts +0 -23
- package/src/fs/static-typescript-file.ts +0 -37
- package/src/fs/static-vue-file.ts +0 -39
- package/src/fs/static-yaml-file.ts +0 -33
- package/src/internal/docs/providers.ts +0 -286
- package/src/runtime/bind.ts +0 -95
- package/src/runtime/global.ts +0 -10
- package/src/runtime/plugin.ts +0 -163
- package/src/runtime/shims.js +0 -34
- package/src/runtime/state.ts +0 -9
- package/src/web/astro.ts +0 -643
- package/src/web/shadcn-component.ts +0 -72
- package/src/web/shadcn.ts +0 -221
- package/src/web/tailwind.ts +0 -167
- package/src/web/vite.ts +0 -407
- package/src/web/vitepress/config.ts +0 -50
- package/src/web/vitepress/custom-theme.ts +0 -514
- package/src/web/vitepress/dependencies.ts +0 -69
- package/src/web/vitepress/home-page.ts +0 -378
- package/src/web/vitepress/index.ts +0 -5
- package/src/web/vitepress/process-front-matter-files.ts +0 -107
- package/src/web/vitepress/vitepress.ts +0 -372
- package/templates/sveltekit/bun.lock +0 -1099
package/src/ai/json-file.ts
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
import { generateObject, generateText } from "ai";
|
|
2
|
-
import type { JsonSchema, Type, type } from "arktype";
|
|
3
|
-
import type { Context } from "../context.ts";
|
|
4
|
-
import { StaticJsonFile } from "../fs/static-json-file.ts";
|
|
5
|
-
import { Resource } from "../resource.ts";
|
|
6
|
-
import type { Secret } from "../secret.ts";
|
|
7
|
-
import { ark } from "./ark.ts";
|
|
8
|
-
import { type ModelConfig, createModel } from "./client.ts";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Properties for creating or updating a JSONFile
|
|
12
|
-
*/
|
|
13
|
-
export interface JSONFileProps<
|
|
14
|
-
T extends Type<any, any> | undefined = undefined,
|
|
15
|
-
> {
|
|
16
|
-
/**
|
|
17
|
-
* Path to the JSON file
|
|
18
|
-
*/
|
|
19
|
-
path: string;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Optional ArkType schema to validate and structure the generated JSON
|
|
23
|
-
* When provided, the resource will use generateObject with schema validation
|
|
24
|
-
* When not provided, it will extract JSON from between ```json fences
|
|
25
|
-
*/
|
|
26
|
-
schema?: T;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Base URL for the OpenAI API
|
|
30
|
-
* @default 'https://api.openai.com/v1'
|
|
31
|
-
*/
|
|
32
|
-
baseURL?: string;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Prompt for generating content
|
|
36
|
-
* Use alchemy template literals to include file context:
|
|
37
|
-
* @example
|
|
38
|
-
* prompt: await alchemy`
|
|
39
|
-
* Generate a JSON configuration for:
|
|
40
|
-
* ${alchemy.file("src/config.ts")}
|
|
41
|
-
* `
|
|
42
|
-
*/
|
|
43
|
-
prompt: string;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* System prompt for the model
|
|
47
|
-
* This is used to provide instructions to the model about how to format the response
|
|
48
|
-
* @default Depends on whether schema is provided
|
|
49
|
-
*/
|
|
50
|
-
system?: string;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* OpenAI API key to use for generating content
|
|
54
|
-
* If not provided, will use OPENAI_API_KEY environment variable
|
|
55
|
-
*/
|
|
56
|
-
apiKey?: Secret;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Model configuration
|
|
60
|
-
*/
|
|
61
|
-
model?: ModelConfig;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Temperature for controlling randomness in generation.
|
|
65
|
-
* Higher values (e.g., 0.8) make output more random,
|
|
66
|
-
* lower values (e.g., 0.2) make it more deterministic.
|
|
67
|
-
* @default 0.7
|
|
68
|
-
*/
|
|
69
|
-
temperature?: number;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Whether to pretty-print the JSON with indentation
|
|
73
|
-
* @default true
|
|
74
|
-
*/
|
|
75
|
-
pretty?: boolean;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Number of spaces to use for indentation when pretty-printing
|
|
79
|
-
* @default 2
|
|
80
|
-
*/
|
|
81
|
-
indent?: number;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* A JSON file that can be created, updated, and deleted
|
|
86
|
-
*/
|
|
87
|
-
export interface JSONFile<T = any>
|
|
88
|
-
extends Omit<JSONFileProps, "schema">,
|
|
89
|
-
Resource<"ai::JSONFile"> {
|
|
90
|
-
/**
|
|
91
|
-
* Content of the JSON file as a string
|
|
92
|
-
*/
|
|
93
|
-
content: string;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Parsed JSON object
|
|
97
|
-
*/
|
|
98
|
-
json: T;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Schema used to validate the JSON (if provided)
|
|
102
|
-
*/
|
|
103
|
-
schema?: JsonSchema;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Time at which the file was created
|
|
107
|
-
*/
|
|
108
|
-
createdAt: number;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Time at which the file was last updated
|
|
112
|
-
*/
|
|
113
|
-
updatedAt: number;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Default system prompt for JSON file generation without schema
|
|
118
|
-
*/
|
|
119
|
-
const DEFAULT_JSON_SYSTEM_PROMPT =
|
|
120
|
-
"You are a JSON generator. Create valid JSON based on the user's requirements. Your response MUST include only JSON inside ```json fences. Do not include any other text, explanations, or multiple code blocks.";
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Resource for generating JSON files using AI models.
|
|
124
|
-
* Can operate in two modes:
|
|
125
|
-
* 1. With schema: Uses generateObject with type validation
|
|
126
|
-
* 2. Without schema: Extracts JSON from between ```json fences
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* // Generate a configuration file with freeform JSON
|
|
130
|
-
* const config = await JSONFile("app-config", {
|
|
131
|
-
* path: "./config/app.json",
|
|
132
|
-
* prompt: await alchemy`
|
|
133
|
-
* Generate a configuration for a web application with:
|
|
134
|
-
* - Server settings (port, host, timeout)
|
|
135
|
-
* - Database connection details (redact any passwords)
|
|
136
|
-
* - Logging configuration
|
|
137
|
-
* - Feature flags
|
|
138
|
-
* `,
|
|
139
|
-
* model: {
|
|
140
|
-
* id: "gpt-4o",
|
|
141
|
-
* provider: "openai"
|
|
142
|
-
* }
|
|
143
|
-
* });
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* // Generate JSON with schema validation
|
|
147
|
-
* import { type } from "arktype";
|
|
148
|
-
*
|
|
149
|
-
* const userSchema = type({
|
|
150
|
-
* users: [{
|
|
151
|
-
* id: "string",
|
|
152
|
-
* name: "string",
|
|
153
|
-
* email: "string",
|
|
154
|
-
* role: "'admin' | 'user' | 'guest'",
|
|
155
|
-
* permissions: "string[]",
|
|
156
|
-
* active: "boolean"
|
|
157
|
-
* }]
|
|
158
|
-
* });
|
|
159
|
-
*
|
|
160
|
-
* const userData = await JSONFile("user-data", {
|
|
161
|
-
* path: "./data/users.json",
|
|
162
|
-
* schema: userSchema,
|
|
163
|
-
* prompt: "Generate sample user data for an application with various roles and permissions",
|
|
164
|
-
* temperature: 0.2
|
|
165
|
-
* });
|
|
166
|
-
*
|
|
167
|
-
* // Type-safe access to the generated data
|
|
168
|
-
* console.log(userData.json.users[0].role); // Typed as 'admin' | 'user' | 'guest'
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* // Generate API mock data with custom system prompt
|
|
172
|
-
* const apiMock = await JSONFile("api-mock", {
|
|
173
|
-
* path: "./mocks/products-api.json",
|
|
174
|
-
* prompt: await alchemy`
|
|
175
|
-
* Create mock data for a product catalog API response with:
|
|
176
|
-
* - 10 products with different categories
|
|
177
|
-
* - Each product should have id, name, price, category, inventory, and image_url
|
|
178
|
-
* - Include pagination metadata (total, page, limit)
|
|
179
|
-
* `,
|
|
180
|
-
* system: "You are an API design expert. Create realistic mock JSON data that follows REST API best practices. Your response must be valid JSON inside ```json fences.",
|
|
181
|
-
* model: {
|
|
182
|
-
* id: "claude-3-opus-20240229",
|
|
183
|
-
* provider: "anthropic"
|
|
184
|
-
* },
|
|
185
|
-
* pretty: true,
|
|
186
|
-
* indent: 4
|
|
187
|
-
* });
|
|
188
|
-
*/
|
|
189
|
-
export const JSONFile = Resource("ai::JSONFile", async function <
|
|
190
|
-
const T extends Type<any, any> | undefined = undefined,
|
|
191
|
-
>(this: Context<JSONFile<T extends Type<any, any> ? type.infer<T> : any>>, _id: string, props: JSONFileProps<T>): Promise<
|
|
192
|
-
JSONFile<T extends Type<any, any> ? type.infer<T> : any>
|
|
193
|
-
> {
|
|
194
|
-
// Handle deletion phase
|
|
195
|
-
if (this.phase === "delete") {
|
|
196
|
-
return this.destroy();
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
let jsonContent: string;
|
|
200
|
-
let jsonObject: any;
|
|
201
|
-
|
|
202
|
-
// Check if schema is provided
|
|
203
|
-
if (props.schema) {
|
|
204
|
-
// Use schema-based generation
|
|
205
|
-
const { object } = await generateObject({
|
|
206
|
-
model: createModel(props),
|
|
207
|
-
schema: ark.schema<type.infer<typeof props.schema>>(props.schema),
|
|
208
|
-
providerOptions: props.model?.options,
|
|
209
|
-
system:
|
|
210
|
-
props.system ||
|
|
211
|
-
"Generate a valid JSON object based on the provided requirements.",
|
|
212
|
-
prompt: props.prompt,
|
|
213
|
-
...(props.temperature === undefined
|
|
214
|
-
? {}
|
|
215
|
-
: { temperature: props.temperature }),
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
jsonObject = object;
|
|
219
|
-
|
|
220
|
-
// Use StaticJsonFile to create the file
|
|
221
|
-
const file = await StaticJsonFile("file", props.path, jsonObject);
|
|
222
|
-
jsonContent = file.content;
|
|
223
|
-
} else {
|
|
224
|
-
// Use fence-based extraction
|
|
225
|
-
// Use provided system prompt or default
|
|
226
|
-
const system = props.system || DEFAULT_JSON_SYSTEM_PROMPT;
|
|
227
|
-
|
|
228
|
-
// Generate initial content
|
|
229
|
-
const { text } = await generateText({
|
|
230
|
-
model: createModel(props),
|
|
231
|
-
prompt: props.prompt,
|
|
232
|
-
system,
|
|
233
|
-
providerOptions: props.model?.options,
|
|
234
|
-
...(props.temperature === undefined
|
|
235
|
-
? {}
|
|
236
|
-
: { temperature: props.temperature }),
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
// Extract and validate JSON content
|
|
240
|
-
let { content, error } = await extractJSONContent(text);
|
|
241
|
-
|
|
242
|
-
// Re-prompt if there are validation errors
|
|
243
|
-
if (error) {
|
|
244
|
-
const errorSystem = `${system}\n\nERROR: ${error}\n\nPlease try again and ensure your response contains exactly one valid JSON block inside \`\`\`json fences.`;
|
|
245
|
-
|
|
246
|
-
const { text: retryText } = await generateText({
|
|
247
|
-
model: createModel(props),
|
|
248
|
-
prompt: props.prompt,
|
|
249
|
-
system: errorSystem,
|
|
250
|
-
providerOptions: props.model?.options,
|
|
251
|
-
...(props.temperature === undefined
|
|
252
|
-
? {}
|
|
253
|
-
: { temperature: props.temperature }),
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
const retryResult = await extractJSONContent(retryText);
|
|
257
|
-
|
|
258
|
-
if (retryResult.error) {
|
|
259
|
-
throw new Error(`Failed to generate valid JSON: ${retryResult.error}`);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
content = retryResult.content;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Parse JSON to get the object representation
|
|
266
|
-
jsonObject = JSON.parse(content);
|
|
267
|
-
|
|
268
|
-
// Use StaticJsonFile to create the file
|
|
269
|
-
const file = await StaticJsonFile("file", props.path, jsonObject);
|
|
270
|
-
jsonContent = file.content;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// Return the resource
|
|
274
|
-
return this({
|
|
275
|
-
...props,
|
|
276
|
-
schema: props.schema,
|
|
277
|
-
content: jsonContent,
|
|
278
|
-
json: jsonObject,
|
|
279
|
-
createdAt: Date.now(),
|
|
280
|
-
updatedAt: Date.now(),
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Extracts JSON content from between ```json fences
|
|
286
|
-
* Validates that exactly one JSON code block exists
|
|
287
|
-
*
|
|
288
|
-
* @param text The text to extract JSON from
|
|
289
|
-
* @returns The extracted JSON or error message
|
|
290
|
-
*/
|
|
291
|
-
async function extractJSONContent(
|
|
292
|
-
text: string,
|
|
293
|
-
): Promise<{ content: string; error?: string }> {
|
|
294
|
-
const jsonCodeRegex = /```json\s*([\s\S]*?)```/g;
|
|
295
|
-
const matches = Array.from(text.matchAll(jsonCodeRegex));
|
|
296
|
-
|
|
297
|
-
if (matches.length === 0) {
|
|
298
|
-
return {
|
|
299
|
-
content: "",
|
|
300
|
-
error:
|
|
301
|
-
"No JSON code block found in the response. Please include your JSON within ```json fences.",
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (matches.length > 1) {
|
|
306
|
-
return {
|
|
307
|
-
content: "",
|
|
308
|
-
error:
|
|
309
|
-
"Multiple JSON code blocks found in the response. Please provide exactly one JSON block within ```json fences.",
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const content = matches[0][1].trim();
|
|
314
|
-
|
|
315
|
-
// Validate JSON can be parsed
|
|
316
|
-
try {
|
|
317
|
-
JSON.parse(content);
|
|
318
|
-
return { content };
|
|
319
|
-
} catch (e) {
|
|
320
|
-
return {
|
|
321
|
-
content: "",
|
|
322
|
-
error: `Invalid JSON: ${(e as Error).message}. Please provide valid JSON syntax.`,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
}
|
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import { generateText } from "ai";
|
|
2
|
-
import type { Context } from "../context.ts";
|
|
3
|
-
import { StaticTypeScriptFile } from "../fs/static-typescript-file.ts";
|
|
4
|
-
import { Resource } from "../resource.ts";
|
|
5
|
-
import type { Secret } from "../secret.ts";
|
|
6
|
-
import { createModel, type ModelConfig } from "./client.ts";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Properties for creating or updating a TypeScriptFile
|
|
10
|
-
*/
|
|
11
|
-
export interface TypeScriptFileProps {
|
|
12
|
-
/**
|
|
13
|
-
* Path to the TypeScript file
|
|
14
|
-
*/
|
|
15
|
-
path: string;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Base URL for the OpenAI API
|
|
19
|
-
* @default 'https://api.openai.com/v1'
|
|
20
|
-
*/
|
|
21
|
-
baseURL?: string;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Prompt for generating content
|
|
25
|
-
* Use alchemy template literals to include file context:
|
|
26
|
-
* @example
|
|
27
|
-
* prompt: await alchemy`
|
|
28
|
-
* Generate a TypeScript utility function using:
|
|
29
|
-
* ${alchemy.file("src/types.ts")}
|
|
30
|
-
* `
|
|
31
|
-
*/
|
|
32
|
-
prompt: string;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* System prompt for the model
|
|
36
|
-
* This is used to provide instructions to the model about how to format the response
|
|
37
|
-
* The default system prompt instructs the model to return TypeScript code inside ```ts fences
|
|
38
|
-
* @default "You are a TypeScript code generator. Create TypeScript code based on the user's requirements. Your response MUST include only TypeScript code inside ```ts fences. Do not include any other text, explanations, or multiple code blocks."
|
|
39
|
-
*/
|
|
40
|
-
system?: string;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* OpenAI API key to use for generating content
|
|
44
|
-
* If not provided, will use OPENAI_API_KEY environment variable
|
|
45
|
-
*/
|
|
46
|
-
apiKey?: Secret;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Model configuration
|
|
50
|
-
*/
|
|
51
|
-
model?: ModelConfig;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Temperature for controlling randomness in generation.
|
|
55
|
-
* Higher values (e.g., 0.8) make output more random,
|
|
56
|
-
* lower values (e.g., 0.2) make it more deterministic.
|
|
57
|
-
* @default 0.7
|
|
58
|
-
*/
|
|
59
|
-
temperature?: number;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Prettier configuration to use for formatting the TypeScript code
|
|
63
|
-
* If not provided, will use the default Prettier configuration
|
|
64
|
-
*/
|
|
65
|
-
prettierConfig?: object;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* A TypeScript file that can be created, updated, and deleted
|
|
70
|
-
*/
|
|
71
|
-
export interface TypeScriptFile
|
|
72
|
-
extends TypeScriptFileProps,
|
|
73
|
-
Resource<"ai::TypeScriptFile"> {
|
|
74
|
-
/**
|
|
75
|
-
* Content of the TypeScript file
|
|
76
|
-
*/
|
|
77
|
-
content: string;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Time at which the file was created
|
|
81
|
-
*/
|
|
82
|
-
createdAt: number;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Time at which the file was last updated
|
|
86
|
-
*/
|
|
87
|
-
updatedAt: number;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Default system prompt for TypeScript file generation
|
|
92
|
-
*/
|
|
93
|
-
const DEFAULT_TS_SYSTEM_PROMPT =
|
|
94
|
-
"You are a TypeScript code generator. Create TypeScript code based on the user's requirements. Your response MUST include only TypeScript code inside ```ts fences. Do not include any other text, explanations, or multiple code blocks.";
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Resource for generating TypeScript files using AI models.
|
|
98
|
-
* Extracts TypeScript code from between ```ts fences, validates the response,
|
|
99
|
-
* and formats the code with Prettier.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* // Create a utility function
|
|
103
|
-
* const utils = await TypeScriptFile("string-utils", {
|
|
104
|
-
* path: "./src/utils/string-utils.ts",
|
|
105
|
-
* prompt: await alchemy`
|
|
106
|
-
* Generate TypeScript utility functions for string manipulation:
|
|
107
|
-
* - Capitalize first letter
|
|
108
|
-
* - Truncate with ellipsis
|
|
109
|
-
* - Convert to camelCase and kebab-case
|
|
110
|
-
* - Remove special characters
|
|
111
|
-
* `,
|
|
112
|
-
* model: {
|
|
113
|
-
* id: "gpt-4o",
|
|
114
|
-
* provider: "openai"
|
|
115
|
-
* }
|
|
116
|
-
* });
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* // Generate a TypeScript class with custom formatting
|
|
120
|
-
* const userService = await TypeScriptFile("user-service", {
|
|
121
|
-
* path: "./src/services/UserService.ts",
|
|
122
|
-
* prompt: await alchemy`
|
|
123
|
-
* Create a UserService class that handles user authentication and profile management.
|
|
124
|
-
* The service should use the User type from:
|
|
125
|
-
* ${alchemy.file("src/types/User.ts")}
|
|
126
|
-
*
|
|
127
|
-
* Include methods for:
|
|
128
|
-
* - login(email, password)
|
|
129
|
-
* - register(user)
|
|
130
|
-
* - updateProfile(userId, profileData)
|
|
131
|
-
* - deleteAccount(userId)
|
|
132
|
-
* `,
|
|
133
|
-
* temperature: 0.2,
|
|
134
|
-
* prettierConfig: {
|
|
135
|
-
* semi: false,
|
|
136
|
-
* singleQuote: true,
|
|
137
|
-
* printWidth: 120
|
|
138
|
-
* }
|
|
139
|
-
* });
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* // Generate a React hook with custom system prompt
|
|
143
|
-
* const useFormHook = await TypeScriptFile("use-form", {
|
|
144
|
-
* path: "./src/hooks/useForm.ts",
|
|
145
|
-
* prompt: await alchemy`
|
|
146
|
-
* Create a custom React hook called useForm that handles form state, validation, and submission.
|
|
147
|
-
* It should support:
|
|
148
|
-
* - Initial values
|
|
149
|
-
* - Validation rules
|
|
150
|
-
* - Field errors
|
|
151
|
-
* - Form submission with loading state
|
|
152
|
-
* - Reset functionality
|
|
153
|
-
* `,
|
|
154
|
-
* system: "You are an expert React developer specializing in TypeScript hooks. Create a single TypeScript file inside ```ts fences with no additional text. Follow React best practices and include proper typing.",
|
|
155
|
-
* model: {
|
|
156
|
-
* id: "claude-3-opus-20240229",
|
|
157
|
-
* provider: "anthropic"
|
|
158
|
-
* }
|
|
159
|
-
* });
|
|
160
|
-
*/
|
|
161
|
-
export const TypeScriptFile = Resource(
|
|
162
|
-
"ai::TypeScriptFile",
|
|
163
|
-
async function (
|
|
164
|
-
this: Context<TypeScriptFile>,
|
|
165
|
-
_id: string,
|
|
166
|
-
props: TypeScriptFileProps,
|
|
167
|
-
): Promise<TypeScriptFile> {
|
|
168
|
-
// Handle delete phase
|
|
169
|
-
if (this.phase === "delete") {
|
|
170
|
-
// StaticTypeScriptFile will handle the deletion
|
|
171
|
-
return this.destroy();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Use provided system prompt or default
|
|
175
|
-
const system = props.system || DEFAULT_TS_SYSTEM_PROMPT;
|
|
176
|
-
|
|
177
|
-
// Generate initial content
|
|
178
|
-
const { text } = await generateText({
|
|
179
|
-
model: createModel(props),
|
|
180
|
-
prompt: props.prompt,
|
|
181
|
-
system,
|
|
182
|
-
providerOptions: props.model?.options,
|
|
183
|
-
...(props.temperature === undefined
|
|
184
|
-
? {}
|
|
185
|
-
: { temperature: props.temperature }),
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// Extract and validate TypeScript code
|
|
189
|
-
let { code, error } = await extractTypeScriptCode(text);
|
|
190
|
-
|
|
191
|
-
// Re-prompt if there are validation errors
|
|
192
|
-
if (error) {
|
|
193
|
-
const errorSystem = `${system}\n\nERROR: ${error}\n\nPlease try again and ensure your response contains exactly one TypeScript code block inside \`\`\`ts fences.`;
|
|
194
|
-
|
|
195
|
-
const { text: retryText } = await generateText({
|
|
196
|
-
model: createModel(props),
|
|
197
|
-
prompt: props.prompt,
|
|
198
|
-
system: errorSystem,
|
|
199
|
-
providerOptions: props.model?.options,
|
|
200
|
-
...(props.temperature === undefined
|
|
201
|
-
? {}
|
|
202
|
-
: { temperature: props.temperature }),
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
const retryResult = await extractTypeScriptCode(retryText);
|
|
206
|
-
|
|
207
|
-
if (retryResult.error) {
|
|
208
|
-
throw new Error(
|
|
209
|
-
`Failed to generate valid TypeScript code: ${retryResult.error}`,
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
code = retryResult.code;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// Use StaticTypeScriptFile to create/update the file
|
|
217
|
-
const file = await StaticTypeScriptFile("file", props.path, code);
|
|
218
|
-
|
|
219
|
-
// Return the resource
|
|
220
|
-
return this({
|
|
221
|
-
...props,
|
|
222
|
-
content: file.content,
|
|
223
|
-
createdAt: Date.now(),
|
|
224
|
-
updatedAt: Date.now(),
|
|
225
|
-
});
|
|
226
|
-
},
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Extracts TypeScript code from between ```ts fences
|
|
231
|
-
* Validates that exactly one TypeScript code block exists
|
|
232
|
-
*
|
|
233
|
-
* @param text The text to extract TypeScript code from
|
|
234
|
-
* @returns The extracted TypeScript code or error message
|
|
235
|
-
*/
|
|
236
|
-
async function extractTypeScriptCode(
|
|
237
|
-
text: string,
|
|
238
|
-
): Promise<{ code: string; error?: string }> {
|
|
239
|
-
const tsCodeRegex = /```ts\s*([\s\S]*?)```/g;
|
|
240
|
-
const matches = Array.from(text.matchAll(tsCodeRegex));
|
|
241
|
-
|
|
242
|
-
if (matches.length === 0) {
|
|
243
|
-
return {
|
|
244
|
-
code: "",
|
|
245
|
-
error:
|
|
246
|
-
"No TypeScript code block found in the response. Please include your code within ```ts fences.",
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (matches.length > 1) {
|
|
251
|
-
return {
|
|
252
|
-
code: "",
|
|
253
|
-
error:
|
|
254
|
-
"Multiple TypeScript code blocks found in the response. Please provide exactly one code block within ```ts fences.",
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return { code: matches[0][1].trim() };
|
|
259
|
-
}
|