@bowmark/web 1.25.1 → 1.25.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,27 +39,24 @@ declarations below AND the `.pyi`, `gate:public-types` asserts the two languages
39
39
  same functions, and all three packages ship at one version — so a caller in either
40
40
  language is looking at the same library.
41
41
 
42
- Real TypeScript for the whole `bowmark.*` surface, with no Bowmark source on the
43
- caller's disk. Their code runs in their editor and their process; the capability calls
44
- execute on our servers.
45
-
46
- **One package, not two.** The generated declarations ship inside this one rather than
47
- beside it in a `@bowmark/catalog-types`, because installing one thing and getting
48
- autocomplete is the entire promise. What exists to call is listed, one row per
49
- function, in
42
+ ---
43
+
44
+ ## Using this package — start here
45
+
46
+ This is everything you need to write code that calls Bowmark:
47
+
48
+ - **[The session is the surface](#the-session-is-the-surface)** — How to use `session()` to keep your control flow on your machine
49
+ - **[The three other entry points](#the-three-other-entry-points)** — `bowmark`, `client()`, `openManagedSession()`, `run()` and when to use each
50
+ - **[Signing in](#signing-in--login-connection-and-bmconnections)** — How `login()` and `{ connection }` work
51
+ - **[Error handling](#what-it-throws)** — What exceptions to expect and how to handle them
52
+ - **[Configuration](#configuration)** — How to pass your API key and other options
53
+
54
+ Stop here if you just need to call the library. What exists to call is listed in
50
55
  [`CAPABILITIES.md`](https://github.com/bowmark-ai/web/blob/main/CAPABILITIES.md) and
51
56
  [`PROVIDERS.md`](https://github.com/bowmark-ai/web/blob/main/PROVIDERS.md) — absolute
52
- URLs, because this README is read on npm where a relative link resolves to nothing. What
53
- changed between versions is
54
- [`CHANGELOG.md`](https://github.com/bowmark-ai/web/blob/main/CHANGELOG.md), which is
55
- generated by diffing those same two tables, so it describes the callable surface and
56
- nothing else.
57
-
58
- **Zero runtime dependencies, permanently.** Not an aspiration — the argument guard is
59
- plain JS rather than a validator library, and the envelope shapes are hand-restated
60
- rather than imported from `@bowmark/schema`, for exactly this reason. A `@bowmark/*`
61
- import here would compile and typecheck in this repo and fail to install for every
62
- consumer outside it; `tests/unit/bowmark-web-envelopes.test.ts` refuses one.
57
+ URLs, because this README is read on npm where a relative link resolves to nothing.
58
+
59
+ ---
63
60
 
64
61
  ## The session is the surface
65
62
 
@@ -189,223 +186,6 @@ A caller header cannot displace the key.
189
186
 
190
187
  ## For maintainers of this package
191
188
 
192
- Everything below describes how `@bowmark/web` is built, generated and published. Skip
193
- this section unless you are changing how the SDK itself works.
194
-
195
- ## Internals — how this package is built, generated and published
196
-
197
- Everything above is what you need to call the library. Everything below is for someone
198
- working on this package itself — the generator, the guards, the publish pipeline. Skip
199
- it unless you're changing how the SDK is built.
200
-
201
- ### The two halves, and why they are split
202
-
203
- - **`src/{index,session,transport,guard,validate}.ts`** — hand-written, ~700 lines,
204
- changes almost never.
205
- - **`src/generated/library.d.ts`** — every capability and provider, generated,
206
- committed, regenerated whenever a unit lands.
207
- - **`src/generated/validators.ts`** — the same functions' argument shapes as DATA, for
208
- the runtime half of the same job.
209
-
210
- The generated half is **ambient**: it declares globals and exports nothing, and
211
- `index.ts` reaches it with a `/// <reference>`. An `import` would make it a module, every
212
- declaration in it would stop being global, and the churn split would buy nothing — the
213
- types would become a real dependency of the client. `@cloudflare/workers-types` and
214
- `@types/node` are the precedent.
215
-
216
- `index.ts` therefore **aliases** rather than re-exports (`export type Library =
217
- BowmarkLibrary`). A global from an ambient file is not a local declaration, so
218
- `export type { BowmarkLibrary }` is `TS2661`.
219
-
220
- **The same declarations describe TWO implementations, deliberately.** `bowmark` exported
221
- here is a real Proxy over HTTP in the caller's process; `bowmark` inside a `run()` script
222
- is the sandbox's own global (`packages/runtime/src/namespace.ts`) in an isolate on ours.
223
- The types are generated once and describe both, so the two must stay in sync.
224
-
225
- **The Proxy accepts every name at runtime** — `bowmark.anything.at.all()` builds a path
226
- and sends it. That is not a bug; it is why the generated types are load-bearing rather
227
- than decorative. The Proxy makes a correct call work without enumerating half a million
228
- names, and TypeScript makes a wrong one a compile error. Neither half is sufficient
229
- alone. It does refuse two things locally: a path shorter than `<unit>.<fn>`, and an
230
- argument the wire cannot carry.
231
-
232
- **A proxy node answers `undefined` for `then`, `catch`, `finally` and `toJSON`.** Without
233
- that, `await bowmark.music` would find a callable `then`, invoke it as a thenable, and
234
- hang forever waiting for a resolve a path segment can never call.
235
-
236
- ### The wire guard is a checked COPY
237
-
238
- `src/guard.ts` duplicates `wireProblem` from `packages/schema/src/wire.ts`, because
239
- importing the workspace package would break the tarball for everyone outside this repo.
240
- A copy drifts, so `tests/unit/bowmark-web-guard.test.ts` runs both over one fixture
241
- table and asserts identical `{ path, reason }` for every entry. Add a refusal to
242
- `wire.ts` and this fails by name.
243
-
244
- It is a walk, not a `try { JSON.stringify(args) }`: stringify throws on exactly two
245
- things (a circular structure and a `BigInt`) and silently mangles everything else —
246
- `Date` → string, `Map`/`Set` → `{}`, class instance → plain object, function-valued key
247
- → dropped. Temporal shipped that exact bug, diagnosed it as a typing problem, and closed
248
- it won't-fix.
249
-
250
- ### The argument guard is TWO guards, in this order
251
-
252
- `assertWireSafeArgs` asks whether the value can cross at all — a `Date`, a `Map`, a
253
- function, a circular structure. `assertArgShape` asks whether it matches what the
254
- function declares. Wire first, always: shape-first would report a `Date` as "expected a
255
- string" and send the caller after the wrong bug.
256
-
257
- The shape half is `src/generated/validators.ts` (data, generated from the same manifest
258
- as the declarations) read by `src/validate.ts` (one interpreter, ~250 lines). Not 192
259
- emitted functions: 192 emitted functions are 192 pieces of code no test ever runs, and
260
- one interpreter over a fixture table is testable. No validator library on either side —
261
- zero runtime dependencies is the product.
262
-
263
- **Every rule leans toward ACCEPTING, and that is the design.** A false refusal is a
264
- caller whose correct argument their own client rejects, with no server to appeal to. A
265
- false accept costs one round trip and lands them exactly where they were before this
266
- existed. So:
267
-
268
- - **An object is OPEN.** An unlisted property is accepted — TypeScript's
269
- excess-property check fires on literals only, and a caller who spread a wider object
270
- is doing something legal.
271
- - **Anything the compiler could not model becomes `any`** and accepts everything. It
272
- never guesses a shape from a name, and `Required<T>` compiles to `T` rather than to
273
- T-with-everything-mandatory, because widening is free and narrowing is not.
274
- - **Arity is checked DOWNWARD only.** A missing required argument is refused; a surplus
275
- one is not, because that is what a caller on a version older than a new parameter has.
276
- - **A union reports the arm the value got FURTHEST into.** `string | { query: string }`
277
- given `{ query: 5 }` names `args[0].query`, not six arms and no location.
278
-
279
- The one deliberate strictness is a string literal union (`sort?: "hot" | "new"`), because
280
- a typo'd enum value is the commonest wrong argument and the accepted set is a legible
281
- message.
282
-
283
- **What it fails CLOSED on, and the two things it must not.** A known unit with an
284
- unknown FUNCTION is refused — the table is authoritative about a unit it carries. An
285
- unknown UNIT passes straight through, because a family MEMBER (`providers.gymshark`) is
286
- absent from the RUNTIME validator table **by design** — `listProviders()` excludes
287
- members and always will — so refusing an unknown unit would refuse the largest part of
288
- the library. A function with no readable argument shape is an EXPLICIT `null` in the
289
- table rather than an absence, and passes through; that distinction is what makes the
290
- first rule safe at all.
291
-
292
- Note the deliberate asymmetry with the TYPES: since 2026-08-06 a member IS declared in
293
- `library.d.ts`, so `providers.gymshark.search(…)` completes and type-checks. The two
294
- answer different questions. Types are a build-time artifact and can afford one line per
295
- member; the validator table is loaded into every client process at runtime, where 51,711
296
- entries would be a cost paid on every call to buy nothing — the family's arguments are
297
- already checked by the shared interface the compiler saw.
298
-
299
- **A parameter may not offer a type the wire cannot carry.** Every argument crosses as
300
- JSON on every surface, so `requestedTime?: string | Date` has an arm refused 100% of the
301
- time while the library says otherwise. `gate:public-types`' `wire-impossible-param`
302
- refuses one, with no exception set — an exception would be a declaration that a
303
- parameter is uncallable. Found once, on `pizzahut.priceOrder`, by generating validators
304
- for all 253 typed parameters.
305
-
306
- ### What ships is compiled, not `src/` verbatim
307
-
308
- `main`/`types` point at `dist/index.{js,d.ts}`. `dist/` is never committed — it does not
309
- exist in this workspace and does not exist in the public mirror's git history either — it
310
- is produced once, in the mirror's own `publish.yml`, by `npm run build`
311
- (`scripts/build.mjs`, `tsconfig.build.json`), immediately before `npm publish`. Nobody
312
- runs it but that one CI job:
313
-
314
- - **This workspace never does.** `pnpm typecheck` is `tsc -p tsconfig.json --noEmit` —
315
- reads `src/` directly, emits nothing, unaffected.
316
- - **A consumer never does.** `npm i @bowmark/web` installs the already-compiled `dist/`;
317
- there is still no build step on their side, which is the property this package has
318
- always promised.
319
-
320
- Why compiled at all: Node refuses to strip types out of a `.ts` file found inside
321
- `node_modules`, so shipping `main: src/index.ts` made plain `node app.mjs` fail with
322
- `ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING` for every consumer who was not already on
323
- `tsx`, Bun, or a bundler.
324
- `docs/decisions/2026-09-01-the-published-npm-client-ships-compiled-js.md` in Bowmark's
325
- internal engineering repo (not public).
326
-
327
- **One thing `tsc`'s declaration emit does not do on its own, and `build.mjs` does by
328
- hand:** `src/generated/library.d.ts` is ambient (no imports, no exports — see below) and
329
- `index.ts` reaches it only with `/// <reference path="./generated/library.d.ts" />`. tsc
330
- consumes that directive for this package's own compile but does not carry it into the
331
- emitted `dist/index.d.ts`. Left alone, a downstream `tsc` never loads `library.d.ts` at
332
- all and `BowmarkLibrary` — the type this package exists to ship — reads as `Cannot find
333
- name`. `build.mjs` re-inserts the reference line and copies `library.d.ts` into
334
- `dist/generated/` verbatim (it has nothing to compile).
335
-
336
- ### Regenerating
337
-
338
- ```bash
339
- pnpm run gen:public-types # writes src/generated/{library.d.ts,validators.ts}
340
- pnpm run gate:public-types # fails on a leak, a new refusal, a wire-impossible type
341
- pnpm run gate:public-types:drift # …and on the committed copy being stale
342
- ```
343
-
344
- **Only the middle one runs on your PR, and staleness is deliberately not fatal there.**
345
- The committed copy goes stale every time any unit anywhere lands a function, which is not
346
- something your branch can keep true — `regen-public-types.yml` repairs it on `main`. See
347
- `.claude/rules/public-types.md` § The gate is SPLIT.
348
-
349
- **`skipLibCheck: false` in this package's `tsconfig.json` is load-bearing**, and the base
350
- config sets the opposite. That flag skips type checking of every `.d.ts`, and this
351
- package's whole deliverable IS a `.d.ts` — with the inherited default, `pnpm typecheck`
352
- reported green over a generated file carrying 40 unresolved type names. Do not "tidy" it
353
- back to the inherited value.
354
-
355
- The file is **committed**, for the reason the tier barrels are: this repo consumes
356
- TypeScript with no build step, so a generate-at-build artifact leaves `tsc` and vitest
357
- with nothing to read on a fresh clone. Committed plus a staleness gate is the only shape
358
- that works. Never hand-edit it.
359
-
360
- ### Four things the generator does that look like bugs and are not
361
-
362
- **One namespace per unit.** `music` and `flights` both declare `CallOptions`; `Track` and
363
- `Store` are names any provider may take. Each unit's `types` block is emitted VERBATIM
364
- inside `declare namespace BowmarkCapability_<id>` / `BowmarkProvider_<id>`, so a signature
365
- reading `Promise<MusicSearchResult>` resolves against its own block with no rewriting.
366
- Verbatim is the property that matters: what a caller compiles against is byte-for-byte
367
- what an agent reads from `get_library`.
368
-
369
- **The tier is in the namespace name.** `cars` is a capability AND a provider. A single
370
- `Bowmark_cars` would have emitted one and silently dropped the other.
371
-
372
- **20 provider functions are deliberately absent**, and none gets a
373
- `(...args: unknown[])` stand-in — a stand-in compiles, ships, and tells a caller nothing,
374
- which is the untyped surface this package exists to replace. They stay callable at
375
- runtime; only the compile-time claim is withheld, because there is no claim to make.
376
- Each one has a comment in its place saying which class it is and why.
377
-
378
- - **20 · untyped argument.** The declared argument is a bare destructuring pattern with
379
- no field types — `findStores({ near, radiusMiles?, limit? })` tells a model everything
380
- and a compiler nothing.
381
- - **0 · undeclared type.** The signature names a type the unit's own `types` block never
382
- declares. This was **11 functions across 7 providers** when the generator first
383
- compiled a provider's rendered types; all were fixed on 2026-08-05 by copying the real
384
- interface, and everything it transitively references, into the block. The class is now
385
- gated at source: `gate:capabilities`' `rendered-types-match-source` runs over the
386
- provider and family tiers, so it cannot come back silently.
387
-
388
- `gate:public-types` holds the two lists as separate SETS — merged, a provider could "fix"
389
- an undeclared type by making the argument untyped and stay green. Both can only shrink.
390
-
391
- **Seven providers have NO typed surface at all** — `aa`, `dickssportinggoods`,
392
- `flightradar24`, `ford`, `mailchimp`, `mcdonalds`, `namecheap`. Every function they
393
- declare is refused, so their interface is empty. The generated file says so in words,
394
- because an empty interface reads as "this unit does nothing", which is a different and
395
- wronger claim than "we can make no typed claim about anything it does".
396
-
397
- ### Scale
398
-
399
- Measured 2026-08-05 on synthetic units, one namespace each:
400
-
401
- | Units | raw | gzipped | `tsc` | editor cold load | member completion |
402
- |---|---|---|---|---|---|
403
- | 10,000 | 6.3 MB | 0.13 MB | 0.7s | 0.4s | 0.2 ms |
404
- | 500,000 | 321 MB | 6.5 MB | exit 0, 28.3s | 14.5s | **0.4 ms** |
405
-
406
- Reproduce with `pnpm tsx scripts/bench-public-types.ts <units>`. Completion — the only
407
- number a person feels — is flat. **The hard ceiling is ~849,000 units**, where the emitted
408
- string passes V8's `String::kMaxLength`; the generator throws there by name rather than
409
- letting `Array.prototype.join` produce a bare `RangeError`. Going past it needs the FAMILY
410
- shape (one shared interface, one line per member), which needs the manifest to describe a
411
- family and does not today.
189
+ How `@bowmark/web` is built, generated and published — the generator, the guards, the
190
+ publish pipeline — now lives in [`CONTRIBUTING.md`](./CONTRIBUTING.md), not here.
191
+ Nothing past this point is needed to call the library.