@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
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { R as RequestOptions, S as ShashuConfig, W as WorkflowContext, a as ShashuError, D as Decision, M as MemoryActivity, N as N8nHeaderSnippet } from './types-Rs49lJyD.js';
2
- export { A as Attachment, b as AttachmentFinding, c as AttachmentState, d as Attachments, B as BODY_KEY, e as DECISIONS, f as DECISION_ALLOW, g as DECISION_ALLOW_ALTERED, h as DECISION_BLOCK, i as DECISION_FAIL, j as DECISION_NOT_CHECKED, k as DECISION_REFUSE, l as DEFAULT_RETRY_POLICY, m as DELIVERED_DECISIONS, H as HEADER_ATTACHMENTS, n as HEADER_CODE, o as HEADER_DECISION, p as HEADER_INSPECTION, q as HEADER_MEMORY, r as HEADER_REQUEST_ID, s as HEADER_SHASHU_REQUEST_ID, t as HEADER_SHOULD_RETRY, u as HEADER_TRACE_ID, v as MemoryItem, P as Provider, w as RetryPolicy, x as RoutePolicy, y as RuntimeMetadata, z as decisionFrom, C as executeWithRetry, E as isShashuBlock, F as resolveRetryPolicy, G as shashuDecision } from './types-Rs49lJyD.js';
3
- import { F as FetchLike } from './_joiner-p5LFxJcu.js';
4
- export { w as withRetrievalJoiner } from './_joiner-p5LFxJcu.js';
5
- export { D as DeclareRetrievalOptions, R as RagContext, a as RagDoc, b as RagSource, S as SOURCES, c as attachRagContext, d as buildRagContext, e as createShashuLangChainConfig, f as declareRetrieval, m as makeRagContext, r as retrievalScope } from './langchain-DNOsiRna.js';
1
+ import { R as RequestOptions, S as ShashuConfig, W as WorkflowContext, a as ShashuError, D as Decision, M as MemoryActivity, N as N8nHeaderSnippet } from './types-BLs_TMFv.js';
2
+ export { A as Attachment, b as AttachmentFinding, c as AttachmentState, d as Attachments, B as BODY_KEY, e as DECISIONS, f as DECISION_ALLOW, g as DECISION_ALLOW_ALTERED, h as DECISION_BLOCK, i as DECISION_FAIL, j as DECISION_NOT_CHECKED, k as DECISION_REFUSE, l as DEFAULT_RETRY_POLICY, m as DELIVERED_DECISIONS, H as HEADER_ATTACHMENTS, n as HEADER_CODE, o as HEADER_DECISION, p as HEADER_INSPECTION, q as HEADER_MEMORY, r as HEADER_REQUEST_ID, s as HEADER_SHASHU_REQUEST_ID, t as HEADER_SHOULD_RETRY, u as HEADER_TRACE_ID, v as MemoryItem, P as Provider, w as RetryPolicy, x as RoutePolicy, y as RuntimeMetadata, z as decisionFrom, C as executeWithRetry, E as isShashuBlock, F as resolveRetryPolicy, G as shashuDecision } from './types-BLs_TMFv.js';
3
+ import { F as FetchLike } from './_joiner-DGi8GsY7.js';
4
+ export { w as withRetrievalJoiner } from './_joiner-DGi8GsY7.js';
5
+ export { D as DeclareRetrievalOptions, R as RagContext, a as RagDoc, b as RagSource, S as SOURCES, c as attachRagContext, d as buildRagContext, e as createShashuLangChainConfig, f as declareRetrieval, m as makeRagContext, r as retrievalScope } from './langchain-QCATTIR4.js';
6
6
  export { ShashuOpenAIOptions, createShashuOpenAIOptions, getShashuHeaders } from './middleware/vercel-ai.js';
7
7
  export { createShashuAnthropicConfig, getAnthropicHeaders } from './middleware/anthropic.js';
8
8
  export { createShashuGeminiConfig, getGeminiHeaders } from './middleware/google.js';
@@ -35,7 +35,7 @@ export { createShashuGeminiConfig, getGeminiHeaders } from './middleware/google.
35
35
  interface AuditConversation {
36
36
  messages?: Record<string, unknown>[];
37
37
  response?: string;
38
- trustgate_metadata?: Record<string, unknown>;
38
+ shashu_metadata?: Record<string, unknown>;
39
39
  /** Free-form passthrough preserved alongside the canonical conversation. */
40
40
  extra?: Record<string, unknown>;
41
41
  }
