@shashu-ai/sdk 1.1.0 → 1.2.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +61 -44
  2. package/NOTICE +1 -1
  3. package/README.md +7 -4
  4. package/dist/{_joiner-CmR7qVK8.d.cts → _joiner-D_FGAaoc.d.cts} +1 -11
  5. package/dist/{_joiner-CmR7qVK8.d.ts → _joiner-D_FGAaoc.d.ts} +1 -11
  6. package/dist/{chunk-QJQ4MWQ4.js → chunk-CWC6GQTL.js} +2 -2
  7. package/dist/{chunk-QLK5CQSP.js → chunk-K4ZIXS2U.js} +1 -1
  8. package/dist/{chunk-WC3BKVXK.js → chunk-MLFWJAEH.js} +2 -2
  9. package/dist/{chunk-NTIOPTYF.js → chunk-MZGHCDWX.js} +23 -2
  10. package/dist/{chunk-QHWUNZQS.js → chunk-TI45NK2R.js} +2 -2
  11. package/dist/{chunk-L6GKR3SC.js → chunk-YSAQRZFP.js} +127 -12
  12. package/dist/index.cjs +80 -37
  13. package/dist/index.d.cts +17 -17
  14. package/dist/index.d.ts +17 -17
  15. package/dist/index.js +37 -119
  16. package/dist/{langchain-B9Q9eL7g.d.cts → langchain-CoNoZ_vQ.d.cts} +4 -4
  17. package/dist/{langchain-CHjjdhDr.d.ts → langchain-D9Xo9IMm.d.ts} +4 -4
  18. package/dist/middleware/anthropic.cjs +2 -2
  19. package/dist/middleware/anthropic.d.cts +3 -3
  20. package/dist/middleware/anthropic.d.ts +3 -3
  21. package/dist/middleware/anthropic.js +3 -3
  22. package/dist/middleware/google.cjs +1 -1
  23. package/dist/middleware/google.d.cts +2 -2
  24. package/dist/middleware/google.d.ts +2 -2
  25. package/dist/middleware/google.js +2 -2
  26. package/dist/middleware/langchain.cjs +159 -43
  27. package/dist/middleware/langchain.d.cts +3 -3
  28. package/dist/middleware/langchain.d.ts +3 -3
  29. package/dist/middleware/langchain.js +3 -3
  30. package/dist/middleware/vercel-ai.cjs +2 -2
  31. package/dist/middleware/vercel-ai.d.cts +3 -3
  32. package/dist/middleware/vercel-ai.d.ts +3 -3
  33. package/dist/middleware/vercel-ai.js +3 -3
  34. package/dist/{types-BLs_TMFv.d.ts → types-BQVfxZJP.d.cts} +7 -3
  35. package/dist/{types-BLs_TMFv.d.cts → types-BQVfxZJP.d.ts} +7 -3
  36. package/package.json +3 -4
@@ -1,21 +1,126 @@
1
1
  import {
2
2
  MAX_EVENTS,
3
3
  declareRetrieval,
4
- withRetrievalJoiner
5
- } from "./chunk-NTIOPTYF.js";
4
+ pinOutgoing
5
+ } from "./chunk-MZGHCDWX.js";
6
6
  import {
7
7
  CredentialResolver,
8
8
  applyContractVersion,
9
9
  buildContextHeaders,
10
+ gatewayRetryAfter,
10
11
  getWorkflowContextFromEnv,
11
12
  isDisabled,
12
13
  passRefusalCodeFromText,
13
14
  requireBaseUrl,
14
15
  shouldRetryPassRefused
15
- } from "./chunk-QJQ4MWQ4.js";
16
+ } from "./chunk-CWC6GQTL.js";
16
17
 
17
18
  // src/middleware/langchain.ts
18
19
  import { randomUUID } from "crypto";
