@intuned/browser-dev 0.1.14-dev.1 → 0.1.14-dev.3
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/.claude/settings.local.json +8 -0
- package/dist/common/loadRuntime.js +11 -2
- package/dist/intunedServices/ApiGateway/aiApiGateway.js +21 -55
- package/dist/intunedServices/ApiGateway/providers/Anthropic.js +1 -1
- package/dist/intunedServices/ApiGateway/providers/Gemini.js +1 -1
- package/dist/intunedServices/ApiGateway/providers/OpenAI.js +1 -1
- package/dist/intunedServices/ApiGateway/tests/testApiGateway.spec.js +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.loadRuntime = void 0;
|
|
6
|
+
exports.loadRuntime = exports.loadGetAiGatewayConfig = void 0;
|
|
7
7
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
8
8
|
const loadRuntime = async () => {
|
|
9
9
|
try {
|
|
@@ -13,4 +13,13 @@ const loadRuntime = async () => {
|
|
|
13
13
|
return () => null;
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
exports.loadRuntime = loadRuntime;
|
|
16
|
+
exports.loadRuntime = loadRuntime;
|
|
17
|
+
const loadGetAiGatewayConfig = async () => {
|
|
18
|
+
const runtime = await Promise.resolve().then(() => _interopRequireWildcard(require("@intuned/runtime")));
|
|
19
|
+
const fn = runtime.getAiGatewayConfig;
|
|
20
|
+
if (typeof fn !== "function") {
|
|
21
|
+
throw new Error("@intuned/runtime does not export getAiGatewayConfig. Please upgrade to a newer version.");
|
|
22
|
+
}
|
|
23
|
+
return fn;
|
|
24
|
+
};
|
|
25
|
+
exports.loadGetAiGatewayConfig = loadGetAiGatewayConfig;
|
|
@@ -10,7 +10,6 @@ var _OpenAI = require("./providers/OpenAI");
|
|
|
10
10
|
var _Gemini = require("./providers/Gemini");
|
|
11
11
|
var _dotenv = require("dotenv");
|
|
12
12
|
var _loadRuntime = require("../../common/loadRuntime");
|
|
13
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
13
|
(0, _dotenv.config)();
|
|
15
14
|
class APIGateway {
|
|
16
15
|
useGateway = false;
|
|
@@ -37,18 +36,7 @@ class APIGateway {
|
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
39
38
|
await this.validateIntunedContext();
|
|
40
|
-
this.config = this.getDefaultConfig();
|
|
41
|
-
this.validateGatewayConfig(this.config);
|
|
42
39
|
this.useGateway = true;
|
|
43
|
-
try {
|
|
44
|
-
const runtime = await Promise.resolve().then(() => _interopRequireWildcard(require("@intuned/runtime")));
|
|
45
|
-
const {
|
|
46
|
-
apiKey
|
|
47
|
-
} = runtime.getAiGatewayConfig();
|
|
48
|
-
if (apiKey) {
|
|
49
|
-
this.gatewayAuthToken = apiKey;
|
|
50
|
-
}
|
|
51
|
-
} catch {}
|
|
52
40
|
this.isInitialized = true;
|
|
53
41
|
}
|
|
54
42
|
getApiKeyFromEnv(provider) {
|
|
@@ -72,41 +60,11 @@ class APIGateway {
|
|
|
72
60
|
throw new Error("No API key provided and not running in Intuned context. " + "Please provide an API key or ensure @intuned/runtime is installed and you're running within an Intuned workflow. " + `Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
73
61
|
}
|
|
74
62
|
}
|
|
75
|
-
validateGatewayConfig(config) {
|
|
76
|
-
const missingVars = [];
|
|
77
|
-
if (!config.functionsDomain) {
|
|
78
|
-
missingVars.push("FUNCTIONS_DOMAIN");
|
|
79
|
-
}
|
|
80
|
-
if (!config.workspaceId) {
|
|
81
|
-
missingVars.push("INTUNED_WORKSPACE_ID");
|
|
82
|
-
}
|
|
83
|
-
if (!config.integrationId) {
|
|
84
|
-
missingVars.push("INTUNED_PROJECT_ID");
|
|
85
|
-
}
|
|
86
|
-
if (missingVars.length > 0) {
|
|
87
|
-
throw new Error(`Gateway configuration is incomplete. Missing environment variables: ${missingVars.join(", ")}. ` + "These are required when running in Intuned context without an API key.");
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
getDefaultConfig() {
|
|
91
|
-
return {
|
|
92
|
-
functionsDomain: process.env.FUNCTIONS_DOMAIN,
|
|
93
|
-
workspaceId: process.env.INTUNED_WORKSPACE_ID,
|
|
94
|
-
integrationId: process.env.INTUNED_PROJECT_ID || process.env.INTUNED_INTEGRATION_ID || undefined
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
63
|
detectProvider(model) {
|
|
98
64
|
const modelLower = model.toLowerCase();
|
|
99
65
|
return (0, _getModelProvider.getModelProvider)(modelLower);
|
|
100
66
|
}
|
|
101
|
-
|
|
102
|
-
var _this$config$function;
|
|
103
|
-
if (!this.config) {
|
|
104
|
-
throw new Error("Gateway configuration not initialized");
|
|
105
|
-
}
|
|
106
|
-
const baseDomain = (_this$config$function = this.config.functionsDomain) === null || _this$config$function === void 0 ? void 0 : _this$config$function.replace(/\/$/, "");
|
|
107
|
-
return `${baseDomain}/api/${this.config.workspaceId}/functions/${this.config.integrationId}/intuned-ai-gateway`;
|
|
108
|
-
}
|
|
109
|
-
getModelConfig(extraHeaders) {
|
|
67
|
+
async getModelConfig(extraHeaders) {
|
|
110
68
|
if (!this.useGateway && this.apiKey) {
|
|
111
69
|
return {
|
|
112
70
|
model: this.model,
|
|
@@ -115,23 +73,31 @@ class APIGateway {
|
|
|
115
73
|
baseUrl: undefined
|
|
116
74
|
};
|
|
117
75
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
76
|
+
try {
|
|
77
|
+
const getAiGatewayConfig = await (0, _loadRuntime.loadGetAiGatewayConfig)();
|
|
78
|
+
const {
|
|
79
|
+
baseUrl,
|
|
80
|
+
apiKey
|
|
81
|
+
} = getAiGatewayConfig();
|
|
82
|
+
return {
|
|
83
|
+
model: this.model,
|
|
84
|
+
apiKey,
|
|
85
|
+
extraHeaders,
|
|
86
|
+
baseUrl
|
|
87
|
+
};
|
|
88
|
+
} catch (error) {
|
|
89
|
+
throw new Error("Failed to load gateway configuration from @intuned/runtime. " + `Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
90
|
+
}
|
|
125
91
|
}
|
|
126
92
|
async createProviderInstance(extraHeaders) {
|
|
127
93
|
await this.ensureInitialized();
|
|
128
|
-
const
|
|
94
|
+
const modelConfig = await this.getModelConfig(extraHeaders);
|
|
129
95
|
const provider = this.detectProvider(this.model);
|
|
130
96
|
const input = {
|
|
131
|
-
apiKey:
|
|
132
|
-
headers:
|
|
133
|
-
model:
|
|
134
|
-
baseUrl:
|
|
97
|
+
apiKey: modelConfig.apiKey,
|
|
98
|
+
headers: modelConfig.extraHeaders,
|
|
99
|
+
model: modelConfig.model,
|
|
100
|
+
baseUrl: modelConfig.baseUrl
|
|
135
101
|
};
|
|
136
102
|
const providerFactories = {
|
|
137
103
|
anthropic: () => (0, _Anthropic.createAnthropicInstance)(input),
|
|
@@ -17,7 +17,7 @@ const createAnthropicInstance = input => {
|
|
|
17
17
|
});
|
|
18
18
|
} else {
|
|
19
19
|
return (0, _anthropic.createAnthropic)({
|
|
20
|
-
apiKey
|
|
20
|
+
apiKey,
|
|
21
21
|
baseURL: baseUrl,
|
|
22
22
|
fetch: _jwtTokenManager.backendFunctionsTokenManager.fetchWithToken.bind(_jwtTokenManager.backendFunctionsTokenManager)
|
|
23
23
|
});
|
|
@@ -19,7 +19,7 @@ const createGoogleInstance = input => {
|
|
|
19
19
|
});
|
|
20
20
|
} else {
|
|
21
21
|
return (0, _google.createGoogleGenerativeAI)({
|
|
22
|
-
apiKey
|
|
22
|
+
apiKey,
|
|
23
23
|
headers,
|
|
24
24
|
baseURL: baseUrl,
|
|
25
25
|
fetch: _jwtTokenManager.backendFunctionsTokenManager.fetchWithToken.bind(_jwtTokenManager.backendFunctionsTokenManager)
|
|
@@ -19,7 +19,7 @@ const createOpenAIInstance = input => {
|
|
|
19
19
|
});
|
|
20
20
|
} else {
|
|
21
21
|
return (0, _openai.createOpenAI)({
|
|
22
|
-
apiKey
|
|
22
|
+
apiKey,
|
|
23
23
|
headers,
|
|
24
24
|
baseURL: baseUrl,
|
|
25
25
|
fetch: _jwtTokenManager.backendFunctionsTokenManager.fetchWithToken.bind(_jwtTokenManager.backendFunctionsTokenManager)
|
|
@@ -233,7 +233,7 @@ const mockLoadRuntime = _vitest.vi.mocked(_loadRuntime.loadRuntime);
|
|
|
233
233
|
});
|
|
234
234
|
const result = await gateway.createProviderInstance();
|
|
235
235
|
(0, _extendedTest.expect)(mockCreateAnthropicInstance).toHaveBeenCalledWith({
|
|
236
|
-
apiKey:
|
|
236
|
+
apiKey: "--THIS_VALUE_WILL_BE_REPLACED_BY_INTUNED_BE--",
|
|
237
237
|
headers: undefined,
|
|
238
238
|
model: "claude-3-sonnet",
|
|
239
239
|
baseUrl: "https://functions.example.com/api/workspace123/functions/integration456/intuned-ai-gateway"
|