@@ -51,7 +51,7 @@ interface AuditEventInput {
51
51
  userContext?: Record<string, unknown>;
52
52
  /**
53
53
  * Distributed trace ID linking related connector events. If absent, the
54
- * gateway falls back to the x-trustgate-trace-id header (auto-detected
54
+ * gateway falls back to the x-shashu-trace-id header (auto-detected
55
55
  * from env or tracer context); without either, the AuditLog row will only
56
56
  * have transaction_id.
57
57
  */
@@ -109,7 +109,7 @@ declare class Shashu {
109
109
  private readonly _sessionId;
110
110
  /**
111
111
  * This agent's OWN id (ADR-007 §4.1). Seeded by the `agentId` option and refreshed from
112
- * each gateway response's `x-trustgate-agent-id` header (read on EVERY response, incl.
112
+ * each gateway response's `x-shashu-agent-id` header (read on EVERY response, incl.
113
113
  * 4xx). Used by {@link buildInvocationHeaders} to stamp caller = self when invoking a
114
114
  * downstream agent — never sent as the gateway call's caller. Advisory lineage, never auth.
115
115
  */
@@ -128,7 +128,7 @@ declare class Shashu {
128
128
  */
129
129
  get sessionId(): string;
130
130
  /**
131
- * Cache this agent's own id from the gateway's `x-trustgate-agent-id` response header
131
+ * Cache this agent's own id from the gateway's `x-shashu-agent-id` response header
132
132
  * (delivered by WP-A2A-1). Used by {@link buildInvocationHeaders} to stamp caller = self
133
133
  * on a downstream invocation. Read on EVERY response — including non-2xx — so even a
134
134
  * blocked response seeds the self-id. NEVER an auth credential. Fail-soft: never throws.
@@ -140,7 +140,7 @@ declare class Shashu {
140
140
  * refreshed from gateway responses); trace / hop / session default from the tracer so the
141
141
  * served flow is propagated. The downstream agent calls `captureIncoming()` on these
142
142
  * headers. Throws if self-id is not known yet — set the `agentId` option or make one
143
- * gateway call first so the `x-trustgate-agent-id` response header can seed it.
143
+ * gateway call first so the `x-shashu-agent-id` response header can seed it.
144
144
  */
145
145
  buildInvocationHeaders(opts?: {
146
146
  traceId?: string;
@@ -207,7 +207,7 @@ declare class Shashu {
207
207
  /** How the gateway should encode a block. A default, not a hardcode. */
208
208
  declare const DEFAULT_BLOCK_ENCODING = "explicit";
209
209
  /** The header `DEFAULT_BLOCK_ENCODING` is sent under. Lowercase. */
210
- declare const BLOCK_ENCODING_HEADER = "trustgate-block-encoding";
210
+ declare const BLOCK_ENCODING_HEADER = "shashu-block-encoding";
211
211
  interface ShashuFetchOptions {
212
212
  /** Session every request this fetch makes joins. Minted once when omitted. */
213
213
  sessionId?: string;
@@ -222,12 +222,12 @@ interface ShashuFetchOptions {
222
222
  /** Callable returning the current cloud pass. Mutually exclusive with apiKey. */
223
223
  tokenProvider?: () => string | Promise<string>;
224
224
  /**
225
- * `TrustGate-Block-Encoding`. Default `explicit`. Pass `null` to send no
225
+ * `Shashu-Block-Encoding`. Default `explicit`. Pass `null` to send no
226
226
  * such header.
227
227
  */
228
228
  blockEncoding?: string | null;
229
229
  /**
230
- * `trustgate-version`. Default `DEFAULT_CONTRACT_VERSION` (`"2026-09-01"`).
230
+ * `shashu-version`. Default `DEFAULT_CONTRACT_VERSION` (`"2026-09-01"`).
231
231
  * Without it the gateway serves its legacy contract and discards the block
232
232
  * encoding above. Pass `null` to send no such header.
233
233
  */
@@ -236,7 +236,7 @@ interface ShashuFetchOptions {
236
236
  /**
237
237
  * A `fetch` to hand to a provider SDK's `fetch` option.
238
238
  *
239
- * Carries the retrieval joiner and the `x-trustgate-*` header set, so a
239
+ * Carries the retrieval joiner and the `x-shashu-*` header set, so a
240
240
  * LangChain / Vercel AI / raw-`openai` call made through it is attributed,
241
241
  * traced and able to declare its retrieval — with nothing patched.
242
242
  */
@@ -257,17 +257,17 @@ declare const PASS_CODES: readonly ["pass_provider_not_set_up", "pass_not_licens
257
257
  type PassRefusalCode = (typeof PASS_CODES)[number];
258
258
 
259
259
  /** Lowercase header prefix for proxy/gateway parity with Python SDK. */
260
- declare const HEADER_PREFIX = "x-trustgate";
260
+ declare const HEADER_PREFIX = "x-shashu";
261
261
  /** Header carrying the full context JSON (structurally identical to Python SDK). */
262
- declare const SOURCE_TOOL_HEADER = "x-trustgate-source-tool";
262
+ declare const SOURCE_TOOL_HEADER = "x-shashu-source-tool";
263
263
  /**
264
264
  * The contract generation this SDK speaks, declared on every request — the
265
265
  * same value the Python SDK sends (`trustgate.context.DEFAULT_CONTRACT_VERSION`).
266
266
  *
267
- * The gateway resolves an ABSENT `trustgate-version` header to its legacy
267
+ * The gateway resolves an ABSENT `shashu-version` header to its legacy
268
268
  * contract: a refusal is a 200 with prose in `message.content`, the body
269
269
  * carries no envelope (so memory and file items reach a caller as header
270
- * counts only), and the `trustgate-block-encoding` header `shashuFetch`
270
+ * counts only), and the `shashu-block-encoding` header `shashuFetch`
271
271
  * sends is read and discarded.
272
272
  *
273
273
  * A documented default, not a hardcode: pass `contractVersion` to pin another,
@@ -276,7 +276,7 @@ declare const SOURCE_TOOL_HEADER = "x-trustgate-source-tool";
276
276
  */
277
277
  declare const DEFAULT_CONTRACT_VERSION = "2026-09-01";
278
278
  /** The header {@link DEFAULT_CONTRACT_VERSION} is sent under. Lowercase. */
279
- declare const CONTRACT_VERSION_HEADER = "trustgate-version";
279
+ declare const CONTRACT_VERSION_HEADER = "shashu-version";
280
280
  /**
281
281
  * Searches process.env for workflow metadata from n8n, Vercel, or GitHub.
282
282
  * If no managed environment is detected, returns context with source "local_script"
@@ -285,7 +285,7 @@ declare const CONTRACT_VERSION_HEADER = "trustgate-version";
285
285
  */
286
286
  declare function getWorkflowContextFromEnv(): WorkflowContext;
287
287
  /**
288
- * JSON payload for x-trustgate-source-tool header (structurally identical to Python SDK).
288
+ * JSON payload for x-shashu-source-tool header (structurally identical to Python SDK).
289
289
  */
290
290
  declare function buildSourceToolJson(ctx: WorkflowContext): string;
291
291
  /** Prefix for runtime/metadata headers (e.g. x-trustlog-node-version). */
@@ -529,9 +529,9 @@ declare class ShashuProviderError extends ShashuError {
529
529
  * The gateway blocked the content. ONE type, both encodings.
530
530
  *
531
531
  * A security block reaches the caller in one of two shapes, and which one
532
- * depends on request headers (`trustgate-version`, `trustgate-block-encoding`)
532
+ * depends on request headers (`shashu-version`, `shashu-block-encoding`)
533
533
  * or an account default the caller may not control. Since 4.0.0 this SDK
534
- * sends `trustgate-version: 2026-09-01` by default, so the 400 is what a
534
+ * sends `shashu-version: 2026-09-01` by default, so the 400 is what a
535
535
  * caller sees unless they pass `contractVersion: null`:
536
536
  *
537
537
  * - `compatible` / legacy — **HTTP 200**, `finish_reason "content_filter"`.
@@ -607,9 +607,9 @@ interface A2ACapture {
607
607
  traceId: string;
608
608
  /** The captured inbound session id, if any. */
609
609
  sessionId?: string;
610
- /** Advisory inbound hop depth from x-trustgate-hop-depth (0 if absent). */
610
+ /** Advisory inbound hop depth from x-shashu-hop-depth (0 if absent). */
611
611
  inboundHopDepth: number;
612
- /** The upstream agent that INVOKED this hop (x-trustgate-caller-agent-id), FORWARDED
612
+ /** The upstream agent that INVOKED this hop (x-shashu-caller-agent-id), FORWARDED
613
613
  * on the outbound gateway call — never this agent's own id (§4.1). */
614
614
  inboundCallerAgentId?: string;
615
615
  }
@@ -656,12 +656,12 @@ declare class Tracer {
656
656
  get isA2aHop(): boolean;
657
657
  /** The captured inbound session id, or undefined when none was propagated. */
658
658
  get sessionId(): string | undefined;
659
- /** Advisory inbound hop depth captured from x-trustgate-hop-depth (0 if absent). */
659
+ /** Advisory inbound hop depth captured from x-shashu-hop-depth (0 if absent). */
660
660
  get inboundHopDepth(): number;
661
661
  /** Hop depth to advertise on the next downstream call = inbound + 1 (advisory; the
662
662
  * gateway recounts authoritatively). */
663
663
  get outboundHopDepth(): number;
664
- /** The captured inbound x-trustgate-caller-agent-id — the upstream agent that INVOKED
664
+ /** The captured inbound x-shashu-caller-agent-id — the upstream agent that INVOKED
665
665
  * this hop. The SDK FORWARDS this on the outbound gateway call so the gateway records
666
666
  * the real (invoker -> this agent) edge, NEVER this agent's own id (§4.1). undefined at
667
667
  * origin / caller-stripped. */
@@ -669,7 +669,7 @@ declare class Tracer {
669
669
  /**
670
670
  * Capture an inbound flow from the headers of a request this agent is SERVING into the
671
671
  * AsyncLocalStorage store, so a downstream call made through the SDK propagates the SAME
672
- * flow (WP-A2A-4 / ADR-007 §0). Reads (case-insensitively) x-trustgate-trace-id (the flow
672
+ * flow (WP-A2A-4 / ADR-007 §0). Reads (case-insensitively) x-shashu-trace-id (the flow
673
673
  * id), -session-id, -hop-depth, and -caller-agent-id (the upstream INVOKER). The captured
674
674
  * trace is PROPAGATED on the next outbound call (never re-minted); the session, inbound hop
675
675
  * depth, and inbound caller ride along — the caller is FORWARDED on the gateway call (§4.1),
@@ -718,11 +718,11 @@ declare function captureIncoming(headers: unknown): boolean;
718
718
  /**
719
719
  * Returns a pre-formatted JSON object of headers for use in n8n "HTTP Request" nodes.
720
720
  * Header keys are lowercase for gateway parity. Includes Shashu auth and workflow
721
- * context (workflow_id, execution_id, source, x-trustgate-source-tool JSON).
721
+ * context (workflow_id, execution_id, source, x-shashu-source-tool JSON).
722
722
  *
723
723
  * Resolution order: (1) arguments apiKey/baseUrl, (2) tracer.configure() values, (3) process.env.
724
- * When tracer.isActive, context headers include x-trustgate-trace-id, x-trustgate-span-id,
725
- * and x-trustgate-parent-id so the n8n workflow appears as a child of the current span.
724
+ * When tracer.isActive, context headers include x-shashu-trace-id, x-shashu-span-id,
725
+ * and x-shashu-parent-id so the n8n workflow appears as a child of the current span.
726
726
  *
727
727
  * Use in n8n:
728
728
  * 1. Add an "HTTP Request" node.
package/dist/index.js CHANGED
@@ -1,18 +1,21 @@
1
1
  import {
2
2
  createShashuAnthropicConfig,
3
3
  getAnthropicHeaders
4
- } from "./chunk-Z6DROYQA.js";
4
+ } from "./chunk-3GAMCQ6R.js";
5
5
  import {
6
6
  createShashuGeminiConfig,
7
7
  getGeminiHeaders
8
- } from "./chunk-BEU2UWW3.js";
8
+ } from "./chunk-3JZXUKNA.js";
9
9
  import {
10
- createShashuLangChainConfig
11
- } from "./chunk-4CDQ7JMK.js";
10
+ DEFAULT_RETRY_POLICY,
11
+ createShashuLangChainConfig,
12
+ executeWithRetry,
13
+ resolveRetryPolicy
14
+ } from "./chunk-F4CXDZQB.js";
12
15
  import {
13
16
  createShashuOpenAIOptions,
14
17
  getShashuHeaders
15
- } from "./chunk-M4JDSAUC.js";
18
+ } from "./chunk-3X5IUBIA.js";
16
19
  import {
17
20
  SOURCES,
18
21
  attachRagContext,
@@ -21,14 +24,13 @@ import {
21
24
  declareRetrieval,
22
25
  makeRagContext,
23
26
  memoryScope,
27
+ pinOutgoing,
24
28
  retrievalScope,
25
29
  withRetrievalJoiner
26
- } from "./chunk-5TW3FISD.js";
30
+ } from "./chunk-M7EMWSNS.js";
27
31
  import {
28
32
  API_KEY_ENV,
29
- API_KEY_ENV_LEGACY,
30
33
  BASE_URL_ENV,
31
- BASE_URL_ENV_LEGACY,
32
34
  CONTRACT_VERSION_HEADER,
33
35
  CredentialResolver,
34
36
  DEFAULT_CONTRACT_VERSION,
@@ -70,7 +72,7 @@ import {
70
72
  requireBaseUrl,
71
73
  shouldRetryPassRefused,
72
74
  tracer
73
- } from "./chunk-IQYB5OZ6.js";
75
+ } from "./chunk-TGD6KDWT.js";
74
76
 
75
77
  // src/client.ts
76
78
  import { randomUUID } from "crypto";
@@ -122,75 +124,6 @@ var Audit = class {
122
124
  }
123
125
  };
124
126
 
125
- // src/retry.ts
126
- var DEFAULT_RETRY_POLICY = {
127
- maxRetries: 2,
128
- backoffBaseSeconds: 0.5,
129
- backoffMaxSeconds: 30,
130
- retryOnConnectionErrors: true,
131
- retryOn429: true,
132
- retryOn5xx: false,
133
- neverRetryStatus: [400, 401, 403, 404],
134
- ignoreRetryAfter: false
135
- };
136
- function resolveRetryPolicy(policy) {
137
- if (policy === null) return null;
138
- if (policy === void 0) return { ...DEFAULT_RETRY_POLICY };
139
- return { ...DEFAULT_RETRY_POLICY, ...policy };
140
- }
141
- function shouldRetryStatus(policy, status) {
142
- if (policy.neverRetryStatus.includes(status)) return false;
143
- if (status === 429) return policy.retryOn429;
144
- if (status >= 500 && status <= 599) return policy.retryOn5xx;
145
- return false;
146
- }
147
- function shouldRetryResponse(policy, res, retryAfter) {
148
- if (!shouldRetryStatus(policy, res.status)) return false;
149
- if (res.status === 429) return retryAfter !== void 0;
150
- return true;
151
- }
152
- function delayFor(policy, attempt, res, retryAfter) {
153
- if (res !== null && res.status === 429 && !policy.ignoreRetryAfter && retryAfter !== void 0) {
154
- return Math.min(policy.backoffMaxSeconds, retryAfter);
155
- }
156
- return Math.min(policy.backoffMaxSeconds, policy.backoffBaseSeconds * 2 ** attempt);
157
- }
158
- function isConnectionError(err) {
159
- return err instanceof TypeError;
160
- }
161
- var defaultSleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
162
- async function peekJson(res) {
163
- try {
164
- return await res.clone().json();
165
- } catch {
166
- return void 0;
167
- }
168
- }
169
- async function executeWithRetry(send, policy, sleep = defaultSleep) {
170
- if (policy === null) return send();
171
- let attempt = 0;
172
- for (; ; ) {
173
- let res;
174
- try {
175
- res = await send();
176
- } catch (err) {
177
- if (policy.retryOnConnectionErrors && isConnectionError(err) && attempt < policy.maxRetries) {
178
- await sleep(delayFor(policy, attempt, null, void 0));
179
- attempt += 1;
180
- continue;
181
- }
182
- throw err;
183
- }
184
- const retryAfter = res.status === 429 ? gatewayRetryAfter(res, await peekJson(res)) : void 0;
185
- if (attempt < policy.maxRetries && shouldRetryResponse(policy, res, retryAfter)) {
186
- await sleep(delayFor(policy, attempt, res, retryAfter));
187
- attempt += 1;
188
- continue;
189
- }
190
- return res;
191
- }
192
- }
193
-
194
127
  // src/decision.ts
195
128
  var DECISION_ALLOW = "allow";
196
129
  var DECISION_ALLOW_ALTERED = "allow_altered";
@@ -211,16 +144,16 @@ var DELIVERED_DECISIONS = /* @__PURE__ */ new Set([
211
144
  DECISION_ALLOW_ALTERED,
212
145
  DECISION_NOT_CHECKED
213
146
  ]);
214
- var BODY_KEY = "trustgate";
215
- var HEADER_DECISION = "x-trustgate-decision";
216
- var HEADER_CODE = "x-trustgate-code";
217
- var HEADER_INSPECTION = "x-trustgate-inspection";
147
+ var BODY_KEY = "shashu";
148
+ var HEADER_DECISION = "x-shashu-decision";
149
+ var HEADER_CODE = "x-shashu-code";
150
+ var HEADER_INSPECTION = "x-shashu-inspection";
218
151
  var HEADER_SHOULD_RETRY = "x-should-retry";
219
152
  var HEADER_REQUEST_ID = "x-request-id";
220
- var HEADER_SHASHU_REQUEST_ID = "x-trustgate-request-id";
221
- var HEADER_TRACE_ID = "x-trustgate-trace-id";
222
- var HEADER_ATTACHMENTS = "x-trustgate-attachments";
223
- var HEADER_MEMORY = "x-trustgate-memory";
153
+ var HEADER_SHASHU_REQUEST_ID = "x-shashu-request-id";
154
+ var HEADER_TRACE_ID = "x-shashu-trace-id";
155
+ var HEADER_ATTACHMENTS = "x-shashu-attachments";
156
+ var HEADER_MEMORY = "x-shashu-memory";
224
157
  var ATTACHMENT_STATES = /* @__PURE__ */ new Set([
225
158
  "scanned",
226
159
  "scanned_partial",
@@ -689,14 +622,14 @@ var Shashu = class {
689
622
  return this._sessionId;
690
623
  }
691
624
  /**
692
- * Cache this agent's own id from the gateway's `x-trustgate-agent-id` response header
625
+ * Cache this agent's own id from the gateway's `x-shashu-agent-id` response header
693
626
  * (delivered by WP-A2A-1). Used by {@link buildInvocationHeaders} to stamp caller = self
694
627
  * on a downstream invocation. Read on EVERY response — including non-2xx — so even a
695
628
  * blocked response seeds the self-id. NEVER an auth credential. Fail-soft: never throws.
696
629
  */
697
630
  captureAgentId(res) {
698
631
  try {
699
- const aid = res.headers.get("x-trustgate-agent-id");
632
+ const aid = res.headers.get("x-shashu-agent-id");
700
633
  if (aid) this._agentId = aid;
701
634
  } catch {
702
635
  }
@@ -707,12 +640,12 @@ var Shashu = class {
707
640
  * refreshed from gateway responses); trace / hop / session default from the tracer so the
708
641
  * served flow is propagated. The downstream agent calls `captureIncoming()` on these
709
642
  * headers. Throws if self-id is not known yet — set the `agentId` option or make one
710
- * gateway call first so the `x-trustgate-agent-id` response header can seed it.
643
+ * gateway call first so the `x-shashu-agent-id` response header can seed it.
711
644
  */
712
645
  buildInvocationHeaders(opts) {
713
646
  if (!this._agentId) {
714
647
  throw new Error(
715
- "self agent id is unknown \u2014 set the agentId option or make one gateway call first so the x-trustgate-agent-id response header can seed it."
648
+ "self agent id is unknown \u2014 set the agentId option or make one gateway call first so the x-shashu-agent-id response header can seed it."
716
649
  );
717
650
  }
718
651
  return buildInvocationHeaders({ callerAgentId: this._agentId, ...opts });
@@ -741,27 +674,30 @@ var Shashu = class {
741
674
  const context = resolveContext(this.config, options);
742
675
  const url = path.startsWith("http") ? path : `${this.resolvedBaseUrl}/${path.replace(/^\//, "")}`;
743
676
  const timeout = options?.timeout ?? 6e4;
744
- const send = async () => {
745
- const token = await this.resolver.get();
746
- const headers = mergeHeaders(
747
- this.config,
748
- options,
749
- context,
750
- {
677
+ const headersOnce = applyContractVersion(
678
+ {
679
+ ...mergeHeaders(this.config, options, context, {
751
680
  defaultSessionId: this._sessionId,
752
681
  requestSessionId: options?.sessionId
753
- },
754
- token
755
- );
682
+ }),
683
+ ...init.headers
684
+ },
685
+ this.config.contractVersion
686
+ );
687
+ const frozenHeaders = { ...headersOnce };
688
+ delete frozenHeaders["authorization"];
689
+ delete frozenHeaders["Authorization"];
690
+ const pinned = pinOutgoing(url, { ...init, headers: frozenHeaders });
691
+ const send = async () => {
692
+ const token = await this.resolver.get();
756
693
  const controller = new AbortController();
757
694
  const id = setTimeout(() => controller.abort(), timeout);
758
695
  try {
759
- return await joiningFetch(url, {
760
- ...init,
761
- headers: applyContractVersion(
762
- { ...headers, ...init.headers },
763
- this.config.contractVersion
764
- ),
696
+ const headers = { ...pinned.init?.headers };
697
+ if (token) headers["authorization"] = `Bearer ${token}`;
698
+ return await joiningFetch(pinned.input, {
699
+ ...pinned.init,
700
+ headers,
765
701
  signal: init.signal ?? controller.signal
766
702
  });
767
703
  } finally {
@@ -875,7 +811,7 @@ var Shashu = class {
875
811
  // src/fetch.ts
876
812
  import { randomUUID as randomUUID2 } from "crypto";
877
813
  var DEFAULT_BLOCK_ENCODING = "explicit";
878
- var BLOCK_ENCODING_HEADER = "trustgate-block-encoding";
814
+ var BLOCK_ENCODING_HEADER = "shashu-block-encoding";
879
815
  function shashuFetch(options = {}) {
880
816
  const resolver = new CredentialResolver({
881
817
  apiKey: options.apiKey,
@@ -929,8 +865,8 @@ function shashuFetch(options = {}) {
929
865
 
930
866
  // src/n8n.ts
931
867
  function getN8nHeaderSnippet(apiKey, baseUrl) {
932
- const key = apiKey ?? tracer.apiKey ?? envGet(API_KEY_ENV, API_KEY_ENV_LEGACY) ?? "";
933
- const url = baseUrl ?? tracer.gatewayUrl ?? envGet(BASE_URL_ENV, BASE_URL_ENV_LEGACY) ?? "";
868
+ const key = apiKey ?? tracer.apiKey ?? envGet(API_KEY_ENV) ?? "";
869
+ const url = baseUrl ?? tracer.gatewayUrl ?? envGet(BASE_URL_ENV) ?? "";
934
870
  const ctx = getWorkflowContextFromEnv();
935
871
  const contextHeaders = buildContextHeaders(ctx);
936
872
  const headers = [];
@@ -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.cjs';
2
+ import { F as FetchLike } from './_joiner-DGi8GsY7.cjs';
3
3
 
4
4
  /** One document as `rag_context.v1` spells it. */
5
5
  interface BusDoc {
@@ -22,13 +22,13 @@ interface RetrievalEvent {
22
22
  * Helpers for attaching structured RAG context to a chat-completion request body.
23
23
  *
24
24
  * The Shashu gateway scans retrieved documents on a dedicated `ingress-rag`
25
- * surface when the request body carries `trustgate_metadata.rag_context`.
25
+ * surface when the request body carries `shashu_metadata.rag_context`.
26
26
  * This is materially better than letting retrieved documents be scanned as
27
27
  * plain user text — the rag scanner has access to corpus + per-doc scores +
28
28
  * per-doc previews, which dramatically reduces false-positives on legitimate
29
29
  * RAG flows.
30
30
  *
31
- * The gateway pops `trustgate_metadata` from the body before forwarding to
31
+ * The gateway pops `shashu_metadata` from the body before forwarding to
32
32
  * the LLM provider, so the upstream model never sees the control plane.
33
33
  *
34
34
  * @example
@@ -60,8 +60,8 @@ interface RagContext {
60
60
  }
61
61
  declare function makeRagContext(input: RagContext): RagContext;
62
62
  /**
63
- * Merge a rag_context dict into `body.trustgate_metadata.rag_context`
64
- * without clobbering other trustgate_metadata fields the caller may have set.
63
+ * Merge a rag_context dict into `body.shashu_metadata.rag_context`
64
+ * without clobbering other shashu_metadata fields the caller may have set.
65
65
  *
66
66
  * Returns the same body object (mutated) for chaining convenience.
67
67
  */
@@ -103,7 +103,7 @@ interface DeclareRetrievalOptions {
103
103
  * can be seen -- the alternative is a payload the gateway rejects at the far end
104
104
  * of a customer's stack.
105
105
  *
106
- * A no-op when `TRUSTGATE_DISABLE=1`.
106
+ * A no-op when `SHASHU_DISABLE=1`.
107
107
  */
108
108
  declare function declareRetrieval(docs: unknown, options: DeclareRetrievalOptions): void;
109
109
  /**
@@ -124,7 +124,7 @@ declare function declareRetrieval(docs: unknown, options: DeclareRetrievalOption
124
124
  * leak into the frame that started the task, where `enterWith` does. See
125
125
  * `_bus.ts` for the measured table.
126
126
  *
127
- * A no-op wrapper when `TRUSTGATE_DISABLE=1`: `fn` still runs, nothing is
127
+ * A no-op wrapper when `SHASHU_DISABLE=1`: `fn` still runs, nothing is
128
128
  * declared.
129
129
  */
130
130
  declare function retrievalScope<T>(docs: unknown, options: DeclareRetrievalOptions, fn: () => T | Promise<T>): Promise<T>;
@@ -209,7 +209,7 @@ declare function buildRagContext(events: readonly RetrievalEvent[]): RagContext
209
209
  * `handleLLMStart`, which run inline in the model step's own async context --
210
210
  * the same context the HTTP call is made in. Delivery calls
211
211
  * {@link declareRetrieval}, so the caps, the coercion table and
212
- * `TRUSTGATE_DISABLE` are the one implementation shared with the manual path.
212
+ * `SHASHU_DISABLE` are the one implementation shared with the manual path.
213
213
  *
214
214
  * `install()` also has to force a `CallbackManager` to exist at all:
215
215
  * `CallbackManager.configure()` returns `undefined` when a chain is invoked with
@@ -228,10 +228,10 @@ declare function buildRagContext(events: readonly RetrievalEvent[]): RagContext
228
228
  /**
229
229
  * Configuration to pass to LangChain's ChatOpenAI (or other OpenAI-based classes).
230
230
  * Sets baseURL and defaultHeaders (lowercase keys) so requests go through Shashu
231
- * with workflow context and x-trustgate-source-tool JSON for Shadow AI detection,
231
+ * with workflow context and x-shashu-source-tool JSON for Shadow AI detection,
232
232
  * and a `fetch` that attaches any declared retrieval to the outgoing body.
233
233
  *
234
- * Returns `{}` when TRUSTGATE_DISABLE is set: the provider client is then left
234
+ * Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
235
235
  * exactly as it was — its own endpoint, its own credential, no Shashu context
236
236
  * headers — which is the same no-op the Python SDK's patchers perform. The
237
237
  * 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.cjs';
2
- import { F as FetchLike } from './_joiner-p5LFxJcu.cjs';
1
+ import { S as ShashuConfig } from './types-BLs_TMFv.js';
2
+ import { F as FetchLike } from './_joiner-DGi8GsY7.js';
3
3
 
4
4
  /** One document as `rag_context.v1` spells it. */
5
5
  interface BusDoc {
@@ -22,13 +22,13 @@ interface RetrievalEvent {
22
22
  * Helpers for attaching structured RAG context to a chat-completion request body.
23
23
  *
24
24
  * The Shashu gateway scans retrieved documents on a dedicated `ingress-rag`
25
- * surface when the request body carries `trustgate_metadata.rag_context`.
25
+ * surface when the request body carries `shashu_metadata.rag_context`.
26
26
  * This is materially better than letting retrieved documents be scanned as
27
27
  * plain user text — the rag scanner has access to corpus + per-doc scores +
28
28
  * per-doc previews, which dramatically reduces false-positives on legitimate
29
29
  * RAG flows.
30
30
  *
31
- * The gateway pops `trustgate_metadata` from the body before forwarding to
31
+ * The gateway pops `shashu_metadata` from the body before forwarding to
32
32
  * the LLM provider, so the upstream model never sees the control plane.
33
33
  *
34
34
  * @example
@@ -60,8 +60,8 @@ interface RagContext {
60
60
  }
61
61
  declare function makeRagContext(input: RagContext): RagContext;
62
62
  /**
63
- * Merge a rag_context dict into `body.trustgate_metadata.rag_context`
64
- * without clobbering other trustgate_metadata fields the caller may have set.
63
+ * Merge a rag_context dict into `body.shashu_metadata.rag_context`
64
+ * without clobbering other shashu_metadata fields the caller may have set.
65
65
  *
66
66
  * Returns the same body object (mutated) for chaining convenience.
67
67
  */
@@ -103,7 +103,7 @@ interface DeclareRetrievalOptions {
103
103
  * can be seen -- the alternative is a payload the gateway rejects at the far end
104
104
  * of a customer's stack.
105
105
  *
106
- * A no-op when `TRUSTGATE_DISABLE=1`.
106
+ * A no-op when `SHASHU_DISABLE=1`.
107
107
  */
108
108
  declare function declareRetrieval(docs: unknown, options: DeclareRetrievalOptions): void;
109
109
  /**
@@ -124,7 +124,7 @@ declare function declareRetrieval(docs: unknown, options: DeclareRetrievalOption
124
124
  * leak into the frame that started the task, where `enterWith` does. See
125
125
  * `_bus.ts` for the measured table.
126
126
  *
127
- * A no-op wrapper when `TRUSTGATE_DISABLE=1`: `fn` still runs, nothing is
127
+ * A no-op wrapper when `SHASHU_DISABLE=1`: `fn` still runs, nothing is
128
128
  * declared.
129
129
  */
130
130
  declare function retrievalScope<T>(docs: unknown, options: DeclareRetrievalOptions, fn: () => T | Promise<T>): Promise<T>;
@@ -209,7 +209,7 @@ declare function buildRagContext(events: readonly RetrievalEvent[]): RagContext
209
209
  * `handleLLMStart`, which run inline in the model step's own async context --
210
210
  * the same context the HTTP call is made in. Delivery calls
211
211
  * {@link declareRetrieval}, so the caps, the coercion table and
212
- * `TRUSTGATE_DISABLE` are the one implementation shared with the manual path.
212
+ * `SHASHU_DISABLE` are the one implementation shared with the manual path.
213
213
  *
214
214
  * `install()` also has to force a `CallbackManager` to exist at all:
215
215
  * `CallbackManager.configure()` returns `undefined` when a chain is invoked with
@@ -228,10 +228,10 @@ declare function buildRagContext(events: readonly RetrievalEvent[]): RagContext
228
228
  /**
229
229
  * Configuration to pass to LangChain's ChatOpenAI (or other OpenAI-based classes).
230
230
  * Sets baseURL and defaultHeaders (lowercase keys) so requests go through Shashu
231
- * with workflow context and x-trustgate-source-tool JSON for Shadow AI detection,
231
+ * with workflow context and x-shashu-source-tool JSON for Shadow AI detection,
232
232
  * and a `fetch` that attaches any declared retrieval to the outgoing body.
233
233
  *
234
- * Returns `{}` when TRUSTGATE_DISABLE is set: the provider client is then left
234
+ * Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
235
235
  * exactly as it was — its own endpoint, its own credential, no Shashu context
236
236
  * headers — which is the same no-op the Python SDK's patchers perform. The
237
237
  * caller's tg_sk_ key is deliberately NOT handed back, since it would be sent to