@shashu-ai/sdk 0.0.0-stage → 1.0.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,880 @@
1
+ # Changelog
2
+
3
+ All notable changes to SHASHU by Trustgate AI (Node.js SDK, `@shashu-ai/sdk`) are
4
+ documented here. This project adheres to [Semantic Versioning](https://semver.org/).
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [1.0.0] — 2026-11-14
9
+
10
+ Rename and cloud-pass sign-in. Keys (`tg_sk_…`) keep working exactly as before.
11
+
12
+ ### Fixed: the pass retry now fires (pass refusals are read by code)
13
+
14
+ The gateway refuses a cloud pass with HTTP 401, a fixed `error.code` and its own
15
+ sentence. The SDK used to look for six "Pass refused: …" sentences the gateway
16
+ never sends, so the one-time retry on an expired pass never happened.
17
+
18
+ - `pass_expired` (pass mode only): the cached pass is dropped, a new one is
19
+ fetched, and the request is retried **once** (streaming: only before any byte
20
+ has arrived).
21
+ - Every other pass refusal (`pass_provider_not_set_up`, `pass_not_licensed`,
22
+ `pass_wrong_audience`, `pass_wrong_issuer`, `pass_unknown_agent`) is raised as
23
+ `ShashuAuthenticationError` with `.code` set and the gateway's message
24
+ unchanged. No retry.
25
+ - A 401 with no such code (an older gateway) is not retried. Key mode is
26
+ unchanged.
27
+ - New constants: `PASS_CODES` and `PASS_PROVIDER_NOT_SET_UP`, `PASS_NOT_LICENSED`,
28
+ `PASS_EXPIRED`, `PASS_WRONG_AUDIENCE`, `PASS_WRONG_ISSUER`, `PASS_UNKNOWN_AGENT`.
29
+
30
+ ### Added: `tokenProvider` (cloud pass)
31
+
32
+ `Shashu`, `shashuFetch`, and the Vercel AI, LangChain and Anthropic
33
+ middlewares take a function that returns the current short-lived pass (or a
34
+ Promise). The SDK never calls Entra, Google or AWS. Give either a SHASHU key or
35
+ a token provider, not both. The pass is cached until 60 seconds before JWT
36
+ `exp`, refreshed once under concurrency, and retried once on an HTTP 401 whose
37
+ body is one of the six gateway `Pass refused:` messages. Streaming retries only
38
+ if no bytes have arrived. Policy blocks (403) are never retried.
39
+
40
+ `createShashuGeminiConfig` is key only for now. `getN8nHeaderSnippet` is a
41
+ paste-once header list (key only).
42
+
43
+ ### Changed: package name, licence, env, public names
44
+
45
+ Package is `@shashu-ai/sdk`, version `1.0.0`, Apache-2.0.
46
+ Environment variables are `SHASHU_*` first, then `TRUSTGATE_*` (warn once).
47
+ Public type, function and exception names are SHASHU (`Shashu`, `ShashuError`,
48
+ `shashuFetch`, `createShashuLangChainConfig`, …). Wire names (`x-trustgate-*`,
49
+ `trustgate_metadata`, `tg_sk_`) are unchanged.
50
+
51
+ ## [4.0.0] — unreleased
52
+
53
+ One behaviour change, plus everything merged since `3.0.1`. Read the first
54
+ section before upgrading.
55
+
56
+ ### Behaviour change: `trustgate-version: 2026-09-01` is sent by default
57
+
58
+ Every request this SDK makes now carries `trustgate-version: 2026-09-01`, the
59
+ same value the Trustgate AI Python SDK has sent since `0.15.2`. That covers the
60
+ `Shashu` client (`fetch` and `fetchStream`), `shashuFetch()`, and the
61
+ headers built by the Anthropic, Gemini, LangChain and Vercel AI middleware.
62
+
63
+ Without that header the gateway served this SDK its `legacy` contract. With
64
+ it:
65
+
66
+ - **Refusals arrive as errors, not as 200 replies.** A content block is an
67
+ HTTP **400** (`error.type: "content_filter"`, `error.code` naming the
68
+ finding). A policy refusal is a **403**, and a blocked memory write is
69
+ `MemoryWriteBlocked`. Plan limits are **402**, quota is **429**, and a
70
+ fail-closed scan is **503**. Under `legacy` each of these was a 200 with
71
+ `finish_reason: "content_filter"`.
72
+ - **`ShashuContentFilterError` is still the type for a content block, but
73
+ its fields change.** `status` is `400` instead of `200`, `finishReason` is
74
+ `null` instead of `"content_filter"`, `message` is the gateway's own plain
75
+ sentence (`error.message`), and `code` names the finding. Code that catches
76
+ the type keeps working. Code that reads `err.status === 200` or
77
+ `err.finishReason` does not.
78
+ - **Refusals that are not content blocks now raise their own types.** Under
79
+ `legacy`, every refusal was a `ShashuContentFilterError`. Now a policy
80
+ refusal is `ShashuPolicyViolation` (`error.type: "permission_error"`,
81
+ `error.code` a reason such as `tool_policy` rather than `"403"`), a quota
82
+ refusal is `ShashuRateLimitError`, and a fail-closed scan is
83
+ `ShashuProviderError`.
84
+ - **Provider SDKs raise their own errors.** A provider SDK given
85
+ `shashuFetch()` or a middleware config (raw `openai`, Vercel AI,
86
+ LangChain, Anthropic, Gemini) now raises its own 400 or 403 error on a
87
+ refusal (`BadRequestError`, `PermissionDeniedError`, …). Under `legacy` it
88
+ returned the refusal as an ordinary 200 reply. The
89
+ `trustgate-block-encoding: explicit` header `shashuFetch()` already sent
90
+ now takes effect, because the gateway ignores it without a version.
91
+ - **Full memory and inspection details are in the body.** A reply carries the
92
+ `trustgate` block, so `decision.memory.items` lists each memory save and
93
+ recall (`kind`, `state`, `reason`, `tool`, `store`, …). Before, a flagged
94
+ save under Monitor was counted in `x-trustgate-memory` but not listed.
95
+ `decision.memory.carrier` is now `"body"`.
96
+ - **Unchanged by design:** under Block mode, a memory save the gateway strips
97
+ from a reply is still a normal delivered reply, with `memoryBlocked === 1`
98
+ and no exception. `MemoryWriteBlocked` is raised only for a 403 refusal.
99
+
100
+ **To turn it off**, pass `contractVersion: null` to `new Shashu({...})`,
101
+ `shashuFetch({...})` or any middleware config. The SDK then sends no
102
+ `trustgate-version` header and the gateway serves the account default,
103
+ `legacy` unless an operator changed it. Pass `contractVersion: "<date>"` to pin
104
+ another version. A `trustgate-version` entry you put in `headers` yourself
105
+ always wins.
106
+
107
+ New public names: `DEFAULT_CONTRACT_VERSION`, `CONTRACT_VERSION_HEADER`, and
108
+ the `contractVersion` option on `ShashuConfig` and `ShashuFetchOptions`.
109
+ `getShashuHeaders()` (Vercel AI middleware) takes an optional third
110
+ argument, `contractVersion`.
111
+
112
+ ### Added: `declareMemory()` / `memoryScope()` (`memory_context.v1`)
113
+
114
+ These sit beside `declareRetrieval()` / `retrievalScope()`. An app declares
115
+ the items it recalled from memory, and the next model call carries them to the
116
+ gateway as `memory_context.v1` (`contracts/memory_context.v1.schema.json`), so
117
+ memory checks can run on them.
118
+
119
+ - `declareMemory(items, { store, scope?, source? })` declares for the current
120
+ async context. `memoryScope(items, options, fn)` declares for the duration
121
+ of `fn` only.
122
+ - `store` is required. `scope` is `agent` (default), `crew` or `tenant`.
123
+ `source` is one of the `memory_context.v1` values (default `sdk`). Anything
124
+ else throws `TypeError`.
125
+ - A no-op under `TRUSTGATE_DISABLE`. No collectors are included: a framework's
126
+ memory is not captured automatically.
127
+
128
+ ### Added: reading file, memory and route-policy results (FILE-06)
129
+
130
+ The gateway's decision now carries per-file results, memory results and a
131
+ route-policy block (`contracts/decision-envelope.v1.md`, contract
132
+ `2026-10-01`). They are readable, read-only, off the decision:
133
+
134
+ - **Files** — `d.attachments`, `d.filesUnverified`, `d.filesBlocked`. Body first; on a header-only (streaming) response the
135
+ counts come from `x-trustgate-attachments` and `attachments.carrier` says
136
+ `"header"`. `files_unverified` is `not_inspected + scanned_partial`.
137
+ - **Memory** — `d.memory`, `d.memoryBlocked`, `d.memoryRecallsFlagged`, `d.memoryCoverage`.
138
+ - **Route policy** — `d.routePolicy`, and `err.routePolicy` on the refusal, so an app can
139
+ say "route X is not approved for PHI" without parsing the message.
140
+ - **`MemoryWriteBlocked`** — a subclass of `ShashuPolicyViolation`, raised for a 403 whose
141
+ decision reports a blocked memory write. Existing `catch` clauses for the
142
+ parent still catch it.
143
+ - **Nothing unknown throws.** An unknown code, reason, field or attachment
144
+ state is read, not raised on: an unknown state is `AttachmentState`
145
+ unknown with the wire value on `rawState`. No reason vocabulary is held.
146
+
147
+ New public names: `MemoryWriteBlocked`, `HEADER_ATTACHMENTS`, `HEADER_MEMORY` (values) and the types `Attachments`, `Attachment`, `AttachmentFinding`, `AttachmentState`, `MemoryActivity`, `MemoryItem`, `RoutePolicy`. The block helper is unchanged — every new refusal
148
+ is `refuse`, not `block`. `contracts/sdk-surface.v1.md` is amended to match.
149
+
150
+ ## [3.0.1] — 2026-09-15
151
+
152
+ Package metadata only. No code change from `3.0.0`.
153
+
154
+ - The npm page no longer lists a source repository link. Shashu is closed
155
+ source, and the link pointed at a private repository that returned 404.
156
+
157
+ ### Release pipeline: one publish gate removed
158
+
159
+ `npm-publish.yml` no longer runs the step **"package.json must declare its
160
+ repository (npm provenance needs it)"**. That gate refused to publish unless
161
+ `repository.url` named this GitHub repository, because `npm publish
162
+ --provenance` needs it. Two things made it obsolete:
163
+
164
+ - Provenance is off. npm refuses it for a private source repository (HTTP 422,
165
+ measured on the `v3.0.0` tag), so `3.0.0` already published without it.
166
+ - This release removes the `repository` field, so the gate would fail every
167
+ build.
168
+
169
+ All other gates are unchanged: tag matches `package.json`, `src/version.ts`
170
+ matches `package.json`, type-check, tests, build, and the built bundle carries
171
+ the release version.
172
+
173
+ ## [3.0.0] — 2026-09-14
174
+
175
+ Three behaviour changes. Read these before upgrading from `1.8.0`.
176
+ (`2.0.0` was cut in git and never published; npm `latest` is still `1.8.0`.)
177
+
178
+ ### Upgrading from 1.8.0: `isolateRetrieval()` is gone
179
+
180
+ **`isolateRetrieval()` is no longer exported.** `retrievalScope()` is the
181
+ replacement. Call sites that import `isolateRetrieval` from this package will
182
+ fail to compile. See the removal section below for the before/after.
183
+
184
+ ### Upgrading from 1.8.0: a 400 content block is no longer a `ShashuBadRequestError`
185
+
186
+ Under the gateway's `explicit` block encoding, a content block arrives as
187
+ HTTP 400 with `error.type: "content_filter"`. This SDK used to throw
188
+ `ShashuBadRequestError` for that. It now throws `ShashuContentFilterError`.
189
+ **`catch (e) { if (e instanceof ShashuBadRequestError) }` no longer catches
190
+ a content block.** Adapters must add a `ShashuContentFilterError` branch
191
+ before their bad-request one. This change is on the `Shashu` client, not
192
+ the middleware path.
193
+
194
+ ### Upgrading from 1.8.0: session limits can start firing, with no change on your side
195
+
196
+ **`new Shashu()` traffic now carries a client-sent `x-trustgate-session-id`.**
197
+ Until now it carried none, and the gateway filled in a derived id for display
198
+ only. The gateway's session-window scan and per-session scan budget act only
199
+ on a client-sent session id. From `3.0.0` they do. An application you have not
200
+ changed can, after upgrading, see blocks or refusals that never occurred on
201
+ `1.8.0` — most likely on a long-lived client whose requests all share one
202
+ session. A long-lived client shared across users must pass a per-request
203
+ `sessionId`.
204
+
205
+ ### Added — session at origin, the gateway's decision, `isShashuBlock`
206
+
207
+ The constructed client now sends `x-trustgate-session-id` on every request,
208
+ including at origin. One client is one session; a captured A2A session
209
+ overrides the construction-time default; a per-request `sessionId` is an
210
+ instruction that wins. Without this header the gateway synthesises
211
+ `derived-` + sha256(agent + first message), so every run of an agent whose
212
+ first message is a static system prompt collapses into one Sessions row.
213
+
214
+ `shashuDecision` / `decisionFrom` read all six outcomes (`allow`,
215
+ `allow_altered`, `not_checked`, `block`, `refuse`, `fail`) from both
216
+ carriers (`body.trustgate` and the `x-trustgate-*` headers). Absence is
217
+ today's behaviour: a response with neither carrier is unchanged.
218
+ `isShashuBlock(err)` inspects an error and answers yes or no. It
219
+ replaces nothing and fails closed; `raiseForResponse` still fails open as
220
+ to block-ness, because it _does_ replace. Block-ness is carried by
221
+ `decision` alone — there is no copy of the `code` list.
222
+
223
+ `shashuFetch(...)` is the factory for a provider SDK's `fetch` option.
224
+ LangChain `install()` stays and is not deprecated: the standing rewiring
225
+ ruling covers provider clients, not a framework the customer chose. See
226
+ `docs/RULING-RUNTIME-REWIRING.md`.
227
+
228
+ The joiner refuses to attach when a snapshot holds conflicting corpora, so
229
+ a fan-out that shared a declaration before its first `await` becomes a
230
+ miss rather than a merge.
231
+
232
+ ### Fixed — BREAKING for adapters: a 400 content block is no longer a `ShashuBadRequestError`
233
+
234
+ Under the gateway's `explicit` block encoding (the default at contract version
235
+ `2026-09-01`) a DLP, jailbreak or prompt-injection block arrives as **HTTP 400**
236
+ with `error.type: "content_filter"`. This SDK threw `ShashuBadRequestError`
237
+ for it — "your request was malformed" — so a caller with correct code was sent
238
+ to fix a payload that was never the problem, and the block never reached
239
+ whatever handles blocks.
240
+
241
+ It now throws **`ShashuContentFilterError`**: the same type the 200 +
242
+ `finish_reason: "content_filter"` encoding has always thrown. The two are one
243
+ event on two serialisations, and which one a caller sees is chosen by a request
244
+ header or an account default the calling code may not control — so throwing
245
+ different types would break a `catch` clause on the day an operator moved the
246
+ default, with no change on the customer's side. `finishReason` is now
247
+ `string | null` (`null` on the 400 encoding), `status` is the real status
248
+ instead of a hardcoded 200, and `error.code` carries the finding: `jailbreak`,
249
+ `dlp`, `pii_output`, `secret`, `prompt_injection`.
250
+
251
+ **`catch (e) { if (e instanceof ShashuBadRequestError) }` no longer catches a
252
+ content block.** That is the point of the change and it is the thing that
253
+ breaks: an adapter that funnels blocks through its bad-request branch stops
254
+ seeing them there, and — because `ShashuContentFilterError` and
255
+ `ShashuBadRequestError` are siblings under `ShashuError`, not parent and
256
+ child — an unchanged adapter falls through to whatever handles the base class.
257
+ Adapters must add a `ShashuContentFilterError` branch **before** their
258
+ `ShashuBadRequestError` one. Callers who already narrow on `ShashuError`,
259
+ or who already have a content-filter branch for the 200 encoding, need no
260
+ change.
261
+
262
+ `context_window_exceeded` is unchanged. The `ShashuContentFilterError`
263
+ constructor gained two optional trailing parameters (`status`, `details`) and
264
+ `finishReason` became optional; existing three-argument calls are unaffected.
265
+
266
+ ### Known limitation — this fix is on the `Shashu` client, not the middleware path
267
+
268
+ `createShashuOpenAIOptions()`, `createShashuAnthropicConfig()`,
269
+ `createShashuGeminiConfig()` and `createShashuLangChainConfig()` return
270
+ _configuration_ — a base URL, headers and a `fetch`. They have never thrown a
271
+ Shashu exception and still do not: through a patched provider client a
272
+ refusal reaches the caller as that provider's own error. Measured in-process on
273
+ 2026-09-07 against `openai` and `@anthropic-ai/sdk`:
274
+
275
+ | through a middleware-configured provider client | thrown |
276
+ | ----------------------------------------------- | ----------------------- |
277
+ | 403 | `PermissionDeniedError` |
278
+ | 400 + `content_filter` | `BadRequestError` |
279
+
280
+ The `fetch` seam cannot fix this: both provider SDKs wrap the whole fetch call
281
+ in `catch -> APIConnectionError`, so a `ShashuPolicyViolation` thrown from
282
+ inside it reaches the caller as `APIConnectionError` with the real error only on
283
+ `.cause` — measured, both SDKs. Making a block catchable as a Shashu type on
284
+ that path needs a seam at the method the customer calls, which this package does
285
+ not have (there is no `patchOpenAI()` in the Node SDK, unlike the Python one).
286
+ That is tracked separately rather than half-built here.
287
+
288
+ ### Fixed — `error.code` dispatch describes, and accepts, what the field holds
289
+
290
+ `dispatchCode` preferred `error.code` over the transport status, "a string like
291
+ `"403"`". That is no longer the only thing the field can hold. Measured against
292
+ the gateway on 2026-09-07 it is one of four:
293
+
294
+ - a §3 **reason** — `jailbreak`, `dlp`, `egress_denied`, `auth_expired`, … — on
295
+ every path served under contract `2026-09-01`;
296
+ - the **HTTP status as a string** — still live, and still the default: an
297
+ account that sets no `TrustGate-Version` is served `legacy`, and every refusal
298
+ the gateway's `HTTPException` handler renders carries `str(status_code)`
299
+ whatever the version;
300
+ - the literal `"invalid_request"`, on a schema-invalid body on the LLM wire;
301
+ - **absent** — the 500 crash handler sends `error` as a bare string, and the
302
+ Anthropic-shaped envelope on `/v1/messages` drops the field.
303
+
304
+ The preference is **kept**, because the second case is the default path. What
305
+ changed is that it is now honoured only for a value matching `/^[0-9]{3}$/` in
306
+ 100–599, instead of anything `parseInt` would swallow. `parseInt` reads a
307
+ numeric PREFIX and discards the rest, so `parseInt("403_policy", 10) === 403`
308
+ would have dispatched a content block on a 400 as a policy refusal nobody
309
+ raised, and `parseInt("4_0_3", 10) === 4` as a status that exists nowhere. The
310
+ fail-closed property now belongs to the function rather than to what `parseInt`
311
+ happens to reject, and `test/exceptions.test.ts` pins all five cases:
312
+ content-filter 400, an unrecognised code on a 403, an unrecognised code on a
313
+ 400, no code at all, and a numeric-looking one.
314
+
315
+ ### Removed — `isolateRetrieval()`, so the surface carries two retrieval functions
316
+
317
+ **Breaking, and the version line moves 2.0.0 -> 3.0.0.**
318
+ `isolateRetrieval()` is no longer exported from the package root.
319
+ **`retrievalScope()` is the replacement**, for every shape `isolateRetrieval()`
320
+ was offered for:
321
+
322
+ ```ts
323
+ // before
324
+ await Promise.all(
325
+ batches.map((b) =>
326
+ isolateRetrieval(async () => {
327
+ declareRetrieval(b.docs, { corpus: 'policy_docs_v2' });
328
+ return openai.chat.completions.create({ model, messages: b.messages });
329
+ })
330
+ )
331
+ );
332
+
333
+ // after
334
+ await Promise.all(
335
+ batches.map((b) =>
336
+ retrievalScope(b.docs, { corpus: 'policy_docs_v2' }, () =>
337
+ openai.chat.completions.create({ model, messages: b.messages })
338
+ )
339
+ )
340
+ );
341
+ ```
342
+
343
+ **Why.** `contracts/sdk-surface.v1.md` in the gateway repo now freezes the
344
+ customer-facing surface of all four SDKs: **two** public retrieval functions and
345
+ no third. Four SDKs will exist and two do; the code under the hood differs per
346
+ language and that is fine, but what a customer types must not. Node was the one
347
+ that diverged -- Python already conformed -- and `isolateRetrieval()` was the
348
+ divergence. Its whole customer-facing job was already `retrievalScope()`'s, which
349
+ the source said itself.
350
+
351
+ **No published release carried it.** npm `latest` is 1.8.0; 2.0.0 was cut but
352
+ never published, and this function only ever existed in `[Unreleased]`. So the
353
+ major bump records a deliberate freeze of the public surface, **not** a
354
+ migration anyone on npm has to perform. If you are building against this repo
355
+ rather than the registry, the rewrite above is the whole change.
356
+
357
+ **Nothing else moved.** No behaviour, no cap, no wire output. The implementation
358
+ stays in `src/rag.ts` as internal -- `retrievalScope()` reaches the same
359
+ `AsyncLocalStorage.run` boundary, and `test/bus.test.ts` and
360
+ `test/conformance/manual.test.ts` still drive it directly by its internal path to
361
+ prove the isolation `retrievalScope()` depends on.
362
+
363
+ `test/surface.test.ts` now asserts the exported name set exactly, so the next
364
+ name that leaks fails the build instead of reaching a customer. It also measures
365
+ -- rather than assumes -- that `retrievalScope()` covers both shapes:
366
+ per-task isolation in a fan-out, and a helper that declares after it has already
367
+ awaited.
368
+
369
+ ### Added — declare retrieval once, anywhere
370
+
371
+ `declareRetrieval(docs, { corpus, query })` records what a retrieval returned
372
+ wherever it happened, and the SDK attaches it to the next model call as
373
+ `trustgate_metadata.rag_context`. `retrievalScope()` bounds one declaration to a
374
+ block, including a `Promise.all` fan-out where each task declares before its
375
+ first `await`. The contract
376
+ (`contracts/rag_context.v1.schema.json`) is vendored byte-for-byte from the
377
+ gateway repo, digest-pinned in `test/contract.test.ts` and held to LF by
378
+ `.gitattributes`; the caps come from it (64 documents, 2048-character previews,
379
+ 8 declarations, newest kept).
380
+
381
+ Sibling of the Python SDK's `2c9c36e` and `12b6156`, with two differences that
382
+ are Node's, not ours, and are measured rather than assumed:
383
+
384
+ - **LCEL isolates its steps, as Python's does.** An `AsyncLocalStorage.enterWith`
385
+ from `handleRetrieverEnd` is invisible to the `llm` step and to the caller.
386
+ Worse than Python's, in fact: LangChain JS dispatches handlers through
387
+ `consumeCallback`, which either wraps them in `asyncLocalStorage.run(undefined,
388
+ …)` or defers them onto a `p-queue` — both of which discard the write. So the
389
+ collector wraps `CallbackManager` itself: capture at
390
+ `CallbackManagerForRetrieverRun.handleRetrieverEnd` (inline, ordering
391
+ guaranteed) and delivery at `CallbackManager.handleChatModelStart` (inline, in
392
+ the model step's own context). `install()` is one line and needs nothing passed
393
+ to `invoke()`.
394
+ - **A retriever invoked outside any chain is declaration-only.** Its run has no
395
+ parent to associate a later model call with, and three separate context seams
396
+ were measured not to reach the caller. A prototype wrap that did reach the
397
+ caller was rejected for handing eight concurrent tasks each other's documents.
398
+
399
+ ### Added — the joiner, on every client that offers a `fetch`
400
+
401
+ `withRetrievalJoiner()` wraps a `fetch` and attaches the carried declaration to
402
+ the outgoing JSON body. It is supplied automatically by
403
+ `createShashuLangChainConfig()`, `createShashuAnthropicConfig()`,
404
+ `createShashuOpenAIOptions()` and `new Shashu()`. With an empty bus it
405
+ forwards the caller's own `input`/`init` object references untouched. An explicit
406
+ `rag_context` on the body always wins. The bus is emptied the moment it is
407
+ written to a request, so declaration N never reaches request N+1.
408
+
409
+ **`createShashuGeminiConfig()` is the exception and is documented as such.**
410
+ `@google/generative-ai`'s `RequestOptions` carries `timeout`, `apiVersion`,
411
+ `apiClient`, `baseUrl` and `customHeaders` and nothing else; a `fetch` put in
412
+ that bag is ignored and the SDK calls the global one. That path is
413
+ declaration-only, and `test/conformance/seams.test.ts` asserts it.
414
+
415
+ ### Changed — the LangChain callback
416
+
417
+ `ShashuLangChainCallback` no longer injects into
418
+ `invocationParams.extra_body`, which never reached an LCEL chain. It is now the
419
+ presence handler `install()` registers so a `CallbackManager` exists at all
420
+ (`CallbackManager.configure()` returns `undefined` for a chain invoked with no
421
+ callbacks, and then nothing can be observed). `lcDocumentsToRagContext()` is
422
+ unchanged and still exported.
423
+
424
+ ### Added — CI
425
+
426
+ This repository had no test workflow: `npm-publish.yml` ran the gates, but only
427
+ on a `v*` tag push, so nothing in a pull request was ever checked.
428
+ `.github/workflows/ci.yml` runs type-check, build and the test suite (Node 20 and 22) on a bare `pull_request:` — no `paths:` filter, no `branches:` filter, no
429
+ job-level `if:`, each of which produces a check-run indistinguishable from a
430
+ pass. Nothing is marked required; `main` is unprotected on this repository, and
431
+ adding protection is a separate change.
432
+
433
+ ## [2.0.0] — 2026-09-05
434
+
435
+ > **Why a major bump.** Two breaking changes, and both are the point of the
436
+ > release. A process that never configured a gateway address used to work — it
437
+ > silently sent its prompts to a vendor-branded host — and now throws. The
438
+ > `DEFAULT_GATEWAY_URL` export that held that host is gone.
439
+
440
+ Sibling of the Python SDK's `b3a92fb`, which made the same change there. The
441
+ Python `trustgate/_config.py` is the reference this implementation matches,
442
+ down to the error wording.
443
+
444
+ ### Removed — the default gateway host, at all seven sites
445
+
446
+ SHASHU is self-hosted. The operator's gateway is on their network, under
447
+ their name. An SDK that falls back to a vendor hostname when nobody configured
448
+ one does not fail — it succeeds, at the wrong destination, and the operator has
449
+ no signal that it happened. That fallback was present at **seven** places:
450
+
451
+ | Site | Was |
452
+ | ------------------------------- | ----------------------------------------- |
453
+ | `new Shashu()` | `baseUrl` ?? env ?? default host |
454
+ | `tracer` (constructor) | env ?? default host |
455
+ | `createShashuAnthropicConfig()` | option ?? env ?? default host |
456
+ | `createShashuGeminiConfig()` | option ?? env ?? default host |
457
+ | `createShashuLangChainConfig()` | option ?? env ?? default host |
458
+ | `createShashuOpenAIOptions()` | option ?? env ?? default host |
459
+ | `types.ts` | the `DEFAULT_GATEWAY_URL` constant itself |
460
+
461
+ All six call sites now route through **one** helper (`src/config.ts`), rather
462
+ than six copies of the same expression that had already drifted — only the
463
+ client guarded `typeof process !== "undefined"`; the other five would throw in
464
+ an edge runtime. Resolution is now, everywhere:
465
+
466
+ **explicit `baseUrl` option → `TRUSTGATE_BASE_URL` → `ShashuConfigError`.**
467
+
468
+ A blank or whitespace-only env var counts as unset. Trailing slashes are still
469
+ stripped.
470
+
471
+ ### Removed — `DEFAULT_GATEWAY_URL` (breaking)
472
+
473
+ The constant is no longer exported from the package root.
474
+
475
+ **Deleted rather than deprecated.** A deprecation notice does not stop
476
+ `new Shashu({ baseUrl: DEFAULT_GATEWAY_URL })` from compiling and running, so
477
+ keeping the export would keep the exact string this release exists to remove
478
+ available to consumers — and it would keep it in the shipped bundle, which is
479
+ the thing being removed. With no consumer left inside the SDK it would also be
480
+ dead code. The behaviour change above is breaking on its own, so removing the
481
+ export costs no additional version increment.
482
+
483
+ If you were importing it, replace it with your own gateway address — passed as
484
+ `baseUrl` or set as `TRUSTGATE_BASE_URL`.
485
+
486
+ ### Added — `ShashuConfigError`
487
+
488
+ ```ts
489
+ import { ShashuConfigError } from '@trustgateai/sdk';
490
+ ```
491
+
492
+ A `ShashuError` subclass, so existing `catch (e) { e instanceof ShashuError }`
493
+ code already sees it. It is the odd one out in `exceptions.ts`: every other class
494
+ there is HTTP-status shaped and describes a response, while this one is thrown
495
+ before any request. Its `status` is **`0`** — not an HTTP status, but the honest
496
+ statement that nothing was sent.
497
+
498
+ Its message names the environment variable, the option and the entry point, and
499
+ deliberately names **no hostname**: there is no address to suggest.
500
+
501
+ ### Added — `TRUSTGATE_DISABLE`
502
+
503
+ Set `TRUSTGATE_DISABLE=1` (or `true` / `yes` / `on`, any case) to make the SDK a
504
+ no-op without a code change, matching the Python SDK. The four middleware
505
+ helpers then return `{}` and throw nothing even with no address configured —
506
+ your provider client keeps its own endpoint, its own credential and no Shashu
507
+ headers, which is exactly what Python's patchers do when disabled. The tracer
508
+ records and flushes no spans, while still maintaining trace context so an app
509
+ reading `tracer.traceId` keeps working.
510
+
511
+ It does **not** disable `new Shashu({...})`, matching Python: that client
512
+ exists only to call your gateway, so there is nothing for it to no-op into.
513
+
514
+ ### Changed — middleware return types (breaking)
515
+
516
+ `baseURL` / `baseUrl` and `apiKey` are now optional on the four middleware
517
+ return types, because `{}` is what a disabled SDK returns. Code that read
518
+ `config.baseURL` as a `string` needs a null check.
519
+
520
+ ### Changed — `tracer.gatewayUrl` is `string | undefined` (breaking)
521
+
522
+ The tracer resolves its address **optionally**, unlike every other entry point.
523
+ It is constructed when the module is imported (`export const tracer = new Tracer()`),
524
+ so throwing there would make `import '@trustgateai/sdk'` fail for anyone who has
525
+ not set the variable — a far worse failure than the one being fixed. Unconfigured,
526
+ it holds no address and posts no span telemetry. Same shape as the Python SDK's
527
+ telemetry path.
528
+
529
+ ### Tests
530
+
531
+ `test/config.test.ts` — 62 cases: the loud failure and its wording at each of the
532
+ five requiring entry points, resolution order at each, the tracer's optional
533
+ path, the kill switch, and a repo-wide assertion that the vendor hostname appears
534
+ in no runtime code path (it states its own denominator, so a green result cannot
535
+ be silence). `test/setup.ts` makes any `fetch` or socket connect from any test in
536
+ the suite an immediate failure, so a regression that resolves to a host cannot
537
+ quietly succeed against a real gateway.
538
+
539
+ Both directions were proven: reintroducing the fallback in `requireBaseUrl`
540
+ fails 19 of them, and reintroducing it in the tracer fails 3.
541
+
542
+ ## [1.8.0] — 2026-09-01
543
+
544
+ > **Why a minor bump and not a patch.** A patch release announces "nothing
545
+ > observable changed", and that is not true here: `ShashuBudgetExceededError`
546
+ > is no longer thrown, the 401 documentation was inverted, the `/budget/i`
547
+ > dispatch is gone from the shipped bundles, the retry policy now declines a
548
+ > status it used to accept, and outgoing header NAMES change case in managed
549
+ > runtimes. One `instanceof` check can stop matching. The version number says so.
550
+
551
+ **Three of these are wrong-since-`1.6.0`, published to npm on 2026-05-29** — 95
552
+ days. One field the SDK advertised has been `undefined` that whole time, one
553
+ class of refusal has been misclassified, and one kind of 429 has been retried in
554
+ a way that made it worse. If you wrote error handling against this SDK, read
555
+ _[If you built against the old behaviour](#if-you-built-against-the-old-behaviour)_
556
+ below.
557
+
558
+ Error-contract corrections. Everything below was verified against
559
+ `sdks/e2e/capture_error_contract.py` in the trustgate-ai repo, which drives a
560
+ live gateway and records what it actually sends. Nothing here is asserted from
561
+ reading gateway source. Sibling of the Python SDK 0.10.0 change.
562
+
563
+ ### Fixed — `scope` and `retry_after_seconds` were read one level too shallow
564
+
565
+ The 429 dispatch read `error.scope` and `error.retry_after_seconds`. The gateway
566
+ nests both under **`error.details.error`**: the rate limiter hands FastAPI a dict
567
+ detail and the gateway's `HTTPException` handler repackages any dict detail
568
+ there. Captured body:
569
+
570
+ ```json
571
+ {
572
+ "error": {
573
+ "message": "error",
574
+ "type": "invalid_request_error",
575
+ "param": null,
576
+ "code": "429",
577
+ "details": {
578
+ "error": {
579
+ "type": "rate_limit_exceeded",
580
+ "scope": "agent",
581
+ "retry_after_seconds": 1,
582
+ "message": "Rate limit exceeded (agent). Retry after 1 second(s)."
583
+ }
584
+ }
585
+ },
586
+ "choices": []
587
+ }
588
+ ```
589
+
590
+ Measured against a live gateway before this change:
591
+
592
+ - **`ShashuRateLimitError.scope` was `undefined` on every rate-limit
593
+ rejection.** Nothing else populated it — a field the SDK advertised and never
594
+ filled.
595
+ - `retryAfterSeconds` looked correct only by luck: the body read returned
596
+ `undefined` and the `Retry-After` header fallback supplied the value. It now
597
+ comes from the captured field, with the header still used as a fallback.
598
+ - **`err.message` was the literal string `"error"`.** The outer `error.message`
599
+ on a token-bucket rejection is that literal; the readable sentence is inside
600
+ the detail, and is now what the error carries.
601
+
602
+ ### Changed — 403 is no longer split by matching words in the message
603
+
604
+ `ShashuBudgetExceededError` was thrown when `/budget/i` matched the 403
605
+ message. That is guessing from prose: measured before this change, a policy
606
+ denial worded _"Access Denied: this agent has no budget headroom for that
607
+ route."_ was thrown as a budget error. It would equally miss a real budget denial
608
+ the moment someone reworded the message.
609
+
610
+ The gateway sends **no** discriminator — every 403 it raises carries an identical
611
+ `{type: "invalid_request_error", code: "403"}` envelope — so the split cannot be
612
+ made correctly and is gone.
613
+
614
+ Dispatch now keys on **`error.code`**, the one field the gateway populates
615
+ consistently (the HTTP status as a string), falling back to the transport status
616
+ when the body omits it — which the 500 crash handler and the Anthropic-shaped
617
+ `/v1/messages` envelope both do. Both fallbacks are covered by tests.
618
+
619
+ **Breaking for one narrow case.** `ShashuBudgetExceededError` is still
620
+ exported and still extends `ShashuPermissionError`, so imports and
621
+ `catch (e) { e instanceof ShashuPermissionError }` are unaffected — but
622
+ nothing throws it any more. Code that checks _only_ for the budget subclass will
623
+ now see `ShashuPolicyViolation`. Check the parent to cover both. The class
624
+ becomes reachable again if the gateway ships a real discriminator (ticket
625
+ [`TRUSTGATE-403-DISCRIMINATOR`](https://github.com/aisquad001/trustgate-ai/issues/736)).
626
+
627
+ ### Fixed — a 401 was documented as the gateway's own auth failure
628
+
629
+ The module header mapped `401 -> type="authentication_error"`. That is backwards.
630
+ The gateway's own agent-key failure sends `type="invalid_request_error"` with
631
+ message `"Invalid TrustGate API Key"` (or `"Not authenticated"`, plus a
632
+ `WWW-Authenticate: Bearer` header). Both captured.
633
+
634
+ `authentication_error` is what a **provider pass-through** carries: the gateway's
635
+ own stored provider credential was rejected upstream, and the message is prefixed
636
+ `TrustGate Provider Error:`. The caller's `tg_sk_` key is fine in that case and
637
+ rotating it fixes nothing — a gateway operator has to replace the provider
638
+ secret. The old header pointed every reader at the wrong credential. The same
639
+ applies to 403 (`ProviderPermissionError`), 404, 429 and the 5xx family.
640
+
641
+ - New: **`ShashuAuthenticationError.isProviderPassthrough`** — reads
642
+ `error.type`, falling back to the message prefix, so the two cases can be told
643
+ apart in code rather than by eye.
644
+ - Also corrected: there is no `"provider_error"` error type. Provider failures
645
+ carry the gateway's own provider-error class name (`ProviderServerError`,
646
+ `ProviderModelNotFoundError`, …). The dead `type === "provider_error"`
647
+ dispatch condition is removed.
648
+
649
+ ### Fixed — a 429 the gateway marked permanent was retried, and made worse
650
+
651
+ The retry policy treated 429 as categorically retryable. The gateway returns 429
652
+ for two unrelated reasons:
653
+
654
+ - the **token bucket** sends `Retry-After` and `retry_after_seconds`. It is
655
+ telling you when to come back — retryable, at that time.
656
+ - the **identical-request breaker** (the same body repeated inside one trace id)
657
+ sends **no** `Retry-After` and no detail. Retrying it was actively harmful: the
658
+ gateway increments the breaker's counter on every hit and refreshes its
659
+ 60-second window from the last one, so the SDK held the caller inside the block
660
+ it was trying to escape. Measured before this change: **3 gateway calls** for
661
+ one caller request — the original plus two backoff retries, each one extending
662
+ the block.
663
+
664
+ The rule is now **retry a refusal only when the gateway named a time to come
665
+ back** — `gatewayRetryAfter()` returns `undefined` when it did not, and
666
+ `undefined` is a decision, not a missing value. Status alone no longer authorizes
667
+ a retry. Measured after: **1 gateway call**.
668
+
669
+ - New: `gatewayRetryAfter(res, parsedBody)`, exported from the package root.
670
+ - The retry loop reads the body from `res.clone()`, so a 429 the caller receives
671
+ is still readable — covered by a test.
672
+ - This also declines to retry a provider rate limit passed through from upstream,
673
+ which carries no retry time either. Deliberate, and consistent with 5xx being
674
+ off by default: by the time a provider error reaches you, the gateway has
675
+ already spent its own three attempts on it.
676
+
677
+ ### Fixed — header names were uppercase inside GitHub Actions, n8n and Vercel
678
+
679
+ `buildContextHeaders()` built its metadata header names straight from
680
+ environment-variable names, so a process running in a managed environment sent
681
+ keys like `x-trustlog-GITHUB-ACTION`, `x-trustlog-N8N-WORKFLOW-ID` or
682
+ `x-trustlog-VERCEL-URL`. Every header name is now lowercased on the way out,
683
+ matching the Python SDK, which has always done this in both of its header
684
+ builders.
685
+
686
+ **This is a correctness fix, not cosmetics.** HTTP/2 requires header field names
687
+ to be lowercase and treats a request carrying an uppercase one as **malformed**
688
+ (RFC 9113 §8.2.1), and the gateway parses these names literally.
689
+
690
+ **What changes for you:** if you run this SDK inside GitHub Actions, n8n or
691
+ Vercel, the `x-trustlog-*` metadata header **names** change case — six of them
692
+ under GitHub Actions, measured. Values are untouched, and no header is added or
693
+ removed. Nothing changes at all for a local process or an unmanaged runtime,
694
+ where the metadata keys were already lowercase. If you have gateway-side rules,
695
+ log queries or dashboards matching those names case-sensitively, they need the
696
+ lowercase form.
697
+
698
+ The bug dates to `dd7a33e` (2026-02-13). The test that catches it was written on
699
+ 2026-06-22 and had been failing ever since — invisibly, because this repository
700
+ had no CI until 1.8.0 added a publish pipeline, whose first run caught it.
701
+
702
+ ### Tests
703
+
704
+ Bodies now come from `test/captured.ts` — verbatim harness recordings, one
705
+ constant per captured scenario. Stubbed `fetch` returns whatever it is handed,
706
+ which is exactly how the three wrong shapes above stayed green for months.
707
+
708
+ **Not covered, and deliberately so:** provider pass-throughs for 401 / 403 / 429
709
+ and the whole 5xx family. The harness cannot produce them without a deliberately
710
+ broken or throttled provider credential, so there is no captured body to assert
711
+ and no test pretending otherwise. The 5xx retry tests assert call counts and
712
+ sleeps only, never an envelope; `isProviderPassthrough` has negative coverage
713
+ only (captured gateway 401s, asserting `false`).
714
+
715
+ ### If you built against the old behaviour
716
+
717
+ **1. Stop catching `ShashuBudgetExceededError` on its own.** It is still
718
+ exported and still extends `ShashuPermissionError`, so imports keep working —
719
+ but nothing throws it any more. Since 1.6.0 it was thrown whenever the 403
720
+ message happened to match `/budget/i`, which caught ordinary policy denials and
721
+ would have missed a reworded budget denial. Check the parent:
722
+
723
+ ```ts
724
+ catch (e) {
725
+ if (e instanceof ShashuPermissionError) { /* policy AND budget */ }
726
+ }
727
+ ```
728
+
729
+ This is the one source-compatible break in the release. An
730
+ `instanceof ShashuBudgetExceededError` check will stop matching.
731
+
732
+ **2. `err.scope` works now — and if you logged it, your logs say `undefined`.**
733
+ It was read from `error.scope`, which the gateway has never populated; the real
734
+ value is at `error.details.error.scope`. Every rate-limit rejection this SDK
735
+ threw since 1.6.0 carried `scope === undefined`, so any dashboard or alert keyed
736
+ on tenant-vs-agent rate limiting has been blind. It now reports `"tenant"`,
737
+ `"agent"` or `"tpm"`. Nothing to change in your code — but re-read any conclusion
738
+ you drew from that field.
739
+
740
+ **3. `err.message` on a 429 was the literal string `"error"`.** The readable
741
+ sentence lives in the nested detail and is now what the error carries. If you
742
+ matched on the message text, that match was against `"error"`.
743
+
744
+ **4. If you disabled retries because they made 429s worse, re-enable them.**
745
+ The gateway sends two unrelated 429s. The token bucket names a retry time; the
746
+ identical-request breaker does not, and refreshes its 60-second window on every
747
+ hit — so the old policy's backoff retries held you inside the block. Retry now
748
+ happens only when the gateway named a time to come back, via the newly exported
749
+ `gatewayRetryAfter()`. Measured: 3 gateway calls for one caller request before,
750
+ 1 after.
751
+
752
+ **5. A 401 does not mean your API key is wrong.** The module header mapped
753
+ `401 -> type="authentication_error"`; backwards. Your own key failing sends
754
+ `type="invalid_request_error"` with `"Invalid TrustGate API Key"`.
755
+ `authentication_error` means the **gateway's stored provider credential** was
756
+ rejected upstream — rotating your `tg_sk_` key fixes nothing, an operator has to
757
+ replace the provider secret. Use the new
758
+ `ShashuAuthenticationError.isProviderPassthrough` to tell them apart before
759
+ sending a user to regenerate a key that was never the problem.
760
+
761
+ **6. If you read the response body of a 429 after a retry**, it still works —
762
+ the retry loop now reads via `res.clone()`, so the body the caller finally
763
+ receives is unconsumed. Covered by a test.
764
+
765
+ ## [1.7.2] — 2026-07-30
766
+
767
+ Wire-parity fixes vs the Python SDK reference (`trustgate` `context.py`).
768
+
769
+ ### Fixed
770
+
771
+ - **`x-trustgate-parent-id` no longer equals `x-trustgate-span-id`.** The header
772
+ block set both to the current span's id, so every span reported itself as its
773
+ own parent on the wire. `x-trustgate-parent-id` now carries the REAL parent
774
+ span id via the new `tracer.parentSpanId` getter — `""` for a root span
775
+ (Python parity).
776
+ - **A trace id is now ALWAYS emitted at origin.** With no active span and no
777
+ captured A2A flow, no `x-trustgate-trace-id` was emitted at all. Origin now
778
+ resolves one mirroring Python `_get_trace_id()`: `N8N_EXECUTION_ID` →
779
+ `GITHUB_RUN_ID` → `CI_PIPELINE_ID` (when `GITLAB_CI` is set) → a fresh UUID.
780
+ The mid-flow (`isA2aHop`) and in-span branches are unchanged.
781
+
782
+ ### Added
783
+
784
+ - `tracer.parentSpanId` — the current span's parent span id (`undefined` at
785
+ origin or for a root span).
786
+
787
+ ## [1.7.1] — 2026-06-22
788
+
789
+ ### Fixed
790
+
791
+ - **Package entry points now resolve under ESM** (long-standing packaging bug, present
792
+ since ≤1.4.0). With `"type": "module"` the build emits `dist/index.js` (ESM) and
793
+ `dist/index.cjs` (CJS), but `main` / `module` / `exports` pointed `import` at a
794
+ non-existent `dist/index.mjs` and `require` at the ESM `dist/index.js`. `import` from
795
+ an ESM project therefore threw `ERR_MODULE_NOT_FOUND`. The `exports` map (root + all
796
+ middleware subpaths), `main`, and `module` are corrected to the emitted files
797
+ (`import` → `.js`, `require` → `.cjs`). No source/behavior change.
798
+
799
+ ## [1.7.0] — 2026-06-22
800
+
801
+ Mirrors the Python SDK v0.9.1 — agent-to-agent (A2A) flow propagation with the
802
+ locked ADR-007 §4.1 caller semantics.
803
+
804
+ ### Added
805
+
806
+ - **A2A inbound-capture + outbound propagation.** When your agent is SERVING a
807
+ request, capture the inbound flow so a downstream call through the SDK PROPAGATES
808
+ it (one lineage / one session across hops) instead of minting a fresh trace per process.
809
+ - `captureIncoming(headers)` and the scoped `tracer.incoming(headers, fn)` read
810
+ `x-trustgate-trace-id` / `-session-id` / `-hop-depth` **and `-caller-agent-id`**
811
+ (the upstream invoker) into the `AsyncLocalStorage` tracer (case-insensitive;
812
+ plain objects, `Headers`, `Map`, or pair-arrays).
813
+ - The outbound **gateway** call propagates the captured trace (minted only at
814
+ origin), and attaches `x-trustgate-session-id`, `x-trustgate-hop-depth` (inbound+1),
815
+ and `x-trustgate-caller-agent-id` = **the FORWARDED inbound caller** — the upstream
816
+ invoker, NEVER this agent's own id (so the gateway records the real invoker→callee
817
+ edge, not a self-edge). Origin / caller-stripped ⇒ the caller header is omitted.
818
+ - `buildInvocationHeaders({ callerAgentId })` (and `Shashu.buildInvocationHeaders()`,
819
+ which uses the client's cached self-id) build the lineage headers for the **invoking**
820
+ side — the one place caller = self: the message this agent sends to a downstream agent.
821
+ - `Shashu` gained an `agentId` option; the client caches this agent's id from each
822
+ gateway response's `x-trustgate-agent-id` header (incl. 4xx) for use as the invocation caller.
823
+
824
+ ### Notes
825
+
826
+ - **Origin (non-A2A) behavior is unchanged** — no A2A headers are emitted unless an inbound
827
+ flow was captured. This release corrects the caller semantics to ADR-007 §4.1 (matching the
828
+ shared SDK wire-contract and the Python 0.9.1 reference).
829
+
830
+ ## [1.6.0] — 2026-05-28
831
+
832
+ Mirrors the Python SDK v0.8.0 (typed exceptions + conservative retries).
833
+
834
+ ### Added
835
+
836
+ - **Typed exception hierarchy** (`src/exceptions.ts`), mapped to the error bodies
837
+ the gateway actually returns. `ShashuError` remains the base (still exported
838
+ from the same path), so existing `catch (e) { e instanceof ShashuError }`
839
+ keeps working — every typed error is a subclass:
840
+ - `ShashuAuthenticationError` (401), `ShashuBadRequestError` (400),
841
+ `ShashuContextWindowExceeded` (400), `ShashuRateLimitError` (429 —
842
+ with `.scope` and `.retryAfterSeconds`), `ShashuPermissionError` (403)
843
+ with `ShashuBudgetExceededError` and `ShashuPolicyViolation` under it,
844
+ `ShashuProviderError` (502/503/504), and `ShashuContentFilterError`.
845
+ - **Conservative client-side retries** (`src/retry.ts`, `RetryPolicy`). Defaults:
846
+ retry connection errors + HTTP 429 (honoring `Retry-After`), `maxRetries: 2`,
847
+ exponential backoff. **5xx OFF by default** (the gateway already retries
848
+ providers). Configure via `new Shashu({ retryPolicy: {...} })` or disable
849
+ with `retryPolicy: null`.
850
+
851
+ ### Changed (behavior — why this is a minor bump)
852
+
853
+ - **`client.fetch()` now throws typed exceptions on all non-2xx** responses
854
+ (previously it only threw on 403 and returned the `Response` for other errors).
855
+ - **A 200 with `finish_reason="content_filter"` now throws
856
+ `ShashuContentFilterError`** (detected via a non-consuming `Response.clone()`
857
+ peek, so the returned `Response` body is still readable). Previously a
858
+ content-filtered response passed through silently.
859
+
860
+ ### Backwards compatibility
861
+
862
+ - `ShashuError` keeps its import path and `(message, status, body)` constructor
863
+ (a 4th optional `details` argument was added). All new errors subclass it.
864
+
865
+ ### Known limitations
866
+
867
+ - **403 budget-vs-policy split is best-effort** (matches `/budget/i` in the
868
+ message) because every soft-block 403 shares
869
+ `{type:"invalid_request_error", code:"403"}`. Replaced once the gateway emits a
870
+ stable discriminator (ticket `TRUSTGATE-403-DISCRIMINATOR`).
871
+ - Streaming (`fetchStream`) remains inert against the current gateway (it
872
+ force-buffers chat responses and emits no chat SSE regardless of the `stream`
873
+ flag or DLP settings). `fetchStream` now carries a NOTICE in its docstring and
874
+ logs a one-time `console.warn` on first use; it degrades to the buffered JSON
875
+ response. The method is retained (not removed) for forward compatibility once
876
+ gateway streaming lands.
877
+
878
+ ### Dev
879
+
880
+ - Added `vitest` and `npm test` / `npm run test:watch`. Tests mock global `fetch`.