All files / src/constants Defaults.ts

100% Statements 1/1
100% Branches 0/0
100% Functions 0/0
100% Lines 1/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203                                28x                                                                                                                                                                                                                                                                                                                                                                                    
import { CloudflareConfiguration } from '@/types/CloudflareConfiguration'
 
/**
 * Default settings for the Cloudflare-backed modules.
 *
 * @remarks
 * The conventional binding names from `wrangler.json` plus conservative
 * per-binding defaults. Nothing here is application-specific; anything that is
 * belongs in an override in `src/config/`.
 *
 * @constant
 *
 * @author Bayu Dwiyan Satria
 * @version 1.0.0
 * @since 1.0.0
 */
export const cloudflareDefaults: CloudflareConfiguration = {
  /**
   * Workers AI — the `AI` binding, running Llama 3.1 8B unless a call or an
   * override names another model.
   */
  ai: {
    binding: 'AI',
    model: '@cf/meta/llama-3.1-8b-instruct'
  },
 
  /**
   * AI Search, single instance — the `AI_SEARCH` binding, with no retrieval
   * options, so Cloudflare's own defaults apply: ten results above a 0.4 score.
   * Set `options` from `config/` where a deployment wants a different recall
   * and precision trade than every call site restating one.
   */
  aiSearch: {
    binding: 'AI_SEARCH'
  },
 
  /**
   * AI Search, namespace-scoped — the `AI_SEARCH_NAMESPACE` binding. A
   * different default name from `aiSearch` above on purpose: the two are
   * separate bindings, and a Worker declaring both cannot give them one name.
   */
  aiSearchNamespace: {
    binding: 'AI_SEARCH_NAMESPACE'
  },
 
  /**
   * Telemetry — request and domain metrics, written through the `TELEMETRY`
   * binding. The dataset it points at is named in `wrangler.json`; this is only
   * the code-side handle, which is why renaming one does not rename the other.
   *
   * Only failures are recorded; see `AnalyticsSettings.minRequestStatus`.
   */
  analytics: {
    binding: 'TELEMETRY',
    enabled: true,
    minRequestStatus: 500
  },
 
  /**
   * D1 — the `DB` binding.
   */
  d1: {
    binding: 'DB'
  },
 
  /**
   * Durable Objects — the `DO` binding, with no location hint so objects are
   * created near their first caller.
   */
  durableObject: {
    binding: 'DO'
  },
 
  /**
   * Hyperdrive — the `HYPERDRIVE` binding.
   */
  hyperdrive: {
    binding: 'HYPERDRIVE'
  },
 
  /**
   * Browser Rendering — the `BROWSER` binding.
   */
  browser: {
    binding: 'BROWSER'
  },
 
  /**
   * Flagship — the `FLAGS` binding, with no deployment-wide evaluation context.
   * Set `context` from `config/` to give every targeting rule the attributes
   * this deployment already knows about itself, rather than restating them at
   * each call site.
   */
  flagship: {
    binding: 'FLAGS'
  },
 
  /**
   * Workers KV — the `KV` binding, with a five-minute default expiry so a
   * forgotten TTL cannot pin a value forever.
   */
  kv: {
    binding: 'KV',
    expirationTtl: 300
  },
 
  /**
   * Pipelines — the `PIPELINE` binding. Batching, destination and file format
   * are configured on the pipeline itself and apply to every producer, so
   * nothing about them is decided here.
   */
  pipeline: {
    binding: 'PIPELINE'
  },
 
  /**
   * Queues — the `QUEUE` binding, sending with Cloudflare's own delay and
   * content-type defaults.
   */
  queue: {
    binding: 'QUEUE'
  },
 
  /**
   * R2 — the `BUCKET` binding.
   */
  r2: {
    binding: 'BUCKET'
  },
 
  /**
   * Rate limiting — the `RATE_LIMITER` binding, failing open when it is absent
   * so an unconfigured limiter degrades to no limit rather than to no service.
   * The rate itself lives in `wrangler.json`; see `RateLimitSettings`.
   */
  rateLimit: {
    binding: 'RATE_LIMITER',
    failOpen: true
  },
 
  /**
   * Vectorize — the `VECTORIZE` binding, returning five matches per query.
   */
  vectorize: {
    binding: 'VECTORIZE',
    topK: 5
  },
 
  /**
   * Workers VPC, one private service — the `VPC_SERVICE` binding. Which service
   * it reaches is `service_id` in `wrangler.json` and fixed at deploy time,
   * which is the point: this binding can reach one endpoint and no other.
   */
  vpcService: {
    binding: 'VPC_SERVICE'
  },
 
  /**
   * Workers VPC, a whole private network — the `VPC_NETWORK` binding. Reaches
   * anything on the bound tunnel or mesh, with the destination chosen per call.
   * Prefer `vpcService` above wherever one endpoint will do.
   */
  vpcNetwork: {
    binding: 'VPC_NETWORK'
  },
 
  /**
   * Workflows — the `WORKFLOW` binding, with no retention policy, so a
   * deployment that does not state one keeps instance state for as long as the
   * account allows. Set `successRetention` and `errorRetention` from `config/`
   * where a finished run need not outlive the endpoint that reads it.
   */
  workflow: {
    binding: 'WORKFLOW'
  },
 
  /**
   * Logging — `info` and above, carrying only what Cloudflare does not already
   * record.
   *
   * Every stored log record arrives wrapped in a `$metadata` envelope the
   * platform builds: the script name as `service`, the severity as `level`, the
   * `message`, and `trigger` — the method and path joined. Two of those,
   * `level` and `message`, it lifts from the top of the object we log; the rest
   * it knows on its own. A Worker that restates the service name is paying to
   * ingest a column the dashboard already renders.
   *
   * What Cloudflare does *not* have on that record is the correlation id that
   * survives a Service Binding hop, the client address once Pseudo-IPv4 has
   * overwritten it, and the response status. Those are the line.
   *
   * `LOG_FIELDS` in `wrangler.json` overrides this per deployment, and should:
   * a Worker whose lines leave this console — Logpush, an OTel export, a file —
   * needs `service` back, because a record that only means something inside one
   * vendor's dashboard is not a record. `colo`, `country`, `component`,
   * `durationMs` and `time` are available the same way.
   */
  logging: {
    level: 'info',
    fields: ['requestId', 'method', 'path', 'ip', 'status']
  }
}