20
+
21
+ // src/retry.ts
22
+ var DEFAULT_RETRY_POLICY = {
23
+ maxRetries: 2,
24
+ backoffBaseSeconds: 0.5,
25
+ backoffMaxSeconds: 30,
26
+ retryOnConnectionErrors: true,
27
+ retryOn429: true,
28
+ retryOn5xx: false,
29
+ neverRetryStatus: [400, 401, 403, 404],
30
+ ignoreRetryAfter: false,
31
+ jitterFraction: 0.2
32
+ };
33
+ function resolveRetryPolicy(policy) {
34
+ if (policy === null) return null;
35
+ if (policy === void 0) return { ...DEFAULT_RETRY_POLICY };
36
+ return { ...DEFAULT_RETRY_POLICY, ...policy };
37
+ }
38
+ function shouldRetryStatus(policy, status) {
39
+ if (policy.neverRetryStatus.includes(status)) return false;
40
+ if (status === 429) return policy.retryOn429;
41
+ if (status === 503) return true;
42
+ if (status >= 500 && status <= 599) return policy.retryOn5xx;
43
+ return false;
44
+ }
45
+ function truthyHeader(value) {
46
+ return ["1", "true", "yes", "on"].includes((value ?? "").trim().toLowerCase());
47
+ }
48
+ function gatewaySaysBusyRetry(res, retryAfter) {
49
+ if (res.status !== 429 && res.status !== 503) return false;
50
+ if (truthyHeader(res.headers.get("x-should-retry"))) return true;
51
+ return retryAfter !== void 0;
52
+ }
53
+ function shouldRetryResponse(policy, res, retryAfter) {
54
+ if (policy.neverRetryStatus.includes(res.status)) return false;
55
+ if (res.status === 429 || res.status === 503) {
56
+ if (res.status === 429 && !policy.retryOn429) return false;
57
+ return gatewaySaysBusyRetry(res, retryAfter);
58
+ }
59
+ if (!shouldRetryStatus(policy, res.status)) return false;
60
+ return true;
61
+ }
62
+ function delayFor(policy, attempt, res, retryAfter) {
63
+ const jitter = (seconds) => {
64
+ const frac = policy.jitterFraction ?? 0.2;
65
+ const capped = Math.min(policy.backoffMaxSeconds, seconds);
66
+ if (frac <= 0) return capped;
67
+ return Math.min(policy.backoffMaxSeconds, capped * (1 + Math.random() * frac));
68
+ };
69
+ if (res !== null && (res.status === 429 || res.status === 503) && !policy.ignoreRetryAfter && retryAfter !== void 0) {
70
+ return jitter(retryAfter);
71
+ }
72
+ return jitter(policy.backoffBaseSeconds * 2 ** attempt);
73
+ }
74
+ var UNSENT_CODES = /* @__PURE__ */ new Set([
75
+ "ECONNREFUSED",
76
+ "ENOTFOUND",
77
+ "EAI_AGAIN",
78
+ "ENETUNREACH",
79
+ "EHOSTUNREACH",
80
+ "UND_ERR_CONNECT",
81
+ "UND_ERR_CONNECT_TIMEOUT"
82
+ ]);
83
+ function requestNeverLeft(err) {
84
+ if (!(err instanceof TypeError)) return false;
85
+ const cause = err.cause;
86
+ const code = cause?.code ?? "";
87
+ if (UNSENT_CODES.has(code)) return true;
88
+ return cause?.name === "ConnectTimeoutError" || cause?.name === "ConnectError";
89
+ }
90
+ var defaultSleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
91
+ async function peekJson(res) {
92
+ try {
93
+ return await res.clone().json();
94
+ } catch {
95
+ return void 0;
96
+ }
97
+ }
98
+ async function executeWithRetry(send, policy, sleep = defaultSleep) {
99
+ if (policy === null) return send();
100
+ let attempt = 0;
101
+ for (; ; ) {
102
+ let res;
103
+ try {
104
+ res = await send();
105
+ } catch (err) {
106
+ if (policy.retryOnConnectionErrors && requestNeverLeft(err) && attempt < policy.maxRetries) {
107
+ await sleep(delayFor(policy, attempt, null, void 0));
108
+ attempt += 1;
109
+ continue;
110
+ }
111
+ throw err;
112
+ }
113
+ const retryAfter = res.status === 429 || res.status === 503 ? gatewayRetryAfter(res, await peekJson(res)) : void 0;
114
+ if (attempt < policy.maxRetries && shouldRetryResponse(policy, res, retryAfter)) {
115
+ await sleep(delayFor(policy, attempt, res, retryAfter));
116
+ attempt += 1;
117
+ continue;
118
+ }
119
+ return res;
120
+ }
121
+ }
122
+
123
+ // src/middleware/langchain.ts
19
124
  function createShashuLangChainConfig(config) {
20
125
  if (isDisabled()) return {};
21
126
  const baseUrl = requireBaseUrl(config.baseUrl, {
@@ -31,12 +136,21 @@ function createShashuLangChainConfig(config) {
31
136
  ...buildContextHeaders(ctx, { defaultSessionId: config.sessionId ?? randomUUID() })
32
137
  };
33
138
  applyContractVersion(headers, config.contractVersion);
34
- const joining = withRetrievalJoiner();
35
139
  const fetch = async (input, init) => {
36
- const token = await resolver.get();
37
- const next = new Headers(init?.headers);
38
- if (token) next.set("authorization", `Bearer ${token}`);
39
- const res = await joining(input, { ...init, headers: next });
140
+ const baseHeaders = new Headers(init?.headers);
141
+ baseHeaders.delete("authorization");
142
+ const headerObj = {};
143
+ baseHeaders.forEach((v, k) => {
144
+ headerObj[k] = v;
145
+ });
146
+ const pinned = pinOutgoing(input, { ...init, headers: headerObj });
147
+ const send = async () => {
148
+ const token = await resolver.get();
149
+ const headers2 = { ...pinned.init?.headers || {} };
150
+ if (token) headers2.authorization = `Bearer ${token}`;
151
+ return globalThis.fetch(pinned.input, { ...pinned.init, headers: headers2 });
152
+ };
153
+ const res = await executeWithRetry(send, resolveRetryPolicy(config.retryPolicy));
40
154
  if (!resolver.usesProvider || res.status !== 401) return res;
41
155
  const code = passRefusalCodeFromText(await res.clone().text());
42
156
  if (!shouldRetryPassRefused({
@@ -48,9 +162,7 @@ function createShashuLangChainConfig(config) {
48
162
  return res;
49
163
  }
50
164
  resolver.invalidate();
51
- const retryToken = await resolver.get();
52
- if (retryToken) next.set("authorization", `Bearer ${retryToken}`);
53
- return joining(input, { ...init, headers: next });
165
+ return send();
54
166
  };
55
167
  return {
56
168
  baseURL: baseUrl,
@@ -87,7 +199,7 @@ var SOURCE = "langchain";
87
199
  var DEFAULT_CORPUS = "langchain-retriever";
88
200
  var MAX_TRACKED_RUNS = 64;
89
201
  var captured = /* @__PURE__ */ new Map();
90
- var QUERY = /* @__PURE__ */ Symbol.for("trustgate.langchain.query");
202
+ var QUERY = /* @__PURE__ */ Symbol.for("shashu.langchain.query");
91
203
  var enabled = false;
92
204
  var patched = false;
93
205
  var corpusName = DEFAULT_CORPUS;
@@ -217,6 +329,9 @@ function isInstalled() {
217
329
  }
218
330
 
219
331
  export {
332
+ DEFAULT_RETRY_POLICY,
333
+ resolveRetryPolicy,
334
+ executeWithRetry,
220
335
  createShashuLangChainConfig,
221
336
  lcDocumentsToRagContext,
222
337
  SOURCE,
package/dist/index.cjs CHANGED
@@ -130,7 +130,7 @@ var ShashuError = class _ShashuError extends Error {
130
130
  };
131
131
 
132
132
  // src/exceptions.ts
133
- var PROVIDER_ERROR_PREFIX = "TrustGate Provider Error:";
133
+ var PROVIDER_ERROR_PREFIX = "SHASHU Provider Error:";
134
134
  var ShashuConfigError = class _ShashuConfigError extends ShashuError {
135
135
  constructor(message) {
136
136
  super(message, 0);
@@ -360,7 +360,7 @@ function requireBaseUrl(baseUrl, opts) {
360
360
  var import_node_crypto2 = require("crypto");
361
361
 
362
362
  // src/version.ts
363
- var SDK_VERSION = "1.1.0";
363
+ var SDK_VERSION = "1.2.0";
364
364
 
365
365
  // src/tracer.ts
366
366
  var import_node_async_hooks = require("async_hooks");
@@ -866,8 +866,21 @@ function delayFor(policy, attempt, res, retryAfter) {
866
866
  }
867
867
  return jitter(policy.backoffBaseSeconds * 2 ** attempt);
868
868
  }
869
- function isConnectionError(err) {
870
- return err instanceof TypeError;
869
+ var UNSENT_CODES = /* @__PURE__ */ new Set([
870
+ "ECONNREFUSED",
871
+ "ENOTFOUND",
872
+ "EAI_AGAIN",
873
+ "ENETUNREACH",
874
+ "EHOSTUNREACH",
875
+ "UND_ERR_CONNECT",
876
+ "UND_ERR_CONNECT_TIMEOUT"
877
+ ]);
878
+ function requestNeverLeft(err) {
879
+ if (!(err instanceof TypeError)) return false;
880
+ const cause = err.cause;
881
+ const code = cause?.code ?? "";
882
+ if (UNSENT_CODES.has(code)) return true;
883
+ return cause?.name === "ConnectTimeoutError" || cause?.name === "ConnectError";
871
884
  }
872
885
  var defaultSleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
873
886
  async function peekJson(res) {
@@ -885,7 +898,7 @@ async function executeWithRetry(send, policy, sleep = defaultSleep) {
885
898
  try {
886
899
  res = await send();
887
900
  } catch (err) {
888
- if (policy.retryOnConnectionErrors && isConnectionError(err) && attempt < policy.maxRetries) {
901
+ if (policy.retryOnConnectionErrors && requestNeverLeft(err) && attempt < policy.maxRetries) {
889
902
  await sleep(delayFor(policy, attempt, null, void 0));
890
903
  attempt += 1;
891
904
  continue;
@@ -1356,8 +1369,28 @@ function takeContextFor(body) {
1356
1369
  }
1357
1370
  return mutated ? body : void 0;
1358
1371
  }
1372
+ function pinOutgoing(input, init) {
1373
+ if (!hasEvents()) return { input, init };
1374
+ if (isDisabled()) {
1375
+ clear();
1376
+ return { input, init };
1377
+ }
1378
+ const body = parseJsonObject(init?.body);
1379
+ if (body === void 0) return { input, init };
1380
+ const merged = takeContextFor(body);
1381
+ if (merged === void 0) return { input, init };
1382
+ const encoded = JSON.stringify(merged);
1383
+ return {
1384
+ input,
1385
+ init: {
1386
+ ...init,
1387
+ body: encoded,
1388
+ headers: fixContentLength(init?.headers, byteLength(encoded))
1389
+ }
1390
+ };
1391
+ }
1359
1392
  function withRetrievalJoiner(underlying = globalFetch) {
1360
- return async function trustgateJoiningFetch(input, init) {
1393
+ return async function shashuJoiningFetch(input, init) {
1361
1394
  if (!hasEvents()) return underlying(input, init);
1362
1395
  if (isDisabled()) {
1363
1396
  clear();
@@ -1647,10 +1680,10 @@ function blockSource(bodyEnv, headers) {
1647
1680
  }
1648
1681
  return headers != null ? { headers } : void 0;
1649
1682
  }
1650
- var SOURCE = /* @__PURE__ */ Symbol("trustgate.decision.blocks");
1651
- var ATTACHMENTS = /* @__PURE__ */ Symbol("trustgate.decision.attachments");
1652
- var MEMORY = /* @__PURE__ */ Symbol("trustgate.decision.memory");
1653
- var UNREAD = /* @__PURE__ */ Symbol("trustgate.decision.unread");
1683
+ var SOURCE = /* @__PURE__ */ Symbol("shashu.decision.blocks");
1684
+ var ATTACHMENTS = /* @__PURE__ */ Symbol("shashu.decision.attachments");
1685
+ var MEMORY = /* @__PURE__ */ Symbol("shashu.decision.memory");
1686
+ var UNREAD = /* @__PURE__ */ Symbol("shashu.decision.unread");
1654
1687
  var _a, _b;
1655
1688
  SOURCE, _b = ATTACHMENTS, _a = MEMORY;
1656
1689
  var DecisionRecord = class {
@@ -1923,14 +1956,14 @@ var CredentialResolver = class {
1923
1956
  };
1924
1957
 
1925
1958
  // src/client.ts
1926
- var USER_AGENT = `trustgate-node/${SDK_VERSION}`;
1959
+ var USER_AGENT = `shashu-node/${SDK_VERSION}`;
1927
1960
  var joiningFetch = withRetrievalJoiner();
1928
1961
  var streamingInertWarningEmitted = false;
1929
1962
  function warnStreamingInert() {
1930
1963
  if (streamingInertWarningEmitted) return;
1931
1964
  streamingInertWarningEmitted = true;
1932
1965
  console.warn(
1933
- "[trustgate] Streaming is not yet supported end-to-end: the gateway buffers /v1/chat/completions and returns full JSON regardless of the `stream` flag, so no incremental tokens are produced. fetchStream() will fall back to the buffered response. (warned once per process)"
1966
+ "[shashu] Streaming is not yet supported end-to-end: the gateway buffers /v1/chat/completions and returns full JSON regardless of the `stream` flag, so no incremental tokens are produced. fetchStream() will fall back to the buffered response. (warned once per process)"
1934
1967
  );
1935
1968
  }
1936
1969
  function resolveContext(config, options) {
@@ -2038,27 +2071,30 @@ var Shashu = class {
2038
2071
  const context = resolveContext(this.config, options);
2039
2072
  const url = path.startsWith("http") ? path : `${this.resolvedBaseUrl}/${path.replace(/^\//, "")}`;
2040
2073
  const timeout = options?.timeout ?? 6e4;
2041
- const send = async () => {
2042
- const token = await this.resolver.get();
2043
- const headers = mergeHeaders(
2044
- this.config,
2045
- options,
2046
- context,
2047
- {
2074
+ const headersOnce = applyContractVersion(
2075
+ {
2076
+ ...mergeHeaders(this.config, options, context, {
2048
2077
  defaultSessionId: this._sessionId,
2049
2078
  requestSessionId: options?.sessionId
2050
- },
2051
- token
2052
- );
2079
+ }),
2080
+ ...init.headers
2081
+ },
2082
+ this.config.contractVersion
2083
+ );
2084
+ const frozenHeaders = { ...headersOnce };
2085
+ delete frozenHeaders["authorization"];
2086
+ delete frozenHeaders["Authorization"];
2087
+ const pinned = pinOutgoing(url, { ...init, headers: frozenHeaders });
2088
+ const send = async () => {
2089
+ const token = await this.resolver.get();
2053
2090
  const controller = new AbortController();
2054
2091
  const id = setTimeout(() => controller.abort(), timeout);
2055
2092
  try {
2056
- return await joiningFetch(url, {
2057
- ...init,
2058
- headers: applyContractVersion(
2059
- { ...headers, ...init.headers },
2060
- this.config.contractVersion
2061
- ),
2093
+ const headers = { ...pinned.init?.headers };
2094
+ if (token) headers["authorization"] = `Bearer ${token}`;
2095
+ return await joiningFetch(pinned.input, {
2096
+ ...pinned.init,
2097
+ headers,
2062
2098
  signal: init.signal ?? controller.signal
2063
2099
  });
2064
2100
  } finally {
@@ -2190,7 +2226,7 @@ function shashuFetch(options = {}) {
2190
2226
  if (options.headers) {
2191
2227
  for (const [k, v] of Object.entries(options.headers)) baked[k.toLowerCase()] = v;
2192
2228
  }
2193
- return async function trustgateFetching(input, init) {
2229
+ return async function shashuFetching(input, init) {
2194
2230
  const send = async () => {
2195
2231
  const headers = { ...baked };
2196
2232
  const extra = init?.headers;
@@ -2322,12 +2358,21 @@ function createShashuLangChainConfig(config) {
2322
2358
  ...buildContextHeaders(ctx, { defaultSessionId: config.sessionId ?? (0, import_node_crypto6.randomUUID)() })
2323
2359
  };
2324
2360
  applyContractVersion(headers, config.contractVersion);
2325
- const joining = withRetrievalJoiner();
2326
2361
  const fetch2 = async (input, init) => {
2327
- const token = await resolver.get();
2328
- const next = new Headers(init?.headers);
2329
- if (token) next.set("authorization", `Bearer ${token}`);
2330
- const res = await joining(input, { ...init, headers: next });
2362
+ const baseHeaders = new Headers(init?.headers);
2363
+ baseHeaders.delete("authorization");
2364
+ const headerObj = {};
2365
+ baseHeaders.forEach((v, k) => {
2366
+ headerObj[k] = v;
2367
+ });
2368
+ const pinned = pinOutgoing(input, { ...init, headers: headerObj });
2369
+ const send = async () => {
2370
+ const token = await resolver.get();
2371
+ const headers2 = { ...pinned.init?.headers || {} };
2372
+ if (token) headers2.authorization = `Bearer ${token}`;
2373
+ return globalThis.fetch(pinned.input, { ...pinned.init, headers: headers2 });
2374
+ };
2375
+ const res = await executeWithRetry(send, resolveRetryPolicy(config.retryPolicy));
2331
2376
  if (!resolver.usesProvider || res.status !== 401) return res;
2332
2377
  const code = passRefusalCodeFromText(await res.clone().text());
2333
2378
  if (!shouldRetryPassRefused({
@@ -2339,9 +2384,7 @@ function createShashuLangChainConfig(config) {
2339
2384
  return res;
2340
2385
  }
2341
2386
  resolver.invalidate();
2342
- const retryToken = await resolver.get();
2343
- if (retryToken) next.set("authorization", `Bearer ${retryToken}`);
2344
- return joining(input, { ...init, headers: next });
2387
+ return send();
2345
2388
  };
2346
2389
  return {
2347
2390
  baseURL: baseUrl,
package/dist/index.d.cts 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-BLs_TMFv.cjs';
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.cjs';
3
- import { F as FetchLike } from './_joiner-CmR7qVK8.cjs';
4
- export { w as withRetrievalJoiner } from './_joiner-CmR7qVK8.cjs';
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-B9Q9eL7g.cjs';
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-BQVfxZJP.cjs';
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-BQVfxZJP.cjs';
3
+ import { F as FetchLike } from './_joiner-D_FGAaoc.cjs';
4
+ export { w as withRetrievalJoiner } from './_joiner-D_FGAaoc.cjs';
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-CoNoZ_vQ.cjs';
6
6
  export { ShashuOpenAIOptions, createShashuOpenAIOptions, getShashuHeaders } from './middleware/vercel-ai.cjs';
7
7
  export { createShashuAnthropicConfig, getAnthropicHeaders } from './middleware/anthropic.cjs';
8
8
  export { createShashuGeminiConfig, getGeminiHeaders } from './middleware/google.cjs';
@@ -97,7 +97,7 @@ declare class Audit {
97
97
 
98
98
  /**
99
99
  * Shashu Node.js client. All traffic is sent to the Shashu gateway with
100
- * Bearer auth (tg_sk_...). The gateway routes to OpenAI/Anthropic based on
100
+ * Bearer auth (shashu_sk_...). The gateway routes to OpenAI/Anthropic based on
101
101
  * the `model` field in the request body.
102
102
  */
103
103
  declare class Shashu {
@@ -262,7 +262,7 @@ declare const HEADER_PREFIX = "x-shashu";
262
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
- * same value the Python SDK sends (`trustgate.context.DEFAULT_CONTRACT_VERSION`).
265
+ * same value the Python SDK sends (`shashu.context.DEFAULT_CONTRACT_VERSION`).
266
266
  *
267
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
@@ -337,7 +337,7 @@ declare function buildInvocationHeaders(opts: InvocationHeaderOptions): Record<s
337
337
  * Shashu SDK exception hierarchy (mirrors the Python SDK).
338
338
  *
339
339
  * Every shape named below is a verbatim capture from a running gateway, taken
340
- * with `sdks/e2e/capture_error_contract.py` in the trustgate-ai repo. That
340
+ * with `sdks/e2e/capture_error_contract.py` in the gateway repo. That
341
341
  * harness is the source of truth for this module; a claim that cannot be
342
342
  * reproduced with it does not belong here. The previous version of this header
343
343
  * was derived from an investigation write-up and got three things wrong — see
@@ -373,11 +373,11 @@ declare function buildInvocationHeaders(opts: InvocationHeaderOptions): Record<s
373
373
  * not the discriminator this module once called it.
374
374
  *
375
375
  * **A 401 is not always about your key.** The gateway's own auth failure sends
376
- * `type="invalid_request_error"` with message `"Invalid TrustGate API Key"` or
376
+ * `type="invalid_request_error"` with message `"Invalid SHASHU API Key"` or
377
377
  * `"Not authenticated"` (the latter with a `WWW-Authenticate: Bearer` header).
378
378
  * A 401 carrying `type="authentication_error"` and a message prefixed
379
- * `"TrustGate Provider Error: "` is a **pass-through**: the gateway's own stored
380
- * provider credential was rejected upstream. Your `tg_sk_` key is fine and
379
+ * `"SHASHU Provider Error: "` is a **pass-through**: the gateway's own stored
380
+ * provider credential was rejected upstream. Your `shashu_sk_` key is fine and
381
381
  * rotating it changes nothing — a gateway operator has to fix the provider
382
382
  * secret. The same is true of 403 (`ProviderPermissionError`), 404, 429 and the
383
383
  * 5xx family. This module used to attribute `authentication_error` to the
@@ -400,7 +400,7 @@ declare function buildInvocationHeaders(opts: InvocationHeaderOptions): Record<s
400
400
  * still exported so existing `catch` clauses type-check, but nothing throws it —
401
401
  * every 403 is a `ShashuPolicyViolation`. Catch `ShashuPermissionError` to
402
402
  * cover both. It becomes reachable again if the gateway ships a real
403
- * discriminator (ticket TRUSTGATE-403-DISCRIMINATOR).
403
+ * discriminator (the 403 discriminator ticket).
404
404
  *
405
405
  * `ShashuError` remains the base (re-exported from "./types.js" for
406
406
  * backward compatibility), so existing `catch (e) { e instanceof ShashuError }`
@@ -440,11 +440,11 @@ declare class ShashuConfigError extends ShashuError {
440
440
  * Two different producers land here and they need opposite fixes:
441
441
  *
442
442
  * - the **gateway's own** agent-key check — missing, unknown, deactivated or
443
- * rotated `tg_sk_` key. `type="invalid_request_error"`, message
444
- * `"Invalid TrustGate API Key"` or `"Not authenticated"`. Fix: your key.
443
+ * rotated `shashu_sk_` key. `type="invalid_request_error"`, message
444
+ * `"Invalid SHASHU API Key"` or `"Not authenticated"`. Fix: your key.
445
445
  * - a **provider pass-through** — the gateway's stored provider credential was
446
446
  * rejected upstream. `type="authentication_error"`, message prefixed
447
- * `"TrustGate Provider Error: "`. Your key is fine; rotating it changes
447
+ * `"SHASHU Provider Error: "`. Your key is fine; rotating it changes
448
448
  * nothing. Fix: a gateway operator replaces the provider secret.
449
449
  *
450
450
  * {@link isProviderPassthrough} tells them apart.
@@ -492,8 +492,8 @@ declare class ShashuPermissionError extends ShashuError {
492
492
  * Kept exported so existing `catch` clauses still type-check. Catch
493
493
  * {@link ShashuPermissionError} to cover budget and policy together. This
494
494
  * class becomes reachable again if the gateway ships a real discriminator
495
- * (ticket TRUSTGATE-403-DISCRIMINATOR,
496
- * https://github.com/aisquad001/trustgate-ai/issues/736).
495
+ * (the 403 discriminator ticket,
496
+ * the gateway issue tracker (403 discriminator)).
497
497
  */
498
498
  declare class ShashuBudgetExceededError extends ShashuPermissionError {
499
499
  constructor(message: string, status: number, body?: unknown, details?: ErrorDetails);
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-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-CmR7qVK8.js';
4
- export { w as withRetrievalJoiner } from './_joiner-CmR7qVK8.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-CHjjdhDr.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-BQVfxZJP.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-BQVfxZJP.js';
3
+ import { F as FetchLike } from './_joiner-D_FGAaoc.js';
4
+ export { w as withRetrievalJoiner } from './_joiner-D_FGAaoc.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-D9Xo9IMm.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';
@@ -97,7 +97,7 @@ declare class Audit {
97
97
 
98
98
  /**
99
99
  * Shashu Node.js client. All traffic is sent to the Shashu gateway with
100
- * Bearer auth (tg_sk_...). The gateway routes to OpenAI/Anthropic based on
100
+ * Bearer auth (shashu_sk_...). The gateway routes to OpenAI/Anthropic based on
101
101
  * the `model` field in the request body.
102
102
  */
103
103
  declare class Shashu {
@@ -262,7 +262,7 @@ declare const HEADER_PREFIX = "x-shashu";
262
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
- * same value the Python SDK sends (`trustgate.context.DEFAULT_CONTRACT_VERSION`).
265
+ * same value the Python SDK sends (`shashu.context.DEFAULT_CONTRACT_VERSION`).
266
266
  *
267
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
@@ -337,7 +337,7 @@ declare function buildInvocationHeaders(opts: InvocationHeaderOptions): Record<s
337
337
  * Shashu SDK exception hierarchy (mirrors the Python SDK).
338
338
  *
339
339
  * Every shape named below is a verbatim capture from a running gateway, taken
340
- * with `sdks/e2e/capture_error_contract.py` in the trustgate-ai repo. That
340
+ * with `sdks/e2e/capture_error_contract.py` in the gateway repo. That
341
341
  * harness is the source of truth for this module; a claim that cannot be
342
342
  * reproduced with it does not belong here. The previous version of this header
343
343
  * was derived from an investigation write-up and got three things wrong — see
@@ -373,11 +373,11 @@ declare function buildInvocationHeaders(opts: InvocationHeaderOptions): Record<s
373
373
  * not the discriminator this module once called it.
374
374
  *
375
375
  * **A 401 is not always about your key.** The gateway's own auth failure sends
376
- * `type="invalid_request_error"` with message `"Invalid TrustGate API Key"` or
376
+ * `type="invalid_request_error"` with message `"Invalid SHASHU API Key"` or
377
377
  * `"Not authenticated"` (the latter with a `WWW-Authenticate: Bearer` header).
378
378
  * A 401 carrying `type="authentication_error"` and a message prefixed
379
- * `"TrustGate Provider Error: "` is a **pass-through**: the gateway's own stored
380
- * provider credential was rejected upstream. Your `tg_sk_` key is fine and
379
+ * `"SHASHU Provider Error: "` is a **pass-through**: the gateway's own stored
380
+ * provider credential was rejected upstream. Your `shashu_sk_` key is fine and
381
381
  * rotating it changes nothing — a gateway operator has to fix the provider
382
382
  * secret. The same is true of 403 (`ProviderPermissionError`), 404, 429 and the
383
383
  * 5xx family. This module used to attribute `authentication_error` to the
@@ -400,7 +400,7 @@ declare function buildInvocationHeaders(opts: InvocationHeaderOptions): Record<s
400
400
  * still exported so existing `catch` clauses type-check, but nothing throws it —
401
401
  * every 403 is a `ShashuPolicyViolation`. Catch `ShashuPermissionError` to
402
402
  * cover both. It becomes reachable again if the gateway ships a real
403
- * discriminator (ticket TRUSTGATE-403-DISCRIMINATOR).
403
+ * discriminator (the 403 discriminator ticket).
404
404
  *
405
405
  * `ShashuError` remains the base (re-exported from "./types.js" for
406
406
  * backward compatibility), so existing `catch (e) { e instanceof ShashuError }`
@@ -440,11 +440,11 @@ declare class ShashuConfigError extends ShashuError {
440
440
  * Two different producers land here and they need opposite fixes:
441
441
  *
442
442
  * - the **gateway's own** agent-key check — missing, unknown, deactivated or
443
- * rotated `tg_sk_` key. `type="invalid_request_error"`, message
444
- * `"Invalid TrustGate API Key"` or `"Not authenticated"`. Fix: your key.
443
+ * rotated `shashu_sk_` key. `type="invalid_request_error"`, message
444
+ * `"Invalid SHASHU API Key"` or `"Not authenticated"`. Fix: your key.
445
445
  * - a **provider pass-through** — the gateway's stored provider credential was
446
446
  * rejected upstream. `type="authentication_error"`, message prefixed
447
- * `"TrustGate Provider Error: "`. Your key is fine; rotating it changes
447
+ * `"SHASHU Provider Error: "`. Your key is fine; rotating it changes
448
448
  * nothing. Fix: a gateway operator replaces the provider secret.
449
449
  *
450
450
  * {@link isProviderPassthrough} tells them apart.
@@ -492,8 +492,8 @@ declare class ShashuPermissionError extends ShashuError {
492
492
  * Kept exported so existing `catch` clauses still type-check. Catch
493
493
  * {@link ShashuPermissionError} to cover budget and policy together. This
494
494
  * class becomes reachable again if the gateway ships a real discriminator
495
- * (ticket TRUSTGATE-403-DISCRIMINATOR,
496
- * https://github.com/aisquad001/trustgate-ai/issues/736).
495
+ * (the 403 discriminator ticket,
496
+ * the gateway issue tracker (403 discriminator)).
497
497
  */
498
498
  declare class ShashuBudgetExceededError extends ShashuPermissionError {
499
499
  constructor(message: string, status: number, body?: unknown, details?: ErrorDetails);