@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,71 @@
1
+ import { S as ShashuConfig } from '../types-BLs_TMFv.cjs';
2
+
3
+ /**
4
+ * Google Gemini middleware: use Shashu with @google/generative-ai.
5
+ *
6
+ * Pass the returned config when creating the client or when making requests.
7
+ * The legacy @google/generative-ai SDK constructor accepts (apiKey); use the
8
+ * returned apiKey to point at Shashu (gateway key), and pass headers via
9
+ * a custom fetch if your setup supports it.
10
+ *
11
+ * Example (gateway as proxy; SDK may require custom fetch for full header control):
12
+ *
13
+ * import { GoogleGenerativeAI } from '@google/generative-ai';
14
+ * import { createShashuGeminiConfig } from '@shashu-ai/sdk/middleware/google';
15
+ *
16
+ * const config = createShashuGeminiConfig({
17
+ * baseUrl: process.env.SHASHU_BASE_URL!,
18
+ * apiKey: process.env.SHASHU_API_KEY,
19
+ * });
20
+ *
21
+ * const genAI = new GoogleGenerativeAI(config.apiKey ?? '');
22
+ * const model = genAI.getGenerativeModel({ model: 'gemini-1.5-flash' });
23
+ *
24
+ * For full Shashu header injection (x-shashu-source-tool, etc.), use
25
+ * the Shashu client's fetch with provider: 'google' or pass config.headers
26
+ * via a custom fetch implementation if the SDK supports it.
27
+ */
28
+
29
+ /**
30
+ * Returns headers compatible with @google/generative-ai. Uses x-api-key and
31
+ * Shashu context. Use when building requests or with a custom fetch.
32
+ */
33
+ declare function getGeminiHeaders(config: ShashuConfig): Record<string, string>;
34
+ /**
35
+ * Returns a config object for use with @google/generative-ai (or compatible clients).
36
+ * Injects Shashu context headers and x-api-key. Use apiKey for the gateway and
37
+ * baseUrl/headers when using a custom fetch or wrapper.
38
+ *
39
+ * Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
40
+ * exactly as it was — its own endpoint, its own credential, no Shashu context
41
+ * headers — which is the same no-op the Python SDK's patchers perform. The
42
+ * caller's tg_sk_ key is deliberately NOT handed back, since it would be sent to
43
+ * the provider directly.
44
+ *
45
+ * @throws {ShashuConfigError} when no address is configured and the SDK is
46
+ * not disabled. There is no default host. See ../config.ts.
47
+ *
48
+ * **No retrieval joiner on this path.** The other three middlewares hand back a
49
+ * `fetch` the provider SDK will use, which is where a `declareRetrieval()` is
50
+ * attached to the outgoing body. `@google/generative-ai` has no such seam: its
51
+ * `RequestOptions` carries `timeout`, `apiVersion`, `apiClient`, `baseUrl` and
52
+ * `customHeaders` and nothing else, and it calls the global `fetch` directly
53
+ * (measured — a client built with a `fetch`/`customFetch` in that bag ignored
54
+ * both and went to the network). Retrieval on the Gemini path is therefore
55
+ * DECLARATION-ONLY: it reaches the gateway when the call is made through
56
+ * Shashu's own client, or through a fetch the caller wraps with
57
+ * `withRetrievalJoiner()` themselves. It is not automatic, and must not be
58
+ * described as if it were.
59
+ *
60
+ * Note the divergence from the Python SDK, whose Gemini PATCHER resolves the
61
+ * address optionally and leaves an unconfigured client talking to Google with
62
+ * only headers added. This function has no such half-state: its whole return
63
+ * contract is a Shashu baseUrl, and its caller asked for one by name.
64
+ */
65
+ declare function createShashuGeminiConfig(config: ShashuConfig): {
66
+ baseUrl?: string;
67
+ apiKey?: string | null;
68
+ headers?: Record<string, string>;
69
+ };
70
+
71
+ export { createShashuGeminiConfig, getGeminiHeaders };
@@ -0,0 +1,71 @@
1
+ import { S as ShashuConfig } from '../types-BLs_TMFv.js';
2
+
3
+ /**
4
+ * Google Gemini middleware: use Shashu with @google/generative-ai.
5
+ *
6
+ * Pass the returned config when creating the client or when making requests.
7
+ * The legacy @google/generative-ai SDK constructor accepts (apiKey); use the
8
+ * returned apiKey to point at Shashu (gateway key), and pass headers via
9
+ * a custom fetch if your setup supports it.
10
+ *
11
+ * Example (gateway as proxy; SDK may require custom fetch for full header control):
12
+ *
13
+ * import { GoogleGenerativeAI } from '@google/generative-ai';
14
+ * import { createShashuGeminiConfig } from '@shashu-ai/sdk/middleware/google';
15
+ *
16
+ * const config = createShashuGeminiConfig({
17
+ * baseUrl: process.env.SHASHU_BASE_URL!,
18
+ * apiKey: process.env.SHASHU_API_KEY,
19
+ * });
20
+ *
21
+ * const genAI = new GoogleGenerativeAI(config.apiKey ?? '');
22
+ * const model = genAI.getGenerativeModel({ model: 'gemini-1.5-flash' });
23
+ *
24
+ * For full Shashu header injection (x-shashu-source-tool, etc.), use
25
+ * the Shashu client's fetch with provider: 'google' or pass config.headers
26
+ * via a custom fetch implementation if the SDK supports it.
27
+ */
28
+
29
+ /**
30
+ * Returns headers compatible with @google/generative-ai. Uses x-api-key and
31
+ * Shashu context. Use when building requests or with a custom fetch.
32
+ */
33
+ declare function getGeminiHeaders(config: ShashuConfig): Record<string, string>;
34
+ /**
35
+ * Returns a config object for use with @google/generative-ai (or compatible clients).
36
+ * Injects Shashu context headers and x-api-key. Use apiKey for the gateway and
37
+ * baseUrl/headers when using a custom fetch or wrapper.
38
+ *
39
+ * Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
40
+ * exactly as it was — its own endpoint, its own credential, no Shashu context
41
+ * headers — which is the same no-op the Python SDK's patchers perform. The
42
+ * caller's tg_sk_ key is deliberately NOT handed back, since it would be sent to
43
+ * the provider directly.
44
+ *
45
+ * @throws {ShashuConfigError} when no address is configured and the SDK is
46
+ * not disabled. There is no default host. See ../config.ts.
47
+ *
48
+ * **No retrieval joiner on this path.** The other three middlewares hand back a
49
+ * `fetch` the provider SDK will use, which is where a `declareRetrieval()` is
50
+ * attached to the outgoing body. `@google/generative-ai` has no such seam: its
51
+ * `RequestOptions` carries `timeout`, `apiVersion`, `apiClient`, `baseUrl` and
52
+ * `customHeaders` and nothing else, and it calls the global `fetch` directly
53
+ * (measured — a client built with a `fetch`/`customFetch` in that bag ignored
54
+ * both and went to the network). Retrieval on the Gemini path is therefore
55
+ * DECLARATION-ONLY: it reaches the gateway when the call is made through
56
+ * Shashu's own client, or through a fetch the caller wraps with
57
+ * `withRetrievalJoiner()` themselves. It is not automatic, and must not be
58
+ * described as if it were.
59
+ *
60
+ * Note the divergence from the Python SDK, whose Gemini PATCHER resolves the
61
+ * address optionally and leaves an unconfigured client talking to Google with
62
+ * only headers added. This function has no such half-state: its whole return
63
+ * contract is a Shashu baseUrl, and its caller asked for one by name.
64
+ */
65
+ declare function createShashuGeminiConfig(config: ShashuConfig): {
66
+ baseUrl?: string;
67
+ apiKey?: string | null;
68
+ headers?: Record<string, string>;
69
+ };
70
+
71
+ export { createShashuGeminiConfig, getGeminiHeaders };
@@ -0,0 +1,9 @@
1
+ import {
2
+ createShashuGeminiConfig,
3
+ getGeminiHeaders
4
+ } from "../chunk-QLK5CQSP.js";
5
+ import "../chunk-QJQ4MWQ4.js";
6
+ export {
7
+ createShashuGeminiConfig,
8
+ getGeminiHeaders
9
+ };