@shashu-ai/sdk 0.0.0-stage → 1.0.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 +880 -0
- package/LICENSE +142 -0
- package/NOTICE +8 -0
- package/README.md +391 -2
- package/dist/_joiner-p5LFxJcu.d.cts +48 -0
- package/dist/_joiner-p5LFxJcu.d.ts +48 -0
- package/dist/chunk-4CDQ7JMK.js +228 -0
- package/dist/chunk-5TW3FISD.js +509 -0
- package/dist/chunk-BEU2UWW3.js +40 -0
- package/dist/chunk-IQYB5OZ6.js +820 -0
- package/dist/chunk-M4JDSAUC.js +71 -0
- package/dist/chunk-Z6DROYQA.js +74 -0
- package/dist/index.cjs +2535 -0
- package/dist/index.d.cts +748 -0
- package/dist/index.d.ts +748 -0
- package/dist/index.js +1038 -0
- package/dist/langchain-DNOsiRna.d.ts +322 -0
- package/dist/langchain-xCWwa1Ud.d.cts +322 -0
- package/dist/middleware/anthropic.cjs +948 -0
- package/dist/middleware/anthropic.d.cts +49 -0
- package/dist/middleware/anthropic.d.ts +49 -0
- package/dist/middleware/anthropic.js +10 -0
- package/dist/middleware/google.cjs +548 -0
- package/dist/middleware/google.d.cts +71 -0
- package/dist/middleware/google.d.ts +71 -0
- package/dist/middleware/google.js +9 -0
- package/dist/middleware/langchain.cjs +1244 -0
- package/dist/middleware/langchain.d.cts +3 -0
- package/dist/middleware/langchain.d.ts +3 -0
- package/dist/middleware/langchain.js +22 -0
- package/dist/middleware/vercel-ai.cjs +945 -0
- package/dist/middleware/vercel-ai.d.cts +70 -0
- package/dist/middleware/vercel-ai.d.ts +70 -0
- package/dist/middleware/vercel-ai.js +10 -0
- package/dist/types-Rs49lJyD.d.cts +442 -0
- package/dist/types-Rs49lJyD.d.ts +442 -0
- package/package.json +106 -4
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { S as ShashuConfig } from '../types-Rs49lJyD.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.TRUSTGATE_BASE_URL!,
|
|
18
|
+
* apiKey: process.env.TRUSTGATE_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-trustgate-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 TRUSTGATE_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-Rs49lJyD.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.TRUSTGATE_BASE_URL!,
|
|
18
|
+
* apiKey: process.env.TRUSTGATE_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-trustgate-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 TRUSTGATE_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 };
|