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