| 1 | /// <reference types="@cloudflare/workers-types" /> |
| 2 | |
| 3 | /** |
| 4 | * Plain (non-Effect) Worker handler exercising the two AI Search binding |
| 5 | * shapes wired via `env`: |
| 6 | * - `SEARCH` is a single-instance `ai_search` binding (an `AiSearchInstance`). |
| 7 | * - `NS` is an `ai_search_namespace` binding (`.get(name)` selects an |
| 8 | * instance within the namespace). |
| 9 | * |
| 10 | * The `/bindings` route only reports that the bindings are present and |
| 11 | * shaped correctly at runtime — it does not run a query (that needs indexed |
| 12 | * data). Proving the bindings are injected is enough to validate that the |
| 13 | * Worker deploy accepted them. |
| 14 | */ |
| 15 | interface Env { |
| 16 | SEARCH: AiSearchInstance; |
| 17 | NS: AiSearchNamespace; |
| 18 | } |
| 19 | |
| 20 | export default { |
| 21 | fetch: async (request: Request, env: Env) => { |
| 22 | const url = new URL(request.url); |
| 23 | if (url.pathname === "/bindings") { |
| 24 | return Response.json({ |
| 25 | search: typeof env.SEARCH, |
| 26 | searchChatCompletions: typeof env.SEARCH?.chatCompletions, |
| 27 | searchSearch: typeof env.SEARCH?.search, |
| 28 | ns: typeof env.NS, |
| 29 | nsGet: typeof env.NS?.get, |
| 30 | }); |
| 31 | } |
| 32 | return new Response("ok"); |
| 33 | }, |
| 34 | }; |