@shashu-ai/sdk 1.0.0 → 1.1.1

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +18 -18
  3. package/dist/{_joiner-p5LFxJcu.d.cts → _joiner-DGi8GsY7.d.cts} +1 -11
  4. package/dist/{_joiner-p5LFxJcu.d.ts → _joiner-DGi8GsY7.d.ts} +1 -11
  5. package/dist/{chunk-Z6DROYQA.js → chunk-3GAMCQ6R.js} +2 -2
  6. package/dist/{chunk-BEU2UWW3.js → chunk-3JZXUKNA.js} +1 -1
  7. package/dist/{chunk-M4JDSAUC.js → chunk-3X5IUBIA.js} +2 -2
  8. package/dist/{chunk-4CDQ7JMK.js → chunk-F4CXDZQB.js} +113 -11
  9. package/dist/{chunk-5TW3FISD.js → chunk-M7EMWSNS.js} +27 -6
  10. package/dist/{chunk-IQYB5OZ6.js → chunk-TGD6KDWT.js} +33 -53
  11. package/dist/index.cjs +133 -101
  12. package/dist/index.d.cts +30 -30
  13. package/dist/index.d.ts +30 -30
  14. package/dist/index.js +45 -109
  15. package/dist/{langchain-DNOsiRna.d.ts → langchain-DKyrUjk4.d.cts} +11 -11
  16. package/dist/{langchain-xCWwa1Ud.d.cts → langchain-QCATTIR4.d.ts} +11 -11
  17. package/dist/middleware/anthropic.cjs +34 -52
  18. package/dist/middleware/anthropic.d.cts +5 -5
  19. package/dist/middleware/anthropic.d.ts +5 -5
  20. package/dist/middleware/anthropic.js +3 -3
  21. package/dist/middleware/google.cjs +28 -46
  22. package/dist/middleware/google.d.cts +5 -5
  23. package/dist/middleware/google.d.ts +5 -5
  24. package/dist/middleware/google.js +2 -2
  25. package/dist/middleware/langchain.cjs +178 -93
  26. package/dist/middleware/langchain.d.cts +3 -3
  27. package/dist/middleware/langchain.d.ts +3 -3
  28. package/dist/middleware/langchain.js +3 -3
  29. package/dist/middleware/vercel-ai.cjs +34 -52
  30. package/dist/middleware/vercel-ai.d.cts +8 -8
  31. package/dist/middleware/vercel-ai.d.ts +8 -8
  32. package/dist/middleware/vercel-ai.js +3 -3
  33. package/dist/{types-Rs49lJyD.d.ts → types-BLs_TMFv.d.cts} +18 -16
  34. package/dist/{types-Rs49lJyD.d.cts → types-BLs_TMFv.d.ts} +18 -16
  35. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- import { S as ShashuConfig } from '../types-Rs49lJyD.cjs';
2
- import { F as FetchLike } from '../_joiner-p5LFxJcu.cjs';
1
+ import { S as ShashuConfig } from '../types-BLs_TMFv.cjs';
2
+ import { F as FetchLike } from '../_joiner-DGi8GsY7.cjs';
3
3
 
4
4
  /**
5
5
  * Vercel AI SDK middleware: swap the provider to Shashu with one line.
@@ -14,8 +14,8 @@ import { F as FetchLike } from '../_joiner-p5LFxJcu.cjs';
14
14
  * import { createShashuOpenAI } from '@shashu-ai/sdk/middleware/vercel-ai';
15
15
  *
16
16
  * const openai = createShashuOpenAI({
17
- * baseUrl: process.env.TRUSTGATE_BASE_URL!,
18
- * apiKey: process.env.TRUSTGATE_API_KEY,
17
+ * baseUrl: process.env.SHASHU_BASE_URL!,
18
+ * apiKey: process.env.SHASHU_API_KEY,
19
19
  * });
20
20
  *
21
21
  * // Then use `openai` with streamText() as usual — requests go through Shashu.
@@ -30,7 +30,7 @@ interface ShashuOpenAIOptions extends ShashuConfig {
30
30
  }
31
31
  /**
32
32
  * Returns extra headers (lowercase keys) to pass to the Vercel AI SDK OpenAI provider
33
- * so that requests sent to Shashu include workflow context and x-trustgate-source-tool
33
+ * so that requests sent to Shashu include workflow context and x-shashu-source-tool
34
34
  * JSON for Shadow AI detection. Use with createOpenAI({ baseURL, headers: getShashuHeaders() }).
35
35
  */
