@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
@@ -73,53 +73,58 @@ var ShashuConfigError = class _ShashuConfigError extends ShashuError {
73
73
  Object.setPrototypeOf(this, _ShashuConfigError.prototype);
74
74
  }
75
75
  };
76
+ function rateLimitDetail(err) {
77
+ const inner = err?.details?.error;
78
+ return inner && typeof inner === "object" ? inner : {};
79
+ }
80
+ function gatewayRetryAfter(res, parsedBody) {
81
+ const fromHeader = parseRetryAfter(res.headers.get("retry-after"));
82
+ if (fromHeader !== void 0) return fromHeader;
83
+ if (!parsedBody || typeof parsedBody !== "object") return void 0;
84
+ const err = parsedBody.error;
85
+ const seconds = rateLimitDetail(err).retry_after_seconds;
86
+ return typeof seconds === "number" ? seconds : void 0;
87
+ }
88
+ function parseRetryAfter(value) {
89
+ if (!value) return void 0;
90
+ const trimmed = value.trim();
91
+ const asInt = Number(trimmed);
92
+ if (Number.isFinite(asInt)) return asInt;
93
+ const asDate = Date.parse(trimmed);
94
+ if (!Number.isNaN(asDate)) {
95
+ return Math.max(0, (asDate - Date.now()) / 1e3);
96
+ }
97
+ return void 0;
98
+ }
76
99
 
77
100
  // src/config.ts
78
101
  var BASE_URL_ENV = "SHASHU_BASE_URL";
79
- var BASE_URL_ENV_LEGACY = "TRUSTGATE_BASE_URL";
80
102
  var API_KEY_ENV = "SHASHU_API_KEY";
81
- var API_KEY_ENV_LEGACY = "TRUSTGATE_API_KEY";
82
103
  var DISABLE_ENV = "SHASHU_DISABLE";
83
- var DISABLE_ENV_LEGACY = "TRUSTGATE_DISABLE";
84
- var fallbackWarned = /* @__PURE__ */ new Set();
85
104
  var TRUTHY = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
86
105
  function env() {
87
106
  return typeof process !== "undefined" && process.env ? process.env : {};
88
107
  }
