@trustgateai/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/dist/{chunk-UUGIIO3Q.mjs → chunk-HWMHN2XV.mjs} +1 -1
- package/dist/chunk-OCDNSTSM.mjs +31 -0
- package/dist/chunk-QJUVF52Z.mjs +31 -0
- package/dist/{chunk-R2YXTU4L.mjs → chunk-STJ53FX3.mjs} +1 -1
- package/dist/{chunk-SV5FTXAH.mjs → chunk-Z2D2AATH.mjs} +1 -1
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +70 -3
- package/dist/index.mjs +32 -5
- package/dist/middleware/anthropic.d.mts +38 -0
- package/dist/middleware/anthropic.d.ts +38 -0
- package/dist/middleware/anthropic.js +158 -0
- package/dist/middleware/anthropic.mjs +9 -0
- package/dist/middleware/google.d.mts +45 -0
- package/dist/middleware/google.d.ts +45 -0
- package/dist/middleware/google.js +158 -0
- package/dist/middleware/google.mjs +9 -0
- package/dist/middleware/langchain.d.mts +1 -1
- package/dist/middleware/langchain.d.ts +1 -1
- package/dist/middleware/langchain.js +1 -1
- package/dist/middleware/langchain.mjs +2 -2
- package/dist/middleware/vercel-ai.d.mts +1 -1
- package/dist/middleware/vercel-ai.d.ts +1 -1
- package/dist/middleware/vercel-ai.js +1 -1
- package/dist/middleware/vercel-ai.mjs +2 -2
- package/dist/{types-BxyYog9f.d.ts → types-QFksyF5p.d.mts} +7 -1
- package/dist/{types-BxyYog9f.d.mts → types-QFksyF5p.d.ts} +7 -1
- package/package.json +70 -56
- package/src/client.ts +141 -125
- package/src/context.ts +132 -132
- package/src/index.ts +41 -31
- package/src/middleware/anthropic.ts +56 -0
- package/src/middleware/google.ts +63 -0
- package/src/middleware/langchain.ts +57 -57
- package/src/middleware/vercel-ai.ts +78 -78
- package/src/n8n.ts +51 -51
- package/src/types.ts +75 -68
- package/src/version.ts +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildContextHeaders,
|
|
3
|
+
getWorkflowContextFromEnv
|
|
4
|
+
} from "./chunk-Z2D2AATH.mjs";
|
|
5
|
+
|
|
6
|
+
// src/middleware/google.ts
|
|
7
|
+
function getGeminiHeaders(config) {
|
|
8
|
+
const ctx = config.workflowContext ?? getWorkflowContextFromEnv();
|
|
9
|
+
const headers = {
|
|
10
|
+
...config.headers,
|
|
11
|
+
...buildContextHeaders(ctx)
|
|
12
|
+
};
|
|
13
|
+
if (config.apiKey) {
|
|
14
|
+
headers["x-api-key"] = config.apiKey;
|
|
15
|
+
}
|
|
16
|
+
return headers;
|
|
17
|
+
}
|
|
18
|
+
function createTrustGateGeminiConfig(config) {
|
|
19
|
+
const baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
20
|
+
const headers = getGeminiHeaders(config);
|
|
21
|
+
return {
|
|
22
|
+
baseUrl,
|
|
23
|
+
apiKey: config.apiKey ?? null,
|
|
24
|
+
headers: Object.keys(headers).length ? headers : void 0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
getGeminiHeaders,
|
|
30
|
+
createTrustGateGeminiConfig
|
|
31
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildContextHeaders,
|
|
3
|
+
getWorkflowContextFromEnv
|
|
4
|
+
} from "./chunk-Z2D2AATH.mjs";
|
|
5
|
+
|
|
6
|
+
// src/middleware/anthropic.ts
|
|
7
|
+
function getAnthropicHeaders(config) {
|
|
8
|
+
const ctx = config.workflowContext ?? getWorkflowContextFromEnv();
|
|
9
|
+
const headers = {
|
|
10
|
+
...config.headers,
|
|
11
|
+
...buildContextHeaders(ctx)
|
|
12
|
+
};
|
|
13
|
+
if (config.apiKey) {
|
|
14
|
+
headers["x-api-key"] = config.apiKey;
|
|
15
|
+
}
|
|
16
|
+
return headers;
|
|
17
|
+
}
|
|
18
|
+
function createTrustGateAnthropicConfig(config) {
|
|
19
|
+
const baseURL = config.baseUrl.replace(/\/$/, "");
|
|
20
|
+
const headers = getAnthropicHeaders(config);
|
|
21
|
+
return {
|
|
22
|
+
baseURL,
|
|
23
|
+
apiKey: config.apiKey ?? null,
|
|
24
|
+
defaultHeaders: Object.keys(headers).length ? headers : void 0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
getAnthropicHeaders,
|
|
30
|
+
createTrustGateAnthropicConfig
|
|
31
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { T as TrustGateConfig, R as RequestOptions, W as WorkflowContext, N as N8nHeaderSnippet } from './types-
|
|
2
|
-
export { a as RuntimeMetadata } from './types-
|
|
1
|
+
import { T as TrustGateConfig, R as RequestOptions, W as WorkflowContext, N as N8nHeaderSnippet } from './types-QFksyF5p.mjs';
|
|
2
|
+
export { P as Provider, a as RuntimeMetadata } from './types-QFksyF5p.mjs';
|
|
3
3
|
export { TrustGateOpenAIOptions, createTrustGateOpenAIOptions, getTrustGateHeaders } from './middleware/vercel-ai.mjs';
|
|
4
4
|
export { createTrustGateLangChainConfig } from './middleware/langchain.mjs';
|
|
5
|
+
export { createTrustGateAnthropicConfig, getAnthropicHeaders } from './middleware/anthropic.mjs';
|
|
6
|
+
export { createTrustGateGeminiConfig, getGeminiHeaders } from './middleware/google.mjs';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* TrustGate Node.js client. Forwards requests to the TrustGate gateway with
|
|
@@ -24,6 +26,8 @@ declare class TrustGate {
|
|
|
24
26
|
getWorkflowContext(options?: RequestOptions): WorkflowContext;
|
|
25
27
|
/**
|
|
26
28
|
* Perform a non-streaming JSON request through TrustGate.
|
|
29
|
+
* @param options.provider - Optional provider for this request ('openai' | 'anthropic' | 'google');
|
|
30
|
+
* controls auth header format (e.g. x-api-key only for anthropic/google).
|
|
27
31
|
*/
|
|
28
32
|
fetch(path: string, init?: RequestInit, options?: RequestOptions): Promise<Response>;
|
|
29
33
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { T as TrustGateConfig, R as RequestOptions, W as WorkflowContext, N as N8nHeaderSnippet } from './types-
|
|
2
|
-
export { a as RuntimeMetadata } from './types-
|
|
1
|
+
import { T as TrustGateConfig, R as RequestOptions, W as WorkflowContext, N as N8nHeaderSnippet } from './types-QFksyF5p.js';
|
|
2
|
+
export { P as Provider, a as RuntimeMetadata } from './types-QFksyF5p.js';
|
|
3
3
|
export { TrustGateOpenAIOptions, createTrustGateOpenAIOptions, getTrustGateHeaders } from './middleware/vercel-ai.js';
|
|
4
4
|
export { createTrustGateLangChainConfig } from './middleware/langchain.js';
|
|
5
|
+
export { createTrustGateAnthropicConfig, getAnthropicHeaders } from './middleware/anthropic.js';
|
|
6
|
+
export { createTrustGateGeminiConfig, getGeminiHeaders } from './middleware/google.js';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* TrustGate Node.js client. Forwards requests to the TrustGate gateway with
|
|
@@ -24,6 +26,8 @@ declare class TrustGate {
|
|
|
24
26
|
getWorkflowContext(options?: RequestOptions): WorkflowContext;
|
|
25
27
|
/**
|
|
26
28
|
* Perform a non-streaming JSON request through TrustGate.
|
|
29
|
+
* @param options.provider - Optional provider for this request ('openai' | 'anthropic' | 'google');
|
|
30
|
+
* controls auth header format (e.g. x-api-key only for anthropic/google).
|
|
27
31
|
*/
|
|
28
32
|
fetch(path: string, init?: RequestInit, options?: RequestOptions): Promise<Response>;
|
|
29
33
|
/**
|
package/dist/index.js
CHANGED
|
@@ -25,8 +25,12 @@ __export(index_exports, {
|
|
|
25
25
|
TrustGate: () => TrustGate,
|
|
26
26
|
buildContextHeaders: () => buildContextHeaders,
|
|
27
27
|
buildSourceToolJson: () => buildSourceToolJson,
|
|
28
|
+
createTrustGateAnthropicConfig: () => createTrustGateAnthropicConfig,
|
|
29
|
+
createTrustGateGeminiConfig: () => createTrustGateGeminiConfig,
|
|
28
30
|
createTrustGateLangChainConfig: () => createTrustGateLangChainConfig,
|
|
29
31
|
createTrustGateOpenAIOptions: () => createTrustGateOpenAIOptions,
|
|
32
|
+
getAnthropicHeaders: () => getAnthropicHeaders,
|
|
33
|
+
getGeminiHeaders: () => getGeminiHeaders,
|
|
30
34
|
getN8nHeaderSnippet: () => getN8nHeaderSnippet,
|
|
31
35
|
getTrustGateHeaders: () => getTrustGateHeaders,
|
|
32
36
|
getWorkflowContextFromEnv: () => getWorkflowContextFromEnv
|
|
@@ -34,7 +38,7 @@ __export(index_exports, {
|
|
|
34
38
|
module.exports = __toCommonJS(index_exports);
|
|
35
39
|
|
|
36
40
|
// src/version.ts
|
|
37
|
-
var SDK_VERSION = "1.
|
|
41
|
+
var SDK_VERSION = "1.1.0";
|
|
38
42
|
|
|
39
43
|
// src/context.ts
|
|
40
44
|
var HEADER_PREFIX = "x-trustgate";
|
|
@@ -142,6 +146,19 @@ function buildContextHeaders(ctx) {
|
|
|
142
146
|
function resolveContext(config, options) {
|
|
143
147
|
return options?.workflowContext ?? config.workflowContext ?? getWorkflowContextFromEnv();
|
|
144
148
|
}
|
|
149
|
+
function authHeadersForProvider(apiKey, provider) {
|
|
150
|
+
switch (provider) {
|
|
151
|
+
case "anthropic":
|
|
152
|
+
case "google":
|
|
153
|
+
return { "x-api-key": apiKey };
|
|
154
|
+
case "openai":
|
|
155
|
+
default:
|
|
156
|
+
return {
|
|
157
|
+
authorization: `Bearer ${apiKey}`,
|
|
158
|
+
"x-api-key": apiKey
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
145
162
|
function mergeHeaders(config, options, context) {
|
|
146
163
|
const out = {
|
|
147
164
|
"content-type": "application/json",
|
|
@@ -149,8 +166,8 @@ function mergeHeaders(config, options, context) {
|
|
|
149
166
|
...options?.headers
|
|
150
167
|
};
|
|
151
168
|
if (config.apiKey) {
|
|
152
|
-
|
|
153
|
-
out
|
|
169
|
+
const provider = options?.provider ?? config.provider;
|
|
170
|
+
Object.assign(out, authHeadersForProvider(config.apiKey, provider));
|
|
154
171
|
}
|
|
155
172
|
if (context) {
|
|
156
173
|
Object.assign(out, buildContextHeaders(context));
|
|
@@ -175,6 +192,8 @@ var TrustGate = class {
|
|
|
175
192
|
}
|
|
176
193
|
/**
|
|
177
194
|
* Perform a non-streaming JSON request through TrustGate.
|
|
195
|
+
* @param options.provider - Optional provider for this request ('openai' | 'anthropic' | 'google');
|
|
196
|
+
* controls auth header format (e.g. x-api-key only for anthropic/google).
|
|
178
197
|
*/
|
|
179
198
|
async fetch(path, init = {}, options) {
|
|
180
199
|
const context = resolveContext(this.config, options);
|
|
@@ -299,6 +318,50 @@ function createTrustGateLangChainConfig(config) {
|
|
|
299
318
|
}
|
|
300
319
|
};
|
|
301
320
|
}
|
|
321
|
+
|
|
322
|
+
// src/middleware/anthropic.ts
|
|
323
|
+
function getAnthropicHeaders(config) {
|
|
324
|
+
const ctx = config.workflowContext ?? getWorkflowContextFromEnv();
|
|
325
|
+
const headers = {
|
|
326
|
+
...config.headers,
|
|
327
|
+
...buildContextHeaders(ctx)
|
|
328
|
+
};
|
|
329
|
+
if (config.apiKey) {
|
|
330
|
+
headers["x-api-key"] = config.apiKey;
|
|
331
|
+
}
|
|
332
|
+
return headers;
|
|
333
|
+
}
|
|
334
|
+
function createTrustGateAnthropicConfig(config) {
|
|
335
|
+
const baseURL = config.baseUrl.replace(/\/$/, "");
|
|
336
|
+
const headers = getAnthropicHeaders(config);
|
|
337
|
+
return {
|
|
338
|
+
baseURL,
|
|
339
|
+
apiKey: config.apiKey ?? null,
|
|
340
|
+
defaultHeaders: Object.keys(headers).length ? headers : void 0
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/middleware/google.ts
|
|
345
|
+
function getGeminiHeaders(config) {
|
|
346
|
+
const ctx = config.workflowContext ?? getWorkflowContextFromEnv();
|
|
347
|
+
const headers = {
|
|
348
|
+
...config.headers,
|
|
349
|
+
...buildContextHeaders(ctx)
|
|
350
|
+
};
|
|
351
|
+
if (config.apiKey) {
|
|
352
|
+
headers["x-api-key"] = config.apiKey;
|
|
353
|
+
}
|
|
354
|
+
return headers;
|
|
355
|
+
}
|
|
356
|
+
function createTrustGateGeminiConfig(config) {
|
|
357
|
+
const baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
358
|
+
const headers = getGeminiHeaders(config);
|
|
359
|
+
return {
|
|
360
|
+
baseUrl,
|
|
361
|
+
apiKey: config.apiKey ?? null,
|
|
362
|
+
headers: Object.keys(headers).length ? headers : void 0
|
|
363
|
+
};
|
|
364
|
+
}
|
|
302
365
|
// Annotate the CommonJS export names for ESM import in node:
|
|
303
366
|
0 && (module.exports = {
|
|
304
367
|
HEADER_PREFIX,
|
|
@@ -306,8 +369,12 @@ function createTrustGateLangChainConfig(config) {
|
|
|
306
369
|
TrustGate,
|
|
307
370
|
buildContextHeaders,
|
|
308
371
|
buildSourceToolJson,
|
|
372
|
+
createTrustGateAnthropicConfig,
|
|
373
|
+
createTrustGateGeminiConfig,
|
|
309
374
|
createTrustGateLangChainConfig,
|
|
310
375
|
createTrustGateOpenAIOptions,
|
|
376
|
+
getAnthropicHeaders,
|
|
377
|
+
getGeminiHeaders,
|
|
311
378
|
getN8nHeaderSnippet,
|
|
312
379
|
getTrustGateHeaders,
|
|
313
380
|
getWorkflowContextFromEnv
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createTrustGateAnthropicConfig,
|
|
3
|
+
getAnthropicHeaders
|
|
4
|
+
} from "./chunk-QJUVF52Z.mjs";
|
|
5
|
+
import {
|
|
6
|
+
createTrustGateGeminiConfig,
|
|
7
|
+
getGeminiHeaders
|
|
8
|
+
} from "./chunk-OCDNSTSM.mjs";
|
|
1
9
|
import {
|
|
2
10
|
createTrustGateLangChainConfig
|
|
3
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-STJ53FX3.mjs";
|
|
4
12
|
import {
|
|
5
13
|
createTrustGateOpenAIOptions,
|
|
6
14
|
getTrustGateHeaders
|
|
7
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-HWMHN2XV.mjs";
|
|
8
16
|
import {
|
|
9
17
|
HEADER_PREFIX,
|
|
10
18
|
SOURCE_TOOL_HEADER,
|
|
11
19
|
buildContextHeaders,
|
|
12
20
|
buildSourceToolJson,
|
|
13
21
|
getWorkflowContextFromEnv
|
|
14
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-Z2D2AATH.mjs";
|
|
15
23
|
|
|
16
24
|
// src/client.ts
|
|
17
25
|
function resolveContext(config, options) {
|
|
18
26
|
return options?.workflowContext ?? config.workflowContext ?? getWorkflowContextFromEnv();
|
|
19
27
|
}
|
|
28
|
+
function authHeadersForProvider(apiKey, provider) {
|
|
29
|
+
switch (provider) {
|
|
30
|
+
case "anthropic":
|
|
31
|
+
case "google":
|
|
32
|
+
return { "x-api-key": apiKey };
|
|
33
|
+
case "openai":
|
|
34
|
+
default:
|
|
35
|
+
return {
|
|
36
|
+
authorization: `Bearer ${apiKey}`,
|
|
37
|
+
"x-api-key": apiKey
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
20
41
|
function mergeHeaders(config, options, context) {
|
|
21
42
|
const out = {
|
|
22
43
|
"content-type": "application/json",
|
|
@@ -24,8 +45,8 @@ function mergeHeaders(config, options, context) {
|
|
|
24
45
|
...options?.headers
|
|
25
46
|
};
|
|
26
47
|
if (config.apiKey) {
|
|
27
|
-
|
|
28
|
-
out
|
|
48
|
+
const provider = options?.provider ?? config.provider;
|
|
49
|
+
Object.assign(out, authHeadersForProvider(config.apiKey, provider));
|
|
29
50
|
}
|
|
30
51
|
if (context) {
|
|
31
52
|
Object.assign(out, buildContextHeaders(context));
|
|
@@ -50,6 +71,8 @@ var TrustGate = class {
|
|
|
50
71
|
}
|
|
51
72
|
/**
|
|
52
73
|
* Perform a non-streaming JSON request through TrustGate.
|
|
74
|
+
* @param options.provider - Optional provider for this request ('openai' | 'anthropic' | 'google');
|
|
75
|
+
* controls auth header format (e.g. x-api-key only for anthropic/google).
|
|
53
76
|
*/
|
|
54
77
|
async fetch(path, init = {}, options) {
|
|
55
78
|
const context = resolveContext(this.config, options);
|
|
@@ -136,8 +159,12 @@ export {
|
|
|
136
159
|
TrustGate,
|
|
137
160
|
buildContextHeaders,
|
|
138
161
|
buildSourceToolJson,
|
|
162
|
+
createTrustGateAnthropicConfig,
|
|
163
|
+
createTrustGateGeminiConfig,
|
|
139
164
|
createTrustGateLangChainConfig,
|
|
140
165
|
createTrustGateOpenAIOptions,
|
|
166
|
+
getAnthropicHeaders,
|
|
167
|
+
getGeminiHeaders,
|
|
141
168
|
getN8nHeaderSnippet,
|
|
142
169
|
getTrustGateHeaders,
|
|
143
170
|
getWorkflowContextFromEnv
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { T as TrustGateConfig } from '../types-QFksyF5p.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Anthropic middleware: use TrustGate as the base URL for @anthropic-ai/sdk.
|
|
5
|
+
*
|
|
6
|
+
* Pass the returned config to the Anthropic client so all requests go through
|
|
7
|
+
* TrustGate with workflow context and x-api-key for Shadow AI detection.
|
|
8
|
+
*
|
|
9
|
+
* Example:
|
|
10
|
+
*
|
|
11
|
+
* import Anthropic from '@anthropic-ai/sdk';
|
|
12
|
+
* import { createTrustGateAnthropicConfig } from '@trustgateai/sdk/middleware/anthropic';
|
|
13
|
+
*
|
|
14
|
+
* const config = createTrustGateAnthropicConfig({
|
|
15
|
+
* baseUrl: process.env.TRUSTGATE_BASE_URL!,
|
|
16
|
+
* apiKey: process.env.TRUSTGATE_API_KEY,
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* const anthropic = new Anthropic(config);
|
|
20
|
+
* const message = await anthropic.messages.create({ model: 'claude-3-5-sonnet-20241022', ... });
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns headers compatible with @anthropic-ai/sdk. Uses x-api-key only (no
|
|
25
|
+
* Authorization header). Use with defaultHeaders or when building requests manually.
|
|
26
|
+
*/
|
|
27
|
+
declare function getAnthropicHeaders(config: TrustGateConfig): Record<string, string>;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a config object for the Anthropic SDK (baseURL, apiKey, defaultHeaders).
|
|
30
|
+
* Injects TrustGate context headers and x-api-key so requests go through the gateway.
|
|
31
|
+
*/
|
|
32
|
+
declare function createTrustGateAnthropicConfig(config: TrustGateConfig): {
|
|
33
|
+
baseURL: string;
|
|
34
|
+
apiKey: string | null;
|
|
35
|
+
defaultHeaders?: Record<string, string>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { createTrustGateAnthropicConfig, getAnthropicHeaders };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { T as TrustGateConfig } from '../types-QFksyF5p.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Anthropic middleware: use TrustGate as the base URL for @anthropic-ai/sdk.
|
|
5
|
+
*
|
|
6
|
+
* Pass the returned config to the Anthropic client so all requests go through
|
|
7
|
+
* TrustGate with workflow context and x-api-key for Shadow AI detection.
|
|
8
|
+
*
|
|
9
|
+
* Example:
|
|
10
|
+
*
|
|
11
|
+
* import Anthropic from '@anthropic-ai/sdk';
|
|
12
|
+
* import { createTrustGateAnthropicConfig } from '@trustgateai/sdk/middleware/anthropic';
|
|
13
|
+
*
|
|
14
|
+
* const config = createTrustGateAnthropicConfig({
|
|
15
|
+
* baseUrl: process.env.TRUSTGATE_BASE_URL!,
|
|
16
|
+
* apiKey: process.env.TRUSTGATE_API_KEY,
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* const anthropic = new Anthropic(config);
|
|
20
|
+
* const message = await anthropic.messages.create({ model: 'claude-3-5-sonnet-20241022', ... });
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns headers compatible with @anthropic-ai/sdk. Uses x-api-key only (no
|
|
25
|
+
* Authorization header). Use with defaultHeaders or when building requests manually.
|
|
26
|
+
*/
|
|
27
|
+
declare function getAnthropicHeaders(config: TrustGateConfig): Record<string, string>;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a config object for the Anthropic SDK (baseURL, apiKey, defaultHeaders).
|
|
30
|
+
* Injects TrustGate context headers and x-api-key so requests go through the gateway.
|
|
31
|
+
*/
|
|
32
|
+
declare function createTrustGateAnthropicConfig(config: TrustGateConfig): {
|
|
33
|
+
baseURL: string;
|
|
34
|
+
apiKey: string | null;
|
|
35
|
+
defaultHeaders?: Record<string, string>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { createTrustGateAnthropicConfig, getAnthropicHeaders };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/middleware/anthropic.ts
|
|
21
|
+
var anthropic_exports = {};
|
|
22
|
+
__export(anthropic_exports, {
|
|
23
|
+
createTrustGateAnthropicConfig: () => createTrustGateAnthropicConfig,
|
|
24
|
+
getAnthropicHeaders: () => getAnthropicHeaders
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(anthropic_exports);
|
|
27
|
+
|
|
28
|
+
// src/version.ts
|
|
29
|
+
var SDK_VERSION = "1.1.0";
|
|
30
|
+
|
|
31
|
+
// src/context.ts
|
|
32
|
+
var HEADER_PREFIX = "x-trustgate";
|
|
33
|
+
var SOURCE_TOOL_HEADER = "x-trustgate-source-tool";
|
|
34
|
+
var N8N_KEYS = [
|
|
35
|
+
"N8N_WORKFLOW_ID",
|
|
36
|
+
"N8N_EXECUTION_ID",
|
|
37
|
+
"N8N_WORKFLOW_NAME",
|
|
38
|
+
"N8N_EXECUTION_MODE"
|
|
39
|
+
];
|
|
40
|
+
var VERCEL_KEYS = [
|
|
41
|
+
"VERCEL",
|
|
42
|
+
"VERCEL_ENV",
|
|
43
|
+
"VERCEL_URL",
|
|
44
|
+
"VERCEL_GIT_COMMIT_REF",
|
|
45
|
+
"VERCEL_GIT_REPO_ID",
|
|
46
|
+
"VERCEL_GIT_COMMIT_SHA"
|
|
47
|
+
];
|
|
48
|
+
var GITHUB_KEYS = [
|
|
49
|
+
"GITHUB_ACTION",
|
|
50
|
+
"GITHUB_ACTIONS",
|
|
51
|
+
"GITHUB_WORKFLOW",
|
|
52
|
+
"GITHUB_RUN_ID",
|
|
53
|
+
"GITHUB_RUN_NUMBER",
|
|
54
|
+
"GITHUB_REPOSITORY",
|
|
55
|
+
"GITHUB_SHA"
|
|
56
|
+
];
|
|
57
|
+
function pickEnv(keys) {
|
|
58
|
+
const out = {};
|
|
59
|
+
for (const key of keys) {
|
|
60
|
+
const v = process.env[key];
|
|
61
|
+
if (v !== void 0 && v !== "") out[key] = v;
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
function getBaseMetadata() {
|
|
66
|
+
return {
|
|
67
|
+
sdk_version: SDK_VERSION,
|
|
68
|
+
node_version: process.version,
|
|
69
|
+
os: process.platform,
|
|
70
|
+
arch: process.arch
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function getWorkflowContextFromEnv() {
|
|
74
|
+
const baseMeta = getBaseMetadata();
|
|
75
|
+
const n8n = pickEnv(N8N_KEYS);
|
|
76
|
+
if (Object.keys(n8n).length > 0) {
|
|
77
|
+
return {
|
|
78
|
+
source: "n8n",
|
|
79
|
+
workflow_id: n8n.N8N_WORKFLOW_ID,
|
|
80
|
+
execution_id: n8n.N8N_EXECUTION_ID,
|
|
81
|
+
metadata: { ...baseMeta, ...n8n }
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const vercel = pickEnv(VERCEL_KEYS);
|
|
85
|
+
if (Object.keys(vercel).length > 0) {
|
|
86
|
+
return {
|
|
87
|
+
source: "vercel",
|
|
88
|
+
workflow_id: vercel.VERCEL_GIT_REPO_ID || vercel.VERCEL_URL,
|
|
89
|
+
execution_id: vercel.VERCEL_GIT_COMMIT_SHA,
|
|
90
|
+
metadata: { ...baseMeta, ...vercel }
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const github = pickEnv(GITHUB_KEYS);
|
|
94
|
+
if (Object.keys(github).length > 0) {
|
|
95
|
+
return {
|
|
96
|
+
source: "github",
|
|
97
|
+
workflow_id: github.GITHUB_WORKFLOW || github.GITHUB_REPOSITORY,
|
|
98
|
+
execution_id: github.GITHUB_RUN_ID || github.GITHUB_RUN_NUMBER,
|
|
99
|
+
metadata: { ...baseMeta, ...github }
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
source: "local_script",
|
|
104
|
+
metadata: baseMeta
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function buildSourceToolJson(ctx) {
|
|
108
|
+
const meta = ctx.metadata ?? getBaseMetadata();
|
|
109
|
+
const payload = {
|
|
110
|
+
source: ctx.source,
|
|
111
|
+
metadata: meta
|
|
112
|
+
};
|
|
113
|
+
if (ctx.workflow_id !== void 0) payload.workflow_id = ctx.workflow_id;
|
|
114
|
+
if (ctx.execution_id !== void 0) payload.execution_id = ctx.execution_id;
|
|
115
|
+
if (ctx.workflow_step !== void 0) payload.workflow_step = ctx.workflow_step;
|
|
116
|
+
return JSON.stringify(payload);
|
|
117
|
+
}
|
|
118
|
+
function buildContextHeaders(ctx) {
|
|
119
|
+
const meta = ctx.metadata ?? getBaseMetadata();
|
|
120
|
+
const h = {
|
|
121
|
+
[SOURCE_TOOL_HEADER]: buildSourceToolJson({ ...ctx, metadata: meta }),
|
|
122
|
+
[`${HEADER_PREFIX}-source`]: ctx.source
|
|
123
|
+
};
|
|
124
|
+
if (ctx.workflow_id) h[`${HEADER_PREFIX}-workflow-id`] = ctx.workflow_id;
|
|
125
|
+
if (ctx.execution_id) h[`${HEADER_PREFIX}-execution-id`] = ctx.execution_id;
|
|
126
|
+
if (ctx.workflow_step) h[`${HEADER_PREFIX}-workflow-step`] = ctx.workflow_step;
|
|
127
|
+
for (const [k, v] of Object.entries(meta)) {
|
|
128
|
+
if (v) h[`${HEADER_PREFIX}-meta-${k.toLowerCase()}`] = String(v);
|
|
129
|
+
}
|
|
130
|
+
return h;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/middleware/anthropic.ts
|
|
134
|
+
function getAnthropicHeaders(config) {
|
|
135
|
+
const ctx = config.workflowContext ?? getWorkflowContextFromEnv();
|
|
136
|
+
const headers = {
|
|
137
|
+
...config.headers,
|
|
138
|
+
...buildContextHeaders(ctx)
|
|
139
|
+
};
|
|
140
|
+
if (config.apiKey) {
|
|
141
|
+
headers["x-api-key"] = config.apiKey;
|
|
142
|
+
}
|
|
143
|
+
return headers;
|
|
144
|
+
}
|
|
145
|
+
function createTrustGateAnthropicConfig(config) {
|
|
146
|
+
const baseURL = config.baseUrl.replace(/\/$/, "");
|
|
147
|
+
const headers = getAnthropicHeaders(config);
|
|
148
|
+
return {
|
|
149
|
+
baseURL,
|
|
150
|
+
apiKey: config.apiKey ?? null,
|
|
151
|
+
defaultHeaders: Object.keys(headers).length ? headers : void 0
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
0 && (module.exports = {
|
|
156
|
+
createTrustGateAnthropicConfig,
|
|
157
|
+
getAnthropicHeaders
|
|
158
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { T as TrustGateConfig } from '../types-QFksyF5p.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Google Gemini middleware: use TrustGate 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 TrustGate (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 { createTrustGateGeminiConfig } from '@trustgateai/sdk/middleware/google';
|
|
15
|
+
*
|
|
16
|
+
* const config = createTrustGateGeminiConfig({
|
|
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 TrustGate header injection (x-trustgate-source-tool, etc.), use
|
|
25
|
+
* the TrustGate 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
|
+
* TrustGate context. Use when building requests or with a custom fetch.
|
|
32
|
+
*/
|
|
33
|
+
declare function getGeminiHeaders(config: TrustGateConfig): Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Returns a config object for use with @google/generative-ai (or compatible clients).
|
|
36
|
+
* Injects TrustGate context headers and x-api-key. Use apiKey for the gateway and
|
|
37
|
+
* baseUrl/headers when using a custom fetch or wrapper.
|
|
38
|
+
*/
|
|
39
|
+
declare function createTrustGateGeminiConfig(config: TrustGateConfig): {
|
|
40
|
+
baseUrl: string;
|
|
41
|
+
apiKey: string | null;
|
|
42
|
+
headers?: Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { createTrustGateGeminiConfig, getGeminiHeaders };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { T as TrustGateConfig } from '../types-QFksyF5p.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Google Gemini middleware: use TrustGate 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 TrustGate (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 { createTrustGateGeminiConfig } from '@trustgateai/sdk/middleware/google';
|
|
15
|
+
*
|
|
16
|
+
* const config = createTrustGateGeminiConfig({
|
|
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 TrustGate header injection (x-trustgate-source-tool, etc.), use
|
|
25
|
+
* the TrustGate 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
|
+
* TrustGate context. Use when building requests or with a custom fetch.
|
|
32
|
+
*/
|
|
33
|
+
declare function getGeminiHeaders(config: TrustGateConfig): Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Returns a config object for use with @google/generative-ai (or compatible clients).
|
|
36
|
+
* Injects TrustGate context headers and x-api-key. Use apiKey for the gateway and
|
|
37
|
+
* baseUrl/headers when using a custom fetch or wrapper.
|
|
38
|
+
*/
|
|
39
|
+
declare function createTrustGateGeminiConfig(config: TrustGateConfig): {
|
|
40
|
+
baseUrl: string;
|
|
41
|
+
apiKey: string | null;
|
|
42
|
+
headers?: Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { createTrustGateGeminiConfig, getGeminiHeaders };
|