36
36
  declare function getShashuHeaders(workflowContext?: ShashuConfig['workflowContext'], sessionId?: string, contractVersion?: ShashuConfig['contractVersion']): Record<string, string>;
@@ -44,14 +44,14 @@ declare function getShashuHeaders(workflowContext?: ShashuConfig['workflowContex
44
44
  * import { createShashuOpenAIOptions } from '@shashu-ai/sdk/middleware/vercel-ai';
45
45
  *
46
46
  * const openaiOptions = createShashuOpenAIOptions({
47
- * baseUrl: process.env.TRUSTGATE_BASE_URL!,
48
- * apiKey: process.env.TRUSTGATE_API_KEY,
47
+ * baseUrl: process.env.SHASHU_BASE_URL!,
48
+ * apiKey: process.env.SHASHU_API_KEY,
49
49
  * });
50
50
  *
51
51
  * const openai = createOpenAI(openaiOptions);
52
52
  * // use openai('gpt-4') with streamText()
53
53
  *
54
- * Returns `{}` when TRUSTGATE_DISABLE is set: the provider client is then left
54
+ * Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
55
55
  * exactly as it was — its own endpoint, its own credential, no Shashu context
56
56
  * headers — which is the same no-op the Python SDK's patchers perform. The
57
57
  * caller's tg_sk_ key is deliberately NOT handed back, since it would be sent to
@@ -1,5 +1,5 @@
1
- import { S as ShashuConfig } from '../types-Rs49lJyD.js';
2
- import { F as FetchLike } from '../_joiner-p5LFxJcu.js';
1
+ import { S as ShashuConfig } from '../types-BLs_TMFv.js';
2
+ import { F as FetchLike } from '../_joiner-DGi8GsY7.js';
3
3
 
4
4
  /**
5
5
  * Vercel AI SDK middleware: swap the provider to Shashu with one line.
@@ -14,8 +14,8 @@ import { F as FetchLike } from '../_joiner-p5LFxJcu.js';
14
14
  * import { createShashuOpenAI } from '@shashu-ai/sdk/middleware/vercel-ai';
15
15
  *
16
16
  * const openai = createShashuOpenAI({
17
- * baseUrl: process.env.TRUSTGATE_BASE_URL!,
18
- * apiKey: process.env.TRUSTGATE_API_KEY,
17
+ * baseUrl: process.env.SHASHU_BASE_URL!,
18
+ * apiKey: process.env.SHASHU_API_KEY,
19
19
  * });
20
20
  *
21
21
  * // Then use `openai` with streamText() as usual — requests go through Shashu.
@@ -30,7 +30,7 @@ interface ShashuOpenAIOptions extends ShashuConfig {
30
30
  }
31
31
  /**
32
32
  * Returns extra headers (lowercase keys) to pass to the Vercel AI SDK OpenAI provider
33
- * so that requests sent to Shashu include workflow context and x-trustgate-source-tool
33
+ * so that requests sent to Shashu include workflow context and x-shashu-source-tool
34
34
  * JSON for Shadow AI detection. Use with createOpenAI({ baseURL, headers: getShashuHeaders() }).
35
35
  */
36
36
  declare function getShashuHeaders(workflowContext?: ShashuConfig['workflowContext'], sessionId?: string, contractVersion?: ShashuConfig['contractVersion']): Record<string, string>;
@@ -44,14 +44,14 @@ declare function getShashuHeaders(workflowContext?: ShashuConfig['workflowContex
44
44
  * import { createShashuOpenAIOptions } from '@shashu-ai/sdk/middleware/vercel-ai';
45
45
  *
46
46
  * const openaiOptions = createShashuOpenAIOptions({
47
- * baseUrl: process.env.TRUSTGATE_BASE_URL!,
48
- * apiKey: process.env.TRUSTGATE_API_KEY,
47
+ * baseUrl: process.env.SHASHU_BASE_URL!,
48
+ * apiKey: process.env.SHASHU_API_KEY,
49
49
  * });
50
50
  *
51
51
  * const openai = createOpenAI(openaiOptions);
52
52
  * // use openai('gpt-4') with streamText()
53
53
  *
54
- * Returns `{}` when TRUSTGATE_DISABLE is set: the provider client is then left
54
+ * Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
55
55
  * exactly as it was — its own endpoint, its own credential, no Shashu context
56
56
  * headers — which is the same no-op the Python SDK's patchers perform. The
57
57
  * caller's tg_sk_ key is deliberately NOT handed back, since it would be sent to
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createShashuOpenAIOptions,
3
3
  getShashuHeaders
4
- } from "../chunk-M4JDSAUC.js";
5
- import "../chunk-5TW3FISD.js";
6
- import "../chunk-IQYB5OZ6.js";
4
+ } from "../chunk-3X5IUBIA.js";
5
+ import "../chunk-M7EMWSNS.js";
6
+ import "../chunk-TGD6KDWT.js";
7
7
  export {
8
8
  createShashuOpenAIOptions,
9
9
  getShashuHeaders
@@ -50,8 +50,10 @@ interface RetryPolicy {
50
50
  retryOn5xx: boolean;
51
51
  /** Statuses that are never retried, even if a flag above would allow it. */
52
52
  neverRetryStatus: number[];
53
- /** Ignore the Retry-After header on 429 and use exponential backoff instead. */
53
+ /** Ignore the Retry-After header on 429/503 and use exponential backoff instead. */
54
54
  ignoreRetryAfter: boolean;
55
+ /** Extra wait as a fraction of the chosen delay (0–20% by default). */
56
+ jitterFraction: number;
55
57
  }
56
58
  declare const DEFAULT_RETRY_POLICY: RetryPolicy;
57
59
  /** Resolve a config's retryPolicy: undefined -> default; null -> disabled; object -> merged over defaults. */
@@ -102,18 +104,18 @@ declare const DECISIONS: readonly ["allow", "allow_altered", "not_checked", "blo
102
104
  /** The three where the caller is holding the provider's content. */
103
105
  declare const DELIVERED_DECISIONS: ReadonlySet<string>;
104
106
  /** Top-level on a 200 body; nested INSIDE `error` on an error body. */
105
- declare const BODY_KEY = "trustgate";
106
- declare const HEADER_DECISION = "x-trustgate-decision";
107
- declare const HEADER_CODE = "x-trustgate-code";
108
- declare const HEADER_INSPECTION = "x-trustgate-inspection";
107
+ declare const BODY_KEY = "shashu";
108
+ declare const HEADER_DECISION = "x-shashu-decision";
109
+ declare const HEADER_CODE = "x-shashu-code";
110
+ declare const HEADER_INSPECTION = "x-shashu-inspection";
109
111
  declare const HEADER_SHOULD_RETRY = "x-should-retry";
110
112
  declare const HEADER_REQUEST_ID = "x-request-id";
111
- declare const HEADER_SHASHU_REQUEST_ID = "x-trustgate-request-id";
112
- declare const HEADER_TRACE_ID = "x-trustgate-trace-id";
113
+ declare const HEADER_SHASHU_REQUEST_ID = "x-shashu-request-id";
114
+ declare const HEADER_TRACE_ID = "x-shashu-trace-id";
113
115
  /** Counts only (`total=N;scanned=N;not_inspected=N;blocked=N`), only when one is above zero. */
114
- declare const HEADER_ATTACHMENTS = "x-trustgate-attachments";
116
+ declare const HEADER_ATTACHMENTS = "x-shashu-attachments";
115
117
  /** Counts only (`writes=N;blocked=N;recalls=N;flagged=N`), only when one is above zero. */
116
- declare const HEADER_MEMORY = "x-trustgate-memory";
118
+ declare const HEADER_MEMORY = "x-shashu-memory";
117
119
  /**
118
120
  * What happened to one attached file. A closed set on the gateway; a value
119
121
  * this SDK does not know arrives as `"unknown"`, with the wire string kept on
@@ -202,7 +204,7 @@ interface Decision {
202
204
  readonly retryable: boolean;
203
205
  /** Resolves to the stored audit record. Same value as `x-request-id`. */
204
206
  readonly id: string | undefined;
205
- /** The per-hop request id (`x-trustgate-request-id`), or undefined. */
207
+ /** The per-hop request id (`x-shashu-request-id`), or undefined. */
206
208
  readonly requestId: string | undefined;
207
209
  /** The flow's trace id — the same value as `id`, under its own name. */
208
210
  readonly traceId: string | undefined;
@@ -219,7 +221,7 @@ interface Decision {
219
221
  readonly carrierDisagreement: Record<string, [unknown, unknown]>;
220
222
  /**
221
223
  * What happened to each attached file; undefined when the request had none.
222
- * Read off the body; off the `x-trustgate-attachments` counts when the body
224
+ * Read off the body; off the `x-shashu-attachments` counts when the body
223
225
  * carried no envelope. `attachments.carrier` says which.
224
226
  */
225
227
  readonly attachments: Attachments | undefined;
@@ -284,7 +286,7 @@ declare function isShashuBlock(err: unknown): boolean;
284
286
 
285
287
  /**
286
288
  * Runtime metadata included in every context for parity with the Python SDK.
287
- * Sent in x-trustgate-source-tool and in x-trustgate-meta-* headers.
289
+ * Sent in x-shashu-source-tool and in x-shashu-meta-* headers.
288
290
  */
289
291
  interface RuntimeMetadata {
290
292
  /** SDK version (e.g. "1.0.0"). */
@@ -362,7 +364,7 @@ type Provider = 'openai' | 'anthropic' | 'google';
362
364
  */
363
365
  interface ShashuConfig {
364
366
  /**
365
- * Shashu gateway base URL. Falls back to process.env.TRUSTGATE_BASE_URL.
367
+ * Shashu gateway base URL. Falls back to process.env.SHASHU_BASE_URL.
366
368
  * There is NO default: SHASHU is self-hosted, so an unset address is a
367
369
  * ShashuConfigError, never a vendor host. See ./config.ts.
368
370
  */
@@ -378,7 +380,7 @@ interface ShashuConfig {
378
380
  * This agent's OWN id (ADR-007 §4.1). NOT sent on the gateway call (that FORWARDS the
379
381
  * captured inbound caller); used by `buildInvocationHeaders()` to stamp caller = self when
380
382
  * THIS agent invokes a downstream agent. Seeds the self-id cache, which is then refreshed
381
- * from each gateway response's `x-trustgate-agent-id` header. Advisory lineage only —
383
+ * from each gateway response's `x-shashu-agent-id` header. Advisory lineage only —
382
384
  * NEVER an auth credential.
383
385
  */
384
386
  agentId?: string;
@@ -395,12 +397,12 @@ interface ShashuConfig {
395
397
  /** Extra headers sent with every request */
396
398
  headers?: Record<string, string>;
397
399
  /**
398
- * `trustgate-version`: the contract generation to ask the gateway for.
400
+ * `shashu-version`: the contract generation to ask the gateway for.
399
401
  * Default `DEFAULT_CONTRACT_VERSION` (`"2026-09-01"`, the Python SDK's
400
402
  * value): refusals arrive as errors and the body carries the full decision.
401
403
  * Pass `null` to send no such header — the gateway then serves the account
402
404
  * default, which is the legacy contract unless an operator moved it.
403
- * A `trustgate-version` entry in `headers` wins over this.
405
+ * A `shashu-version` entry in `headers` wins over this.
404
406
  */
405
407
  contractVersion?: string | null;
406
408
  /**
@@ -50,8 +50,10 @@ interface RetryPolicy {
50
50
  retryOn5xx: boolean;
51
51
  /** Statuses that are never retried, even if a flag above would allow it. */
52
52
  neverRetryStatus: number[];
53
- /** Ignore the Retry-After header on 429 and use exponential backoff instead. */
53
+ /** Ignore the Retry-After header on 429/503 and use exponential backoff instead. */
54
54
  ignoreRetryAfter: boolean;
55
+ /** Extra wait as a fraction of the chosen delay (0–20% by default). */
56
+ jitterFraction: number;
55
57
  }
56
58
  declare const DEFAULT_RETRY_POLICY: RetryPolicy;
57
59
  /** Resolve a config's retryPolicy: undefined -> default; null -> disabled; object -> merged over defaults. */
@@ -102,18 +104,18 @@ declare const DECISIONS: readonly ["allow", "allow_altered", "not_checked", "blo
102
104
  /** The three where the caller is holding the provider's content. */
103
105
  declare const DELIVERED_DECISIONS: ReadonlySet<string>;
104
106
  /** Top-level on a 200 body; nested INSIDE `error` on an error body. */
105
- declare const BODY_KEY = "trustgate";
106
- declare const HEADER_DECISION = "x-trustgate-decision";
107
- declare const HEADER_CODE = "x-trustgate-code";
108
- declare const HEADER_INSPECTION = "x-trustgate-inspection";
107
+ declare const BODY_KEY = "shashu";
108
+ declare const HEADER_DECISION = "x-shashu-decision";
109
+ declare const HEADER_CODE = "x-shashu-code";
110
+ declare const HEADER_INSPECTION = "x-shashu-inspection";
109
111
  declare const HEADER_SHOULD_RETRY = "x-should-retry";
110
112
  declare const HEADER_REQUEST_ID = "x-request-id";
111
- declare const HEADER_SHASHU_REQUEST_ID = "x-trustgate-request-id";
112
- declare const HEADER_TRACE_ID = "x-trustgate-trace-id";
113
+ declare const HEADER_SHASHU_REQUEST_ID = "x-shashu-request-id";
114
+ declare const HEADER_TRACE_ID = "x-shashu-trace-id";
113
115
  /** Counts only (`total=N;scanned=N;not_inspected=N;blocked=N`), only when one is above zero. */
114
- declare const HEADER_ATTACHMENTS = "x-trustgate-attachments";
116
+ declare const HEADER_ATTACHMENTS = "x-shashu-attachments";
115
117
  /** Counts only (`writes=N;blocked=N;recalls=N;flagged=N`), only when one is above zero. */
116
- declare const HEADER_MEMORY = "x-trustgate-memory";
118
+ declare const HEADER_MEMORY = "x-shashu-memory";
117
119
  /**
118
120
  * What happened to one attached file. A closed set on the gateway; a value
119
121
  * this SDK does not know arrives as `"unknown"`, with the wire string kept on
@@ -202,7 +204,7 @@ interface Decision {
202
204
  readonly retryable: boolean;
203
205
  /** Resolves to the stored audit record. Same value as `x-request-id`. */
204
206
  readonly id: string | undefined;
205
- /** The per-hop request id (`x-trustgate-request-id`), or undefined. */
207
+ /** The per-hop request id (`x-shashu-request-id`), or undefined. */
206
208
  readonly requestId: string | undefined;
207
209
  /** The flow's trace id — the same value as `id`, under its own name. */
208
210
  readonly traceId: string | undefined;
@@ -219,7 +221,7 @@ interface Decision {
219
221
  readonly carrierDisagreement: Record<string, [unknown, unknown]>;
220
222
  /**
221
223
  * What happened to each attached file; undefined when the request had none.
222
- * Read off the body; off the `x-trustgate-attachments` counts when the body
224
+ * Read off the body; off the `x-shashu-attachments` counts when the body
223
225
  * carried no envelope. `attachments.carrier` says which.
224
226
  */
225
227
  readonly attachments: Attachments | undefined;
@@ -284,7 +286,7 @@ declare function isShashuBlock(err: unknown): boolean;
284
286
 
285
287
  /**
286
288
  * Runtime metadata included in every context for parity with the Python SDK.
287
- * Sent in x-trustgate-source-tool and in x-trustgate-meta-* headers.
289
+ * Sent in x-shashu-source-tool and in x-shashu-meta-* headers.
288
290
  */
289
291
  interface RuntimeMetadata {
290
292
  /** SDK version (e.g. "1.0.0"). */
@@ -362,7 +364,7 @@ type Provider = 'openai' | 'anthropic' | 'google';
362
364
  */
363
365
  interface ShashuConfig {
364
366
  /**
365
- * Shashu gateway base URL. Falls back to process.env.TRUSTGATE_BASE_URL.
367
+ * Shashu gateway base URL. Falls back to process.env.SHASHU_BASE_URL.
366
368
  * There is NO default: SHASHU is self-hosted, so an unset address is a
367
369
  * ShashuConfigError, never a vendor host. See ./config.ts.
368
370
  */
@@ -378,7 +380,7 @@ interface ShashuConfig {
378
380
  * This agent's OWN id (ADR-007 §4.1). NOT sent on the gateway call (that FORWARDS the
379
381
  * captured inbound caller); used by `buildInvocationHeaders()` to stamp caller = self when
380
382
  * THIS agent invokes a downstream agent. Seeds the self-id cache, which is then refreshed
381
- * from each gateway response's `x-trustgate-agent-id` header. Advisory lineage only —
383
+ * from each gateway response's `x-shashu-agent-id` header. Advisory lineage only —
382
384
  * NEVER an auth credential.
383
385
  */
384
386
  agentId?: string;
@@ -395,12 +397,12 @@ interface ShashuConfig {
395
397
  /** Extra headers sent with every request */
396
398
  headers?: Record<string, string>;
397
399
  /**
398
- * `trustgate-version`: the contract generation to ask the gateway for.
400
+ * `shashu-version`: the contract generation to ask the gateway for.
399
401
  * Default `DEFAULT_CONTRACT_VERSION` (`"2026-09-01"`, the Python SDK's
400
402
  * value): refusals arrive as errors and the body carries the full decision.
401
403
  * Pass `null` to send no such header — the gateway then serves the account
402
404
  * default, which is the legacy contract unless an operator moved it.
403
- * A `trustgate-version` entry in `headers` wins over this.
405
+ * A `shashu-version` entry in `headers` wins over this.
404
406
  */
405
407
  contractVersion?: string | null;
406
408
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shashu-ai/sdk",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.1.1",
5
5
  "description": "Node.js client for SHASHU by Trustgate AI, 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",