@shashu-ai/sdk 0.0.0-stage → 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.
@@ -0,0 +1,40 @@
1
+ import {
2
+ applyContractVersion,
3
+ buildContextHeaders,
4
+ getWorkflowContextFromEnv,
5
+ isDisabled,
6
+ rejectKeyOnly,
7
+ requireBaseUrl
8
+ } from "./chunk-QJQ4MWQ4.js";
9
+
10
+ // src/middleware/google.ts
11
+ import { randomUUID } from "crypto";
12
+ function getGeminiHeaders(config) {
13
+ const ctx = config.workflowContext ?? getWorkflowContextFromEnv();
14
+ const headers = {
15
+ ...config.headers,
16
+ ...buildContextHeaders(ctx, { defaultSessionId: config.sessionId })
17
+ };
18
+ if (config.apiKey) {
19
+ headers["x-api-key"] = config.apiKey;
20
+ }
21
+ return applyContractVersion(headers, config.contractVersion);
22
+ }
23
+ function createShashuGeminiConfig(config) {
24
+ if (isDisabled()) return {};
25
+ rejectKeyOnly("createShashuGeminiConfig", config.tokenProvider);
26
+ const baseUrl = requireBaseUrl(config.baseUrl, {
27
+ entryPoint: "createShashuGeminiConfig()"
28
+ });
29
+ const headers = getGeminiHeaders({ ...config, sessionId: config.sessionId ?? randomUUID() });
30
+ return {
31
+ baseUrl,
32
+ apiKey: config.apiKey ?? null,
33
+ headers: Object.keys(headers).length ? headers : void 0
34
+ };
35
+ }
36
+
37
+ export {
38
+ getGeminiHeaders,
39
+ createShashuGeminiConfig
40
+ };
@@ -0,0 +1,74 @@
1
+ import {
2
+ withRetrievalJoiner
3
+ } from "./chunk-NTIOPTYF.js";
4
+ import {
5
+ CredentialResolver,
6
+ applyContractVersion,
7
+ buildContextHeaders,
8
+ getWorkflowContextFromEnv,
9
+ isDisabled,
10
+ passRefusalCodeFromText,
11
+ requireBaseUrl,
12
+ shouldRetryPassRefused
13
+ } from "./chunk-QJQ4MWQ4.js";
14
+
15
+ // src/middleware/anthropic.ts
16
+ import { randomUUID } from "crypto";
17
+ function getAnthropicHeaders(config) {
18
+ const ctx = config.workflowContext ?? getWorkflowContextFromEnv();
19
+ const headers = {
20
+ ...config.headers,
21
+ ...buildContextHeaders(ctx, { defaultSessionId: config.sessionId })
22
+ };
23
+ if (config.apiKey) {
24
+ headers["x-api-key"] = config.apiKey;
25
+ }
26
+ return applyContractVersion(headers, config.contractVersion);
27
+ }
28
+ function createShashuAnthropicConfig(config) {
29
+ if (isDisabled()) return {};
30
+ const baseURL = requireBaseUrl(config.baseUrl, {
31
+ entryPoint: "createShashuAnthropicConfig()"
32
+ });
33
+ const resolver = new CredentialResolver({
34
+ apiKey: config.apiKey ?? void 0,
35
+ tokenProvider: config.tokenProvider
36
+ });
37
+ const headers = getAnthropicHeaders({
38
+ ...config,
39
+ sessionId: config.sessionId ?? randomUUID(),
40
+ apiKey: resolver.usesProvider ? void 0 : config.apiKey
41
+ });
42
+ const joining = withRetrievalJoiner();
43
+ const fetch = async (input, init) => {
44
+ const token = await resolver.get();
45
+ const next = new Headers(init?.headers);
46
+ if (token) next.set("x-api-key", token);
47
+ const res = await joining(input, { ...init, headers: next });
48
+ if (!resolver.usesProvider || res.status !== 401) return res;
49
+ const code = passRefusalCodeFromText(await res.clone().text());
50
+ if (!shouldRetryPassRefused({
51
+ usesProvider: true,
52
+ status: res.status,
53
+ code,
54
+ bytesDelivered: false
55
+ })) {
56
+ return res;
57
+ }
58
+ resolver.invalidate();
59
+ const retryToken = await resolver.get();
60
+ if (retryToken) next.set("x-api-key", retryToken);
61
+ return joining(input, { ...init, headers: next });
62
+ };
63
+ return {
64
+ baseURL,
65
+ apiKey: resolver.usesProvider ? null : config.apiKey ?? null,
66
+ defaultHeaders: Object.keys(headers).length ? headers : void 0,
67
+ fetch
68
+ };
69
+ }
70
+
71
+ export {
72
+ getAnthropicHeaders,
73
+ createShashuAnthropicConfig
74
+ };