Module: Aura::Vercel
- Defined in:
- lib/aura/vercel.rb
Overview
Generates Vercel deployment assets for an .aura file whose generated app is a stateless Rack app – i.e. LLM-only (no Torch). Torch model servers need LibTorch and a long-lived process, which exceed Vercel’s serverless limits (function size, no GPU, short timeouts); for those use ‘aura deploy` (Dockerfile) with a container host. Backs `aura deploy <file> –target vercel`.
Class Method Summary collapse
- .build(filename) ⇒ Object
-
.handler(base) ⇒ Object
Vercel’s Ruby runtime serves a ‘Handler` Rack app from api/*.rb.
- .refuse_torch!(filename) ⇒ Object
-
.uses_torch?(nodes) ⇒ Boolean
Torch is in play when a model is a torch/transfer net, or when the program trains/evaluates (which pulls in LibTorch + datasets).
-
.vercel_json ⇒ Object
Uses the long-standing ‘@vercel/ruby` builder.
Class Method Details
.build(filename) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/aura/vercel.rb', line 14 def build(filename) nodes = Aura.to_nodes(File.read(filename)) refuse_torch!(filename) if uses_torch?(nodes) ruby_code = Aura::CodeGen.generate(nodes) dir = File.dirname(filename) base = File.basename(filename, ".aura") api_dir = File.join(dir, "api") FileUtils.mkdir_p(api_dir) app_file = File.join(dir, "#{base}.rb") index_file = File.join(api_dir, "index.rb") json_file = File.join(dir, "vercel.json") File.write(app_file, ruby_code) File.write(index_file, handler(base)) File.write(json_file, vercel_json) puts "Generated Vercel assets (LLM-only app):" puts " - #{app_file}" puts " - #{index_file}" puts " - #{json_file}" puts " Set secrets in the Vercel dashboard (e.g. OPENAI_API_KEY, AURA_API_TOKEN)," puts " then deploy with: vercel deploy" end |
.handler(base) ⇒ Object
Vercel’s Ruby runtime serves a ‘Handler` Rack app from api/*.rb. We load the transpiled app with the classic-Sinatra boot disabled and expose its Rack application object.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/aura/vercel.rb', line 59 def handler(base) <<~RUBY # Generated by Aura v#{Aura::VERSION} -- Vercel Ruby serverless entrypoint. ENV["RACK_ENV"] ||= "production" require_relative "../#{base}" # Do not boot a listening server inside the serverless function; Vercel # invokes the Rack app directly. Sinatra::Application.set(:run, false) Handler = Sinatra::Application RUBY end |
.refuse_torch!(filename) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/aura/vercel.rb', line 49 def refuse_torch!(filename) raise DeployError, "This app uses Torch, which exceeds Vercel's serverless limits (LibTorch " \ "size, no GPU, short timeouts). Use `aura deploy #{filename}` (Dockerfile) " \ "with a container host (Fly.io / Render / Cloud Run) instead." end |
.uses_torch?(nodes) ⇒ Boolean
Torch is in play when a model is a torch/transfer net, or when the program trains/evaluates (which pulls in LibTorch + datasets).
42 43 44 45 46 47 |
# File 'lib/aura/vercel.rb', line 42 def uses_torch?(nodes) nodes.any? do |n| (n[:type] == :model && %i[torch transfer].include?(n[:kind])) || %i[train evaluate].include?(n[:type]) end end |
.vercel_json ⇒ Object
Uses the long-standing ‘@vercel/ruby` builder. Ruby is a community runtime on Vercel; adjust the builder for your account if the identifier changes.
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/aura/vercel.rb', line 75 def vercel_json <<~JSON { "builds": [ { "src": "api/index.rb", "use": "@vercel/ruby" } ], "routes": [ { "src": "/(.*)", "dest": "/api/index.rb" } ] } JSON end |