@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.
- package/CHANGELOG.md +20 -0
- package/README.md +18 -18
- package/dist/{_joiner-p5LFxJcu.d.cts → _joiner-DGi8GsY7.d.cts} +1 -11
- package/dist/{_joiner-p5LFxJcu.d.ts → _joiner-DGi8GsY7.d.ts} +1 -11
- package/dist/{chunk-Z6DROYQA.js → chunk-3GAMCQ6R.js} +2 -2
- package/dist/{chunk-BEU2UWW3.js → chunk-3JZXUKNA.js} +1 -1
- package/dist/{chunk-M4JDSAUC.js → chunk-3X5IUBIA.js} +2 -2
- package/dist/{chunk-4CDQ7JMK.js → chunk-F4CXDZQB.js} +113 -11
- package/dist/{chunk-5TW3FISD.js → chunk-M7EMWSNS.js} +27 -6
- package/dist/{chunk-IQYB5OZ6.js → chunk-TGD6KDWT.js} +33 -53
- package/dist/index.cjs +133 -101
- package/dist/index.d.cts +30 -30
- package/dist/index.d.ts +30 -30
- package/dist/index.js +45 -109
- package/dist/{langchain-DNOsiRna.d.ts → langchain-DKyrUjk4.d.cts} +11 -11
- package/dist/{langchain-xCWwa1Ud.d.cts → langchain-QCATTIR4.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 +178 -93
- 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
|
@@ -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,
|
|
74
|
-
const
|
|
75
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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-
|
|
146
|
+
const trace = (h["x-shashu-trace-id"] ?? "").trim();
|
|
165
147
|
if (!trace) return void 0;
|
|
166
|
-
const session = (h["x-
|
|
167
|
-
const caller = (h["x-
|
|
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-
|
|
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
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
361
|
-
var SOURCE_TOOL_HEADER = "x-
|
|
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 = "
|
|
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-
|
|
483
|
-
h["x-
|
|
484
|
-
h["x-
|
|
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-
|
|
487
|
-
} else if (!h["x-
|
|
488
|
-
h["x-
|
|
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-
|
|
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-
|
|
495
|
-
h["x-
|
|
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.
|
|
525
|
+
const existing = body.shashu_metadata;
|
|
544
526
|
const meta = existing !== null && typeof existing === "object" ? existing : {};
|
|
545
527
|
meta.rag_context = ragContext;
|
|
546
|
-
body.
|
|
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.
|
|
658
|
+
const existing = bag.shashu_metadata;
|
|
677
659
|
const metadata = existing !== null && typeof existing === "object" ? existing : {};
|
|
678
|
-
bag.
|
|
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.
|
|
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
|
|
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);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as ShashuConfig } from '../types-
|
|
2
|
-
import { F as FetchLike } from '../_joiner-
|
|
1
|
+
import { S as ShashuConfig } from '../types-BLs_TMFv.cjs';
|
|
2
|
+
import { F as FetchLike } from '../_joiner-DGi8GsY7.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Anthropic middleware: use Shashu as the base URL for @anthropic-ai/sdk.
|
|
@@ -13,8 +13,8 @@ import { F as FetchLike } from '../_joiner-p5LFxJcu.cjs';
|
|
|
13
13
|
* import { createShashuAnthropicConfig } from '@shashu-ai/sdk/middleware/anthropic';
|
|
14
14
|
*
|
|
15
15
|
* const config = createShashuAnthropicConfig({
|
|
16
|
-
* baseUrl: process.env.
|
|
17
|
-
* apiKey: process.env.
|
|
16
|
+
* baseUrl: process.env.SHASHU_BASE_URL!,
|
|
17
|
+
* apiKey: process.env.SHASHU_API_KEY,
|
|
18
18
|
* });
|
|
19
19
|
*
|
|
20
20
|
* const anthropic = new Anthropic(config);
|
|
@@ -30,7 +30,7 @@ declare function getAnthropicHeaders(config: ShashuConfig): Record<string, strin
|
|
|
30
30
|
* Returns a config object for the Anthropic SDK (baseURL, apiKey, defaultHeaders).
|
|
31
31
|
* Injects Shashu context headers and x-api-key so requests go through the gateway.
|
|
32
32
|
*
|
|
33
|
-
* Returns `{}` when
|
|
33
|
+
* Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
|
|
34
34
|
* exactly as it was — its own endpoint, its own credential, no Shashu context
|
|
35
35
|
* headers — which is the same no-op the Python SDK's patchers perform. The
|
|
36
36
|
* caller's tg_sk_ key is deliberately NOT handed back, since it would be sent to
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as ShashuConfig } from '../types-
|
|
2
|
-
import { F as FetchLike } from '../_joiner-
|
|
1
|
+
import { S as ShashuConfig } from '../types-BLs_TMFv.js';
|
|
2
|
+
import { F as FetchLike } from '../_joiner-DGi8GsY7.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Anthropic middleware: use Shashu as the base URL for @anthropic-ai/sdk.
|
|
@@ -13,8 +13,8 @@ import { F as FetchLike } from '../_joiner-p5LFxJcu.js';
|
|
|
13
13
|
* import { createShashuAnthropicConfig } from '@shashu-ai/sdk/middleware/anthropic';
|
|
14
14
|
*
|
|
15
15
|
* const config = createShashuAnthropicConfig({
|
|
16
|
-
* baseUrl: process.env.
|
|
17
|
-
* apiKey: process.env.
|
|
16
|
+
* baseUrl: process.env.SHASHU_BASE_URL!,
|
|
17
|
+
* apiKey: process.env.SHASHU_API_KEY,
|
|
18
18
|
* });
|
|
19
19
|
*
|
|
20
20
|
* const anthropic = new Anthropic(config);
|
|
@@ -30,7 +30,7 @@ declare function getAnthropicHeaders(config: ShashuConfig): Record<string, strin
|
|
|
30
30
|
* Returns a config object for the Anthropic SDK (baseURL, apiKey, defaultHeaders).
|
|
31
31
|
* Injects Shashu context headers and x-api-key so requests go through the gateway.
|
|
32
32
|
*
|
|
33
|
-
* Returns `{}` when
|
|
33
|
+
* Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
|
|
34
34
|
* exactly as it was — its own endpoint, its own credential, no Shashu context
|
|
35
35
|
* headers — which is the same no-op the Python SDK's patchers perform. The
|
|
36
36
|
* caller's tg_sk_ key is deliberately NOT handed back, since it would be sent to
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createShashuAnthropicConfig,
|
|
3
3
|
getAnthropicHeaders
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-3GAMCQ6R.js";
|
|
5
|
+
import "../chunk-M7EMWSNS.js";
|
|
6
|
+
import "../chunk-TGD6KDWT.js";
|
|
7
7
|
export {
|
|
8
8
|
createShashuAnthropicConfig,
|
|
9
9
|
getAnthropicHeaders
|
|
@@ -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(current,
|
|
74
|
-
const
|
|
75
|
-
|
|
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 ${current} instead. The TRUSTGATE_* name still works for this release.`
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return old;
|
|
86
|
-
}
|
|
87
|
-
return void 0;
|
|
69
|
+
function envGet(current, _legacy) {
|
|
70
|
+
const now = (env()[current] ?? "").trim();
|
|
71
|
+
return now || void 0;
|
|
88
72
|
}
|
|
89
73
|
function isDisabled() {
|
|
90
|
-
return TRUTHY.has((envGet(DISABLE_ENV
|
|
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
|
|
96
|
-
const legacy = name.startsWith("SHASHU_") ? name.replace("SHASHU_", "TRUSTGATE_") : name.startsWith("TRUSTGATE_") ? name : "";
|
|
97
|
-
const value = legacy && legacy !== current ? envGet(current, 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
|
|
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
|
|
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";
|
|
@@ -125,7 +107,7 @@ function rejectKeyOnly(name, tokenProvider) {
|
|
|
125
107
|
var import_node_crypto2 = require("crypto");
|
|
126
108
|
|
|
127
109
|
// src/version.ts
|
|
128
|
-
var SDK_VERSION = "1.
|
|
110
|
+
var SDK_VERSION = "1.1.1";
|
|
129
111
|
|
|
130
112
|
// src/tracer.ts
|
|
131
113
|
var import_node_async_hooks = require("async_hooks");
|
|
@@ -169,14 +151,14 @@ function parseHopDepth(raw) {
|
|
|
169
151
|
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
170
152
|
}
|
|
171
153
|
function captureFromHeaders(h) {
|
|
172
|
-
const trace = (h["x-
|
|
154
|
+
const trace = (h["x-shashu-trace-id"] ?? "").trim();
|
|
173
155
|
if (!trace) return void 0;
|
|
174
|
-
const session = (h["x-
|
|
175
|
-
const caller = (h["x-
|
|
156
|
+
const session = (h["x-shashu-session-id"] ?? "").trim();
|
|
157
|
+
const caller = (h["x-shashu-caller-agent-id"] ?? "").trim();
|
|
176
158
|
return {
|
|
177
159
|
traceId: trace,
|
|
178
160
|
sessionId: session || void 0,
|
|
179
|
-
inboundHopDepth: parseHopDepth(h["x-
|
|
161
|
+
inboundHopDepth: parseHopDepth(h["x-shashu-hop-depth"]),
|
|
180
162
|
inboundCallerAgentId: caller || void 0
|
|
181
163
|
};
|
|
182
164
|
}
|
|
@@ -196,7 +178,7 @@ var Tracer = class {
|
|
|
196
178
|
this.buffer = [];
|
|
197
179
|
this.flushTimer = null;
|
|
198
180
|
this._gatewayUrl = optionalBaseUrl();
|
|
199
|
-
this._apiKey = envGet(API_KEY_ENV
|
|
181
|
+
this._apiKey = envGet(API_KEY_ENV);
|
|
200
182
|
}
|
|
201
183
|
/**
|
|
202
184
|
* Current gateway base URL (respects configure()), or undefined when none is
|
|
@@ -249,7 +231,7 @@ var Tracer = class {
|
|
|
249
231
|
get sessionId() {
|
|
250
232
|
return a2aStorage.getStore()?.sessionId || void 0;
|
|
251
233
|
}
|
|
252
|
-
/** Advisory inbound hop depth captured from x-
|
|
234
|
+
/** Advisory inbound hop depth captured from x-shashu-hop-depth (0 if absent). */
|
|
253
235
|
get inboundHopDepth() {
|
|
254
236
|
return a2aStorage.getStore()?.inboundHopDepth ?? 0;
|
|
255
237
|
}
|
|
@@ -258,7 +240,7 @@ var Tracer = class {
|
|
|
258
240
|
get outboundHopDepth() {
|
|
259
241
|
return this.inboundHopDepth + 1;
|
|
260
242
|
}
|
|
261
|
-
/** The captured inbound x-
|
|
243
|
+
/** The captured inbound x-shashu-caller-agent-id — the upstream agent that INVOKED
|
|
262
244
|
* this hop. The SDK FORWARDS this on the outbound gateway call so the gateway records
|
|
263
245
|
* the real (invoker -> this agent) edge, NEVER this agent's own id (§4.1). undefined at
|
|
264
246
|
* origin / caller-stripped. */
|
|
@@ -268,7 +250,7 @@ var Tracer = class {
|
|
|
268
250
|
/**
|
|
269
251
|
* Capture an inbound flow from the headers of a request this agent is SERVING into the
|
|
270
252
|
* AsyncLocalStorage store, so a downstream call made through the SDK propagates the SAME
|
|
271
|
-
* flow (WP-A2A-4 / ADR-007 §0). Reads (case-insensitively) x-
|
|
253
|
+
* flow (WP-A2A-4 / ADR-007 §0). Reads (case-insensitively) x-shashu-trace-id (the flow
|
|
272
254
|
* id), -session-id, -hop-depth, and -caller-agent-id (the upstream INVOKER). The captured
|
|
273
255
|
* trace is PROPAGATED on the next outbound call (never re-minted); the session, inbound hop
|
|
274
256
|
* depth, and inbound caller ride along — the caller is FORWARDED on the gateway call (§4.1),
|
|
@@ -365,10 +347,10 @@ var Tracer = class {
|
|
|
365
347
|
var tracer = new Tracer();
|
|
366
348
|
|
|
367
349
|
// src/context.ts
|
|
368
|
-
var HEADER_PREFIX = "x-
|
|
369
|
-
var SOURCE_TOOL_HEADER = "x-
|
|
350
|
+
var HEADER_PREFIX = "x-shashu";
|
|
351
|
+
var SOURCE_TOOL_HEADER = "x-shashu-source-tool";
|
|
370
352
|
var DEFAULT_CONTRACT_VERSION = "2026-09-01";
|
|
371
|
-
var CONTRACT_VERSION_HEADER = "
|
|
353
|
+
var CONTRACT_VERSION_HEADER = "shashu-version";
|
|
372
354
|
function applyContractVersion(headers, contractVersion) {
|
|
373
355
|
if (contractVersion === null) return headers;
|
|
374
356
|
const named = Object.keys(headers).some((k) => k.toLowerCase() === CONTRACT_VERSION_HEADER);
|
|
@@ -487,20 +469,20 @@ function buildContextHeaders(ctx, session) {
|
|
|
487
469
|
if (v) h[`${TRUSTLOG_HEADER_PREFIX}${k.replace(/_/g, "-")}`] = String(v);
|
|
488
470
|
}
|
|
489
471
|
if (tracer.isActive) {
|
|
490
|
-
if (tracer.traceId) h["x-
|
|
491
|
-
h["x-
|
|
492
|
-
h["x-
|
|
472
|
+
if (tracer.traceId) h["x-shashu-trace-id"] = tracer.traceId;
|
|
473
|
+
h["x-shashu-span-id"] = tracer.currentSpanId ?? "";
|
|
474
|
+
h["x-shashu-parent-id"] = tracer.parentSpanId ?? "";
|
|
493
475
|
} else if (tracer.isA2aHop) {
|
|
494
|
-
if (tracer.traceId) h["x-
|
|
495
|
-
} else if (!h["x-
|
|
496
|
-
h["x-
|
|
476
|
+
if (tracer.traceId) h["x-shashu-trace-id"] = tracer.traceId;
|
|
477
|
+
} else if (!h["x-shashu-trace-id"]) {
|
|
478
|
+
h["x-shashu-trace-id"] = resolveOriginTraceId();
|
|
497
479
|
}
|
|
498
480
|
const sessionId = resolveSessionId(session);
|
|
499
|
-
if (sessionId) h["x-
|
|
481
|
+
if (sessionId) h["x-shashu-session-id"] = sessionId;
|
|
500
482
|
if (tracer.isA2aHop) {
|
|
501
483
|
const inboundCaller = tracer.inboundCallerAgentId;
|
|
502
|
-
if (inboundCaller) h["x-
|
|
503
|
-
h["x-
|
|
484
|
+
if (inboundCaller) h["x-shashu-caller-agent-id"] = inboundCaller;
|
|
485
|
+
h["x-shashu-hop-depth"] = String(tracer.outboundHopDepth);
|
|
504
486
|
}
|
|
505
487
|
return lowercaseHeaderKeys(h);
|
|
506
488
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as ShashuConfig } from '../types-
|
|
1
|
+
import { S as ShashuConfig } from '../types-BLs_TMFv.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Google Gemini middleware: use Shashu with @google/generative-ai.
|
|
@@ -14,14 +14,14 @@ import { S as ShashuConfig } from '../types-Rs49lJyD.cjs';
|
|
|
14
14
|
* import { createShashuGeminiConfig } from '@shashu-ai/sdk/middleware/google';
|
|
15
15
|
*
|
|
16
16
|
* const config = createShashuGeminiConfig({
|
|
17
|
-
* baseUrl: process.env.
|
|
18
|
-
* apiKey: process.env.
|
|
17
|
+
* baseUrl: process.env.SHASHU_BASE_URL!,
|
|
18
|
+
* apiKey: process.env.SHASHU_API_KEY,
|
|
19
19
|
* });
|
|
20
20
|
*
|
|
21
21
|
* const genAI = new GoogleGenerativeAI(config.apiKey ?? '');
|
|
22
22
|
* const model = genAI.getGenerativeModel({ model: 'gemini-1.5-flash' });
|
|
23
23
|
*
|
|
24
|
-
* For full Shashu header injection (x-
|
|
24
|
+
* For full Shashu header injection (x-shashu-source-tool, etc.), use
|
|
25
25
|
* the Shashu client's fetch with provider: 'google' or pass config.headers
|
|
26
26
|
* via a custom fetch implementation if the SDK supports it.
|
|
27
27
|
*/
|
|
@@ -36,7 +36,7 @@ declare function getGeminiHeaders(config: ShashuConfig): Record<string, string>;
|
|
|
36
36
|
* Injects Shashu context headers and x-api-key. Use apiKey for the gateway and
|
|
37
37
|
* baseUrl/headers when using a custom fetch or wrapper.
|
|
38
38
|
*
|
|
39
|
-
* Returns `{}` when
|
|
39
|
+
* Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
|
|
40
40
|
* exactly as it was — its own endpoint, its own credential, no Shashu context
|
|
41
41
|
* headers — which is the same no-op the Python SDK's patchers perform. The
|
|
42
42
|
* caller's tg_sk_ key is deliberately NOT handed back, since it would be sent to
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as ShashuConfig } from '../types-
|
|
1
|
+
import { S as ShashuConfig } from '../types-BLs_TMFv.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Google Gemini middleware: use Shashu with @google/generative-ai.
|
|
@@ -14,14 +14,14 @@ import { S as ShashuConfig } from '../types-Rs49lJyD.js';
|
|
|
14
14
|
* import { createShashuGeminiConfig } from '@shashu-ai/sdk/middleware/google';
|
|
15
15
|
*
|
|
16
16
|
* const config = createShashuGeminiConfig({
|
|
17
|
-
* baseUrl: process.env.
|
|
18
|
-
* apiKey: process.env.
|
|
17
|
+
* baseUrl: process.env.SHASHU_BASE_URL!,
|
|
18
|
+
* apiKey: process.env.SHASHU_API_KEY,
|
|
19
19
|
* });
|
|
20
20
|
*
|
|
21
21
|
* const genAI = new GoogleGenerativeAI(config.apiKey ?? '');
|
|
22
22
|
* const model = genAI.getGenerativeModel({ model: 'gemini-1.5-flash' });
|
|
23
23
|
*
|
|
24
|
-
* For full Shashu header injection (x-
|
|
24
|
+
* For full Shashu header injection (x-shashu-source-tool, etc.), use
|
|
25
25
|
* the Shashu client's fetch with provider: 'google' or pass config.headers
|
|
26
26
|
* via a custom fetch implementation if the SDK supports it.
|
|
27
27
|
*/
|
|
@@ -36,7 +36,7 @@ declare function getGeminiHeaders(config: ShashuConfig): Record<string, string>;
|
|
|
36
36
|
* Injects Shashu context headers and x-api-key. Use apiKey for the gateway and
|
|
37
37
|
* baseUrl/headers when using a custom fetch or wrapper.
|
|
38
38
|
*
|
|
39
|
-
* Returns `{}` when
|
|
39
|
+
* Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
|
|
40
40
|
* exactly as it was — its own endpoint, its own credential, no Shashu context
|
|
41
41
|
* headers — which is the same no-op the Python SDK's patchers perform. The
|
|
42
42
|
* caller's tg_sk_ key is deliberately NOT handed back, since it would be sent to
|