89
- function envGet(current2, legacy) {
90
- const e = env();
91
- const now = (e[current2] ?? "").trim();
92
- if (now) return now;
93
- const old = (e[legacy] ?? "").trim();
94
- if (old) {
95
- if (!fallbackWarned.has(legacy)) {
96
- fallbackWarned.add(legacy);
97
- console.warn(
98
- `${legacy} is deprecated; set ${current2} instead. The TRUSTGATE_* name still works for this release.`
99
- );
100
- }
101
- return old;
102
- }
103
- return void 0;
108
+ function envGet(current2, _legacy) {
109
+ const now = (env()[current2] ?? "").trim();
110
+ return now || void 0;
104
111
  }
105
112
  function isDisabled() {
106
- return TRUTHY.has((envGet(DISABLE_ENV, DISABLE_ENV_LEGACY) ?? "").trim().toLowerCase());
113
+ return TRUTHY.has((envGet(DISABLE_ENV) ?? "").trim().toLowerCase());
107
114
  }
108
115
  function firstConfigured(baseUrl, envVars) {
109
116
  if (baseUrl && baseUrl.trim()) return baseUrl.trim().replace(/\/+$/, "");
110
117
  for (const name of envVars) {
111
- const current2 = name.startsWith("TRUSTGATE_") ? name.replace("TRUSTGATE_", "SHASHU_") : name;
112
- const legacy = name.startsWith("SHASHU_") ? name.replace("SHASHU_", "TRUSTGATE_") : name.startsWith("TRUSTGATE_") ? name : "";
113
- const value = legacy && legacy !== current2 ? envGet(current2, legacy) : env()[name]?.trim();
118
+ const value = env()[name]?.trim();
114
119
  if (value) return value.replace(/\/+$/, "");
115
120
  }
116
121
  return void 0;
117
122
  }
118
- function optionalBaseUrl(baseUrl, envVars = [BASE_URL_ENV, BASE_URL_ENV_LEGACY]) {
123
+ function optionalBaseUrl(baseUrl, envVars = [BASE_URL_ENV]) {
119
124
  return firstConfigured(baseUrl, envVars);
120
125
  }
121
126
  function requireBaseUrl(baseUrl, opts) {
122
- const envVars = opts.envVars ?? [BASE_URL_ENV, BASE_URL_ENV_LEGACY];
127
+ const envVars = opts.envVars ?? [BASE_URL_ENV];
123
128
  const resolved = firstConfigured(baseUrl, envVars);
124
129
  if (resolved) return resolved;
125
130
  const option = opts.option ?? "baseUrl";
@@ -133,7 +138,7 @@ function requireBaseUrl(baseUrl, opts) {
133
138
  var import_node_crypto2 = require("crypto");
134
139
 
135
140
  // src/version.ts
136
- var SDK_VERSION = "1.0.0";
141
+ var SDK_VERSION = "1.1.1";
137
142
 
138
143
  // src/tracer.ts
139
144
  var import_node_async_hooks = require("async_hooks");
@@ -177,14 +182,14 @@ function parseHopDepth(raw) {
177
182
  return Number.isFinite(n) && n > 0 ? n : 0;
178
183
  }
179
184
  function captureFromHeaders(h) {
180
- const trace = (h["x-trustgate-trace-id"] ?? "").trim();
185
+ const trace = (h["x-shashu-trace-id"] ?? "").trim();
181
186
  if (!trace) return void 0;
182
- const session = (h["x-trustgate-session-id"] ?? "").trim();
183
- const caller = (h["x-trustgate-caller-agent-id"] ?? "").trim();
187
+ const session = (h["x-shashu-session-id"] ?? "").trim();
188
+ const caller = (h["x-shashu-caller-agent-id"] ?? "").trim();
184
189
  return {
185
190
  traceId: trace,
186
191
  sessionId: session || void 0,
187
- inboundHopDepth: parseHopDepth(h["x-trustgate-hop-depth"]),
192
+ inboundHopDepth: parseHopDepth(h["x-shashu-hop-depth"]),
188
193
  inboundCallerAgentId: caller || void 0
189
194
  };
190
195
  }
@@ -204,7 +209,7 @@ var Tracer = class {
204
209
  this.buffer = [];
205
210
  this.flushTimer = null;
206
211
  this._gatewayUrl = optionalBaseUrl();
207
- this._apiKey = envGet(API_KEY_ENV, API_KEY_ENV_LEGACY);
212
+ this._apiKey = envGet(API_KEY_ENV);
208
213
  }
209
214
  /**
210
215
  * Current gateway base URL (respects configure()), or undefined when none is
@@ -257,7 +262,7 @@ var Tracer = class {
257
262
  get sessionId() {
258
263
  return a2aStorage.getStore()?.sessionId || void 0;
259
264
  }
260
- /** Advisory inbound hop depth captured from x-trustgate-hop-depth (0 if absent). */
265
+ /** Advisory inbound hop depth captured from x-shashu-hop-depth (0 if absent). */
261
266
  get inboundHopDepth() {
262
267
  return a2aStorage.getStore()?.inboundHopDepth ?? 0;
263
268
  }
@@ -266,7 +271,7 @@ var Tracer = class {
266
271
  get outboundHopDepth() {
267
272
  return this.inboundHopDepth + 1;
268
273
  }
269
- /** The captured inbound x-trustgate-caller-agent-id — the upstream agent that INVOKED
274
+ /** The captured inbound x-shashu-caller-agent-id — the upstream agent that INVOKED
270
275
  * this hop. The SDK FORWARDS this on the outbound gateway call so the gateway records
271
276
  * the real (invoker -> this agent) edge, NEVER this agent's own id (§4.1). undefined at
272
277
  * origin / caller-stripped. */
@@ -276,7 +281,7 @@ var Tracer = class {
276
281
  /**
277
282
  * Capture an inbound flow from the headers of a request this agent is SERVING into the
278
283
  * AsyncLocalStorage store, so a downstream call made through the SDK propagates the SAME
279
- * flow (WP-A2A-4 / ADR-007 §0). Reads (case-insensitively) x-trustgate-trace-id (the flow
284
+ * flow (WP-A2A-4 / ADR-007 §0). Reads (case-insensitively) x-shashu-trace-id (the flow
280
285
  * id), -session-id, -hop-depth, and -caller-agent-id (the upstream INVOKER). The captured
281
286
  * trace is PROPAGATED on the next outbound call (never re-minted); the session, inbound hop
282
287
  * depth, and inbound caller ride along — the caller is FORWARDED on the gateway call (§4.1),
@@ -373,10 +378,10 @@ var Tracer = class {
373
378
  var tracer = new Tracer();
374
379
 
375
380
  // src/context.ts
376
- var HEADER_PREFIX = "x-trustgate";
377
- var SOURCE_TOOL_HEADER = "x-trustgate-source-tool";
381
+ var HEADER_PREFIX = "x-shashu";
382
+ var SOURCE_TOOL_HEADER = "x-shashu-source-tool";
378
383
  var DEFAULT_CONTRACT_VERSION = "2026-09-01";
379
- var CONTRACT_VERSION_HEADER = "trustgate-version";
384
+ var CONTRACT_VERSION_HEADER = "shashu-version";
380
385
  function applyContractVersion(headers, contractVersion) {
381
386
  if (contractVersion === null) return headers;
382
387
  const named = Object.keys(headers).some((k) => k.toLowerCase() === CONTRACT_VERSION_HEADER);
@@ -495,20 +500,20 @@ function buildContextHeaders(ctx, session) {
495
500
  if (v) h[`${TRUSTLOG_HEADER_PREFIX}${k.replace(/_/g, "-")}`] = String(v);
496
501
  }
497
502
  if (tracer.isActive) {
498
- if (tracer.traceId) h["x-trustgate-trace-id"] = tracer.traceId;
499
- h["x-trustgate-span-id"] = tracer.currentSpanId ?? "";
500
- h["x-trustgate-parent-id"] = tracer.parentSpanId ?? "";
503
+ if (tracer.traceId) h["x-shashu-trace-id"] = tracer.traceId;
504
+ h["x-shashu-span-id"] = tracer.currentSpanId ?? "";
505
+ h["x-shashu-parent-id"] = tracer.parentSpanId ?? "";
501
506
  } else if (tracer.isA2aHop) {
502
- if (tracer.traceId) h["x-trustgate-trace-id"] = tracer.traceId;
503
- } else if (!h["x-trustgate-trace-id"]) {
504
- h["x-trustgate-trace-id"] = resolveOriginTraceId();
507
+ if (tracer.traceId) h["x-shashu-trace-id"] = tracer.traceId;
508
+ } else if (!h["x-shashu-trace-id"]) {
509
+ h["x-shashu-trace-id"] = resolveOriginTraceId();
505
510
  }
506
511
  const sessionId = resolveSessionId(session);
507
- if (sessionId) h["x-trustgate-session-id"] = sessionId;
512
+ if (sessionId) h["x-shashu-session-id"] = sessionId;
508
513
  if (tracer.isA2aHop) {
509
514
  const inboundCaller = tracer.inboundCallerAgentId;
510
- if (inboundCaller) h["x-trustgate-caller-agent-id"] = inboundCaller;
511
- h["x-trustgate-hop-depth"] = String(tracer.outboundHopDepth);
515
+ if (inboundCaller) h["x-shashu-caller-agent-id"] = inboundCaller;
516
+ h["x-shashu-hop-depth"] = String(tracer.outboundHopDepth);
512
517
  }
513
518
  return lowercaseHeaderKeys(h);
514
519
  }
@@ -587,10 +592,10 @@ function attachRagContext(body, ragContext) {
587
592
  if (ragContext === null || typeof ragContext !== "object") {
588
593
  throw new TypeError("ragContext must be an object");
589
594
  }
590
- const existing = body.trustgate_metadata;
595
+ const existing = body.shashu_metadata;
591
596
  const meta = existing !== null && typeof existing === "object" ? existing : {};
592
597
  meta.rag_context = ragContext;
593
- body.trustgate_metadata = meta;
598
+ body.shashu_metadata = meta;
594
599
  return body;
595
600
  }
596
601
  var SOURCES = [
@@ -817,14 +822,13 @@ function buildMemoryContext(events) {
817
822
  }
818
823
  function attachMemoryContext(body, memoryContext) {
819
824
  const bag = body;
820
- const existing = bag.trustgate_metadata;
825
+ const existing = bag.shashu_metadata;
821
826
  const metadata = existing !== null && typeof existing === "object" ? existing : {};
822
- bag.trustgate_metadata = { ...metadata, memory_context: memoryContext };
827
+ bag.shashu_metadata = { ...metadata, memory_context: memoryContext };
823
828
  return body;
824
829
  }
825
830
 
826
831
  // src/_joiner.ts
827
- var globalFetch = (input, init) => globalThis.fetch(input, init);
828
832
  function parseJsonObject(body) {
829
833
  if (typeof body !== "string") return void 0;
830
834
  if (!/^[\s]*\{/.test(body)) return void 0;
@@ -836,7 +840,7 @@ function parseJsonObject(body) {
836
840
  }
837
841
  }
838
842
  function metadataBag(body) {
839
- const metadata = body.trustgate_metadata;
843
+ const metadata = body.shashu_metadata;
840
844
  if (metadata !== null && typeof metadata === "object") {
841
845
  return metadata;
842
846
  }
@@ -905,38 +909,23 @@ function takeContextFor(body) {
905
909
  }
906
910
  return mutated ? body : void 0;
907
911
  }
908
- function withRetrievalJoiner(underlying = globalFetch) {
909
- return async function trustgateJoiningFetch(input, init) {
910
- if (!hasEvents()) return underlying(input, init);
911
- if (isDisabled()) {
912
- clear();
913
- return underlying(input, init);
914
- }
915
- try {
916
- if (typeof Request !== "undefined" && input instanceof Request) {
917
- const body2 = parseJsonObject(await input.clone().text());
918
- if (body2 === void 0) return underlying(input, init);
919
- const merged2 = takeContextFor(body2);
920
- if (merged2 === void 0) return underlying(input, init);
921
- const encoded2 = JSON.stringify(merged2);
922
- const replacement = new Request(input, { body: encoded2 });
923
- if (replacement.headers.has("content-length")) {
924
- replacement.headers.set("content-length", String(byteLength(encoded2)));
925
- }
926
- return underlying(replacement, init);
927
- }
928
- const body = parseJsonObject(init?.body);
929
- if (body === void 0) return underlying(input, init);
930
- const merged = takeContextFor(body);
931
- if (merged === void 0) return underlying(input, init);
932
- const encoded = JSON.stringify(merged);
933
- return underlying(input, {
934
- ...init,
935
- body: encoded,
936
- headers: fixContentLength(init?.headers, byteLength(encoded))
937
- });
938
- } catch {
939
- return underlying(input, init);
912
+ function pinOutgoing(input, init) {
913
+ if (!hasEvents()) return { input, init };
914
+ if (isDisabled()) {
915
+ clear();
916
+ return { input, init };
917
+ }
918
+ const body = parseJsonObject(init?.body);
919
+ if (body === void 0) return { input, init };
920
+ const merged = takeContextFor(body);
921
+ if (merged === void 0) return { input, init };
922
+ const encoded = JSON.stringify(merged);
923
+ return {
924
+ input,
925
+ init: {
926
+ ...init,
927
+ body: encoded,
928
+ headers: fixContentLength(init?.headers, byteLength(encoded))
940
929
  }
941
930
  };
942
931
  }
@@ -944,6 +933,95 @@ function byteLength(text) {
944
933
  return new TextEncoder().encode(text).length;
945
934
  }
946
935
 
936
+ // src/retry.ts
937
+ var DEFAULT_RETRY_POLICY = {
938
+ maxRetries: 2,
939
+ backoffBaseSeconds: 0.5,
940
+ backoffMaxSeconds: 30,
941
+ retryOnConnectionErrors: true,
942
+ retryOn429: true,
943
+ retryOn5xx: false,
944
+ neverRetryStatus: [400, 401, 403, 404],
945
+ ignoreRetryAfter: false,
946
+ jitterFraction: 0.2
947
+ };
948
+ function resolveRetryPolicy(policy) {
949
+ if (policy === null) return null;
950
+ if (policy === void 0) return { ...DEFAULT_RETRY_POLICY };
951
+ return { ...DEFAULT_RETRY_POLICY, ...policy };
952
+ }
953
+ function shouldRetryStatus(policy, status) {
954
+ if (policy.neverRetryStatus.includes(status)) return false;
955
+ if (status === 429) return policy.retryOn429;
956
+ if (status === 503) return true;
957
+ if (status >= 500 && status <= 599) return policy.retryOn5xx;
958
+ return false;
959
+ }
960
+ function truthyHeader(value) {
961
+ return ["1", "true", "yes", "on"].includes((value ?? "").trim().toLowerCase());
962
+ }
963
+ function gatewaySaysBusyRetry(res, retryAfter) {
964
+ if (res.status !== 429 && res.status !== 503) return false;
965
+ if (truthyHeader(res.headers.get("x-should-retry"))) return true;
966
+ return retryAfter !== void 0;
967
+ }
968
+ function shouldRetryResponse(policy, res, retryAfter) {
969
+ if (policy.neverRetryStatus.includes(res.status)) return false;
970
+ if (res.status === 429 || res.status === 503) {
971
+ if (res.status === 429 && !policy.retryOn429) return false;
972
+ return gatewaySaysBusyRetry(res, retryAfter);
973
+ }
974
+ if (!shouldRetryStatus(policy, res.status)) return false;
975
+ return true;
976
+ }
977
+ function delayFor(policy, attempt, res, retryAfter) {
978
+ const jitter = (seconds) => {
979
+ const frac = policy.jitterFraction ?? 0.2;
980
+ const capped = Math.min(policy.backoffMaxSeconds, seconds);
981
+ if (frac <= 0) return capped;
982
+ return Math.min(policy.backoffMaxSeconds, capped * (1 + Math.random() * frac));
983
+ };
984
+ if (res !== null && (res.status === 429 || res.status === 503) && !policy.ignoreRetryAfter && retryAfter !== void 0) {
985
+ return jitter(retryAfter);
986
+ }
987
+ return jitter(policy.backoffBaseSeconds * 2 ** attempt);
988
+ }
989
+ function isConnectionError(err) {
990
+ return err instanceof TypeError;
991
+ }
992
+ var defaultSleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
993
+ async function peekJson(res) {
994
+ try {
995
+ return await res.clone().json();
996
+ } catch {
997
+ return void 0;
998
+ }
999
+ }
1000
+ async function executeWithRetry(send, policy, sleep = defaultSleep) {
1001
+ if (policy === null) return send();
1002
+ let attempt = 0;
1003
+ for (; ; ) {
1004
+ let res;
1005
+ try {
1006
+ res = await send();
1007
+ } catch (err) {
1008
+ if (policy.retryOnConnectionErrors && isConnectionError(err) && attempt < policy.maxRetries) {
1009
+ await sleep(delayFor(policy, attempt, null, void 0));
1010
+ attempt += 1;
1011
+ continue;
1012
+ }
1013
+ throw err;
1014
+ }
1015
+ const retryAfter = res.status === 429 || res.status === 503 ? gatewayRetryAfter(res, await peekJson(res)) : void 0;
1016
+ if (attempt < policy.maxRetries && shouldRetryResponse(policy, res, retryAfter)) {
1017
+ await sleep(delayFor(policy, attempt, res, retryAfter));
1018
+ attempt += 1;
1019
+ continue;
1020
+ }
1021
+ return res;
1022
+ }
1023
+ }
1024
+
947
1025
  // src/credential.ts
948
1026
  var BOTH_OR_NEITHER = "Give either a SHASHU key or a token provider, not both.";
949
1027
  var REFRESH_SKEW_SECONDS = 60;
@@ -992,7 +1070,7 @@ function shouldRetryPassRefused(opts) {
992
1070
  }
993
1071
  var CredentialResolver = class {
994
1072
  constructor(opts) {
995
- const envKey = envGet(API_KEY_ENV, API_KEY_ENV_LEGACY) ?? void 0;
1073
+ const envKey = envGet(API_KEY_ENV) ?? void 0;
996
1074
  const hasKeyArg = opts.apiKey !== void 0;
997
1075
  const hasProvider = opts.tokenProvider !== void 0;
998
1076
  if (hasKeyArg && hasProvider) throw new ShashuConfigError(BOTH_OR_NEITHER);
@@ -1047,12 +1125,21 @@ function createShashuLangChainConfig(config) {
1047
1125
  ...buildContextHeaders(ctx, { defaultSessionId: config.sessionId ?? (0, import_node_crypto3.randomUUID)() })
1048
1126
  };
1049
1127
  applyContractVersion(headers, config.contractVersion);
1050
- const joining = withRetrievalJoiner();
1051
1128
  const fetch2 = async (input, init) => {
1052
- const token = await resolver.get();
1053
- const next = new Headers(init?.headers);
1054
- if (token) next.set("authorization", `Bearer ${token}`);
1055
- const res = await joining(input, { ...init, headers: next });
1129
+ const baseHeaders = new Headers(init?.headers);
1130
+ baseHeaders.delete("authorization");
1131
+ const headerObj = {};
1132
+ baseHeaders.forEach((v, k) => {
1133
+ headerObj[k] = v;
1134
+ });
1135
+ const pinned = pinOutgoing(input, { ...init, headers: headerObj });
1136
+ const send = async () => {
1137
+ const token = await resolver.get();
1138
+ const headers2 = { ...pinned.init?.headers || {} };
1139
+ if (token) headers2.authorization = `Bearer ${token}`;
1140
+ return globalThis.fetch(pinned.input, { ...pinned.init, headers: headers2 });
1141
+ };
1142
+ const res = await executeWithRetry(send, resolveRetryPolicy(config.retryPolicy));
1056
1143
  if (!resolver.usesProvider || res.status !== 401) return res;
1057
1144
  const code = passRefusalCodeFromText(await res.clone().text());
1058
1145
  if (!shouldRetryPassRefused({
@@ -1064,9 +1151,7 @@ function createShashuLangChainConfig(config) {
1064
1151
  return res;
1065
1152
  }
1066
1153
  resolver.invalidate();
1067
- const retryToken = await resolver.get();
1068
- if (retryToken) next.set("authorization", `Bearer ${retryToken}`);
1069
- return joining(input, { ...init, headers: next });
1154
+ return send();
1070
1155
  };
1071
1156
  return {
1072
1157
  baseURL: baseUrl,
@@ -1,3 +1,3 @@
1
- import '../types-Rs49lJyD.cjs';
2
- import '../_joiner-p5LFxJcu.cjs';
3
- export { g as DEFAULT_CORPUS, h as SOURCE, i as ShashuLangChainCallback, e as createShashuLangChainConfig, j as install, k as isInstalled, l as lcDocumentsToRagContext, u as uninstall } from '../langchain-xCWwa1Ud.cjs';
1
+ import '../types-BLs_TMFv.cjs';
2
+ import '../_joiner-DGi8GsY7.cjs';
3
+ export { g as DEFAULT_CORPUS, h as SOURCE, i as ShashuLangChainCallback, e as createShashuLangChainConfig, j as install, k as isInstalled, l as lcDocumentsToRagContext, u as uninstall } from '../langchain-DKyrUjk4.cjs';
@@ -1,3 +1,3 @@
1
- import '../types-Rs49lJyD.js';
2
- import '../_joiner-p5LFxJcu.js';
3
- export { g as DEFAULT_CORPUS, h as SOURCE, i as ShashuLangChainCallback, e as createShashuLangChainConfig, j as install, k as isInstalled, l as lcDocumentsToRagContext, u as uninstall } from '../langchain-DNOsiRna.js';
1
+ import '../types-BLs_TMFv.js';
2
+ import '../_joiner-DGi8GsY7.js';
3
+ export { g as DEFAULT_CORPUS, h as SOURCE, i as ShashuLangChainCallback, e as createShashuLangChainConfig, j as install, k as isInstalled, l as lcDocumentsToRagContext, u as uninstall } from '../langchain-QCATTIR4.js';
@@ -7,9 +7,9 @@ import {
7
7
  isInstalled,
8
8
  lcDocumentsToRagContext,
9
9
  uninstall
10
- } from "../chunk-4CDQ7JMK.js";
11
- import "../chunk-5TW3FISD.js";
12
- import "../chunk-IQYB5OZ6.js";
10
+ } from "../chunk-F4CXDZQB.js";
11
+ import "../chunk-M7EMWSNS.js";
12
+ import "../chunk-TGD6KDWT.js";
13
13
  export {
14
14
  DEFAULT_CORPUS,
15
15
  SOURCE,
@@ -60,50 +60,32 @@ var ShashuConfigError = class _ShashuConfigError extends ShashuError {
60
60
 
61
61
  // src/config.ts
62
62
  var BASE_URL_ENV = "SHASHU_BASE_URL";
63
- var BASE_URL_ENV_LEGACY = "TRUSTGATE_BASE_URL";
64
63
  var API_KEY_ENV = "SHASHU_API_KEY";
65
- var API_KEY_ENV_LEGACY = "TRUSTGATE_API_KEY";
66
64
  var DISABLE_ENV = "SHASHU_DISABLE";
67
- var DISABLE_ENV_LEGACY = "TRUSTGATE_DISABLE";
68
- var fallbackWarned = /* @__PURE__ */ new Set();
69
65
  var TRUTHY = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
70
66
  function env() {
71
67
  return typeof process !== "undefined" && process.env ? process.env : {};
72
68
  }
73
- function envGet(current2, legacy) {
74
- const e = env();
75
- const now = (e[current2] ?? "").trim();
76
- if (now) return now;
77
- const old = (e[legacy] ?? "").trim();
78
- if (old) {
79
- if (!fallbackWarned.has(legacy)) {
80
- fallbackWarned.add(legacy);
81
- console.warn(
82
- `${legacy} is deprecated; set ${current2} instead. The TRUSTGATE_* name still works for this release.`
83
- );
84
- }
85
- return old;
86
- }
87
- return void 0;
69
+ function envGet(current2, _legacy) {
70
+ const now = (env()[current2] ?? "").trim();
71
+ return now || void 0;
88
72
  }
89
73
  function isDisabled() {
90
- return TRUTHY.has((envGet(DISABLE_ENV, DISABLE_ENV_LEGACY) ?? "").trim().toLowerCase());
74
+ return TRUTHY.has((envGet(DISABLE_ENV) ?? "").trim().toLowerCase());
91
75
  }
92
76
  function firstConfigured(baseUrl, envVars) {
93
77
  if (baseUrl && baseUrl.trim()) return baseUrl.trim().replace(/\/+$/, "");
94
78
  for (const name of envVars) {
95
- const current2 = name.startsWith("TRUSTGATE_") ? name.replace("TRUSTGATE_", "SHASHU_") : name;
96
- const legacy = name.startsWith("SHASHU_") ? name.replace("SHASHU_", "TRUSTGATE_") : name.startsWith("TRUSTGATE_") ? name : "";
97
- const value = legacy && legacy !== current2 ? envGet(current2, legacy) : env()[name]?.trim();
79
+ const value = env()[name]?.trim();
98
80
  if (value) return value.replace(/\/+$/, "");
99
81
  }
100
82
  return void 0;
101
83
  }
102
- function optionalBaseUrl(baseUrl, envVars = [BASE_URL_ENV, BASE_URL_ENV_LEGACY]) {
84
+ function optionalBaseUrl(baseUrl, envVars = [BASE_URL_ENV]) {
103
85
  return firstConfigured(baseUrl, envVars);
104
86
  }
105
87
  function requireBaseUrl(baseUrl, opts) {
106
- const envVars = opts.envVars ?? [BASE_URL_ENV, BASE_URL_ENV_LEGACY];
88
+ const envVars = opts.envVars ?? [BASE_URL_ENV];
107
89
  const resolved = firstConfigured(baseUrl, envVars);
108
90
  if (resolved) return resolved;
109
91
  const option = opts.option ?? "baseUrl";
@@ -117,7 +99,7 @@ function requireBaseUrl(baseUrl, opts) {
117
99
  var import_node_crypto2 = require("crypto");
118
100
 
119
101
  // src/version.ts
120
- var SDK_VERSION = "1.0.0";
102
+ var SDK_VERSION = "1.1.1";
121
103
 
122
104
  // src/tracer.ts
123
105
  var import_node_async_hooks = require("async_hooks");
@@ -161,14 +143,14 @@ function parseHopDepth(raw) {
161
143
  return Number.isFinite(n) && n > 0 ? n : 0;
162
144
  }
163
145
  function captureFromHeaders(h) {
164
- const trace = (h["x-trustgate-trace-id"] ?? "").trim();
146
+ const trace = (h["x-shashu-trace-id"] ?? "").trim();
165
147
  if (!trace) return void 0;
166
- const session = (h["x-trustgate-session-id"] ?? "").trim();
167
- const caller = (h["x-trustgate-caller-agent-id"] ?? "").trim();
148
+ const session = (h["x-shashu-session-id"] ?? "").trim();
149
+ const caller = (h["x-shashu-caller-agent-id"] ?? "").trim();
168
150
  return {
169
151
  traceId: trace,
170
152
  sessionId: session || void 0,
171
- inboundHopDepth: parseHopDepth(h["x-trustgate-hop-depth"]),
153
+ inboundHopDepth: parseHopDepth(h["x-shashu-hop-depth"]),
172
154
  inboundCallerAgentId: caller || void 0
173
155
  };
174
156
  }
@@ -188,7 +170,7 @@ var Tracer = class {
188
170
  this.buffer = [];
189
171
  this.flushTimer = null;
190
172
  this._gatewayUrl = optionalBaseUrl();
191
- this._apiKey = envGet(API_KEY_ENV, API_KEY_ENV_LEGACY);
173
+ this._apiKey = envGet(API_KEY_ENV);
192
174
  }
193
175
  /**
194
176
  * Current gateway base URL (respects configure()), or undefined when none is
@@ -241,7 +223,7 @@ var Tracer = class {
241
223
  get sessionId() {
242
224
  return a2aStorage.getStore()?.sessionId || void 0;
243
225
  }
244
- /** Advisory inbound hop depth captured from x-trustgate-hop-depth (0 if absent). */
226
+ /** Advisory inbound hop depth captured from x-shashu-hop-depth (0 if absent). */
245
227
  get inboundHopDepth() {
246
228
  return a2aStorage.getStore()?.inboundHopDepth ?? 0;
247
229
  }
@@ -250,7 +232,7 @@ var Tracer = class {
250
232
  get outboundHopDepth() {
251
233
  return this.inboundHopDepth + 1;
252
234
  }
253
- /** The captured inbound x-trustgate-caller-agent-id — the upstream agent that INVOKED
235
+ /** The captured inbound x-shashu-caller-agent-id — the upstream agent that INVOKED
254
236
  * this hop. The SDK FORWARDS this on the outbound gateway call so the gateway records
255
237
  * the real (invoker -> this agent) edge, NEVER this agent's own id (§4.1). undefined at
256
238
  * origin / caller-stripped. */
@@ -260,7 +242,7 @@ var Tracer = class {
260
242
  /**
261
243
  * Capture an inbound flow from the headers of a request this agent is SERVING into the
262
244
  * AsyncLocalStorage store, so a downstream call made through the SDK propagates the SAME
263
- * flow (WP-A2A-4 / ADR-007 §0). Reads (case-insensitively) x-trustgate-trace-id (the flow
245
+ * flow (WP-A2A-4 / ADR-007 §0). Reads (case-insensitively) x-shashu-trace-id (the flow
264
246
  * id), -session-id, -hop-depth, and -caller-agent-id (the upstream INVOKER). The captured
265
247
  * trace is PROPAGATED on the next outbound call (never re-minted); the session, inbound hop
266
248
  * depth, and inbound caller ride along — the caller is FORWARDED on the gateway call (§4.1),
@@ -357,10 +339,10 @@ var Tracer = class {
357
339
  var tracer = new Tracer();
358
340
 
359
341
  // src/context.ts
360
- var HEADER_PREFIX = "x-trustgate";
361
- var SOURCE_TOOL_HEADER = "x-trustgate-source-tool";
342
+ var HEADER_PREFIX = "x-shashu";
343
+ var SOURCE_TOOL_HEADER = "x-shashu-source-tool";
362
344
  var DEFAULT_CONTRACT_VERSION = "2026-09-01";
363
- var CONTRACT_VERSION_HEADER = "trustgate-version";
345
+ var CONTRACT_VERSION_HEADER = "shashu-version";
364
346
  function applyContractVersion(headers, contractVersion) {
365
347
  if (contractVersion === null) return headers;
366
348
  const named = Object.keys(headers).some((k) => k.toLowerCase() === CONTRACT_VERSION_HEADER);
@@ -479,20 +461,20 @@ function buildContextHeaders(ctx, session) {
479
461
  if (v) h[`${TRUSTLOG_HEADER_PREFIX}${k.replace(/_/g, "-")}`] = String(v);
480
462
  }
481
463
  if (tracer.isActive) {
482
- if (tracer.traceId) h["x-trustgate-trace-id"] = tracer.traceId;
483
- h["x-trustgate-span-id"] = tracer.currentSpanId ?? "";
484
- h["x-trustgate-parent-id"] = tracer.parentSpanId ?? "";
464
+ if (tracer.traceId) h["x-shashu-trace-id"] = tracer.traceId;
465
+ h["x-shashu-span-id"] = tracer.currentSpanId ?? "";
466
+ h["x-shashu-parent-id"] = tracer.parentSpanId ?? "";
485
467
  } else if (tracer.isA2aHop) {
486
- if (tracer.traceId) h["x-trustgate-trace-id"] = tracer.traceId;
487
- } else if (!h["x-trustgate-trace-id"]) {
488
- h["x-trustgate-trace-id"] = resolveOriginTraceId();
468
+ if (tracer.traceId) h["x-shashu-trace-id"] = tracer.traceId;
469
+ } else if (!h["x-shashu-trace-id"]) {
470
+ h["x-shashu-trace-id"] = resolveOriginTraceId();
489
471
  }
490
472
  const sessionId = resolveSessionId(session);
491
- if (sessionId) h["x-trustgate-session-id"] = sessionId;
473
+ if (sessionId) h["x-shashu-session-id"] = sessionId;
492
474
  if (tracer.isA2aHop) {
493
475
  const inboundCaller = tracer.inboundCallerAgentId;
494
- if (inboundCaller) h["x-trustgate-caller-agent-id"] = inboundCaller;
495
- h["x-trustgate-hop-depth"] = String(tracer.outboundHopDepth);
476
+ if (inboundCaller) h["x-shashu-caller-agent-id"] = inboundCaller;
477
+ h["x-shashu-hop-depth"] = String(tracer.outboundHopDepth);
496
478
  }
497
479
  return lowercaseHeaderKeys(h);
498
480
  }
@@ -540,10 +522,10 @@ function attachRagContext(body, ragContext) {
540
522
  if (ragContext === null || typeof ragContext !== "object") {
541
523
  throw new TypeError("ragContext must be an object");
542
524
  }
543
- const existing = body.trustgate_metadata;
525
+ const existing = body.shashu_metadata;
544
526
  const meta = existing !== null && typeof existing === "object" ? existing : {};
545
527
  meta.rag_context = ragContext;
546
- body.trustgate_metadata = meta;
528
+ body.shashu_metadata = meta;
547
529
  return body;
548
530
  }
549
531
  var PREVIEW_KEYS = ["preview", "text", "content", "pageContent", "page_content", "body"];
@@ -673,9 +655,9 @@ function buildMemoryContext(events) {
673
655
  }
674
656
  function attachMemoryContext(body, memoryContext) {
675
657
  const bag = body;
676
- const existing = bag.trustgate_metadata;
658
+ const existing = bag.shashu_metadata;
677
659
  const metadata = existing !== null && typeof existing === "object" ? existing : {};
678
- bag.trustgate_metadata = { ...metadata, memory_context: memoryContext };
660
+ bag.shashu_metadata = { ...metadata, memory_context: memoryContext };
679
661
  return body;
680
662
  }
681
663
 
@@ -692,7 +674,7 @@ function parseJsonObject(body) {
692
674
  }
693
675
  }
694
676
  function metadataBag(body) {
695
- const metadata = body.trustgate_metadata;
677
+ const metadata = body.shashu_metadata;
696
678
  if (metadata !== null && typeof metadata === "object") {
697
679
  return metadata;
698
680
  }
@@ -848,7 +830,7 @@ function shouldRetryPassRefused(opts) {
848
830
  }
849
831
  var CredentialResolver = class {
850
832
  constructor(opts) {
851
- const envKey = envGet(API_KEY_ENV, API_KEY_ENV_LEGACY) ?? void 0;
833
+ const envKey = envGet(API_KEY_ENV) ?? void 0;
852
834
  const hasKeyArg = opts.apiKey !== void 0;
853
835
  const hasProvider = opts.tokenProvider !== void 0;
854
836
  if (hasKeyArg && hasProvider) throw new ShashuConfigError(BOTH_OR_NEITHER);