pub const CLOUDFLARE_ADAPTER_SRC: &str = "adapter bynk.cloudflare {\n\tconsumes bynk { Fetch }\n\texports capability {\n\t\tKv,\n\t\tService,\n\t\tR2,\n\t\tRateLimit,\n\t\tQueue,\n\t\tAnalytics,\n\t\tEdgeCache,\n\t\tD1,\n\t\tVersion,\n\t\tAi,\n\t\tImages,\n\t\tStoredSecret,\n\t\tEmail,\n\t\tPostgres,\n\t\tMySql,\n\t\tVectorize,\n\t\tContainer,\n\t\tAiSearch,\n\t\tMtlsCertificate,\n\t\tAnalyticsSql,\n\t}\n\texports transparent {\n\t\tKvExpiration,\n\t\tKvPut,\n\t\tKvGet,\n\t\tKvEntry,\n\t\tKvKey,\n\t\tKvList,\n\t\tKvListing,\n\t\tR2Object,\n\t\tR2Put,\n\t\tR2Condition,\n\t\tR2Listing,\n\t\tR2Body,\n\t\tR2Upload,\n\t\tR2UploadOptions,\n\t\tR2Part,\n\t\tQueueSend,\n\t\tRequestCf,\n\t\tDataPoint,\n\t\tSqlValue,\n\t\tSqlStatement,\n\t\tSqlRun,\n\t\tSqlError,\n\t\tSqlReadError,\n\t\tWorkerVersion,\n\t\tAiError,\n\t\tImageFormat,\n\t\tImageFit,\n\t\tImageInfo,\n\t\tOverlay,\n\t\tTransformOptions,\n\t\tOutputOptions,\n\t\tImageResult,\n\t\tImageStream,\n\t\tImagesError,\n\t\tAnalyticsSqlStatistics,\n\t\tAnalyticsSqlResult,\n\t\tAnalyticsSqlError,\n\t\tChatRole,\n\t\tChatMessage,\n\t\tGenerateRequest,\n\t\tTokenUsage,\n\t\tGeneration,\n\t\tEmailAttachment,\n\t\tEmailMessage,\n\t\tEmailError,\n\t\tInboundAttachment,\n\t\tInboundEmail,\n\t\tEmailReply,\n\t\tEmailVerdict,\n\t\tDmarcVerdict,\n\t\tSenderIdentity,\n\t\tPgValue,\n\t\tPgError,\n\t\tPgRun,\n\t\tPgStatement,\n\t\tPgReadError,\n\t\tMySqlValue,\n\t\tMySqlError,\n\t\tMySqlRun,\n\t\tMySqlStatement,\n\t\tMySqlReadError,\n\t\tVector,\n\t\tVectorOf,\n\t\tMetaValue,\n\t\tFilterOp,\n\t\tCondition,\n\t\tMetadataScope,\n\t\tQueryOptions,\n\t\tVectorMatch,\n\t\tMutation,\n\t\tIndexInfo,\n\t\tVectorError,\n\t\tSearchHit,\n\t\tRetrievalType,\n\t\tSearchOptions,\n\t\tSearchAnswer,\n\t\tSearchError,\n\t\tContainerError,\n\t}\n\n\t---\n\tWhen a `Kv.putWith` or `Kv.putBytes` entry expires: `Never`, `After` a\n\tduration (a part second rounds up), or `At` an instant. Either must be at\n\tleast 60 seconds away. KV has further expiry forms, so a `match` over this\n\ttype needs a wildcard.\n\t---\n\ttype KvExpiration =\n\t\t| Never\n\t\t| After(ttl: Duration)\n\t\t| At(instant: Instant)\n\n\t---\n\tThe options of a `Kv.putWith` or `Kv.putBytes` write: when the entry\n\texpires, and the metadata stored beside it (at most 1024 bytes once\n\tserialised as JSON). Leave a field out for `Kv.put`\'s behaviour: no expiry,\n\tno metadata.\n\t---\n\ttype KvPut = {\n\t\texpiration: KvExpiration = KvExpiration.Never,\n\t\tmetadata: Map[String, String] = Map.empty(),\n\t}\n\n\t---\n\tThe options of a `Kv.getWith` read. `cacheTtl` is how long the read may be\n\tserved from Cloudflare\'s edge cache, at least 30 seconds; `None` keeps the\n\tplatform\'s default of 60, and is the default.\n\t---\n\ttype KvGet = {\n\t\tcacheTtl: Option[Duration] = None,\n\t}\n\n\t---\n\tA value read by `Kv.getWith`, with the metadata written beside it.\n\t---\n\ttype KvEntry = {\n\t\tvalue: String,\n\t\tmetadata: Map[String, String],\n\t}\n\n\t---\n\tOne key of a `Kv.listPage`: its name, when it expires (`None` for never),\n\tand its metadata.\n\t---\n\ttype KvKey = {\n\t\tname: String,\n\t\texpiration: Option[Instant],\n\t\tmetadata: Map[String, String],\n\t}\n\n\t---\n\tThe options of a `Kv.listPage`: the keys under `prefix`, from `cursor` (the\n\tprevious page\'s; `None` for the first), at most `limit` of them (1 to 1000;\n\t`None` for 1000).\n\t---\n\ttype KvList = {\n\t\tprefix: Option[String],\n\t\tcursor: Option[String],\n\t\tlimit: Option[Int],\n\t}\n\n\t---\n\tOne page of a `Kv.listPage`: its keys in key order, and the cursor of the\n\tnext page, `None` on the last. A page may be short and still have a\n\tcursor, so loop until the cursor is `None`, not until a page is short.\n\t---\n\ttype KvListing = {\n\t\tkeys: List[KvKey],\n\t\tcursor: Option[String],\n\t}\n\n\t---\n\tA Cloudflare Workers KV namespace: a key/value store with optional per-entry\n\texpiry and prefix listing.\n\n\t`get`, `put`, `putTtl`, `delete` and `list` work on text. The rest\n\t(experimental) add what the platform has beyond that:\n\t- `getWith` reads a value with its metadata, optionally edge-cached for\n\t `cacheTtl`; `putWith` writes one with an expiry and metadata.\n\t- `getBytes` and `putBytes` read and write binary values.\n\t- `listPage` reads one page of keys, with each key\'s expiry and metadata.\n\n\tText and binary values share the namespace, as on the platform: `getBytes`\n\tof a text value gives its UTF-8 bytes, and reading a binary value as text\n\tdecodes it as UTF-8, replacing what is not. Keep each key to one kind.\n\n\tA key over 512 bytes, metadata over 1024 bytes, an expiry under 60 seconds\n\taway, a `cacheTtl` under 30 seconds, or a `limit` outside 1 to 1000 faults\n\tthe new operations before the platform is called; a value over 25 MiB\n\tfaults with the platform\'s error.\n\t---\n\tcapability Kv {\n\t\tfn get(key: String) -> Effect[Option[String]]\n\t\tfn put(key: String, value: String) -> Effect[()]\n\t\tfn putTtl(key: String, value: String, ttlSeconds: Int) -> Effect[()]\n\t\tfn delete(key: String) -> Effect[()]\n\t\tfn list(prefix: Option[String]) -> Effect[List[String]]\n\t\tfn getWith(key: String, options: KvGet) -> Effect[Option[KvEntry]]\n\t\tfn putWith(key: String, value: String, options: KvPut) -> Effect[()]\n\t\tfn getBytes(key: String) -> Effect[Option[Bytes]]\n\t\tfn putBytes(key: String, value: Bytes, options: KvPut) -> Effect[()]\n\t\tfn listPage(options: KvList) -> Effect[KvListing]\n\t}\n\n\t---\n\tA Service Binding to a Worker that is not part of this Bynk project: an\n\tuntyped HTTP call over Cloudflare\'s private channel, never the public\n\tinternet. Used only through a named instance that names its Worker,\n\t`capability Billing = Service @worker(\"legacy-billing\")`, which binds as\n\t`SERVICE_BILLING`; a bare `given Service` names no Worker and is refused.\n\n\t`send` has `Fetch.send`\'s shape and rules: the same `Request` (its\n\theaders checked the same way, refused as `InvalidHeader` before anything\n\tis sent), the same `Response`, and `Network` when the call itself fails.\n\tThe URL\'s host is not used for routing (the binding decides where the\n\trequest goes), but the URL must be absolute and the callee sees it. A\n\tstatus the Worker returns, 5xx included, is an `Ok` response.\n\n\tThe callee is not Bynk\'s: `bynk deploy` neither creates nor checks its\n\tcontract, and warns when no Worker of that name exists in the account\n\t(Cloudflare itself then rejects the upload). `bynk dev` binds a local\n\ttest double unless `--local-worker` names the Worker, and `bynkc test`\n\tfaults until the call is stubbed. A Bynk callee should be consumed with\n\t`consumes` instead, which checks its contract.\n\n\t`Request`, `Response` and `FetchError` are `bynk`\'s types, so a context\n\tthat calls `send` also writes `consumes bynk` to name them.\n\t---\n\tcapability Service {\n\t\tfn send(req: Request) -> Effect[Result[Response, FetchError]]\n\t}\n\n\t---\n\tAn object in an R2 bucket, as `head`, `put`, `putWith` and `list` report\n\tit: no body. `etag` is R2\'s opaque version tag (what `EtagMatches` compares\n\tagainst), `uploaded` when the object was last written. `contentType` is\n\t`None` when none was stored; `metadata` is the custom metadata written\n\twith the object.\n\t---\n\ttype R2Object = {\n\t\tkey: String,\n\t\tsize: Int,\n\t\tetag: String,\n\t\tuploaded: Instant,\n\t\tcontentType: Option[String],\n\t\tmetadata: Map[String, String],\n\t}\n\n\t---\n\tThe precondition of an `R2.putWith` write. `Always` writes\n\tunconditionally, `Absent` only when the key holds no object (create-only,\n\twhich content-addressed storage needs), and `EtagMatches(etag)` only when\n\tthe current object\'s etag is `etag` (compare-and-swap). R2 has further\n\tconditions, so a `match` over this type needs a wildcard.\n\t---\n\ttype R2Condition =\n\t\t| Always\n\t\t| Absent\n\t\t| EtagMatches(etag: String)\n\n\t---\n\tThe options of an `R2.putWith` write: the content type and custom\n\tmetadata to store, and the precondition (`onlyIf`) the write needs. Leave a\n\tfield out for `R2.put`\'s behaviour: no content type, no metadata, always\n\twritten.\n\t---\n\ttype R2Put = {\n\t\tcontentType: Option[String] = None,\n\t\tmetadata: Map[String, String] = Map.empty(),\n\t\tonlyIf: R2Condition = R2Condition.Always,\n\t}\n\n\t---\n\tOne page of an `R2.list`: the objects it holds, and the cursor of the next\n\tpage, `None` on the last.\n\t---\n\ttype R2Listing = {\n\t\tkeys: List[R2Object],\n\t\tcursor: Option[String],\n\t}\n\n\t---\n\tAn object read by `R2.getStream`: its metadata, and its body as a stream\n\tof chunks, read from R2 as they are pulled. The body can be read once\n\t(`collect`, `map`, or handed to `RawStreamed`); a second read faults. A\n\trecord carrying a stream is not data: it can\'t be stored, sent or encoded.\n\t---\n\ttype R2Body = {\n\t\tobject: R2Object,\n\t\tbody: Stream[Bytes],\n\t}\n\n\t---\n\tA multipart upload in progress, as `R2.createUpload` begins it. It is\n\tplain data, so it can be kept (in an agent, say) or handed to a client\n\tbetween the requests that upload its parts. R2 aborts an upload left\n\tincomplete for 7 days.\n\t---\n\ttype R2Upload = {\n\t\tkey: String,\n\t\tuploadId: String,\n\t}\n\n\t---\n\tThe options of an `R2.createUpload`: the content type and custom metadata\n\tof the object the upload completes.\n\t---\n\ttype R2UploadOptions = {\n\t\tcontentType: Option[String],\n\t\tmetadata: Map[String, String],\n\t}\n\n\t---\n\tOne uploaded part of a multipart upload, as `R2.uploadPart` reports it.\n\t`R2.completeUpload` takes every part, in any order.\n\t---\n\ttype R2Part = {\n\t\tpartNumber: Int,\n\t\tetag: String,\n\t}\n\n\t---\n\tThe options of a `Queue.sendWith`. `delay` holds the message back before\n\tit can be delivered: whole seconds (a part second rounds up), at most 12\n\thours; `None`, the default, delivers as soon as the queue can.\n\t---\n\ttype QueueSend = {\n\t\tdelay: Option[Duration] = None,\n\t}\n\n\t---\n\tWhat Cloudflare knows about the connection of an `on http` request, as a\n\thandler\'s `cf: RequestCf` parameter. Every field is optional and defaults\n\tto `None`: Cloudflare derives them, a platform or a test may not supply\n\tthem, and a field of an unexpected shape is `None`, never a fault. A\n\thandler that declares `cf` is therefore written once and works where\n\t`request.cf` is absent.\n\n\tThese facts come from the client\'s IP address, so they can be personal\n\tdata, and they are best-effort: a VPN or a proxy makes them wrong. The\n\tfields are Cloudflare\'s `request.cf` properties\n\t(https://developers.cloudflare.com/workers/runtime-apis/request/); a\n\tfield is added later as a defaulted field. `latitude` and `longitude` are\n\tnumeric strings on the platform and are read as `Float`; `isEuCountry` is\n\t`Some(true)` where Cloudflare reports the country as in the EU.\n\t---\n\ttype RequestCf = {\n\t\tcountry: Option[String] = None,\n\t\tcontinent: Option[String] = None,\n\t\tcity: Option[String] = None,\n\t\tregion: Option[String] = None,\n\t\tregionCode: Option[String] = None,\n\t\tpostalCode: Option[String] = None,\n\t\ttimezone: Option[String] = None,\n\t\tlatitude: Option[Float] = None,\n\t\tlongitude: Option[Float] = None,\n\t\tcolo: Option[String] = None,\n\t\tasn: Option[Int] = None,\n\t\tasOrganization: Option[String] = None,\n\t\thttpProtocol: Option[String] = None,\n\t\ttlsVersion: Option[String] = None,\n\t\tisEuCountry: Option[Bool] = None,\n\t}\n\n\t---\n\tOne event written to an `Analytics` dataset. `index` is the sampling key\n\t(at most 96 bytes; `None` samples the dataset as a whole), `blobs` are\n\ttext dimensions (at most 20, totalling at most 16 KB), and `doubles` are\n\tnumeric values (at most 20, each finite). In the SQL API they are the\n\tcolumns `index1`, `blob1`\u{2026}`blob20` and `double1`\u{2026}`double20`, in order.\n\t---\n\ttype DataPoint = {\n\t\tindex: Option[String],\n\t\tblobs: List[String],\n\t\tdoubles: List[Float],\n\t}\n\n\t---\n\tA value bound to a `?n` parameter of a `D1` statement, by SQLite storage\n\tclass. `Boolean` binds as `1` or `0`, as SQLite has no boolean.\n\t---\n\ttype SqlValue =\n\t\t| Null\n\t\t| Integer(value: Int)\n\t\t| Real(value: Float)\n\t\t| Text(value: String)\n\t\t| Blob(value: Bytes)\n\t\t| Boolean(value: Bool)\n\n\t---\n\tOne statement of a `D1.batch`: its SQL, a string literal, and its\n\tpositional parameters. It stays where it is built: it is never stored,\n\tsent or decoded, since one from outside would carry SQL that was never a\n\tliteral.\n\t---\n\ttype SqlStatement = {\n\t\tsql: String,\n\t\tparams: List[SqlValue],\n\t}\n\n\t---\n\tWhat a `D1.run` (or one statement of a `D1.batch`) changed: the rows it\n\twrote, and the rowid of the last row it inserted.\n\t---\n\ttype SqlRun = {\n\t\tchanges: Int,\n\t\tlastRowId: Int,\n\t}\n\n\t---\n\tWhy a `D1` statement failed. `Constraint` is a UNIQUE, CHECK, NOT NULL or\n\tforeign-key violation, an outcome a handler answers (with a `409`, say);\n\t`Failed` is anything else, with the database\'s message. D1 has further\n\tfailure kinds, so a `match` over this type needs a wildcard.\n\t---\n\ttype SqlError =\n\t\t| Constraint(message: String)\n\t\t| Failed(message: String)\n\n\t---\n\tWhy a typed `D1` read (`select[T]`, `firstAs[T]`) failed: `Sql` is the\n\tstatement\'s own failure, `Decode` a row that did not fit `T` (a column\n\twhose stored value disagrees with its field\'s type).\n\t---\n\ttype SqlReadError =\n\t\t| Sql(error: SqlError)\n\t\t| Decode(error: DecodeError)\n\n\t---\n\tOne file attached to an outbound `EmailMessage`. `content` is the file\'s bytes,\n\t`contentType` its MIME type (`\"application/pdf\"`) and `filename` the name\n\tthe recipient sees. `inline` sends it for display inside the body (an\n\timage the `html` refers to as `cid:logo.png`, its content id being its\n\tfilename) rather than as a download.\n\t---\n\ttype EmailAttachment = {\n\t\tfilename: String,\n\t\tcontentType: String,\n\t\tcontent: Bytes,\n\t\tinline: Bool = false,\n\t}\n\n\t---\n\tOne outbound email for `Email.send`. Addresses are plain `String`s\n\t(`\"[email protected]\"` or `\"Shop <[email protected]>\"`); the platform,\n\tnot Bynk, judges their syntax. At least one of `text` and `html` is\n\trequired. `headers` adds custom headers: `From`, `To`, `Cc`, `Bcc`,\n\t`Subject` and `Reply-To` are set by the fields above and may not be set\n\there, and a name or value with a line break is refused, since either would\n\tlet data inject a header.\n\t---\n\ttype EmailMessage = {\n\t\tfrom: String,\n\t\tto: List[String],\n\t\tcc: List[String] = [],\n\t\tbcc: List[String] = [],\n\t\treplyTo: Option[String] = None,\n\t\tsubject: String,\n\t\ttext: Option[String] = None,\n\t\thtml: Option[String] = None,\n\t\tattachments: List[EmailAttachment] = [],\n\t\theaders: Map[String, String] = Map.empty(),\n\t}\n\n\t---\n\tWhy an `Email.send` was refused by the platform. `SenderNotVerified` is a\n\t`from` address outside a domain verified for sending; `RecipientNotAllowed`\n\ta recipient the instance\'s `@to` or `@allowedRecipients` (or the account)\n\tdoes not permit; `RateLimited` and `DailyLimit` the per-second and\n\tper-day sending limits. All are outcomes a handler can act on (retry\n\tlater, alert); `SendFailed` is any other refusal, with the platform\'s\n\tmessage. Cloudflare has further error codes, so a `match` over this type\n\tneeds a wildcard.\n\t---\n\ttype EmailError =\n\t\t| SenderNotVerified\n\t\t| RecipientNotAllowed\n\t\t| RateLimited\n\t\t| DailyLimit\n\t\t| SendFailed(message: String)\n\n\t---\n\tOne file attached to an inbound `InboundEmail`: its `filename`, MIME\n\t`contentType` and `content` bytes. `inline` is true for a part the HTML body\n\trefers to by content id (an embedded image) rather than a download.\n\t---\n\ttype InboundAttachment = {\n\t\tfilename: String,\n\t\tcontentType: String,\n\t\tcontent: Bytes,\n\t\tinline: Bool = false,\n\t}\n\n\t---\n\tOne email delivered to a `from email(...)` service\'s `on message` handler.\n\t`from` is the **envelope** sender, a claim: anyone can write any address, so\n\ttrust it only when the `Sender` actor\'s `dmarc` is `DmarcPass`. `to` is the\n\tenvelope recipient the service was routed by. `headers` holds the message\'s\n\theaders by lower-case name. `text`, `html` and `attachments` come from the\n\tparsed MIME body (`None` or empty when the message has no such part); a test\n\tbuilds them directly. `size` is the raw message in bytes. Every field after\n\t`to` has a default, so a test writes only what it cares about.\n\t---\n\ttype InboundEmail = {\n\t\tfrom: String,\n\t\tto: String,\n\t\tsubject: String = \"\",\n\t\tmessageId: String = \"\",\n\t\theaders: Map[String, String] = Map.empty(),\n\t\ttext: Option[String] = None,\n\t\thtml: Option[String] = None,\n\t\tattachments: List[InboundAttachment] = [],\n\t\tsize: Int = 0,\n\t}\n\n\t---\n\tThe content of a `Reply` verdict. Only the content is the handler\'s: the\n\truntime fills in `From` (the receiving address), `To` (the sender),\n\t`In-Reply-To` and `References`, so a reply can only go to the sender, from\n\tthe address that received the mail, as the platform requires. `subject`\n\tdefaults to the incoming subject prefixed `Re: `.\n\t---\n\ttype EmailReply = {\n\t\tsubject: Option[String] = None,\n\t\ttext: Option[String] = None,\n\t\thtml: Option[String] = None,\n\t}\n\n\t---\n\tWhat a `from email` handler decides about a message, returned as\n\t`Effect[EmailVerdict]` (the agency rule of ADR 0078, as `QueueResult` is).\n\t`Accept` handles it and nothing else happens; `Reject(reason)` refuses it\n\tpermanently with an SMTP rejection carrying `reason`; `Forward(to)` passes it\n\tto one destination, which must be a verified destination address in the\n\taccount; `Reply(message)` answers the sender. One decision per message.\n\t---\n\ttype EmailVerdict =\n\t\t| Accept\n\t\t| Reject(reason: String)\n\t\t| Forward(to: String)\n\t\t| Reply(message: EmailReply)\n\n\t---\n\tWhether the platform authenticated the sender\'s domain with DMARC, read from\n\tthe `Authentication-Results` header Cloudflare Email Routing prepends: only\n\tthe topmost, and only if it is from `mx.cloudflare.net`, is trusted. `DmarcNone`\n\tis no verdict (the header is absent, is another server\'s, or reports none). The variants carry the `Dmarc`\n\tprefix because a bare `None` would resolve to `Option`\'s.\n\t---\n\ttype DmarcVerdict = enum { DmarcPass, DmarcFail, DmarcNone }\n\n\t---\n\tThe identity of the `Sender` actor, the default actor of a `from email`\n\thandler: the envelope `address` and the platform\'s `dmarc` verdict on it.\n\tThe Worker\'s `email()` entry mints it from the envelope and Email Routing\'s\n\t`Authentication-Results` header; a handler runs in a suite without a\n\tminted identity today, so `s.identity` reads as `()` until that lands.\n\t---\n\ttype SenderIdentity = {\n\t\taddress: String,\n\t\tdmarc: DmarcVerdict,\n\t}\n\n\t---\n\tA value bound to a `$n` parameter of a `Postgres` statement. `PgInteger`\n\tbinds a whole number and `PgReal` a float; `PgText` binds text, `PgBytea` bytes\n\tand `PgBoolean` a flag. `PgTimestamp` binds an `Instant` as a `timestamptz`.\n\t`PgJson` binds JSON text and `PgNumeric` a decimal as text, each as text\n\tthe server types from the column or cast it meets (`$1::jsonb`,\n\t`$2::numeric`), so neither loses a digit to a float. The variants carry the\n\t`Pg` prefix because a bare `Null`, `Integer`, `Real`, `Text` or `Boolean`\n\twould resolve to `SqlValue`\'s, and `Json` and `Timestamp` to a built-in.\n\t---\n\ttype PgValue =\n\t\t| PgNull\n\t\t| PgInteger(value: Int)\n\t\t| PgReal(value: Float)\n\t\t| PgText(value: String)\n\t\t| PgBytea(value: Bytes)\n\t\t| PgBoolean(value: Bool)\n\t\t| PgTimestamp(value: Instant)\n\t\t| PgJson(value: String)\n\t\t| PgNumeric(value: String)\n\n\t---\n\tWhat a `Postgres.run` changed: the rows the statement inserted, updated or\n\tdeleted (or, for a `SELECT`, returned).\n\t---\n\ttype PgRun = {\n\t\trowCount: Int,\n\t}\n\n\t---\n\tWhy a `Postgres` statement failed, with the SQLSTATE where Postgres gave\n\tone. `PgConstraint` is an integrity-constraint violation (class `23`: a\n\tunique, not-null, check or foreign-key violation), an outcome a handler\n\tanswers (with a `409`, say). `PgSerialization` is a serialization failure\n\t(`40001`), which a retry may clear. `PgConnection` is a connection that could not\n\tbe made or was lost; its message names the driver\'s code and never the\n\thost or the connection string. `PgFailed` is anything else, with its SQLSTATE\n\t(empty when the driver reported none) and the database\'s message. Postgres has further failure\n\tkinds, so a `match` over this type needs a wildcard. The variants carry the\n\t`Pg` prefix because `Constraint` and `Failed` are `SqlError`\'s.\n\t---\n\ttype PgError =\n\t\t| PgConstraint(sqlstate: String, message: String)\n\t\t| PgSerialization(message: String)\n\t\t| PgConnection(message: String)\n\t\t| PgFailed(sqlstate: String, message: String)\n\n\t---\n\tOne statement of a `Postgres.transaction`: its SQL, a string literal, and\n\tits positional parameters (`$1`, `$2`, \u{2026}). It stays where it is built: it is\n\tnever stored, sent or decoded, since one from outside would carry SQL that\n\twas never a literal.\n\t---\n\ttype PgStatement = {\n\t\tsql: String,\n\t\tparams: List[PgValue],\n\t}\n\n\t---\n\tWhy a typed `Postgres` read (`select[T]`, `firstAs[T]`) failed: `PgSql` is\n\tthe statement\'s own failure, `PgDecode` a row that did not fit `T` (a\n\tcolumn whose value disagrees with its field\'s type). The variants carry the\n\t`Pg` prefix because `Sql` and `Decode` are `SqlReadError`\'s.\n\t---\n\ttype PgReadError =\n\t\t| PgSql(error: PgError)\n\t\t| PgDecode(error: DecodeError)\n\n\t---\n\tA value bound to a `?` parameter of a `MySql` statement. `MySqlInteger`\n\tbinds a signed whole number and `MySqlReal` a float; `MySqlText` binds text\n\tand `MySqlBytes` bytes. `MySqlBoolean` binds a flag as `1` or `0`, which is\n\twhat a `TINYINT(1)` column holds.\n\n\t`MySqlUnsigned` binds an unsigned integer as its decimal digits, since an\n\t`Int` is signed and a `BIGINT UNSIGNED` reaches past it; a value that is not\n\tdigits only is refused by the server. `MySqlDecimal` binds a `DECIMAL` as\n\ttext and `MySqlJson` binds JSON text for a `JSON` column, so neither loses a\n\tdigit to a float.\n\n\tMySQL has two date and time types that Postgres does not, and Bynk does not\n\tpretend they are one. `MySqlDateTime` binds the wall-clock text of a\n\t`DATETIME` (`2026-11-12 09:30:00`), which has no time zone and is not an\n\tinstant. `MySqlTimestamp` binds an `Instant` as UTC text\n\t(`2026-11-12 09:30:00.000`): right for a `DATETIME` column that holds UTC by\n\tconvention, and for a `TIMESTAMP` column only when the session\'s time zone is\n\tUTC, since MySQL converts a `TIMESTAMP` through the session\'s zone.\n\n\tThe variants carry the `MySql` prefix so nothing collides with `PgValue`\'s or\n\t`SqlValue`\'s.\n\t---\n\ttype MySqlValue =\n\t\t| MySqlNull\n\t\t| MySqlInteger(value: Int)\n\t\t| MySqlUnsigned(value: String)\n\t\t| MySqlReal(value: Float)\n\t\t| MySqlText(value: String)\n\t\t| MySqlBytes(value: Bytes)\n\t\t| MySqlBoolean(value: Bool)\n\t\t| MySqlTimestamp(value: Instant)\n\t\t| MySqlDateTime(value: String)\n\t\t| MySqlJson(value: String)\n\t\t| MySqlDecimal(value: String)\n\n\t---\n\tWhat a `MySql.run` changed: `rowCount` is the rows the statement affected\n\t(for a `SELECT`, returned), and `insertId` the `AUTO_INCREMENT` id of the\n\trow it inserted, `0` when it inserted none. MySQL has no `RETURNING`, so\n\t`insertId` is how a handler learns the key of the row it just wrote. An id\n\tor a count past 2^53 cannot be an `Int`: `run` answers `Err(MySqlFailed(0, \u{2026}))`\n\tnaming it, rather than a `0` that would mean \"inserted none\". Outside a\n\ttransaction the statement has still been applied, so do not retry on it\n\tblindly; inside one, the failure rolls the transaction back.\n\t---\n\ttype MySqlRun = {\n\t\trowCount: Int,\n\t\tinsertId: Int,\n\t}\n\n\t---\n\tWhy a `MySql` statement failed, keyed on MySQL\'s error number. `MySqlConstraint`\n\tis an integrity-constraint violation (`1062` duplicate key, `1048` a column\n\tthat cannot be null, `1452` and `1451` a foreign key, `3819` a check), an\n\toutcome a handler answers (with a `409`, say). `MySqlSerialization` is a\n\tdeadlock (`1213`) or a lock wait timeout (`1205`), which a retry may clear.\n\t`MySqlConnection` is a connection that could not be made or was lost; its\n\tmessage names the driver\'s code and never the host, the user or the\n\tpassword. `MySqlFailed` is anything else, with its error number (`0` when the\n\tdriver reported none) and the database\'s message. MySQL has further failure\n\tkinds, so a `match` over this type needs a wildcard. The variants carry the\n\t`MySql` prefix because `Constraint` and `Failed` are `SqlError`\'s.\n\t---\n\ttype MySqlError =\n\t\t| MySqlConstraint(code: Int, message: String)\n\t\t| MySqlSerialization(code: Int, message: String)\n\t\t| MySqlConnection(message: String)\n\t\t| MySqlFailed(code: Int, message: String)\n\n\t---\n\tOne statement of a `MySql.transaction`: its SQL, a string literal, and its\n\tpositional parameters (`?`). It stays where it is built: it is never stored,\n\tsent or decoded, since one from outside would carry SQL that was never a\n\tliteral.\n\t---\n\ttype MySqlStatement = {\n\t\tsql: String,\n\t\tparams: List[MySqlValue],\n\t}\n\n\t---\n\tWhy a typed `MySql` read (`select[T]`, `firstAs[T]`) failed: `MySqlSql` is\n\tthe statement\'s own failure, `MySqlDecode` a row that did not fit `T` (a\n\tcolumn whose value disagrees with its field\'s type). The variants carry the\n\t`MySql` prefix because `Sql` and `Decode` are `SqlReadError`\'s.\n\t---\n\ttype MySqlReadError =\n\t\t| MySqlSql(error: MySqlError)\n\t\t| MySqlDecode(error: DecodeError)\n\n\t---\n\tAn R2 bucket: objects stored and read as `Bytes` or streamed, with\n\tmetadata, conditional writes and multipart uploads. Used only through a named instance,\n\t`capability Archives = R2`, which binds as `R2_ARCHIVES`; a bare\n\t`given R2` names no bucket and is refused. `@jurisdiction(\"eu\")` (or\n\t`\"fedramp\"`) pins the bucket\'s jurisdiction at creation.\n\n\t`get`, `put` and `putWith` buffer the object in the Worker\'s memory, so\n\teach should stay well under its 128 MB limit. `get` and `head` give `None`\n\tfor a missing key; `delete` is idempotent. `put` writes unconditionally.\n\t`putWith` honours its `onlyIf` and gives `None` when the condition failed\n\t(nothing written). `list` returns one page of up to 1000 objects (fewer\n\tis possible: the cursor decides whether more remain) in key order,\n\toptionally under a prefix; pass the previous page\'s `cursor` for the next.\n\n\tLarger objects stream. `getStream` gives the object\'s metadata and its\n\tbody as a `Stream[Bytes]` (serve it with `RawStreamed`). `putStream` and\n\t`putStreamWith` write a stream of exactly `size` bytes, which R2 needs to\n\tknow up front: a stream that holds more or fewer faults the write, and\n\tnothing is stored.\n\n\tA multipart upload builds one object from parts uploaded separately, in\n\tany order and across requests: `createUpload`, an `uploadPart` per part\n\t(numbered from 1, at most 10,000), then `completeUpload` with every part,\n\tor `abortUpload`. Every part but the last must be the same size, and R2\n\tneeds at least 5 MiB; a completion R2 refuses faults.\n\n\tBucket names are scoped to the Cloudflare account, so `bynk deploy` names\n\teach `<worker>-<capability, kebab>`, environment-qualified.\n\t---\n\tcapability R2 {\n\t\tfn get(key: String) -> Effect[Option[Bytes]]\n\t\tfn head(key: String) -> Effect[Option[R2Object]]\n\t\tfn put(key: String, body: Bytes) -> Effect[R2Object]\n\t\tfn putWith(key: String, body: Bytes, options: R2Put) -> Effect[Option[R2Object]]\n\t\tfn delete(key: String) -> Effect[()]\n\t\tfn list(prefix: Option[String], cursor: Option[String]) -> Effect[R2Listing]\n\t\tfn getStream(key: String) -> Effect[Option[R2Body]]\n\t\tfn putStream(key: String, body: Stream[Bytes], size: Int) -> Effect[R2Object]\n\t\tfn putStreamWith(\n\t\t\tkey: String,\n\t\t\tbody: Stream[Bytes],\n\t\t\tsize: Int,\n\t\t\toptions: R2Put\n\t\t) -> Effect[Option[R2Object]]\n\t\tfn createUpload(key: String, options: R2UploadOptions) -> Effect[R2Upload]\n\t\tfn uploadPart(upload: R2Upload, partNumber: Int, body: Bytes) -> Effect[R2Part]\n\t\tfn completeUpload(upload: R2Upload, parts: List[R2Part]) -> Effect[R2Object]\n\t\tfn abortUpload(upload: R2Upload) -> Effect[()]\n\t}\n\n\t---\n\tA Workers Rate Limiting binding: a counter of calls per key over a fixed\n\twindow. Used only through a named instance that sets both,\n\t`capability LoginLimit = RateLimit @limit(100) @period(60.seconds)`, which\n\tbinds as `RATELIMIT_LOGIN_LIMIT`; a bare `given RateLimit` sets neither\n\tand is refused. The period is `10.seconds` or `60.seconds`, the platform\'s\n\tonly windows.\n\n\t`allow(key)` counts one call for `key` and gives `true` while `key` is\n\twithin the limit, `false` once it is over (refuse the request, typically\n\twith `TooManyRequests`). Counting is approximate: it is kept per Cloudflare\n\tlocation and is eventually consistent, so it suits abuse and cost control,\n\tnot billing or exact quotas (use an agent for those). Each instance counts\n\ton its own: `bynk deploy` gives it its own `namespace_id`.\n\t---\n\tcapability RateLimit {\n\t\tfn allow(key: String) -> Effect[Bool]\n\t}\n\n\t---\n\tA Cloudflare Queue to send messages to. Used only through a named instance\n\tthat names the queue, `capability OrderEvents = Queue @name(\"order-events\")`,\n\twhich binds as `QUEUE_ORDER_EVENTS`; a bare `given Queue` names no queue and\n\tis refused. The name is account-wide: every Worker that names the same\n\tqueue shares it, and a Bynk consumer reads it with\n\t`service \u{2026} from queue(\"order-events\")`. `bynk deploy` creates the queue\n\twhen it is missing, environment-qualified as a consumer\'s is.\n\n\tA body is JSON text, normally `Json.encode(value)`, and the consumer\n\tdecodes it with its message type; text that is not JSON faults the send.\n\t`sendValue(message)` is `send(Json.encode(message))` for any `Codable`\n\tvalue: it puts exactly the same message on the queue, encoding at the call\n\tsite (`Queue.sendValue(order)`). `sendBatch` sends its bodies in one call,\n\tall or none. `sendValueWith(message, options)` and `sendValueBatch(messages)`\n\tare `sendWith` and `sendBatch` for any `Codable` value, encoding at the call\n\tsite: the same messages, the same delay and the same all-or-none rule (a\n\tmessage that cannot be encoded faults before anything is sent). The platform caps a\n\tmessage at 128 KB and a batch at 100 messages and 256 KB; over a cap, the\n\tsend faults. Delivery is at least once and messages are stored by the\n\tplatform, so make consumers idempotent and keep secrets out of bodies.\n\t---\n\tcapability Queue {\n\t\tfn send(body: String) -> Effect[()]\n\t\tfn sendWith(body: String, options: QueueSend) -> Effect[()]\n\t\tfn sendBatch(bodies: List[String]) -> Effect[()]\n\t\tfn sendValue[T: Codable](message: T) -> Effect[()]\n\t\tfn sendValueWith[T: Codable](message: T, options: QueueSend) -> Effect[()]\n\t\tfn sendValueBatch[T: Codable](messages: List[T]) -> Effect[()]\n\t}\n\n\t---\n\tWhat an Analytics SQL query cost to run, as the platform reports it: `elapsedMs`\n\tthe time it took, `rowsRead` and `bytesRead` what it scanned.\n\t---\n\ttype AnalyticsSqlStatistics = {\n\t\telapsedMs: Int,\n\t\trowsRead: Int,\n\t\tbytesRead: Int,\n\t}\n\n\t---\n\tThe reply of `AnalyticsSql.query`: `data` is the result rows as JSON text, an array\n\tof objects keyed by the selected column names, to read with `Json.decode` (the\n\tcolumns and their types are the query\'s, not Bynk\'s, as `Ai.run`\'s reply is the\n\tmodel\'s); `rows` is how many there are, and `statistics` what the query cost.\n\t---\n\ttype AnalyticsSqlResult = {\n\t\tdata: String,\n\t\trows: Int,\n\t\tstatistics: AnalyticsSqlStatistics,\n\t}\n\n\t---\n\tWhy an Analytics SQL query did not give a reply. The platform reports a failure\n\twith a message and one fact, whether repeating the query may succeed, and that is\n\tall this type says: `SqlRetryable` is a failure worth retrying with bounded\n\texponential backoff (a rate or capacity limit, a temporary outage), and\n\t`SqlRejected` one that repeating will not fix (a query the engine refused, a\n\tparameter Analytics SQL cannot take, a reply that is not the shape promised),\n\teach with its message. Cloudflare changes what it reports over time, so a `match`\n\tover this type needs a wildcard.\n\t---\n\ttype AnalyticsSqlError =\n\t\t| SqlRetryable(message: String)\n\t\t| SqlRejected(message: String)\n\n\t---\n\tA Workers Analytics Engine dataset to write events to. Used only through a\n\tnamed instance, `capability Signups = Analytics`, which binds as\n\t`ANALYTICS_SIGNUPS`; a bare `given Analytics` is refused. The dataset\'s\n\tname is derived, never written: context `shop.cart`\'s `Signups` writes to\n\t`shop_cart_signups`, and to `shop_cart_signups_staging` under\n\t`--env staging`. The platform creates it on the first write.\n\n\t`write` checks the point against the platform\'s limits (see `DataPoint`)\n\tand faults on a breach; a Worker invocation may write at most 250 points.\n\tWrites are sent after the response, so one never delays it. Reading is done\n\twith `AnalyticsSql`, and `dataset` names this dataset for the query:\n\t`events.analyticsEngine.shop_cart_signups`, or `..._staging` under\n\t`--env staging`, so a query never hard-codes the environment. Data is kept for three months and\n\treadable with any account analytics token, so keep secrets and personal\n\tdata out of it.\n\t---\n\tcapability Analytics {\n\t\tfn write(point: DataPoint) -> Effect[()]\n\t\tfn dataset() -> Effect[String]\n\t}\n\n\t---\n\tRead analytics data with SQL, from the Worker\'s `[analytics]` binding: it needs no\n\tAPI token. It is account-scoped and bound once per Worker, so it is used bare\n\t(`given AnalyticsSql`) and has no named instances; only a Worker that uses it\n\tdeclares the binding. It reads the datasets `Analytics.write` fills, and Cloudflare\'s\n\tother analytics datasets, as `events.analyticsEngine.<DATASET>`.\n\n\t`query(sql, params)` runs one `SELECT`. Put values in `params`, a `List[SqlValue]`\n\tbound to `$1`, `$2`, \u{2026} by position, and never into the text of `sql`. A `Null`,\n\t`Integer`, `Real`, `Text` or `Boolean` is taken (a `Real` that is not finite is\n\t`SqlRejected`); a `Blob` has no Analytics SQL counterpart and is `SqlRejected` too,\n\tbefore anything is sent. Named\n\t`$name` parameters are not taken yet. A dataset\'s name is an identifier, which a\n\tparameter cannot be, so it is the one value written into `sql`.\n\n\tCloudflare\'s rules for the SQL apply as they do to its own API: the query must carry a\n\tlower time bound (`WHERE timestamp >= NOW() - INTERVAL \'1\' HOUR`), because the binding\n\texposes no separate time range; it must not name `accountTag` or `zoneTag`, because the\n\tbinding supplies the account; and it must not end in a `FORMAT` clause. The dialect is\n\tdeliberately limited; see Cloudflare\'s Analytics SQL reference.\n\n\tThe reply is an `AnalyticsSqlResult`, its `data` the rows as JSON text for `Json.decode`.\n\tA failure is an `AnalyticsSqlError`: `SqlRetryable` when the platform says repeating\n\tmay succeed, `SqlRejected` when it does not. The call never retries by itself.\n\n\tThere is no local implementation of the binding: under `bynk dev` a query runs on\n\tCloudflare, against the deployed datasets, once you allow it, and `bynkc test` faults\n\tuntil the call is stubbed (`stub AnalyticsSql.query(_, _) returns \u{2026}`), so a test never\n\treaches Cloudflare.\n\t---\n\tcapability AnalyticsSql {\n\t\tfn query(\n\t\t\tsql: String,\n\t\t\tparams: List[SqlValue]\n\t\t) -> Effect[Result[AnalyticsSqlResult, AnalyticsSqlError]]\n\t}\n\n\t---\n\tCloudflare\'s edge cache for this context\'s Worker (Workers Cache), and its\n\tpurge. Used only through a named instance, `capability Edge = EdgeCache`,\n\tat most one per context; declaring it is what turns the cache on, so a bare\n\t`given EdgeCache` is refused.\n\n\tAn opted-in Worker is served through the cache: a `2xx` from a `GET` with\n\t`@cache(scope: public)` is stored at Cloudflare\'s edge and served from\n\tthere, without running the Worker, until its `max-age` runs out or it is\n\tpurged. Every other `GET` or `HEAD` response (a route without `@cache`, or\n\tone that is not a `2xx`, a `404` included) is sent `Cache-Control:\n\tno-store`, so nothing else is kept. A `public` response is shared with\n\tevery caller, even one sent to a request carrying `Authorization`, so a\n\t`@cache(scope: public)` route here must be served by an open actor such as\n\t`Visitor`.\n\n\t`purge(prefixes)` removes every cached response whose path starts with one\n\tof `prefixes`, everywhere, and gives `true` once Cloudflare has accepted the\n\tpurge, `false` when it refused one (purges are rate-limited at Cloudflare\'s\n\tFree-tier limits on every plan), so the caller can retry. Each prefix is a\n\tpath starting with `/`, with no query and no control characters; anything\n\telse faults. An empty list purges nothing and gives `true`.\n\n\tThe purge reaches the cache only from the Worker\'s own `fetch`, so it is\n\tcalled from a service handler or what one calls; never from an agent, a\n\tqueue consumer or `on schedule` (whose purge Cloudflare accepts but which\n\tclears nothing). Under `bynk dev` there is no edge cache: every request runs\n\tthe Worker, and `purge` gives `true` after logging that it did nothing.\n\t---\n\tcapability EdgeCache {\n\t\tfn purge(prefixes: List[String]) -> Effect[Bool]\n\t}\n\n\t---\n\tA D1 database: SQLite, queried with SQL text and positional parameters\n\t(`?1`, `?2`, \u{2026}) bound from `SqlValue`s, never spliced into the text. The\n\tSQL is a string literal, so data reaches a statement only as a parameter. Used\n\tonly through a named instance, `capability Orders = D1`, which binds as\n\t`D1_ORDERS`; a bare `given D1` names no database and is refused.\n\t`bynk deploy` creates the database, named `<worker>-<capability, kebab>`\n\tand environment-qualified, and records its id.\n\n\tRows come back as JSON text for `Json.decodeSql`: `all` gives every row as\n\tan array of objects keyed by column name (`Json.decodeSql[List[Row]]`),\n\t`first` the first row as one object, or `None` when there is none. A blob\n\tcolumn arrives as base64, so a `Bytes` field decodes it. SQLite has no\n\tboolean: a flag column arrives as `0` or `1`, which `Json.decodeSql` reads\n\tat a `Bool` field. An integer past \u{b1}2^53 cannot be represented and fails\n\tthe decode.\n\n\t`select[T]` and `firstAs[T]` read rows straight into a record `T`: the\n\targument is the statement from `FROM` on, a string literal that must not\n\titself begin with `SELECT`, and the compiler writes the column list from\n\t`T`\'s field names (each quoted), runs the statement and decodes the rows.\n\t`select` gives `Result[List[T], SqlReadError]`, `firstAs` `Result[Option[T],\n\tSqlReadError]`; `T` must be a row, as for `Json.decodeSql`.\n\n\t`run` executes a write and reports what it changed. `batch` runs its\n\tstatements in order in one transaction: all apply, or none do and the\n\tresult is the failing statement\'s error. Every operation gives a\n\t`SqlError` rather than faulting.\n\t---\n\tcapability D1 {\n\t\tfn all(sql: String, params: List[SqlValue]) -> Effect[Result[String, SqlError]]\n\t\tfn first(sql: String, params: List[SqlValue]) -> Effect[Result[Option[String], SqlError]]\n\t\tfn run(sql: String, params: List[SqlValue]) -> Effect[Result[SqlRun, SqlError]]\n\t\tfn batch(statements: List[SqlStatement]) -> Effect[Result[List[SqlRun], SqlError]]\n\t}\n\n\t---\n\tThe version of this Worker that is running, as `Version.current()`\n\treports it. `id` is the version\'s id, `tag` its tag (`None` when the\n\tversion was uploaded without one), and `deployed` when the version was\n\tcreated.\n\t---\n\ttype WorkerVersion = {\n\t\tid: String,\n\t\ttag: Option[String],\n\t\tdeployed: Instant,\n\t}\n\n\t---\n\tThe running Worker\'s version, from Cloudflare\'s Version metadata binding.\n\tIt is bound once per Worker, so it is used bare (`given Version`) and has\n\tno named instances. Only a Worker that uses it declares the binding.\n\t`current()` gives the same value for every call in a deployment: report it\n\tfrom a health route, or write it beside an `Analytics` point, to tell\n\twhich version served a request. Under `bynk dev` the id is local; in a\n\ttest the value is fixed (id `\"test\"`, no tag, `deployed` at the epoch) and\n\t`stub Version.current() returns \u{2026}` replaces it.\n\t---\n\tcapability Version {\n\t\tfn current() -> Effect[WorkerVersion]\n\t}\n\n\t---\n\tWho said a `ChatMessage`. A `System` message sets how the model behaves, a\n\t`User` message is what it is asked, and an `Assistant` message is an earlier\n\treply of the model, to carry a conversation. Cloudflare adds roles over\n\ttime, so a `match` over this type needs a wildcard.\n\t---\n\ttype ChatRole = enum { System, User, Assistant }\n\n\t---\n\tOne message of a conversation for `Ai.generate`.\n\t---\n\ttype ChatMessage = {\n\t\trole: ChatRole,\n\t\tcontent: String,\n\t}\n\n\t---\n\tThe input of `Ai.generate`: the conversation so far in `messages`, which must\n\tnot be empty, and the sampling settings the platform\'s chat models share.\n\tA setting left `None` is the model\'s own default. `maxTokens` caps the\n\tlength of the reply; `temperature` and `topP` shape how varied it is; `seed`\n\tmakes a run repeatable where the model supports it.\n\t---\n\ttype GenerateRequest = {\n\t\tmessages: List[ChatMessage],\n\t\tmaxTokens: Option[Int] = None,\n\t\ttemperature: Option[Float] = None,\n\t\ttopP: Option[Float] = None,\n\t\tseed: Option[Int] = None,\n\t}\n\n\t---\n\tThe tokens a generation used: `promptTokens` read and `completionTokens`\n\twritten.\n\t---\n\ttype TokenUsage = {\n\t\tpromptTokens: Int,\n\t\tcompletionTokens: Int,\n\t}\n\n\t---\n\tThe reply of `Ai.generate`: the model\'s `text`, which is untrusted input,\n\tand `usage` when the platform reported it (`None` when it did not).\n\t---\n\ttype Generation = {\n\t\ttext: String,\n\t\tusage: Option[TokenUsage],\n\t}\n\n\t---\n\tWhy a Workers AI call did not give a reply. `ModelNotFound` is a model id\n\tthe platform does not know, or has retired; `InvalidInput` is a request the\n\tplatform refused as malformed or too large, with its message; `QuotaExceeded`\n\tis a usage limit of the account, or a model its plan does not include, so\n\tback off or change the plan; `Overloaded` is the platform\'s temporary\n\tcapacity, worth retrying; `BadReply` is a reply that is not the shape the\n\toperation promises (`generate` and `embed` only, never `run`), with what was\n\twrong; `AiFailed` is any other refusal, with the platform\'s message (the `Ai`\n\tprefix because `Failed` is `SqlError`\'s). Cloudflare adds error codes over\n\ttime, so a `match` over this type needs a wildcard.\n\t---\n\ttype AiError =\n\t\t| ModelNotFound\n\t\t| InvalidInput(message: String)\n\t\t| QuotaExceeded\n\t\t| Overloaded\n\t\t| BadReply(message: String)\n\t\t| AiFailed(message: String)\n\n\t---\n\tWorkers AI, from the Worker\'s `[ai]` binding: it needs no API token and no\n\taccount id. It is bound once per Worker, so it is used bare (`given Ai`)\n\tand has no named instances. Only a Worker that uses it declares the\n\tbinding.\n\n\t`run(model, input)` runs any model by its id (`\"@cf/meta/llama-3.2-1b-instruct\"`).\n\t`input` is the model\'s JSON input as text, and the reply is the model\'s JSON\n\toutput as text, so a model Cloudflare ships tomorrow works today: build the\n\tinput with `Json.encode` and read the reply with `Json.decode`. An `input`\n\tthat is not a JSON object, or a `model` that is empty or has characters an\n\tid never has, is a fault. A model that answers with binary data (an image,\n\tsay) is `AiFailed`: `run` carries JSON replies only.\n\n\t`generate(model, request)` is chat-style text generation with the same\n\trequest and reply for every chat model: the text is read from the model\'s\n\t`response`, or from `choices[0].message.content` for a model that answers in\n\tthat shape. `embed(model, texts)` gives one vector per text, in order, all of\n\tone length, for a text-embedding model such as `\"@cf/baai/bge-base-en-v1.5\"`.\n\tBoth return `BadReply` when the platform answers but not in the promised\n\tshape (a model that is not of that kind, say). An empty `messages` or `texts`\n\tis a fault. `embed` does not check how many texts one call may carry: the\n\tlimit is the model\'s, and a call over it is `InvalidInput`. The embeddings use\n\tthe platform\'s default pooling, so an index built from them stays consistent.\n\n\t`runStream(model, input)` is `run` with the reply streamed: the model\'s own\n\tevents, one element each, as the JSON text of that event (the shape is the\n\tmodel\'s, so a handler that wants text deltas maps the stream and decodes each\n\tevent). The binding asks the model to stream; the terminal `[DONE]` marker\n\tis consumed, not yielded. A refusal before the stream starts (an unknown\n\tmodel, a usage limit) is the `Err`, so a handler can answer with an ordinary\n\tresponse; a failure after the first event faults the stream, as a failing\n\tproducer aborts any stream. A model that does not stream is `AiFailed`. Like\n\tevery `Stream`, it is read once and cannot cross a service boundary: the\n\thandler that calls `runStream` is the one that serves it, as in\n\t`Streaming(events)`.\n\n\tWorkers AI is a remote service on your Cloudflare account, so a call\n\tmay be billed, and a model\'s reply is untrusted input like any other\n\tuser text. See Cloudflare\'s Workers AI pricing page for what applies,\n\tand put a `RateLimit` in front of any handler an anonymous caller can reach.\n\tUnder `bynk dev` a call runs the model on Cloudflare. In a test every\n\toperation faults until `stub Ai.run(_, _) returns \u{2026}` replaces it, so a\n\ttest never reaches Workers AI.\n\t---\n\tcapability Ai {\n\t\tfn run(model: String, input: String) -> Effect[Result[String, AiError]]\n\t\tfn generate(model: String, request: GenerateRequest) -> Effect[Result[Generation, AiError]]\n\t\tfn embed(model: String, texts: List[String]) -> Effect[Result[List[List[Float]], AiError]]\n\t\tfn runStream(model: String, input: String) -> Effect[Result[Stream[String], AiError]]\n\t}\n\n\t---\n\tThe format of a raster image. `Jpeg`, `Png`, `Webp`, `Avif` and `Gif` are\n\tthe formats `Images.transform` can write; `Heic` is read only, so asking\n\tfor it as an output is `InvalidImage`. Cloudflare adds formats over time, so\n\ta `match` over this type needs a wildcard.\n\t---\n\ttype ImageFormat = enum { Jpeg, Png, Webp, Avif, Gif, Heic }\n\n\t---\n\tHow a resize fits the image to `width` and `height`. `ScaleDown` (the\n\tplatform\'s default) shrinks to fit and never enlarges; `Contain` fits inside\n\tthe box; `Cover` fills the box and crops the overflow; `Crop` crops to the\n\tbox without scaling up; `Pad` fits inside the box and fills the rest;\n\t`Squeeze` stretches to the box exactly. Cloudflare adds fits over time, so\n\ta `match` over this type needs a wildcard.\n\t---\n\ttype ImageFit = enum { ScaleDown, Contain, Cover, Crop, Pad, Squeeze }\n\n\t---\n\tWhat `Images.info` reads from an image: `Raster` with its `format`, its\n\t`width` and `height` in pixels and its `size` in bytes, or `Svg`, which the\n\tplatform reports without dimensions because it is not a grid of pixels.\n\t---\n\ttype ImageInfo =\n\t\t| Raster(format: ImageFormat, width: Int, height: Int, size: Int)\n\t\t| Svg\n\n\t---\n\tAn image drawn over the one being transformed, from its `image` bytes. The\n\toverlay is placed by an offset in pixels from `top`, `left`, `bottom` or\n\t`right` (centred when none is given; `left` with `right`, or `top` with\n\t`bottom`, is `InvalidImage`), blended at `opacity` from 0 to 1 (`None` is\n\tfully opaque) and tiled across the image when `repeat` is true. Overlays are\n\tdrawn in order, the last on top. The overlay is not resized: size it first\n\twith `Images.transform`.\n\t---\n\ttype Overlay = {\n\t\timage: Bytes,\n\t\topacity: Option[Float] = None,\n\t\ttop: Option[Int] = None,\n\t\tleft: Option[Int] = None,\n\t\tbottom: Option[Int] = None,\n\t\tright: Option[Int] = None,\n\t\trepeat: Bool = false,\n\t}\n\n\t---\n\tWhat `Images.transform` does to the image before it is written. `width` and\n\t`height` are the target size in pixels, and `fit` says how the image fits\n\tthem; `rotate` turns it by 90, 180 or 270 degrees (before the resize, so\n\t`width` and `height` refer to the rotated image); `blur` is a radius from 0\n\tto 250; `overlays` are drawn on the result. A field left `None` is the\n\tplatform\'s default. A `width`, `height` or `blur` the platform refuses is\n\treported by the platform as `InvalidImage`, not checked here.\n\t---\n\ttype TransformOptions = {\n\t\twidth: Option[Int] = None,\n\t\theight: Option[Int] = None,\n\t\tfit: Option[ImageFit] = None,\n\t\trotate: Option[Int] = None,\n\t\tblur: Option[Int] = None,\n\t\toverlays: List[Overlay] = [],\n\t}\n\n\t---\n\tHow `Images.transform` writes the result: the `format` (required, because\n\tthe platform has no default) and the `quality` from 1 to 100 for the formats\n\tthat take one (`None` is the platform\'s default).\n\t---\n\ttype OutputOptions = {\n\t\tformat: ImageFormat,\n\t\tquality: Option[Int] = None,\n\t}\n\n\t---\n\tA transformed image: its `body` (buffered whole in the Worker) and the\n\t`contentType` the platform wrote it with, such as `image/webp`.\n\t---\n\ttype ImageResult = {\n\t\tbody: Bytes,\n\t\tcontentType: String,\n\t}\n\n\t---\n\tA transformed image as a stream, from `Images.transformStream`: the `body`\n\tas chunks read as they are pulled, and the `contentType` the platform wrote\n\tit with. The body can be read once (`collect`, `map`, or handed to\n\t`RawStreamed`); a second read faults. A record carrying a stream is not\n\tdata: it can\'t be stored, sent or encoded.\n\t---\n\ttype ImageStream = {\n\t\tbody: Stream[Bytes],\n\t\tcontentType: String,\n\t}\n\n\t---\n\tWhy an `Images` call did not give an image. `InvalidImage` is an input that\n\tis not an image, or an option the call cannot honour, with the reason;\n\t`UnsupportedImage` is a format the platform cannot read or write;\n\t`ImageTooLarge` is an image over the platform\'s size or area limit (a\n\tconnection the platform lost mid-call is `ImagesFailed`, worth a retry); and\n\t`ImagesFailed` is any other refusal, with the platform\'s message (the\n\t`Image` prefix because `InvalidInput` is `AiError`\'s and `Failed` is\n\t`SqlError`\'s). Cloudflare adds error codes over time, so a `match` over this\n\ttype needs a wildcard.\n\t---\n\ttype ImagesError =\n\t\t| InvalidImage(message: String)\n\t\t| UnsupportedImage\n\t\t| ImageTooLarge\n\t\t| ImagesFailed(message: String)\n\n\t---\n\tCloudflare Images, from the Worker\'s `[images]` binding: it resizes,\n\trotates, blurs, converts and draws on images in the Worker, with no URL and\n\tno round trip to your zone. It is bound once per Worker, so it is used bare\n\t(`given Images`) and has no named instances. Only a Worker that uses it\n\tdeclares the binding.\n\n\t`info(image)` reads an image\'s format and size without transforming it, and\n\tCloudflare does not bill it. An empty or non-image input is `InvalidImage`,\n\tand a format this type does not name is `ImagesFailed`.\n\n\t`transform(image, options, output)` reads `image` (any format the platform\n\treads, at most 20 MB), applies `options` and writes the result as `output`\n\tsays. The result is buffered whole; for a large image use `transformStream`.\n\n\t`transformStream(image, options, output)` is `transform` over a stream: it\n\treads `image` as a `Stream[Bytes]` (read once, as any stream is) and gives\n\tthe result as an `ImageStream`, so a handler can serve it with\n\t`RawStreamed` without holding the output. The input is still bounded by\n\tthe platform\'s limit, and the options are the same. A refusal before the\n\tstream starts (a non-image, an option out of range) is the `Err`; a failure\n\tafter the first chunk faults the stream, as a failing producer aborts any\n\tstream. The overlay images stay `Bytes`, since an overlay is small and a\n\tstream cannot be read twice for `repeat`. Like every `Stream`, the result\n\tcannot cross a service boundary: the handler that calls it is the one that\n\tserves it. The image is untrusted input: an upload\n\tcan be a non-image or very large, so answer `InvalidImage` and\n\t`ImageTooLarge` as the caller\'s mistake, and cap an upload with the request\n\tbody limit. An empty image, a `width` or `height` below 1, a `rotate` other\n\tthan 90, 180 or 270, an `opacity` outside 0 to 1, a `quality` outside 1 to 100\n\tand an overlay positioned from both opposite edges are `InvalidImage`\n\twithout reaching the platform. Cloudflare\'s own limits are enforced by the\n\tplatform and reported as an `ImagesError`; see Cloudflare\'s Images limits\n\tpage for them.\n\n\tCalls are billed by Cloudflare as unique transformations. See Cloudflare\'s\n\tImages pricing page for what applies, and put a `RateLimit` in front of any\n\thandler an anonymous caller can reach. Under `bynk dev` the binding runs\n\tlocally in a low-fidelity form that supports only `width`, `height`,\n\t`rotate` and the output format, so `fit`, `blur`, `overlays`, `quality` and\n\tsome formats are not reproduced there; deploy to see production\'s output.\n\tIn a test every operation faults until `stub Images.transform(_, _, _)\n\treturns \u{2026}` replaces it, so a test never reaches the platform.\n\t---\n\tcapability Images {\n\t\tfn info(image: Bytes) -> Effect[Result[ImageInfo, ImagesError]]\n\t\tfn transform(\n\t\t\timage: Bytes,\n\t\t\toptions: TransformOptions,\n\t\t\toutput: OutputOptions\n\t\t) -> Effect[Result[ImageResult, ImagesError]]\n\t\tfn transformStream(\n\t\t\timage: Stream[Bytes],\n\t\t\toptions: TransformOptions,\n\t\t\toutput: OutputOptions\n\t\t) -> Effect[Result[ImageStream, ImagesError]]\n\t}\n\n\t---\n\tOne secret of a Cloudflare Secrets Store, read as `StripeKey.get()`. A\n\tSecrets Store is account-scoped: its secrets are shared across Workers,\n\trotated centrally and bound one per binding, which is what separates this\n\tfrom `bynk.Secrets`, whose per-Worker secrets are portable. Used only\n\tthrough a named instance that says which store and which secret,\n\t`capability StripeKey = StoredSecret @store(\"payments\") @secret(\"stripe-live\")`,\n\twhich binds as `SECRET_STRIPE_KEY`; both annotations are required, and a\n\tbare `given StoredSecret` is refused.\n\n\t`bynk deploy` links the instance and never creates anything: it looks the\n\tstore up by name, records its id in `bynk.deploy.lock`, and fails, naming\n\tthe store and the secret, when either is missing (create the secret with\n\t`wrangler secrets-store secret create`). The deploy needs\n\t`CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`, the token with\n\t\"Secrets Store: Read\". `get` returns the value as a `String`, not an\n\t`Option`: the binding exists only if the deploy found the secret, so an\n\tabsence at run time is a platform fault, not something a handler can act\n\ton. The value is not logged by Bynk; do not log it either. Under `bynk dev`\n\tthe secret is read from the local store, and a test faults until\n\t`stub StripeKey.get() returns \u{2026}` gives it a value.\n\t---\n\tcapability StoredSecret {\n\t\tfn get() -> Effect[String]\n\t}\n\n\t---\n\tOutbound email through Cloudflare Email Service. Used only through a named\n\tinstance, `capability Mail = Email @allowedSenders([\"[email protected]\"])`,\n\twhich binds as `EMAIL_MAIL`, a `[[send_email]]` entry. The options are\n\tall optional deploy-time policy: `@to(\"[email protected]\")` pins every\n\tmessage to one recipient, `@allowedRecipients([\u{2026}])` limits the recipients\n\tand `@allowedSenders([\u{2026}])` limits the senders. An unknown annotation is\n\trefused.\n\n\t`send` returns the platform\'s message id, or an `EmailError` for an\n\toutcome a handler acts on. A call that breaks a documented limit is a\n\tprogramming error and faults before it reaches the platform: more than\n\t50 recipients across `to`, `cc` and `bcc`, more than 32 attachments,\n\tmore than 25 MiB in total (attachments counted as base64, as sent), no\n\trecipient at all, neither `text` nor\n\t`html`, a reserved header (see `EmailMessage`) or a line break in a header\'s\n\tname or value. Attachments go to the platform as base64 text, which both\n\tthe platform and `wrangler dev` accept; message bodies and attachment\n\tcontent are never logged by Bynk.\n\n\t`bynk deploy` checks, for each `@allowedSenders` address, that its domain\n\thas Email Sending enabled on the account, and fails naming the domain\n\twhen it does not; it never configures a domain. It needs\n\t`CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`. Without\n\t`@allowedSenders`, an unverified `from` surfaces at run time as\n\t`SenderNotVerified`.\n\n\tA handler that sends mail is a spam relay if anyone can call it: put a\n\t`RateLimit` in front of it. Under `bynk dev`, a message with an\n\tattachment the local simulator cannot serialise should be tried with\n\t`--remote`. A test records every sent `EmailMessage` without a stub, so\n\t`expect Mail.send called with \u{2026}` works, and a stub can force an\n\t`EmailError`.\n\t---\n\tcapability Email {\n\t\tfn send(message: EmailMessage) -> Effect[Result[String, EmailError]]\n\t}\n\n\t---\n\tA Postgres database reached through Cloudflare Hyperdrive, over postgres.js:\n\tSQL text and positional parameters (`$1`, `$2`, \u{2026}) bound from `PgValue`s,\n\tnever spliced into the text. The SQL is a string literal, so data reaches\n\ta statement only as a parameter. Used only through a named instance,\n\t`capability Main = Postgres`, which binds as `HYPERDRIVE_MAIN`, a\n\t`[[hyperdrive]]` entry; a bare `given Postgres` names no database and is\n\trefused. Experimental.\n\n\t`bynk deploy` makes the Hyperdrive configuration, from the connection\n\tstring in the environment variable `[deploy.hyperdrive.Main]\n\tconnection_env` names in `bynk.toml`, or adopts one named by `config_id`;\n\tthe generated `wrangler.toml` carries a placeholder `id` it replaces.\n\t`bynk dev` reads the local connection string from the variable\n\t`[dev.hyperdrive.Main] connection_env` names. A connection string is never\n\twritten to `bynk.toml` (see \"Connect an existing Postgres database\" in the\n\tBook).\n\n\tRows come back as JSON text for `Json.decode`: `all` gives every row as an\n\tarray of objects keyed by column name, `first` the first row as one object,\n\tor `None` when there is none. `int8` (`bigint`) and `numeric` arrive as\n\tstrings, so nothing past 2^53 is lost; `timestamptz` as ISO-8601 text;\n\t`bytea` as base64 (a `Bytes` field decodes it); `json` and `jsonb` nested as\n\tJSON. A `boolean` arrives as `true` or `false`, not `0` or `1`.\n\n\t`select[T]` and `firstAs[T]` read rows straight into a record `T`: the\n\targument is the statement from `FROM` on, a string literal that must not\n\titself begin with `SELECT`, and the compiler writes the column list from\n\t`T`\'s field names (each quoted in Postgres style: double quotes, an\n\tembedded quote doubled), runs the statement and decodes the rows. `select`\n\tgives `Result[List[T], PgReadError]`, `firstAs` `Result[Option[T],\n\tPgReadError]`. A row field is an `Int`, `Float`, `String`, `Bool`, `Bytes`,\n\t`Decimal` or `Instant` (or a refined or opaque type over one, or an\n\t`Option` of either). An `Int` reads an `int8` that arrives as text, and an\n\t`Instant` reads the ISO-8601 text of a `timestamptz`, with any offset.\n\n\t`transaction` runs its statements in order on one connection, in one\n\ttransaction: all apply, or none do and the result is the failing\n\tstatement\'s error. It runs a fixed list; a read that decides a later write\n\tneeds an interactive transaction, which this does not offer.\n\n\t`run` executes a write and reports the rows it changed. Every operation\n\tgives a `PgError` rather than faulting. Each statement uses its own\n\tconnection, opened and closed around it, and Cloudflare allows six\n\tsimultaneous connections per Worker invocation, so a `par` over more than\n\tsix queries waits for its turn.\n\t---\n\tcapability Postgres {\n\t\tfn all(sql: String, params: List[PgValue]) -> Effect[Result[String, PgError]]\n\t\tfn first(sql: String, params: List[PgValue]) -> Effect[Result[Option[String], PgError]]\n\t\tfn run(sql: String, params: List[PgValue]) -> Effect[Result[PgRun, PgError]]\n\t\tfn transaction(statements: List[PgStatement]) -> Effect[Result[List[PgRun], PgError]]\n\t}\n\n\t---\n\tA MySQL (or MariaDB) database reached through Cloudflare Hyperdrive, over\n\tmysql2: SQL text and positional parameters (`?`) bound from `MySqlValue`s.\n\tThe SQL is a string literal, so data reaches a statement only as a\n\tparameter. Used only through a named instance, `capability Legacy = MySql`,\n\twhich binds as `HYPERDRIVE_LEGACY`, a `[[hyperdrive]]` entry; a bare\n\t`given MySql` names no database and is refused. Experimental.\n\n\t`@tls(\"\u{2026}\")` sets how Hyperdrive secures its connection to the database:\n\t`\"required\"` (the default), `\"verify-ca\"` or `\"verify-identity\"`. Anything\n\telse is refused. The Worker\'s own connection to Hyperdrive is not part of\n\tit. `bynk deploy` sends the mode with the config it makes; the two `verify`\n\tmodes need a CA certificate the account holds, which `bynk deploy` does not\n\tupload, so such an instance takes a config that exists (`config_id` in\n\t`[deploy.hyperdrive.Legacy]`).\n\n\tDeploy and `bynk dev` work as for `Postgres`: the connection string is\n\tnamed by `[deploy.hyperdrive.Legacy] connection_env` in `bynk.toml` and is a\n\tsecret, a `mysql://user:password@host:3306/database` URL. A statement\'s\n\tparameters are substituted by the driver as escaped literals (mysql2\'s\n\t`query`) and not sent as a prepared statement, so `LIMIT ?, ?` works and a\n\tstatement survives Hyperdrive\'s transaction pooling. `??` (mysql2\'s\n\tidentifier placeholder) is not supported.\n\n\tRows come back as JSON text for `Json.decode`: `all` gives every row as an\n\tarray of objects keyed by column name, `first` the first row as one object,\n\tor `None` when there is none. A `BIGINT` (signed or unsigned) and a `DECIMAL`\n\tarrive as strings, so nothing past 2^53 is lost; a `TINYINT(1)` arrives as\n\t`true` or `false` (any other `TINYINT` as a number); a `BLOB` as base64; a\n\t`JSON` column nested. `DATETIME`, `TIMESTAMP` and `DATE` arrive as the\n\tserver\'s text, `2026-11-12 09:30:00`, with no zone on it: a `String` field\n\treads it and an `Instant` field refuses it.\n\n\t`select[T]` and `firstAs[T]` read rows straight into a record `T`: the\n\targument is the statement from `FROM` on, a string literal that must not\n\titself begin with `SELECT`, and the compiler writes the column list from\n\t`T`\'s field names (each quoted with backticks, an embedded backtick\n\tdoubled), runs the statement and decodes the rows. `select` gives\n\t`Result[List[T], MySqlReadError]`, `firstAs` `Result[Option[T],\n\tMySqlReadError]`.\n\n\t`transaction` runs its statements in order on one connection, in one\n\ttransaction: all apply, or none do and the result is the failing\n\tstatement\'s error. It runs a fixed list; a read that decides a later write\n\tneeds an interactive transaction, which this does not offer. `run`\n\texecutes a write and reports the rows it changed and the id it inserted.\n\tEvery operation gives a `MySqlError` rather than faulting. Each statement\n\tuses its own connection, and Cloudflare allows six simultaneous connections\n\tper Worker invocation.\n\t---\n\tcapability MySql {\n\t\tfn all(sql: String, params: List[MySqlValue]) -> Effect[Result[String, MySqlError]]\n\t\tfn first(\n\t\t\tsql: String,\n\t\t\tparams: List[MySqlValue]\n\t\t) -> Effect[Result[Option[String], MySqlError]]\n\t\tfn run(sql: String, params: List[MySqlValue]) -> Effect[Result[MySqlRun, MySqlError]]\n\t\tfn transaction(\n\t\t\tstatements: List[MySqlStatement]\n\t\t) -> Effect[Result[List[MySqlRun], MySqlError]]\n\t}\n\n\t---\n\tOne vector of a `Vectorize` index: its `id` (at most 64 bytes), its `values`\n\t(as many numbers as the index has dimensions), the `namespace` it lives in\n\twhen it has one, and `metadata`, a JSON object as text (`Json.encode` writes\n\tit, `Json.decode` reads it back). A property can be filtered on only when\n\tthe index declares it in `@indexed`.\n\t---\n\ttype Vector = {\n\t\tid: String,\n\t\tvalues: List[Float],\n\t\tmetadata: Option[String] = None,\n\t\tnamespace: Option[String] = None,\n\t}\n\n\t---\n\tOne vector to write with typed metadata: a `Vector` whose `metadata` is a\n\tvalue of `M`, which `upsertValue` encodes with `M`\'s codec. Reading is not\n\ttyped: `getByIds` and a query\'s matches give the metadata as text, so a\n\tvector stored by an older version of `M` can be skipped or repaired.\n\tKeep the properties a query filters on plain (not `Option`): an `Option` is\n\twritten as a tagged object, as `Json.encode` writes it, so a filter on it\n\twould never match.\n\t---\n\ttype VectorOf[M] = {\n\t\tid: String,\n\t\tvalues: List[Float],\n\t\tmetadata: Option[M] = None,\n\t\tnamespace: Option[String] = None,\n\t}\n\n\t---\n\tA metadata value a `Condition` compares a property with: text, a number or\n\ta flag.\n\t---\n\ttype MetaValue =\n\t\t| MetaText(value: String)\n\t\t| MetaNumber(value: Float)\n\t\t| MetaFlag(value: Bool)\n\n\t---\n\tHow a `Condition` compares a property with a value: equal, not equal, less\n\tthan, at most, greater than, at least, one of a list, or none of a list.\n\tThe platform allows a range over text or numbers only, and a lower and an\n\tupper bound on one property together, not other mixes; it refuses the\n\trest as `VectorInvalidInput`.\n\t---\n\ttype FilterOp =\n\t\t| FilterEq(value: MetaValue)\n\t\t| FilterNe(value: MetaValue)\n\t\t| FilterLt(value: MetaValue)\n\t\t| FilterLte(value: MetaValue)\n\t\t| FilterGt(value: MetaValue)\n\t\t| FilterGte(value: MetaValue)\n\t\t| FilterAnyOf(values: List[MetaValue])\n\t\t| FilterNoneOf(values: List[MetaValue])\n\n\t---\n\tOne test of a `Vectorize` query: the metadata property `field` (a dot nests, as in\n\t`\"author.name\"`) against `op`. A query\'s conditions all have to hold.\n\tThe property has to be declared in the index\'s `@indexed`, and a vector\n\tonly matches once it was written after that index existed. A text property\n\tis indexed by its first 64 bytes only.\n\t---\n\ttype Condition = {\n\t\tfield: String,\n\t\top: FilterOp,\n\t}\n\n\t---\n\tHow much metadata a `Vectorize` query returns: `Omit` none (the default),\n\t`Indexed` only the `@indexed` properties, `All` every property. `All` costs\n\tthe platform more work and lowers how many matches one query may return.\n\t---\n\ttype MetadataScope = enum { Omit, Indexed, All }\n\n\t---\n\tThe options of `Vectorize.query`. `topK` is how many matches to return\n\t(5 unless set; the platform caps it, and caps it lower when `returnValues`\n\tis set or `returnMetadata` is `All`, and says so as `VectorInvalidInput`).\n\t`namespace` restricts the query to one namespace. `filter` is a list of\n\tconditions that must all hold.\n\t---\n\ttype QueryOptions = {\n\t\ttopK: Int = 5,\n\t\treturnValues: Bool = false,\n\t\treturnMetadata: MetadataScope = MetadataScope.Omit,\n\t\tnamespace: Option[String] = None,\n\t\tfilter: List[Condition] = [],\n\t}\n\n\t---\n\tOne match of `Vectorize.query`: the vector\'s `id` and its `score`, whose\n\tmeaning depends on the index\'s metric (a larger cosine score is nearer; a\n\tsmaller euclidean distance is nearer). `values`, `metadata` (a JSON object\n\tas text) and `namespace` are present when the query asked for them and the\n\tvector has them.\n\t---\n\ttype VectorMatch = {\n\t\tid: String,\n\t\tscore: Float,\n\t\tvalues: Option[List[Float]],\n\t\tmetadata: Option[String],\n\t\tnamespace: Option[String],\n\t}\n\n\t---\n\tThe receipt of a write: its `id`. A write is asynchronous. It is queryable\n\tafter the platform has processed it, which takes some seconds, so a handler\n\tthat writes and then queries in the same request will not see its own write.\n\t---\n\ttype Mutation = {\n\t\tid: String,\n\t}\n\n\t---\n\tAn index\'s configuration, as `Vectorize.describe` reports it: its\n\t`dimensions`, and its `metric` when the platform reports one (a real index\'s\n\t`describe` does not, so it is normally `None`; the declaration states it).\n\t---\n\ttype IndexInfo = {\n\t\tdimensions: Int,\n\t\tmetric: Option[String],\n\t}\n\n\t---\n\tWhy a Vectorize call did not succeed. `DimensionMismatch` is a vector or\n\tquery whose length is not the index\'s dimensions, with the platform\'s\n\tmessage; `VectorInvalidInput` is a request the platform refused as malformed\n\tor over a limit (a bad filter, too large a `topK`, too large a batch or too\n\tmuch metadata); `VectorRateLimited` is a rate limit, worth retrying later;\n\t`VectorFailed` is any other refusal, with the platform\'s message. The\n\t`Vector` prefix is because `InvalidInput` is `AiError`\'s, `RateLimited`\n\t`EmailError`\'s and `Failed` `SqlError`\'s. Cloudflare adds error cases over\n\ttime, so a `match` over this type needs a wildcard.\n\t---\n\ttype VectorError =\n\t\t| DimensionMismatch(message: String)\n\t\t| VectorInvalidInput(message: String)\n\t\t| VectorRateLimited\n\t\t| VectorFailed(message: String)\n\n\t---\n\tA Vectorize index: vectors with an id, searched by similarity. Used only\n\tthrough a named instance that states the index\'s fixed shape,\n\t`capability Docs = Vectorize @dimensions(768) @metric(\"cosine\")`, which\n\tbinds as `VECTORIZE_DOCS`, a `[[vectorize]]` entry; both annotations are\n\trequired, and a bare `given Vectorize` is refused. `@metric` is `\"cosine\"`,\n\t`\"euclidean\"` or `\"dot-product\"`. Experimental.\n\n\tAn index\'s dimensions and metric cannot change once it exists, so they are\n\twritten next to the code that depends on them. `@indexed([\"category:string\",\n\t\"year:number\"])` lists the metadata properties a query may filter on (at\n\tmost 10, each `name:type` with the type `string`, `number` or `boolean`).\n\tMetadata indexes should exist before the vectors that carry the property.\n\n\t`upsert` writes vectors, replacing any with the same id in full; `insert`\n\twrites only vectors whose id is new. `upsertValue(vectors)` is `upsert` with\n\tthe metadata of each `VectorOf[M]` encoded by `M`\'s codec, as\n\t`Queue.sendValue` encodes a message. `query(vector, options)` returns the\n\tnearest matches, best first. `getByIds` reads vectors back, `deleteByIds`\n\tremoves them, and `describe` reports the index\'s dimensions and metric.\n\tMetadata is JSON text: write it with `Json.encode` and read it with\n\t`Json.decode`, so a vector stored by an older version of the program can be\n\tskipped or repaired instead of failing the query. The embeddings of\n\t`Ai.embed` are the usual `values`; an index must be queried with the same\n\tmodel and pooling it was built with.\n\n\tA write returns a `Mutation` and is visible to queries only after the\n\tplatform has processed it. Every operation gives a `VectorError` rather\n\tthan faulting, except a call on an index that does not exist, which is a\n\tplatform fault.\n\n\tVectorize is a remote service on your Cloudflare account, so a call may be\n\tbilled; see Cloudflare\'s Vectorize pricing page for what applies, and put a\n\t`RateLimit` in front of any handler an anonymous caller can reach.\n\n\tIn a test each instance is an in-memory index built from its declaration,\n\tso a test never reaches Cloudflare and a retrieval flow (store, filter,\n\trank) runs. It ranks exactly where production ranks approximately, and a\n\twrite is visible at once where production takes some seconds; those are\n\tits two differences. It enforces the dimensions, namespaces, insert versus\n\tupsert, all eight filter operators and the platform limits as of\n\t2026-11-13 (a limit it refuses is a `VectorInvalidInput`). A filter on a\n\tproperty that is not in `@indexed` faults, naming the difference, because\n\tproduction silently matches nothing for it. `stub Docs.query(_, _) returns \u{2026}`\n\tstill replaces any operation.\n\t---\n\tcapability Vectorize {\n\t\tfn upsert(vectors: List[Vector]) -> Effect[Result[Mutation, VectorError]]\n\t\tfn insert(vectors: List[Vector]) -> Effect[Result[Mutation, VectorError]]\n\t\tfn upsertValue[M: Codable](\n\t\t\tvectors: List[VectorOf[M]]\n\t\t) -> Effect[Result[Mutation, VectorError]]\n\t\tfn query(\n\t\t\tvector: List[Float],\n\t\t\toptions: QueryOptions\n\t\t) -> Effect[Result[List[VectorMatch], VectorError]]\n\t\tfn getByIds(ids: List[String]) -> Effect[Result[List[Vector], VectorError]]\n\t\tfn deleteByIds(ids: List[String]) -> Effect[Result[Mutation, VectorError]]\n\t\tfn describe() -> Effect[Result[IndexInfo, VectorError]]\n\t}\n\n\t---\n\tOne retrieved chunk of an `AiSearch` instance: the chunk\'s `id`, its `score`\n\t(0 to 1, larger is a closer match), its `text`, and where it came from: `key`\n\tis the source file\'s path or the page\'s URL, `timestamp` the source item\'s\n\tunix time in milliseconds when the platform reports one (a `timestamp`\n\tcondition in `SearchOptions.filter` compares in the same unit), and `metadata` the item\'s custom\n\tmetadata as a JSON object in text (`None` when it has none). The text is\n\tindexed content, so treat it as untrusted input.\n\t---\n\ttype SearchHit = {\n\t\tid: String,\n\t\tscore: Float,\n\t\ttext: String,\n\t\tkey: String,\n\t\ttimestamp: Option[Int],\n\t\tmetadata: Option[String],\n\t}\n\n\t---\n\tHow an `AiSearch` query finds chunks: by `Vector` (meaning), by `Keyword`\n\t(words), or `Hybrid`, both together. The platform\'s default is `Hybrid`.\n\t---\n\ttype RetrievalType = enum { Vector, Keyword, Hybrid }\n\n\t---\n\tThe options of `AiSearch.search` and `AiSearch.answer` (for `answer` they\n\tshape its retrieval step). A setting left `None` or `false` leaves the\n\tplatform\'s own default in place: `maxResults` is how many chunks to return\n\t(1 to 50, 10 unless set), `matchThreshold` the least score a chunk may have\n\t(0 to 1, 0.4 unless set), and `retrieval` how chunks are found. `rewriteQuery`\n\thas the instance rewrite the question for better retrieval, and `rerank`\n\thas it reorder the chunks with a reranking model; both use the models the\n\tplatform picks. `filter` is a list of conditions on the items\' attributes\n\t(`folder`, `timestamp`, `filename`) and on the instance\'s custom metadata\n\t(at most five fields), and every condition must hold. A text value is\n\tmatched on its first 64 bytes only. Out-of-range values are refused as\n\t`SearchInvalidInput`.\n\t---\n\ttype SearchOptions = {\n\t\tmaxResults: Option[Int] = None,\n\t\tmatchThreshold: Option[Float] = None,\n\t\tretrieval: Option[RetrievalType] = None,\n\t\trewriteQuery: Bool = false,\n\t\trerank: Bool = false,\n\t\tfilter: List[Condition] = [],\n\t}\n\n\t---\n\tThe reply of `AiSearch.answer`: the generated `text`, which is untrusted\n\tinput, the `hits` it was grounded on, and the `usage` of the generation when\n\tthe platform reported it.\n\t---\n\ttype SearchAnswer = {\n\t\ttext: String,\n\t\thits: List[SearchHit],\n\t\tusage: Option[TokenUsage],\n\t}\n\n\t---\n\tWhy an AI Search call did not give a reply. `SearchInvalidInput` is a\n\trequest the platform refused as malformed or out of range (a bad filter or\n\toption), with its message; `SearchRateLimited` is a rate limit, worth\n\tretrying later; `SearchQuotaExceeded` is a usage limit of the account;\n\t`SearchFailed` is any other refusal, or a reply that is not the shape the\n\toperation promises, with a message. The `Search` prefix is because\n\t`InvalidInput` is `AiError`\'s, `RateLimited` `EmailError`\'s, `QuotaExceeded`\n\t`AiError`\'s and `Failed` `SqlError`\'s. Cloudflare adds error cases over time,\n\tso a `match` over this type needs a wildcard.\n\t---\n\ttype SearchError =\n\t\t| SearchInvalidInput(message: String)\n\t\t| SearchRateLimited\n\t\t| SearchQuotaExceeded\n\t\t| SearchFailed(message: String)\n\n\t---\n\tAn AI Search instance: a managed retrieval service that indexes a data source\n\t(an R2 bucket, a website, files uploaded to it) and answers from it. Used\n\tonly through a named instance that names it,\n\t`capability Kb = AiSearch @instance(\"support-docs\")`, which binds as\n\t`AI_SEARCH_KB`, an `[[ai_search]]` entry; the annotation is required, and a\n\tbare `given AiSearch` is refused. Experimental.\n\n\tThe instance is not created by Bynk. It is configured by whoever owns it (the\n\tdata source, the models, the chunking, how it is kept in sync), so you create\n\tit in the Cloudflare dashboard, with `wrangler` or the REST API, and the\n\tWorker only queries it. The name is used as written in every environment.\n\tTo fill an instance backed by an R2 bucket, write the files with `R2.put`;\n\tthe instance indexes them on its own schedule, so a freshly written file is\n\tnot searchable at once, and a query against an instance that has indexed\n\tnothing yet is an empty list, not an error.\n\n\t`search(query, options)` returns the best-matching chunks, best first, for a\n\thandler that shows results or builds its own prompt (with `Ai.generate`).\n\t`answer(messages, options)` retrieves the same way and has the instance\'s own\n\tgeneration model write the reply from the conversation, which must not be\n\tempty; a `SearchAnswer` carries the text, the chunks it used and the token usage.\n\tThe generation model is the instance\'s setting and a call cannot override\n\tit. Every operation gives a `SearchError` rather than faulting, except a call\n\ton an instance that does not exist, which is a platform fault.\n\n\tAI Search is a remote service on your Cloudflare account, so a call may be\n\tbilled; see Cloudflare\'s AI Search pricing page for what applies, and put a\n\t`RateLimit` in front of any handler an anonymous caller can reach. Under\n\t`bynk dev` a call goes to the deployed instance on Cloudflare. In a test every\n\toperation faults until `stub Kb.search(_, _) returns \u{2026}` replaces it, so a test\n\tnever reaches AI Search; to test retrieval logic, use `Vectorize`, which\n\thas an in-memory double.\n\t---\n\tcapability AiSearch {\n\t\tfn search(\n\t\t\tquery: String,\n\t\t\toptions: SearchOptions\n\t\t) -> Effect[Result[List[SearchHit], SearchError]]\n\t\tfn answer(\n\t\t\tmessages: List[ChatMessage],\n\t\t\toptions: SearchOptions\n\t\t) -> Effect[Result[SearchAnswer, SearchError]]\n\t}\n\n\t---\n\tWhy a `Container` call did not succeed. `StartFailed` is a container that\n\twould not start, or whose port never listened, with a message; `Unavailable`\n\tis the platform declining to start another instance (the account\'s limits);\n\t`Timeout` is a start or a call that took too long; `Network` is a failure\n\treaching the instance. Cloudflare adds error cases over time, so a `match`\n\tover this type needs a wildcard.\n\t---\n\ttype ContainerError =\n\t\t| StartFailed(message: String)\n\t\t| Unavailable\n\t\t| Timeout\n\t\t| Network\n\n\t---\n\tA container: a server in a Docker image, run on Cloudflare and reached over\n\tHTTP on one port. Used only through a named instance,\n\t`capability Renderer = Container @build(\"containers/renderer\") @port(8080)`,\n\twhich binds as `CONTAINER_RENDERER`, a Durable Object class the compiler\n\tgenerates; a bare `given Container` is refused. `@build` is the\n\tproject-relative directory that holds the `Dockerfile`, and `@port` the\n\tport its server listens on; both are required. Experimental.\n\n\t`@sleepAfter(5.minutes)` stops an idle container after that long (more than\n\tzero, at most 6 hours); left out, the platform stops it shortly after the\n\tinstance goes inactive, with no figure to rely on. `@instanceType` is\n\t`\"lite\"` (the default), `\"standard-1\"`, `\"standard-2\"`, `\"standard-3\"` or\n\t`\"standard-4\"`. `@forward([\"API_KEY\"])` names Worker secrets the container\'s\n\tprocess reads from its environment: every process and dependency in the\n\timage can read them, and Bynk cannot scope them further.\n\n\t`send(instance, req)` sends `req` to the container named `instance` and\n\treturns its response; `receiveBytes` returns the body as `Bytes`, and\n\t`sendBytes` sends `body` as the request body (`req.body` must be `None`).\n\t`Request`, `Response` and `BytesResponse` are `bynk`\'s, so a context that\n\tcalls them also writes `consumes bynk`. The URL\'s host is not used for\n\trouting, but the URL must be absolute, and the container sees it.\n\n\t`instance` is the name of one container instance, one process: the same\n\tname reaches the same instance, and a new name starts a new one. It is a\n\truntime value, so a handler can use one per tenant, and it is not a secret:\n\tnames appear in Cloudflare\'s dashboards and logs. A name that is empty, over\n\t256 bytes or holds a control character faults the call. The first call to an\n\tinstance starts its container, which takes noticeable time, longer for a\n\tlarger image. A container is not storage: its disk is ephemeral.\n\n\tA container has no internet access: Bynk always starts it with outbound\n\taccess off. Images must be built for `linux/amd64` and live in Cloudflare\'s\n\tregistry. `bynk.cloudflare` puts no ceiling on instances: names are chosen\n\tby the caller and only the account\'s limits apply, so choose `@sleepAfter`\n\tand `@instanceType` with that in mind. A running container costs money; see\n\tCloudflare\'s Containers pricing and limits pages for what applies. A slow\n\tcall from inside an agent handler holds that agent\'s queue, so call from a\n\tservice and hand the result to the agent.\n\n\tDeploy with `wrangler deploy` (Docker running).\n\tIn a test every operation faults until `stub Renderer.send(_, _) returns \u{2026}`\n\treplaces it, so a test never starts a container.\n\t---\n\tcapability Container {\n\t\tfn send(instance: String, req: Request) -> Effect[Result[Response, ContainerError]]\n\t\tfn receiveBytes(\n\t\t\tinstance: String,\n\t\t\treq: Request\n\t\t) -> Effect[Result[BytesResponse, ContainerError]]\n\t\tfn sendBytes(\n\t\t\tinstance: String,\n\t\t\treq: Request,\n\t\t\tbody: Bytes\n\t\t) -> Effect[Result[BytesResponse, ContainerError]]\n\t}\n\n\t---\n\tAn outbound call that presents one of your account\'s client certificates, for\n\tan origin that requires mutual TLS: the server proves its identity and so\n\tdoes the Worker, during the handshake. Used only through a named instance\n\tthat names the certificate,\n\t`capability Backend = MtlsCertificate @certificate(\"acme-client\")`, which\n\tbinds as `MTLS_BACKEND`; a bare `given MtlsCertificate` names no certificate\n\tand is refused.\n\n\tThe certificate is uploaded to the account by its owner (Wrangler\'s\n\t`mtls-certificate upload`, the dashboard or the API) and is named there;\n\t`@certificate` names it, as written in every environment. The deploy links to\n\tit by that name and never uploads it: its private key never reaches Bynk or\n\tthe Worker. A name that no uploaded client certificate carries, or that more\n\tthan one carries, fails the deploy with the problem named.\n\n\t`send` has `Fetch.send`\'s shape and rules: the same `Request` (its headers\n\tchecked the same way, refused as `InvalidHeader` before anything is sent),\n\tthe same `Response`, and `Network` when the call itself fails, which includes\n\ta handshake the origin refuses. Unlike `Service`, the URL\'s host is the\n\tdestination: this is a real outbound call, and the certificate is presented\n\tto whatever origin the URL names. A status the origin returns, 5xx included,\n\tis an `Ok` response.\n\n\tCloudflare does not support presenting a certificate to an origin that is a\n\tproxied zone on Cloudflare; the call fails with a `520`. See Cloudflare\'s\n\tmTLS bindings page for the current rules. There is no local simulation of\n\tthe binding: `bynk dev` runs it on Cloudflare, once you allow it, and\n\t`bynkc test` faults until the call is stubbed, so a test never reaches the\n\torigin.\n\n\t`receiveBytes` and `sendBytes` are `Fetch`\'s byte forms over the same\n\tcertificate: the response body as `Bytes`, and a `Bytes` request body (which\n\t`req.body` must then leave `None`), each with `Fetch`\'s defaults for the\n\ttimeout and redirects.\n\n\t`Request`, `Response`, `BytesResponse` and `FetchError` are `bynk`\'s types, so\n\ta context that calls them also writes `consumes bynk` to name them.\n\t---\n\tcapability MtlsCertificate {\n\t\tfn send(req: Request) -> Effect[Result[Response, FetchError]]\n\t\tfn receiveBytes(req: Request) -> Effect[Result[BytesResponse, FetchError]]\n\t\tfn sendBytes(req: Request, body: Bytes) -> Effect[Result[BytesResponse, FetchError]]\n\t}\n\n\tprovides Kv = WorkersKv\n\n\tprovides Service = WorkersService\n\n\tprovides R2 = WorkersR2\n\n\tprovides RateLimit = WorkersRateLimit\n\n\tprovides Queue = WorkersQueue\n\n\tprovides Analytics = WorkersAnalytics\n\n\tprovides EdgeCache = WorkersEdgeCache\n\n\tprovides D1 = WorkersD1\n\n\tprovides Version = WorkersVersion\n\n\tprovides Ai = WorkersAi\n\n\tprovides Images = WorkersImages\n\n\tprovides StoredSecret = WorkersStoredSecret\n\n\tprovides Email = WorkersEmail\n\n\tprovides Postgres = WorkersPostgres\n\n\tprovides MySql = WorkersMySql\n\n\tprovides Vectorize = WorkersVectorize\n\n\tprovides Container = WorkersContainer\n\n\tprovides AiSearch = WorkersAiSearch\n\n\tprovides MtlsCertificate = WorkersMtls\n\n\tprovides AnalyticsSql = WorkersAnalyticsSql\n}\n";Expand description
The first-party Cloudflare platform adapter (v0.19): the platform’s real
infrastructure capabilities, as they are — no portable intersection
(decision 0016). The v0.19 surface was the minimal, collection-free Kv
(decision 0023); v0.23 adds the list drain and putTtl (0050/0051);
structured values are v0.22-codec composition, and Queue remains its
own future increment. Like the bynk surface it has no binding
clause — the toolchain supplies the binding.