@shashu-ai/sdk 1.2.0 → 1.3.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 +16 -0
- package/README.md +36 -5
- package/package.json +2 -2
- package/dist/_joiner-D_FGAaoc.d.cts +0 -38
- package/dist/_joiner-D_FGAaoc.d.ts +0 -38
- package/dist/chunk-CWC6GQTL.js +0 -800
- package/dist/chunk-K4ZIXS2U.js +0 -40
- package/dist/chunk-MLFWJAEH.js +0 -74
- package/dist/chunk-MZGHCDWX.js +0 -530
- package/dist/chunk-TI45NK2R.js +0 -71
- package/dist/chunk-YSAQRZFP.js +0 -343
- package/dist/index.cjs +0 -2580
- package/dist/index.d.cts +0 -748
- package/dist/index.d.ts +0 -748
- package/dist/index.js +0 -974
- package/dist/langchain-CoNoZ_vQ.d.cts +0 -322
- package/dist/langchain-D9Xo9IMm.d.ts +0 -322
- package/dist/middleware/anthropic.cjs +0 -930
- package/dist/middleware/anthropic.d.cts +0 -49
- package/dist/middleware/anthropic.d.ts +0 -49
- package/dist/middleware/anthropic.js +0 -10
- package/dist/middleware/google.cjs +0 -530
- package/dist/middleware/google.d.cts +0 -71
- package/dist/middleware/google.d.ts +0 -71
- package/dist/middleware/google.js +0 -9
- package/dist/middleware/langchain.cjs +0 -1342
- package/dist/middleware/langchain.d.cts +0 -3
- package/dist/middleware/langchain.d.ts +0 -3
- package/dist/middleware/langchain.js +0 -22
- package/dist/middleware/vercel-ai.cjs +0 -927
- package/dist/middleware/vercel-ai.d.cts +0 -70
- package/dist/middleware/vercel-ai.d.ts +0 -70
- package/dist/middleware/vercel-ai.js +0 -10
- package/dist/types-BQVfxZJP.d.cts +0 -448
- package/dist/types-BQVfxZJP.d.ts +0 -448
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ documented here. This project adheres to [Semantic Versioning](https://semver.or
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [1.3.0] — 2026-11-27
|
|
9
|
+
|
|
10
|
+
Changed: trace ids the SDK creates are now the 32-character standard form
|
|
11
|
+
(lowercase hex, no dashes), the form the gateway stores, so an id you read from
|
|
12
|
+
the SDK finds the same trace in SHASHU. A trace id you pass in is still sent
|
|
13
|
+
unchanged.
|
|
14
|
+
|
|
15
|
+
Fixed: the SDK installs next to the Vercel AI SDK (`ai`) 6 and 7. It still works
|
|
16
|
+
with 3, 4 and 5.
|
|
17
|
+
|
|
18
|
+
Fixed: `fetchStream` no longer warns that streaming is unsupported. The gateway
|
|
19
|
+
streams; the README's "Streaming (SSE)" section says how.
|
|
20
|
+
|
|
21
|
+
Docs: "One trace for a run of calls" explains how to keep several calls in one
|
|
22
|
+
trace with `tracer.span()`. Calls outside a span still get a trace each.
|
|
23
|
+
|
|
8
24
|
## [1.2.0] — 2026-11-26
|
|
9
25
|
|
|
10
26
|
BREAKING: framework state keys are now `shashu_session_id` / `shashu_trace_id`.
|
package/README.md
CHANGED
|
@@ -89,12 +89,12 @@ const res = await client.fetch('/v1/chat/completions', {
|
|
|
89
89
|
body: JSON.stringify({ model: 'gpt-4', messages: [...] }),
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
-
//
|
|
92
|
+
// Streaming (server-sent events)
|
|
93
93
|
const streamRes = await client.fetchStream('/v1/chat/completions', {
|
|
94
94
|
method: 'POST',
|
|
95
95
|
body: JSON.stringify({ model: 'gpt-4', messages: [...], stream: true }),
|
|
96
96
|
});
|
|
97
|
-
//
|
|
97
|
+
// Read streamRes.body (a ReadableStream of SSE events) as usual
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
## Configuring the gateway address
|
|
@@ -213,9 +213,28 @@ const ctx = getWorkflowContextFromEnv();
|
|
|
213
213
|
// { source: 'n8n', workflow_id: '...', execution_id: '...', metadata: {...} }
|
|
214
214
|
```
|
|
215
215
|
|
|
216
|
+
## One trace for a run of calls
|
|
217
|
+
|
|
218
|
+
Each call made outside a span starts its own trace. To keep a run of calls (a
|
|
219
|
+
conversation, an agent run) in one trace, make them inside `tracer.span()`:
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
import { tracer } from '@shashu-ai/sdk';
|
|
223
|
+
|
|
224
|
+
await tracer.span('support-conversation', async () => {
|
|
225
|
+
await client.fetch('/v1/chat/completions', { method: 'POST', body: turn1 });
|
|
226
|
+
await client.fetch('/v1/chat/completions', { method: 'POST', body: turn2 });
|
|
227
|
+
});
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Every call inside the callback sends the same `x-shashu-trace-id`. Trace ids the
|
|
231
|
+
SDK creates are 32 lowercase hex characters. A trace id you bring in, for
|
|
232
|
+
example from an incoming request with `tracer.incoming(headers, () => ...)`, is
|
|
233
|
+
sent unchanged.
|
|
234
|
+
|
|
216
235
|
## Middleware: Vercel AI SDK
|
|
217
236
|
|
|
218
|
-
Point the OpenAI provider at Shashu so all calls go through the gateway with workflow context:
|
|
237
|
+
Works with the Vercel AI SDK (`ai`) 3 to 7. Point the OpenAI provider at Shashu so all calls go through the gateway with workflow context:
|
|
219
238
|
|
|
220
239
|
```ts
|
|
221
240
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
@@ -381,8 +400,20 @@ In n8n, set **Send Headers** (or equivalent) to the `headers` array or paste the
|
|
|
381
400
|
|
|
382
401
|
## Streaming (SSE)
|
|
383
402
|
|
|
384
|
-
|
|
385
|
-
|
|
403
|
+
Send `stream: true` in the body and call `client.fetchStream(path, init, options)`.
|
|
404
|
+
The gateway streams the answer back as server-sent events in the chat streaming
|
|
405
|
+
format; read `response.body` with `getReader()` or hand it to your framework.
|
|
406
|
+
|
|
407
|
+
- **Checked first, then streamed.** The gateway inspects the whole answer before
|
|
408
|
+
any of it reaches you, then sends it as a stream of events. The events arrive
|
|
409
|
+
one by one, but the first one arrives only after the model has finished.
|
|
410
|
+
- **A security block is an error, not a broken stream.** Whether the gateway
|
|
411
|
+
blocks the request (for example an injected prompt) or the answer (for
|
|
412
|
+
example a leaked secret), it answers with an error before any event, and
|
|
413
|
+
`fetchStream` throws the typed exception, as `fetch` does:
|
|
414
|
+
`ShashuContentFilterError` (400) or `ShashuPolicyViolation` (403).
|
|
415
|
+
- A refused pass is retried once, before anything is read. A stream is never
|
|
416
|
+
re-sent once it has started.
|
|
386
417
|
|
|
387
418
|
## License
|
|
388
419
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shashu-ai/sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"description": "Node.js client for SHASHU, a self-hosted AI security gateway. Point it at your own gateway; there is no default endpoint.",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"@langchain/core": "^0.3.0 || ^1.0.0",
|
|
90
90
|
"@langchain/openai": "^0.2.0 || ^1.0.0",
|
|
91
|
-
"ai": "^3.0.0 || ^4.0.0 || ^5.0.0"
|
|
91
|
+
"ai": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
92
92
|
},
|
|
93
93
|
"peerDependenciesMeta": {
|
|
94
94
|
"ai": {
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Join the carried retrieval declaration onto the outgoing request.
|
|
3
|
-
*
|
|
4
|
-
* The Python SDK patches its own httpx transport, so it sees every outgoing
|
|
5
|
-
* request whoever made it. Node has no such chokepoint: our own client owns its
|
|
6
|
-
* `fetch`, and the middlewares only RETURN a config object the customer hands to
|
|
7
|
-
* THEIR SDK. What makes this work is that the OpenAI, Anthropic, LangChain and
|
|
8
|
-
* Vercel AI SDKs all accept a `fetch` in exactly that config, so the joiner is
|
|
9
|
-
* supplied there and runs inside the provider client. `@google/generative-ai`
|
|
10
|
-
* does not (its `RequestOptions` carries `timeout`, `apiVersion`, `apiClient`,
|
|
11
|
-
* `baseUrl` and `customHeaders`, and nothing else), so the Gemini path is
|
|
12
|
-
* declaration-only -- see `src/middleware/google.ts`.
|
|
13
|
-
*
|
|
14
|
-
* Four properties it has to hold, in this order:
|
|
15
|
-
*
|
|
16
|
-
* 1. **Zero cost when nothing was retrieved.** The first thing it does is a
|
|
17
|
-
* single `AsyncLocalStorage.getStore()`. With an empty bus it forwards the
|
|
18
|
-
* caller's own `input` and `init` OBJECT REFERENCES untouched, so the bytes
|
|
19
|
-
* on the wire are the bytes the unwrapped client produced -- asserted by
|
|
20
|
-
* reference identity in `test/joiner.test.ts`.
|
|
21
|
-
* 2. **Explicit always wins.** A body already carrying
|
|
22
|
-
* `shashu_metadata.rag_context` is left exactly as the caller built it.
|
|
23
|
-
* The ambient declaration is consumed and discarded, not deferred: a
|
|
24
|
-
* declaration that lost this call must not turn up on the next one.
|
|
25
|
-
* 3. **Snapshot and clear.** The bus is emptied the moment it is written to a
|
|
26
|
-
* request. Retrieval declared for request N never reaches request N+1.
|
|
27
|
-
* 4. **Never corrupt a body it does not understand.** A non-JSON body, a
|
|
28
|
-
* non-object JSON body, or a stream upload is passed through untouched and
|
|
29
|
-
* does NOT consume the bus -- the next real model call still carries the
|
|
30
|
-
* declaration, and a multi-gigabyte file upload does not eat it.
|
|
31
|
-
*
|
|
32
|
-
* Sibling of the Python SDK's `shashu/_joiner.py`.
|
|
33
|
-
*/
|
|
34
|
-
/** The `fetch` shape every provider SDK's option accepts. */
|
|
35
|
-
type FetchLike = (input: any, init?: any) => Promise<Response>;
|
|
36
|
-
declare function withRetrievalJoiner(underlying?: FetchLike): FetchLike;
|
|
37
|
-
|
|
38
|
-
export { type FetchLike as F, withRetrievalJoiner as w };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Join the carried retrieval declaration onto the outgoing request.
|
|
3
|
-
*
|
|
4
|
-
* The Python SDK patches its own httpx transport, so it sees every outgoing
|
|
5
|
-
* request whoever made it. Node has no such chokepoint: our own client owns its
|
|
6
|
-
* `fetch`, and the middlewares only RETURN a config object the customer hands to
|
|
7
|
-
* THEIR SDK. What makes this work is that the OpenAI, Anthropic, LangChain and
|
|
8
|
-
* Vercel AI SDKs all accept a `fetch` in exactly that config, so the joiner is
|
|
9
|
-
* supplied there and runs inside the provider client. `@google/generative-ai`
|
|
10
|
-
* does not (its `RequestOptions` carries `timeout`, `apiVersion`, `apiClient`,
|
|
11
|
-
* `baseUrl` and `customHeaders`, and nothing else), so the Gemini path is
|
|
12
|
-
* declaration-only -- see `src/middleware/google.ts`.
|
|
13
|
-
*
|
|
14
|
-
* Four properties it has to hold, in this order:
|
|
15
|
-
*
|
|
16
|
-
* 1. **Zero cost when nothing was retrieved.** The first thing it does is a
|
|
17
|
-
* single `AsyncLocalStorage.getStore()`. With an empty bus it forwards the
|
|
18
|
-
* caller's own `input` and `init` OBJECT REFERENCES untouched, so the bytes
|
|
19
|
-
* on the wire are the bytes the unwrapped client produced -- asserted by
|
|
20
|
-
* reference identity in `test/joiner.test.ts`.
|
|
21
|
-
* 2. **Explicit always wins.** A body already carrying
|
|
22
|
-
* `shashu_metadata.rag_context` is left exactly as the caller built it.
|
|
23
|
-
* The ambient declaration is consumed and discarded, not deferred: a
|
|
24
|
-
* declaration that lost this call must not turn up on the next one.
|
|
25
|
-
* 3. **Snapshot and clear.** The bus is emptied the moment it is written to a
|
|
26
|
-
* request. Retrieval declared for request N never reaches request N+1.
|
|
27
|
-
* 4. **Never corrupt a body it does not understand.** A non-JSON body, a
|
|
28
|
-
* non-object JSON body, or a stream upload is passed through untouched and
|
|
29
|
-
* does NOT consume the bus -- the next real model call still carries the
|
|
30
|
-
* declaration, and a multi-gigabyte file upload does not eat it.
|
|
31
|
-
*
|
|
32
|
-
* Sibling of the Python SDK's `shashu/_joiner.py`.
|
|
33
|
-
*/
|
|
34
|
-
/** The `fetch` shape every provider SDK's option accepts. */
|
|
35
|
-
type FetchLike = (input: any, init?: any) => Promise<Response>;
|
|
36
|
-
declare function withRetrievalJoiner(underlying?: FetchLike): FetchLike;
|
|
37
|
-
|
|
38
|
-
export { type FetchLike as F, withRetrievalJoiner as w };
|