@blaxel/vercel 0.2.49-dev.213 → 0.2.49-dev1

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/model.js ADDED
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blModel = void 0;
4
+ const anthropic_1 = require("@ai-sdk/anthropic");
5
+ const cerebras_1 = require("@ai-sdk/cerebras");
6
+ const cohere_1 = require("@ai-sdk/cohere");
7
+ const google_1 = require("@ai-sdk/google");
8
+ const groq_1 = require("@ai-sdk/groq");
9
+ const openai_1 = require("@ai-sdk/openai");
10
+ const core_1 = require("@blaxel/core");
11
+ const blModel = async (model, options) => {
12
+ const url = `${core_1.settings.runUrl}/${core_1.settings.workspace}/models/${model}`;
13
+ const modelData = await (0, core_1.getModelMetadata)(model);
14
+ if (!modelData) {
15
+ throw new Error(`Model ${model} not found`);
16
+ }
17
+ await (0, core_1.authenticate)();
18
+ const type = modelData?.spec?.runtime?.type || "openai";
19
+ const modelId = modelData?.spec?.runtime?.model || "gpt-4o";
20
+ // Custom fetch function that refreshes authentication on each request
21
+ const authenticatedFetch = async (input, init) => {
22
+ await (0, core_1.authenticate)();
23
+ const headers = {
24
+ ...init?.headers,
25
+ ...core_1.settings.headers,
26
+ };
27
+ return fetch(input, {
28
+ ...init,
29
+ headers,
30
+ });
31
+ };
32
+ try {
33
+ if (type === "gemini") {
34
+ return (0, google_1.createGoogleGenerativeAI)({
35
+ apiKey: "replaced",
36
+ fetch: async (_, options) => {
37
+ await (0, core_1.authenticate)();
38
+ const headers = {
39
+ ...options?.headers,
40
+ ...core_1.settings.headers,
41
+ };
42
+ return fetch(`${url}/v1beta/models/${modelId}:generateContent`, {
43
+ ...options,
44
+ headers,
45
+ });
46
+ },
47
+ ...options,
48
+ })(modelId);
49
+ }
50
+ else if (type === "anthropic") {
51
+ return (0, anthropic_1.createAnthropic)({
52
+ apiKey: "replaced",
53
+ baseURL: `${url}/v1`,
54
+ fetch: authenticatedFetch,
55
+ ...options,
56
+ })(modelId);
57
+ }
58
+ else if (type === "groq") {
59
+ return (0, groq_1.createGroq)({
60
+ apiKey: "replaced",
61
+ baseURL: `${url}`,
62
+ fetch: authenticatedFetch,
63
+ ...options,
64
+ })(modelId);
65
+ }
66
+ else if (type === "cerebras") {
67
+ return (0, cerebras_1.createCerebras)({
68
+ apiKey: "replaced",
69
+ baseURL: `${url}/v1`,
70
+ fetch: authenticatedFetch,
71
+ ...options,
72
+ })(modelId);
73
+ }
74
+ else if (type === "cohere") {
75
+ return (0, cohere_1.createCohere)({
76
+ apiKey: "replaced",
77
+ baseURL: `${url}/v2`,
78
+ fetch: authenticatedFetch,
79
+ ...options,
80
+ })(modelId);
81
+ }
82
+ return (0, openai_1.createOpenAI)({
83
+ apiKey: "replaced",
84
+ baseURL: `${url}/v1`,
85
+ fetch: authenticatedFetch,
86
+ ...options,
87
+ })(modelId);
88
+ }
89
+ catch (err) {
90
+ (0, core_1.handleDynamicImportError)(err);
91
+ throw err;
92
+ }
93
+ };
94
+ exports.blModel = blModel;
@@ -0,0 +1,4 @@
1
+ import { ToolOptions } from "@blaxel/core/tools/mcpTool";
2
+ import type { Tool } from "ai";
3
+ export declare const blTool: (name: string, options?: ToolOptions | number) => Promise<Record<string, Tool>>;
4
+ export declare const blTools: (names: string[], options?: ToolOptions | number) => Promise<Record<string, Tool>>;
package/dist/tools.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blTools = exports.blTool = void 0;
4
+ const core_1 = require("@blaxel/core");
5
+ const ai_1 = require("ai");
6
+ const blTool = async (name, options) => {
7
+ try {
8
+ const toolFormated = {};
9
+ const blaxelTool = await (0, core_1.getTool)(name, options);
10
+ for (const t of blaxelTool) {
11
+ // @ts-ignore - Type instantiation depth issue with ai package in some environments
12
+ const toolInstance = (0, ai_1.tool)({
13
+ description: t.description,
14
+ parameters: t.inputSchema,
15
+ execute: t.call.bind(t),
16
+ });
17
+ toolFormated[t.name] = toolInstance;
18
+ }
19
+ return toolFormated;
20
+ }
21
+ catch (err) {
22
+ (0, core_1.handleDynamicImportError)(err);
23
+ throw err;
24
+ }
25
+ };
26
+ exports.blTool = blTool;
27
+ const blTools = async (names, options) => {
28
+ const toolArrays = await Promise.all(names.map((n) => (0, exports.blTool)(n, options)));
29
+ const toolFormated = {};
30
+ for (const toolServer of toolArrays) {
31
+ for (const toolName in toolServer) {
32
+ toolFormated[toolName] = toolServer[toolName];
33
+ }
34
+ }
35
+ return toolFormated;
36
+ };
37
+ exports.blTools = blTools;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/vercel",
3
- "version": "0.2.49-dev.213",
3
+ "version": "0.2.49-dev1",
4
4
  "description": "Blaxel SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",
@@ -48,7 +48,7 @@
48
48
  "@ai-sdk/openai": "^2.0.57",
49
49
  "@ai-sdk/provider": "^2.0.0",
50
50
  "ai": "^5.0.82",
51
- "@blaxel/core": "0.2.49-dev.213"
51
+ "@blaxel/core": "0.2.49-dev1"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@eslint/js": "^9.26.0",