@shashu-ai/sdk 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +18 -18
- package/dist/{_joiner-p5LFxJcu.d.cts → _joiner-CmR7qVK8.d.cts} +1 -1
- package/dist/{_joiner-p5LFxJcu.d.ts → _joiner-CmR7qVK8.d.ts} +1 -1
- package/dist/{chunk-4CDQ7JMK.js → chunk-L6GKR3SC.js} +2 -2
- package/dist/{chunk-5TW3FISD.js → chunk-NTIOPTYF.js} +6 -6
- package/dist/{chunk-M4JDSAUC.js → chunk-QHWUNZQS.js} +2 -2
- package/dist/{chunk-IQYB5OZ6.js → chunk-QJQ4MWQ4.js} +33 -53
- package/dist/{chunk-BEU2UWW3.js → chunk-QLK5CQSP.js} +1 -1
- package/dist/{chunk-Z6DROYQA.js → chunk-WC3BKVXK.js} +2 -2
- package/dist/index.cjs +79 -77
- package/dist/index.d.cts +30 -30
- package/dist/index.d.ts +30 -30
- package/dist/index.js +47 -29
- package/dist/{langchain-DNOsiRna.d.ts → langchain-B9Q9eL7g.d.cts} +11 -11
- package/dist/{langchain-xCWwa1Ud.d.cts → langchain-CHjjdhDr.d.ts} +11 -11
- package/dist/middleware/anthropic.cjs +34 -52
- package/dist/middleware/anthropic.d.cts +5 -5
- package/dist/middleware/anthropic.d.ts +5 -5
- package/dist/middleware/anthropic.js +3 -3
- package/dist/middleware/google.cjs +28 -46
- package/dist/middleware/google.d.cts +5 -5
- package/dist/middleware/google.d.ts +5 -5
- package/dist/middleware/google.js +2 -2
- package/dist/middleware/langchain.cjs +34 -52
- package/dist/middleware/langchain.d.cts +3 -3
- package/dist/middleware/langchain.d.ts +3 -3
- package/dist/middleware/langchain.js +3 -3
- package/dist/middleware/vercel-ai.cjs +34 -52
- package/dist/middleware/vercel-ai.d.cts +8 -8
- package/dist/middleware/vercel-ai.d.ts +8 -8
- package/dist/middleware/vercel-ai.js +3 -3
- package/dist/{types-Rs49lJyD.d.ts → types-BLs_TMFv.d.cts} +18 -16
- package/dist/{types-Rs49lJyD.d.cts → types-BLs_TMFv.d.ts} +18 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -321,50 +321,32 @@ function raiseIfContentFiltered(json, decision, headers) {
|
|
|
321
321
|
|
|
322
322
|
// src/config.ts
|
|
323
323
|
var BASE_URL_ENV = "SHASHU_BASE_URL";
|
|
324
|
-
var BASE_URL_ENV_LEGACY = "TRUSTGATE_BASE_URL";
|
|
325
324
|
var API_KEY_ENV = "SHASHU_API_KEY";
|
|
326
|
-
var API_KEY_ENV_LEGACY = "TRUSTGATE_API_KEY";
|
|
327
325
|
var DISABLE_ENV = "SHASHU_DISABLE";
|
|
328
|
-
var DISABLE_ENV_LEGACY = "TRUSTGATE_DISABLE";
|
|
329
|
-
var fallbackWarned = /* @__PURE__ */ new Set();
|
|
330
326
|
var TRUTHY = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
|
|
331
327
|
function env() {
|
|
332
328
|
return typeof process !== "undefined" && process.env ? process.env : {};
|
|
333
329
|
}
|
|
334
|
-
function envGet(current2,
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
if (now) return now;
|
|
338
|
-
const old = (e[legacy] ?? "").trim();
|
|
339
|
-
if (old) {
|
|
340
|
-
if (!fallbackWarned.has(legacy)) {
|
|
341
|
-
fallbackWarned.add(legacy);
|
|
342
|
-
console.warn(
|
|
343
|
-
`${legacy} is deprecated; set ${current2} instead. The TRUSTGATE_* name still works for this release.`
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
return old;
|
|
347
|
-
}
|
|
348
|
-
return void 0;
|
|
330
|
+
function envGet(current2, _legacy) {
|
|
331
|
+
const now = (env()[current2] ?? "").trim();
|
|
332
|
+
return now || void 0;
|
|
349
333
|
}
|
|
350
334
|
function isDisabled() {
|
|
351
|
-
return TRUTHY.has((envGet(DISABLE_ENV
|
|
335
|
+
return TRUTHY.has((envGet(DISABLE_ENV) ?? "").trim().toLowerCase());
|
|
352
336
|
}
|
|
353
337
|
function firstConfigured(baseUrl, envVars) {
|
|
354
338
|
if (baseUrl && baseUrl.trim()) return baseUrl.trim().replace(/\/+$/, "");
|
|
355
339
|
for (const name of envVars) {
|
|
356
|
-
const
|
|
357
|
-
const legacy = name.startsWith("SHASHU_") ? name.replace("SHASHU_", "TRUSTGATE_") : name.startsWith("TRUSTGATE_") ? name : "";
|
|
358
|
-
const value = legacy && legacy !== current2 ? envGet(current2, legacy) : env()[name]?.trim();
|
|
340
|
+
const value = env()[name]?.trim();
|
|
359
341
|
if (value) return value.replace(/\/+$/, "");
|
|
360
342
|
}
|
|
361
343
|
return void 0;
|
|
362
344
|
}
|
|
363
|
-
function optionalBaseUrl(baseUrl, envVars = [BASE_URL_ENV
|
|
345
|
+
function optionalBaseUrl(baseUrl, envVars = [BASE_URL_ENV]) {
|
|
364
346
|
return firstConfigured(baseUrl, envVars);
|
|
365
347
|
}
|
|
366
348
|
function requireBaseUrl(baseUrl, opts) {
|
|
367
|
-
const envVars = opts.envVars ?? [BASE_URL_ENV
|
|
349
|
+
const envVars = opts.envVars ?? [BASE_URL_ENV];
|
|
368
350
|
const resolved = firstConfigured(baseUrl, envVars);
|
|
369
351
|
if (resolved) return resolved;
|
|
370
352
|
const option = opts.option ?? "baseUrl";
|
|
@@ -378,7 +360,7 @@ function requireBaseUrl(baseUrl, opts) {
|
|
|
378
360
|
var import_node_crypto2 = require("crypto");
|
|
379
361
|
|
|
380
362
|
// src/version.ts
|
|
381
|
-
var SDK_VERSION = "1.
|
|
363
|
+
var SDK_VERSION = "1.1.0";
|
|
382
364
|
|
|
383
365
|
// src/tracer.ts
|
|
384
366
|
var import_node_async_hooks = require("async_hooks");
|
|
@@ -422,14 +404,14 @@ function parseHopDepth(raw) {
|
|
|
422
404
|
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
423
405
|
}
|
|
424
406
|
function captureFromHeaders(h) {
|
|
425
|
-
const trace = (h["x-
|
|
407
|
+
const trace = (h["x-shashu-trace-id"] ?? "").trim();
|
|
426
408
|
if (!trace) return void 0;
|
|
427
|
-
const session = (h["x-
|
|
428
|
-
const caller = (h["x-
|
|
409
|
+
const session = (h["x-shashu-session-id"] ?? "").trim();
|
|
410
|
+
const caller = (h["x-shashu-caller-agent-id"] ?? "").trim();
|
|
429
411
|
return {
|
|
430
412
|
traceId: trace,
|
|
431
413
|
sessionId: session || void 0,
|
|
432
|
-
inboundHopDepth: parseHopDepth(h["x-
|
|
414
|
+
inboundHopDepth: parseHopDepth(h["x-shashu-hop-depth"]),
|
|
433
415
|
inboundCallerAgentId: caller || void 0
|
|
434
416
|
};
|
|
435
417
|
}
|
|
@@ -449,7 +431,7 @@ var Tracer = class {
|
|
|
449
431
|
this.buffer = [];
|
|
450
432
|
this.flushTimer = null;
|
|
451
433
|
this._gatewayUrl = optionalBaseUrl();
|
|
452
|
-
this._apiKey = envGet(API_KEY_ENV
|
|
434
|
+
this._apiKey = envGet(API_KEY_ENV);
|
|
453
435
|
}
|
|
454
436
|
/**
|
|
455
437
|
* Current gateway base URL (respects configure()), or undefined when none is
|
|
@@ -502,7 +484,7 @@ var Tracer = class {
|
|
|
502
484
|
get sessionId() {
|
|
503
485
|
return a2aStorage.getStore()?.sessionId || void 0;
|
|
504
486
|
}
|
|
505
|
-
/** Advisory inbound hop depth captured from x-
|
|
487
|
+
/** Advisory inbound hop depth captured from x-shashu-hop-depth (0 if absent). */
|
|
506
488
|
get inboundHopDepth() {
|
|
507
489
|
return a2aStorage.getStore()?.inboundHopDepth ?? 0;
|
|
508
490
|
}
|
|
@@ -511,7 +493,7 @@ var Tracer = class {
|
|
|
511
493
|
get outboundHopDepth() {
|
|
512
494
|
return this.inboundHopDepth + 1;
|
|
513
495
|
}
|
|
514
|
-
/** The captured inbound x-
|
|
496
|
+
/** The captured inbound x-shashu-caller-agent-id — the upstream agent that INVOKED
|
|
515
497
|
* this hop. The SDK FORWARDS this on the outbound gateway call so the gateway records
|
|
516
498
|
* the real (invoker -> this agent) edge, NEVER this agent's own id (§4.1). undefined at
|
|
517
499
|
* origin / caller-stripped. */
|
|
@@ -521,7 +503,7 @@ var Tracer = class {
|
|
|
521
503
|
/**
|
|
522
504
|
* Capture an inbound flow from the headers of a request this agent is SERVING into the
|
|
523
505
|
* AsyncLocalStorage store, so a downstream call made through the SDK propagates the SAME
|
|
524
|
-
* flow (WP-A2A-4 / ADR-007 §0). Reads (case-insensitively) x-
|
|
506
|
+
* flow (WP-A2A-4 / ADR-007 §0). Reads (case-insensitively) x-shashu-trace-id (the flow
|
|
525
507
|
* id), -session-id, -hop-depth, and -caller-agent-id (the upstream INVOKER). The captured
|
|
526
508
|
* trace is PROPAGATED on the next outbound call (never re-minted); the session, inbound hop
|
|
527
509
|
* depth, and inbound caller ride along — the caller is FORWARDED on the gateway call (§4.1),
|
|
@@ -621,10 +603,10 @@ function captureIncoming(headers) {
|
|
|
621
603
|
}
|
|
622
604
|
|
|
623
605
|
// src/context.ts
|
|
624
|
-
var HEADER_PREFIX = "x-
|
|
625
|
-
var SOURCE_TOOL_HEADER = "x-
|
|
606
|
+
var HEADER_PREFIX = "x-shashu";
|
|
607
|
+
var SOURCE_TOOL_HEADER = "x-shashu-source-tool";
|
|
626
608
|
var DEFAULT_CONTRACT_VERSION = "2026-09-01";
|
|
627
|
-
var CONTRACT_VERSION_HEADER = "
|
|
609
|
+
var CONTRACT_VERSION_HEADER = "shashu-version";
|
|
628
610
|
function applyContractVersion(headers, contractVersion) {
|
|
629
611
|
if (contractVersion === null) return headers;
|
|
630
612
|
const named = Object.keys(headers).some((k) => k.toLowerCase() === CONTRACT_VERSION_HEADER);
|
|
@@ -743,20 +725,20 @@ function buildContextHeaders(ctx, session) {
|
|
|
743
725
|
if (v) h[`${TRUSTLOG_HEADER_PREFIX}${k.replace(/_/g, "-")}`] = String(v);
|
|
744
726
|
}
|
|
745
727
|
if (tracer.isActive) {
|
|
746
|
-
if (tracer.traceId) h["x-
|
|
747
|
-
h["x-
|
|
748
|
-
h["x-
|
|
728
|
+
if (tracer.traceId) h["x-shashu-trace-id"] = tracer.traceId;
|
|
729
|
+
h["x-shashu-span-id"] = tracer.currentSpanId ?? "";
|
|
730
|
+
h["x-shashu-parent-id"] = tracer.parentSpanId ?? "";
|
|
749
731
|
} else if (tracer.isA2aHop) {
|
|
750
|
-
if (tracer.traceId) h["x-
|
|
751
|
-
} else if (!h["x-
|
|
752
|
-
h["x-
|
|
732
|
+
if (tracer.traceId) h["x-shashu-trace-id"] = tracer.traceId;
|
|
733
|
+
} else if (!h["x-shashu-trace-id"]) {
|
|
734
|
+
h["x-shashu-trace-id"] = resolveOriginTraceId();
|
|
753
735
|
}
|
|
754
736
|
const sessionId = resolveSessionId(session);
|
|
755
|
-
if (sessionId) h["x-
|
|
737
|
+
if (sessionId) h["x-shashu-session-id"] = sessionId;
|
|
756
738
|
if (tracer.isA2aHop) {
|
|
757
739
|
const inboundCaller = tracer.inboundCallerAgentId;
|
|
758
|
-
if (inboundCaller) h["x-
|
|
759
|
-
h["x-
|
|
740
|
+
if (inboundCaller) h["x-shashu-caller-agent-id"] = inboundCaller;
|
|
741
|
+
h["x-shashu-hop-depth"] = String(tracer.outboundHopDepth);
|
|
760
742
|
}
|
|
761
743
|
return lowercaseHeaderKeys(h);
|
|
762
744
|
}
|
|
@@ -776,11 +758,11 @@ function buildInvocationHeaders(opts) {
|
|
|
776
758
|
const hop = opts.hopDepth ?? tracer.outboundHopDepth;
|
|
777
759
|
const session = resolveSessionId({ requestSessionId: opts.sessionId });
|
|
778
760
|
const h = {
|
|
779
|
-
"x-
|
|
780
|
-
"x-
|
|
781
|
-
"x-
|
|
761
|
+
"x-shashu-trace-id": String(trace),
|
|
762
|
+
"x-shashu-caller-agent-id": String(opts.callerAgentId),
|
|
763
|
+
"x-shashu-hop-depth": String(hop)
|
|
782
764
|
};
|
|
783
|
-
if (session) h["x-
|
|
765
|
+
if (session) h["x-shashu-session-id"] = String(session);
|
|
784
766
|
return lowercaseHeaderKeys(h);
|
|
785
767
|
}
|
|
786
768
|
|
|
@@ -840,7 +822,8 @@ var DEFAULT_RETRY_POLICY = {
|
|
|
840
822
|
retryOn429: true,
|
|
841
823
|
retryOn5xx: false,
|
|
842
824
|
neverRetryStatus: [400, 401, 403, 404],
|
|
843
|
-
ignoreRetryAfter: false
|
|
825
|
+
ignoreRetryAfter: false,
|
|
826
|
+
jitterFraction: 0.2
|
|
844
827
|
};
|
|
845
828
|
function resolveRetryPolicy(policy) {
|
|
846
829
|
if (policy === null) return null;
|
|
@@ -850,19 +833,38 @@ function resolveRetryPolicy(policy) {
|
|
|
850
833
|
function shouldRetryStatus(policy, status) {
|
|
851
834
|
if (policy.neverRetryStatus.includes(status)) return false;
|
|
852
835
|
if (status === 429) return policy.retryOn429;
|
|
836
|
+
if (status === 503) return true;
|
|
853
837
|
if (status >= 500 && status <= 599) return policy.retryOn5xx;
|
|
854
838
|
return false;
|
|
855
839
|
}
|
|
840
|
+
function truthyHeader(value) {
|
|
841
|
+
return ["1", "true", "yes", "on"].includes((value ?? "").trim().toLowerCase());
|
|
842
|
+
}
|
|
843
|
+
function gatewaySaysBusyRetry(res, retryAfter) {
|
|
844
|
+
if (res.status !== 429 && res.status !== 503) return false;
|
|
845
|
+
if (truthyHeader(res.headers.get("x-should-retry"))) return true;
|
|
846
|
+
return retryAfter !== void 0;
|
|
847
|
+
}
|
|
856
848
|
function shouldRetryResponse(policy, res, retryAfter) {
|
|
849
|
+
if (policy.neverRetryStatus.includes(res.status)) return false;
|
|
850
|
+
if (res.status === 429 || res.status === 503) {
|
|
851
|
+
if (res.status === 429 && !policy.retryOn429) return false;
|
|
852
|
+
return gatewaySaysBusyRetry(res, retryAfter);
|
|
853
|
+
}
|
|
857
854
|
if (!shouldRetryStatus(policy, res.status)) return false;
|
|
858
|
-
if (res.status === 429) return retryAfter !== void 0;
|
|
859
855
|
return true;
|
|
860
856
|
}
|
|
861
857
|
function delayFor(policy, attempt, res, retryAfter) {
|
|
862
|
-
|
|
863
|
-
|
|
858
|
+
const jitter = (seconds) => {
|
|
859
|
+
const frac = policy.jitterFraction ?? 0.2;
|
|
860
|
+
const capped = Math.min(policy.backoffMaxSeconds, seconds);
|
|
861
|
+
if (frac <= 0) return capped;
|
|
862
|
+
return Math.min(policy.backoffMaxSeconds, capped * (1 + Math.random() * frac));
|
|
863
|
+
};
|
|
864
|
+
if (res !== null && (res.status === 429 || res.status === 503) && !policy.ignoreRetryAfter && retryAfter !== void 0) {
|
|
865
|
+
return jitter(retryAfter);
|
|
864
866
|
}
|
|
865
|
-
return
|
|
867
|
+
return jitter(policy.backoffBaseSeconds * 2 ** attempt);
|
|
866
868
|
}
|
|
867
869
|
function isConnectionError(err) {
|
|
868
870
|
return err instanceof TypeError;
|
|
@@ -890,7 +892,7 @@ async function executeWithRetry(send, policy, sleep = defaultSleep) {
|
|
|
890
892
|
}
|
|
891
893
|
throw err;
|
|
892
894
|
}
|
|
893
|
-
const retryAfter = res.status === 429 ? gatewayRetryAfter(res, await peekJson(res)) : void 0;
|
|
895
|
+
const retryAfter = res.status === 429 || res.status === 503 ? gatewayRetryAfter(res, await peekJson(res)) : void 0;
|
|
894
896
|
if (attempt < policy.maxRetries && shouldRetryResponse(policy, res, retryAfter)) {
|
|
895
897
|
await sleep(delayFor(policy, attempt, res, retryAfter));
|
|
896
898
|
attempt += 1;
|
|
@@ -973,10 +975,10 @@ function attachRagContext(body, ragContext) {
|
|
|
973
975
|
if (ragContext === null || typeof ragContext !== "object") {
|
|
974
976
|
throw new TypeError("ragContext must be an object");
|
|
975
977
|
}
|
|
976
|
-
const existing = body.
|
|
978
|
+
const existing = body.shashu_metadata;
|
|
977
979
|
const meta = existing !== null && typeof existing === "object" ? existing : {};
|
|
978
980
|
meta.rag_context = ragContext;
|
|
979
|
-
body.
|
|
981
|
+
body.shashu_metadata = meta;
|
|
980
982
|
return body;
|
|
981
983
|
}
|
|
982
984
|
var SOURCES = [
|
|
@@ -1266,9 +1268,9 @@ function buildMemoryContext(events) {
|
|
|
1266
1268
|
}
|
|
1267
1269
|
function attachMemoryContext(body, memoryContext) {
|
|
1268
1270
|
const bag = body;
|
|
1269
|
-
const existing = bag.
|
|
1271
|
+
const existing = bag.shashu_metadata;
|
|
1270
1272
|
const metadata = existing !== null && typeof existing === "object" ? existing : {};
|
|
1271
|
-
bag.
|
|
1273
|
+
bag.shashu_metadata = { ...metadata, memory_context: memoryContext };
|
|
1272
1274
|
return body;
|
|
1273
1275
|
}
|
|
1274
1276
|
|
|
@@ -1285,7 +1287,7 @@ function parseJsonObject(body) {
|
|
|
1285
1287
|
}
|
|
1286
1288
|
}
|
|
1287
1289
|
function metadataBag(body) {
|
|
1288
|
-
const metadata = body.
|
|
1290
|
+
const metadata = body.shashu_metadata;
|
|
1289
1291
|
if (metadata !== null && typeof metadata === "object") {
|
|
1290
1292
|
return metadata;
|
|
1291
1293
|
}
|
|
@@ -1413,16 +1415,16 @@ var DELIVERED_DECISIONS = /* @__PURE__ */ new Set([
|
|
|
1413
1415
|
DECISION_ALLOW_ALTERED,
|
|
1414
1416
|
DECISION_NOT_CHECKED
|
|
1415
1417
|
]);
|
|
1416
|
-
var BODY_KEY = "
|
|
1417
|
-
var HEADER_DECISION = "x-
|
|
1418
|
-
var HEADER_CODE = "x-
|
|
1419
|
-
var HEADER_INSPECTION = "x-
|
|
1418
|
+
var BODY_KEY = "shashu";
|
|
1419
|
+
var HEADER_DECISION = "x-shashu-decision";
|
|
1420
|
+
var HEADER_CODE = "x-shashu-code";
|
|
1421
|
+
var HEADER_INSPECTION = "x-shashu-inspection";
|
|
1420
1422
|
var HEADER_SHOULD_RETRY = "x-should-retry";
|
|
1421
1423
|
var HEADER_REQUEST_ID = "x-request-id";
|
|
1422
|
-
var HEADER_SHASHU_REQUEST_ID = "x-
|
|
1423
|
-
var HEADER_TRACE_ID = "x-
|
|
1424
|
-
var HEADER_ATTACHMENTS = "x-
|
|
1425
|
-
var HEADER_MEMORY = "x-
|
|
1424
|
+
var HEADER_SHASHU_REQUEST_ID = "x-shashu-request-id";
|
|
1425
|
+
var HEADER_TRACE_ID = "x-shashu-trace-id";
|
|
1426
|
+
var HEADER_ATTACHMENTS = "x-shashu-attachments";
|
|
1427
|
+
var HEADER_MEMORY = "x-shashu-memory";
|
|
1426
1428
|
var ATTACHMENT_STATES = /* @__PURE__ */ new Set([
|
|
1427
1429
|
"scanned",
|
|
1428
1430
|
"scanned_partial",
|
|
@@ -1881,7 +1883,7 @@ function shouldRetryPassRefused(opts) {
|
|
|
1881
1883
|
}
|
|
1882
1884
|
var CredentialResolver = class {
|
|
1883
1885
|
constructor(opts) {
|
|
1884
|
-
const envKey = envGet(API_KEY_ENV
|
|
1886
|
+
const envKey = envGet(API_KEY_ENV) ?? void 0;
|
|
1885
1887
|
const hasKeyArg = opts.apiKey !== void 0;
|
|
1886
1888
|
const hasProvider = opts.tokenProvider !== void 0;
|
|
1887
1889
|
if (hasKeyArg && hasProvider) throw new ShashuConfigError(BOTH_OR_NEITHER);
|
|
@@ -1984,14 +1986,14 @@ var Shashu = class {
|
|
|
1984
1986
|
return this._sessionId;
|
|
1985
1987
|
}
|
|
1986
1988
|
/**
|
|
1987
|
-
* Cache this agent's own id from the gateway's `x-
|
|
1989
|
+
* Cache this agent's own id from the gateway's `x-shashu-agent-id` response header
|
|
1988
1990
|
* (delivered by WP-A2A-1). Used by {@link buildInvocationHeaders} to stamp caller = self
|
|
1989
1991
|
* on a downstream invocation. Read on EVERY response — including non-2xx — so even a
|
|
1990
1992
|
* blocked response seeds the self-id. NEVER an auth credential. Fail-soft: never throws.
|
|
1991
1993
|
*/
|
|
1992
1994
|
captureAgentId(res) {
|
|
1993
1995
|
try {
|
|
1994
|
-
const aid = res.headers.get("x-
|
|
1996
|
+
const aid = res.headers.get("x-shashu-agent-id");
|
|
1995
1997
|
if (aid) this._agentId = aid;
|
|
1996
1998
|
} catch {
|
|
1997
1999
|
}
|
|
@@ -2002,12 +2004,12 @@ var Shashu = class {
|
|
|
2002
2004
|
* refreshed from gateway responses); trace / hop / session default from the tracer so the
|
|
2003
2005
|
* served flow is propagated. The downstream agent calls `captureIncoming()` on these
|
|
2004
2006
|
* headers. Throws if self-id is not known yet — set the `agentId` option or make one
|
|
2005
|
-
* gateway call first so the `x-
|
|
2007
|
+
* gateway call first so the `x-shashu-agent-id` response header can seed it.
|
|
2006
2008
|
*/
|
|
2007
2009
|
buildInvocationHeaders(opts) {
|
|
2008
2010
|
if (!this._agentId) {
|
|
2009
2011
|
throw new Error(
|
|
2010
|
-
"self agent id is unknown \u2014 set the agentId option or make one gateway call first so the x-
|
|
2012
|
+
"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."
|
|
2011
2013
|
);
|
|
2012
2014
|
}
|
|
2013
2015
|
return buildInvocationHeaders({ callerAgentId: this._agentId, ...opts });
|
|
@@ -2170,7 +2172,7 @@ var Shashu = class {
|
|
|
2170
2172
|
// src/fetch.ts
|
|
2171
2173
|
var import_node_crypto4 = require("crypto");
|
|
2172
2174
|
var DEFAULT_BLOCK_ENCODING = "explicit";
|
|
2173
|
-
var BLOCK_ENCODING_HEADER = "
|
|
2175
|
+
var BLOCK_ENCODING_HEADER = "shashu-block-encoding";
|
|
2174
2176
|
function shashuFetch(options = {}) {
|
|
2175
2177
|
const resolver = new CredentialResolver({
|
|
2176
2178
|
apiKey: options.apiKey,
|
|
@@ -2224,8 +2226,8 @@ function shashuFetch(options = {}) {
|
|
|
2224
2226
|
|
|
2225
2227
|
// src/n8n.ts
|
|
2226
2228
|
function getN8nHeaderSnippet(apiKey, baseUrl) {
|
|
2227
|
-
const key = apiKey ?? tracer.apiKey ?? envGet(API_KEY_ENV
|
|
2228
|
-
const url = baseUrl ?? tracer.gatewayUrl ?? envGet(BASE_URL_ENV
|
|
2229
|
+
const key = apiKey ?? tracer.apiKey ?? envGet(API_KEY_ENV) ?? "";
|
|
2230
|
+
const url = baseUrl ?? tracer.gatewayUrl ?? envGet(BASE_URL_ENV) ?? "";
|
|
2229
2231
|
const ctx = getWorkflowContextFromEnv();
|
|
2230
2232
|
const contextHeaders = buildContextHeaders(ctx);
|
|
2231
2233
|
const headers = [];
|
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-
|
|
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-
|
|
3
|
-
import { F as FetchLike } from './_joiner-
|
|
4
|
-
export { w as withRetrievalJoiner } from './_joiner-
|
|
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-
|
|
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';
|
|
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';
|
|
@@ -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
|
-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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 = "
|
|
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
|
-
* `
|
|
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
|
-
* `
|
|
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-
|
|
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-
|
|
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-
|
|
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 `
|
|
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 `
|
|
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 = "
|
|
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-
|
|
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 (`
|
|
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 `
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
725
|
-
* and x-
|
|
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.
|