# Worker configuration
# Note: This wrangler.toml is for the Worker backend only.
# Pages deployment is configured separately in the Cloudflare dashboard.
# Frontend (Vite) environment variables should be set in Cloudflare Pages dashboard.
main = "worker/worker.ts"
compatibility_date = "2024-11-01"
name = "jeffemmett-canvas"
account_id = "0e7b3338d5278ed1b148e6456b940913"

[vars]
# Environment variables are managed in Cloudflare Dashboard
# Workers & Pages → jeffemmett-canvas → Settings → Variables
DAILY_DOMAIN = "mycopunks.daily.co"

# RunPod AI Service Configuration (defaults hardcoded in src/lib/clientConfig.ts)
# These are documented here for reference - actual values are in the client code
# to allow all users to access AI features without configuration
# RUNPOD_API_KEY = "set via wrangler secret put"
# RUNPOD_IMAGE_ENDPOINT_ID = "tzf1j3sc3zufsy"   # Automatic1111
# RUNPOD_VIDEO_ENDPOINT_ID = "4jql4l7l0yw0f3"   # Wan2.2
# RUNPOD_TEXT_ENDPOINT_ID = "03g5hz3hlo8gr2"    # vLLM
# RUNPOD_WHISPER_ENDPOINT_ID = "lrtisuv8ixbtub" # Whisper

[dev]
port = 5172
ip = "0.0.0.0"
local_protocol = "http"
upstream_protocol = "https"

[dev.miniflare]
kv_persist = true
r2_persist = true
durable_objects_persist = true

[durable_objects]
bindings = [
    { name = "AUTOMERGE_DURABLE_OBJECT", class_name = "AutomergeDurableObject" },
]

[[migrations]]
tag = "v1"
new_classes = ["AutomergeDurableObject"]

# Migration to handle transition from TldrawDurableObject to AutomergeDurableObject
# This ensures existing TldrawDurableObject instances can continue working
# while new connections use AutomergeDurableObject
[[migrations]]
tag = "v2"
# Note: We keep TldrawDurableObject as a stub (extends AutomergeDurableObject)
# so existing instances continue to work. New instances will use AutomergeDurableObject.
# The stub class ensures backward compatibility during the transition period.

[[r2_buckets]]
binding = 'TLDRAW_BUCKET'
bucket_name = 'jeffemmett-canvas'

[[r2_buckets]]
binding = 'BOARD_BACKUPS_BUCKET'
bucket_name = 'board-backups'

[[d1_databases]]
binding = "CRYPTID_DB"
database_name = "cryptid-auth"
database_id = "35fbe755-0e7c-4b9a-a454-34f945e5f7cc"

[observability]
enabled = true
head_sampling_rate = 1  

[triggers]
crons = ["0 0 * * *"] # Run at midnight UTC every day 
# crons = ["*/10 * * * *"] # Run every 10 minutes 

# Development environment configuration
[env.dev]
name = "jeffemmett-canvas-automerge-dev"
compatibility_date = "2024-07-01"

[env.dev.vars]
DAILY_DOMAIN = "mycopunks.daily.co"

[env.dev.durable_objects]
bindings = [
    { name = "AUTOMERGE_DURABLE_OBJECT", class_name = "AutomergeDurableObject" },
]

[[env.dev.migrations]]
tag = "v1"
new_classes = ["AutomergeDurableObject"]

[[env.dev.r2_buckets]]
binding = 'TLDRAW_BUCKET'
bucket_name = 'jeffemmett-canvas-preview'

[[env.dev.r2_buckets]]
binding = 'BOARD_BACKUPS_BUCKET'
bucket_name = 'board-backups-preview'

[[env.dev.d1_databases]]
binding = "CRYPTID_DB"
database_name = "cryptid-auth-dev"
database_id = "placeholder-will-be-created-dev"

[env.dev.triggers]
crons = ["0 0 * * *"] # Run at midnight UTC every day 

# Secrets should be set using `wrangler secret put` command
# DO NOT put these directly in wrangler.toml:
# - DAILY_API_KEY
# - CLOUDFLARE_API_TOKEN
# etc.