@intuned/browser-dev 0.1.14-dev.2 → 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 -45
- package/dist/intunedServices/ApiGateway/providers/Anthropic.js +1 -0
- package/dist/intunedServices/ApiGateway/providers/Gemini.js +1 -0
- package/dist/intunedServices/ApiGateway/providers/OpenAI.js +1 -0
- 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;
|
|
@@ -36,8 +36,6 @@ class APIGateway {
|
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
await this.validateIntunedContext();
|
|
39
|
-
this.config = this.getDefaultConfig();
|
|
40
|
-
this.validateGatewayConfig(this.config);
|
|
41
39
|
this.useGateway = true;
|
|
42
40
|
this.isInitialized = true;
|
|
43
41
|
}
|
|
@@ -62,41 +60,11 @@ class APIGateway {
|
|
|
62
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)}`);
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
|
-
validateGatewayConfig(config) {
|
|
66
|
-
const missingVars = [];
|
|
67
|
-
if (!config.functionsDomain) {
|
|
68
|
-
missingVars.push("FUNCTIONS_DOMAIN");
|
|
69
|
-
}
|
|
70
|
-
if (!config.workspaceId) {
|
|
71
|
-
missingVars.push("INTUNED_WORKSPACE_ID");
|
|
72
|
-
}
|
|
73
|
-
if (!config.integrationId) {
|
|
74
|
-
missingVars.push("INTUNED_PROJECT_ID");
|
|
75
|
-
}
|
|
76
|
-
if (missingVars.length > 0) {
|
|
77
|
-
throw new Error(`Gateway configuration is incomplete. Missing environment variables: ${missingVars.join(", ")}. ` + "These are required when running in Intuned context without an API key.");
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
getDefaultConfig() {
|
|
81
|
-
return {
|
|
82
|
-
functionsDomain: process.env.FUNCTIONS_DOMAIN,
|
|
83
|
-
workspaceId: process.env.INTUNED_WORKSPACE_ID,
|
|
84
|
-
integrationId: process.env.INTUNED_PROJECT_ID || process.env.INTUNED_INTEGRATION_ID || undefined
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
63
|
detectProvider(model) {
|
|
88
64
|
const modelLower = model.toLowerCase();
|
|
89
65
|
return (0, _getModelProvider.getModelProvider)(modelLower);
|
|
90
66
|
}
|
|
91
|
-
|
|
92
|
-
var _this$config$function;
|
|
93
|
-
if (!this.config) {
|
|
94
|
-
throw new Error("Gateway configuration not initialized");
|
|
95
|
-
}
|
|
96
|
-
const baseDomain = (_this$config$function = this.config.functionsDomain) === null || _this$config$function === void 0 ? void 0 : _this$config$function.replace(/\/$/, "");
|
|
97
|
-
return `${baseDomain}/api/${this.config.workspaceId}/functions/${this.config.integrationId}/intuned-ai-gateway`;
|
|
98
|
-
}
|
|
99
|
-
getModelConfig(extraHeaders) {
|
|
67
|
+
async getModelConfig(extraHeaders) {
|
|
100
68
|
if (!this.useGateway && this.apiKey) {
|
|
101
69
|
return {
|
|
102
70
|
model: this.model,
|
|
@@ -105,23 +73,31 @@ class APIGateway {
|
|
|
105
73
|
baseUrl: undefined
|
|
106
74
|
};
|
|
107
75
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
+
}
|
|
115
91
|
}
|
|
116
92
|
async createProviderInstance(extraHeaders) {
|
|
117
93
|
await this.ensureInitialized();
|
|
118
|
-
const
|
|
94
|
+
const modelConfig = await this.getModelConfig(extraHeaders);
|
|
119
95
|
const provider = this.detectProvider(this.model);
|
|
120
96
|
const input = {
|
|
121
|
-
apiKey:
|
|
122
|
-
headers:
|
|
123
|
-
model:
|
|
124
|
-
baseUrl:
|
|
97
|
+
apiKey: modelConfig.apiKey,
|
|
98
|
+
headers: modelConfig.extraHeaders,
|
|
99
|
+
model: modelConfig.model,
|
|
100
|
+
baseUrl: modelConfig.baseUrl
|
|
125
101
|
};
|
|
126
102
|
const providerFactories = {
|
|
127
103
|
anthropic: () => (0, _Anthropic.createAnthropicInstance)(input),
|
|
@@ -17,6 +17,7 @@ const createAnthropicInstance = input => {
|
|
|
17
17
|
});
|
|
18
18
|
} else {
|
|
19
19
|
return (0, _anthropic.createAnthropic)({
|
|
20
|
+
apiKey,
|
|
20
21
|
baseURL: baseUrl,
|
|
21
22
|
fetch: _jwtTokenManager.backendFunctionsTokenManager.fetchWithToken.bind(_jwtTokenManager.backendFunctionsTokenManager)
|
|
22
23
|
});
|
|
@@ -19,6 +19,7 @@ const createGoogleInstance = input => {
|
|
|
19
19
|
});
|
|
20
20
|
} else {
|
|
21
21
|
return (0, _google.createGoogleGenerativeAI)({
|
|
22
|
+
apiKey,
|
|
22
23
|
headers,
|
|
23
24
|
baseURL: baseUrl,
|
|
24
25
|
fetch: _jwtTokenManager.backendFunctionsTokenManager.fetchWithToken.bind(_jwtTokenManager.backendFunctionsTokenManager)
|
|
@@ -19,6 +19,7 @@ const createOpenAIInstance = input => {
|
|
|
19
19
|
});
|
|
20
20
|
} else {
|
|
21
21
|
return (0, _openai.createOpenAI)({
|
|
22
|
+
apiKey,
|
|
22
23
|
headers,
|
|
23
24
|
baseURL: baseUrl,
|
|
24
25
|
fetch: _jwtTokenManager.backendFunctionsTokenManager.fetchWithToken.bind(_jwtTokenManager.backendFunctionsTokenManager)
|