@massa-ai/tools-api 1.32.0 → 1.33.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/index.js +78 -27
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -410,9 +410,9 @@ var init_massa_ai_config = __esm(() => {
|
|
|
410
410
|
},
|
|
411
411
|
embedding: {
|
|
412
412
|
provider: "ollama",
|
|
413
|
-
model: "
|
|
413
|
+
model: "qwen3-embedding:4b",
|
|
414
414
|
baseURL: "http://localhost:11434",
|
|
415
|
-
dimensions:
|
|
415
|
+
dimensions: 2560
|
|
416
416
|
},
|
|
417
417
|
compression: {
|
|
418
418
|
defaultStrategy: "code_structure",
|
|
@@ -51290,6 +51290,18 @@ function _extractJsonObject(text2) {
|
|
|
51290
51290
|
function timeoutSignal(timeoutMs) {
|
|
51291
51291
|
return AbortSignal.timeout(timeoutMs);
|
|
51292
51292
|
}
|
|
51293
|
+
function _isAbortOrTimeoutError(err) {
|
|
51294
|
+
let cur = err;
|
|
51295
|
+
for (let hops = 0;cur && hops < 5; hops++, cur = cur.cause) {
|
|
51296
|
+
const name24 = typeof cur.name === "string" ? cur.name : "";
|
|
51297
|
+
if (name24 === "TimeoutError" || name24 === "AbortError")
|
|
51298
|
+
return true;
|
|
51299
|
+
const message = typeof cur.message === "string" ? cur.message : "";
|
|
51300
|
+
if (/timed out|operation was aborted/i.test(message))
|
|
51301
|
+
return true;
|
|
51302
|
+
}
|
|
51303
|
+
return false;
|
|
51304
|
+
}
|
|
51293
51305
|
async function llmComplete(prompt, opts = {}) {
|
|
51294
51306
|
if (!isLlmEnabled()) {
|
|
51295
51307
|
return { ok: false, error: "llm disabled" };
|
|
@@ -51387,7 +51399,7 @@ async function llmObject(prompt, schema, opts = {}) {
|
|
|
51387
51399
|
});
|
|
51388
51400
|
return { ok: false, error: "schema validation failed (fallback path)" };
|
|
51389
51401
|
} catch (e) {
|
|
51390
|
-
if (llm.disableThink) {
|
|
51402
|
+
if (llm.disableThink && !_isAbortOrTimeoutError(e)) {
|
|
51391
51403
|
const reasoning = _reasoningToText(result).length > 0 ? _reasoningToText(result) : _reasoningToText(e);
|
|
51392
51404
|
if (reasoning.length > 0) {
|
|
51393
51405
|
const parsed = _extractJsonObject(reasoning);
|
|
@@ -93979,7 +93991,7 @@ function createProvider(config3, providerId) {
|
|
|
93979
93991
|
}
|
|
93980
93992
|
return new AISDKEmbeddingProvider(config3, providerId);
|
|
93981
93993
|
}
|
|
93982
|
-
var AISDKEmbeddingProvider;
|
|
93994
|
+
var OLLAMA_EMBED_NUM_CTX, AISDKEmbeddingProvider;
|
|
93983
93995
|
var init_provider = __esm(() => {
|
|
93984
93996
|
init_dist6();
|
|
93985
93997
|
init_dist7();
|
|
@@ -93990,7 +94002,9 @@ var init_provider = __esm(() => {
|
|
|
93990
94002
|
init_metrics2();
|
|
93991
94003
|
init_rate_limiter2();
|
|
93992
94004
|
init_dist();
|
|
94005
|
+
init_config();
|
|
93993
94006
|
init_local_transformers();
|
|
94007
|
+
OLLAMA_EMBED_NUM_CTX = parsePositiveIntEnv(process.env.OLLAMA_EMBEDDING_NUM_CTX, 8192);
|
|
93994
94008
|
AISDKEmbeddingProvider = class AISDKEmbeddingProvider {
|
|
93995
94009
|
config;
|
|
93996
94010
|
providerId;
|
|
@@ -94138,7 +94152,8 @@ var init_provider = __esm(() => {
|
|
|
94138
94152
|
const inputText = this.sanitizeText(this.truncateText(text2));
|
|
94139
94153
|
const response = await this.ollamaFetch("/api/embed", {
|
|
94140
94154
|
model: this.model,
|
|
94141
|
-
input: inputText
|
|
94155
|
+
input: inputText,
|
|
94156
|
+
options: { num_ctx: OLLAMA_EMBED_NUM_CTX }
|
|
94142
94157
|
});
|
|
94143
94158
|
if (!response.ok) {
|
|
94144
94159
|
throw new Error(`Ollama API error: ${response.status} ${response.statusText}`);
|
|
@@ -94228,7 +94243,8 @@ var init_provider = __esm(() => {
|
|
|
94228
94243
|
return await withTimeout(() => withRetry(async () => {
|
|
94229
94244
|
const response = await this.ollamaFetch("/api/embed", {
|
|
94230
94245
|
model: this.model,
|
|
94231
|
-
input: texts.map((t2) => this.sanitizeText(this.truncateText(t2)))
|
|
94246
|
+
input: texts.map((t2) => this.sanitizeText(this.truncateText(t2))),
|
|
94247
|
+
options: { num_ctx: OLLAMA_EMBED_NUM_CTX }
|
|
94232
94248
|
});
|
|
94233
94249
|
if (!response.ok) {
|
|
94234
94250
|
throw new Error(`Ollama batch API error: ${response.status} ${response.statusText}`);
|
|
@@ -105428,18 +105444,36 @@ function hasApiKey(providerName) {
|
|
|
105428
105444
|
}
|
|
105429
105445
|
return !!config3.apiKey;
|
|
105430
105446
|
}
|
|
105431
|
-
var embeddingProviders;
|
|
105447
|
+
var fileEmbedding, selectedProvider, fileFor = (provider) => fileEmbedding?.provider === provider ? fileEmbedding : undefined, SELECTABLE_PROVIDERS, embeddingProviders;
|
|
105432
105448
|
var init_config2 = __esm(() => {
|
|
105433
105449
|
init_config();
|
|
105450
|
+
init_dist();
|
|
105451
|
+
fileEmbedding = loadConfigSafe().embedding;
|
|
105452
|
+
selectedProvider = process.env.EMBEDDING_PROVIDER || fileEmbedding?.provider || "ollama";
|
|
105453
|
+
SELECTABLE_PROVIDERS = new Set([
|
|
105454
|
+
"ollama",
|
|
105455
|
+
"mistral",
|
|
105456
|
+
"google",
|
|
105457
|
+
"openai",
|
|
105458
|
+
"vercel",
|
|
105459
|
+
"litellm",
|
|
105460
|
+
"custom",
|
|
105461
|
+
"transformers",
|
|
105462
|
+
"local"
|
|
105463
|
+
]);
|
|
105464
|
+
if (!SELECTABLE_PROVIDERS.has(selectedProvider)) {
|
|
105465
|
+
logger.warn(`[EmbeddingConfig] selected provider "${selectedProvider}" has no runtime entry \u2014 falling back to priority order`, { source: process.env.EMBEDDING_PROVIDER ? "EMBEDDING_PROVIDER env" : "config.json embedding.provider" });
|
|
105466
|
+
}
|
|
105434
105467
|
embeddingProviders = {
|
|
105435
105468
|
google: (() => {
|
|
105436
|
-
const
|
|
105469
|
+
const file3 = fileFor("google");
|
|
105470
|
+
const model = process.env.GOOGLE_EMBEDDING_MODEL || file3?.model || "gemini-embedding-001";
|
|
105437
105471
|
return {
|
|
105438
105472
|
provider: "google",
|
|
105439
105473
|
model,
|
|
105440
|
-
apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY || process.env.GOOGLE_API_KEY,
|
|
105441
|
-
dimensions: 3072,
|
|
105442
|
-
priority:
|
|
105474
|
+
apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY || process.env.GOOGLE_API_KEY || file3?.apiKey,
|
|
105475
|
+
dimensions: file3?.dimensions ?? 3072,
|
|
105476
|
+
priority: selectedProvider === "google" ? 1 : 10,
|
|
105443
105477
|
timeout: 60000,
|
|
105444
105478
|
maxRetries: 3,
|
|
105445
105479
|
maxChars: getMaxChars("GOOGLE", model),
|
|
@@ -105454,7 +105488,7 @@ var init_config2 = __esm(() => {
|
|
|
105454
105488
|
apiKey: process.env.AI_GATEWAY_API_KEY || process.env.VERCEL_AI_GATEWAY_API_KEY,
|
|
105455
105489
|
baseURL: process.env.VERCEL_AI_GATEWAY_URL,
|
|
105456
105490
|
dimensions: Number(process.env.VERCEL_EMBEDDING_DIMENSIONS || "4096"),
|
|
105457
|
-
priority:
|
|
105491
|
+
priority: selectedProvider === "vercel" ? 1 : 20,
|
|
105458
105492
|
timeout: 60000,
|
|
105459
105493
|
maxRetries: 3,
|
|
105460
105494
|
maxChars: getMaxChars("VERCEL", model),
|
|
@@ -105462,13 +105496,14 @@ var init_config2 = __esm(() => {
|
|
|
105462
105496
|
};
|
|
105463
105497
|
})(),
|
|
105464
105498
|
ollama: (() => {
|
|
105465
|
-
const
|
|
105499
|
+
const file3 = fileFor("ollama");
|
|
105500
|
+
const model = process.env.OLLAMA_EMBEDDING_MODEL || file3?.model || "qwen3-embedding:4b";
|
|
105466
105501
|
return {
|
|
105467
105502
|
provider: "ollama",
|
|
105468
105503
|
model,
|
|
105469
|
-
baseURL: process.env.OLLAMA_BASE_URL || "http://localhost:11434",
|
|
105470
|
-
dimensions: Number(process.env.OLLAMA_EMBEDDING_DIMENSIONS
|
|
105471
|
-
priority:
|
|
105504
|
+
baseURL: process.env.OLLAMA_BASE_URL || file3?.baseURL || "http://localhost:11434",
|
|
105505
|
+
dimensions: process.env.OLLAMA_EMBEDDING_DIMENSIONS ? Number(process.env.OLLAMA_EMBEDDING_DIMENSIONS) : file3?.dimensions ?? 2560,
|
|
105506
|
+
priority: selectedProvider === "ollama" ? 1 : 50,
|
|
105472
105507
|
timeout: 300000,
|
|
105473
105508
|
maxRetries: 2,
|
|
105474
105509
|
maxChars: getMaxChars("OLLAMA", model),
|
|
@@ -105476,13 +105511,14 @@ var init_config2 = __esm(() => {
|
|
|
105476
105511
|
};
|
|
105477
105512
|
})(),
|
|
105478
105513
|
mistralText: (() => {
|
|
105479
|
-
const
|
|
105514
|
+
const file3 = fileFor("mistral");
|
|
105515
|
+
const model = process.env.MISTRAL_TEXT_EMBEDDING_MODEL || file3?.model || "mistral-embed";
|
|
105480
105516
|
return {
|
|
105481
105517
|
provider: "mistral",
|
|
105482
105518
|
model,
|
|
105483
|
-
apiKey: process.env.MISTRAL_API_KEY,
|
|
105484
|
-
dimensions: 1024,
|
|
105485
|
-
priority:
|
|
105519
|
+
apiKey: process.env.MISTRAL_API_KEY || file3?.apiKey,
|
|
105520
|
+
dimensions: file3?.dimensions ?? 1024,
|
|
105521
|
+
priority: selectedProvider === "mistral" ? 1 : 2,
|
|
105486
105522
|
timeout: 60000,
|
|
105487
105523
|
maxRetries: 3,
|
|
105488
105524
|
maxChars: getMaxChars("MISTRAL", model),
|
|
@@ -105494,9 +105530,9 @@ var init_config2 = __esm(() => {
|
|
|
105494
105530
|
return {
|
|
105495
105531
|
provider: "mistral",
|
|
105496
105532
|
model,
|
|
105497
|
-
apiKey: process.env.MISTRAL_API_KEY,
|
|
105533
|
+
apiKey: process.env.MISTRAL_API_KEY || fileFor("mistral")?.apiKey,
|
|
105498
105534
|
dimensions: 1536,
|
|
105499
|
-
priority:
|
|
105535
|
+
priority: selectedProvider === "mistral" ? 1 : 3,
|
|
105500
105536
|
timeout: 60000,
|
|
105501
105537
|
maxRetries: 3,
|
|
105502
105538
|
maxChars: getMaxChars("MISTRAL", model),
|
|
@@ -105511,7 +105547,7 @@ var init_config2 = __esm(() => {
|
|
|
105511
105547
|
apiKey: process.env.LITELLM_API_KEY,
|
|
105512
105548
|
baseURL: process.env.LITELLM_BASE_URL,
|
|
105513
105549
|
dimensions: Number(process.env.LITELLM_EMBEDDING_DIMENSIONS || "1024"),
|
|
105514
|
-
priority:
|
|
105550
|
+
priority: selectedProvider === "litellm" ? 1 : 15,
|
|
105515
105551
|
timeout: Number(process.env.LITELLM_EMBEDDING_TIMEOUT || "60000"),
|
|
105516
105552
|
maxRetries: 3,
|
|
105517
105553
|
maxChars: getMaxChars("LITELLM", model),
|
|
@@ -105526,7 +105562,7 @@ var init_config2 = __esm(() => {
|
|
|
105526
105562
|
apiKey: process.env.CUSTOM_API_KEY,
|
|
105527
105563
|
baseURL: process.env.CUSTOM_EMBEDDING_BASE_URL,
|
|
105528
105564
|
dimensions: Number(process.env.CUSTOM_EMBEDDING_DIMENSIONS || "1536"),
|
|
105529
|
-
priority:
|
|
105565
|
+
priority: selectedProvider === "custom" ? 1 : 100,
|
|
105530
105566
|
timeout: Number(process.env.CUSTOM_EMBEDDING_TIMEOUT || "60000"),
|
|
105531
105567
|
maxRetries: 3,
|
|
105532
105568
|
maxChars: getMaxChars("CUSTOM", model),
|
|
@@ -105539,7 +105575,7 @@ var init_config2 = __esm(() => {
|
|
|
105539
105575
|
provider: "transformers",
|
|
105540
105576
|
model,
|
|
105541
105577
|
dimensions: Number(process.env.TRANSFORMERS_EMBEDDING_DIMENSIONS || "384"),
|
|
105542
|
-
priority:
|
|
105578
|
+
priority: selectedProvider === "transformers" ? 1 : 100,
|
|
105543
105579
|
timeout: 300000,
|
|
105544
105580
|
maxRetries: 1,
|
|
105545
105581
|
maxChars: getMaxChars("TRANSFORMERS", model),
|
|
@@ -105552,12 +105588,27 @@ var init_config2 = __esm(() => {
|
|
|
105552
105588
|
provider: "transformers",
|
|
105553
105589
|
model,
|
|
105554
105590
|
dimensions: Number(process.env.TRANSFORMERS_EMBEDDING_DIMENSIONS || "384"),
|
|
105555
|
-
priority:
|
|
105591
|
+
priority: selectedProvider === "local" ? 1 : 100,
|
|
105556
105592
|
timeout: 300000,
|
|
105557
105593
|
maxRetries: 1,
|
|
105558
105594
|
maxChars: getMaxChars("TRANSFORMERS", model),
|
|
105559
105595
|
rateLimits: getRateLimits("TRANSFORMERS")
|
|
105560
105596
|
};
|
|
105597
|
+
})(),
|
|
105598
|
+
openai: (() => {
|
|
105599
|
+
const file3 = fileFor("openai");
|
|
105600
|
+
const model = process.env.OPENAI_EMBEDDING_MODEL || file3?.model || "text-embedding-3-small";
|
|
105601
|
+
return {
|
|
105602
|
+
provider: "openai",
|
|
105603
|
+
model,
|
|
105604
|
+
apiKey: process.env.OPENAI_API_KEY || file3?.apiKey,
|
|
105605
|
+
dimensions: file3?.dimensions ?? 1536,
|
|
105606
|
+
priority: selectedProvider === "openai" ? 1 : 10,
|
|
105607
|
+
timeout: 60000,
|
|
105608
|
+
maxRetries: 3,
|
|
105609
|
+
maxChars: getMaxChars("OPENAI", model),
|
|
105610
|
+
rateLimits: getRateLimits("OPENAI")
|
|
105611
|
+
};
|
|
105561
105612
|
})()
|
|
105562
105613
|
};
|
|
105563
105614
|
});
|
|
@@ -179113,7 +179164,7 @@ var systemRoutes = new Elysia({ prefix: "/api/v1/system" }).get("/info", async (
|
|
|
179113
179164
|
return {
|
|
179114
179165
|
...ollamaStatus,
|
|
179115
179166
|
models,
|
|
179116
|
-
configuredModel: process.env.OLLAMA_EMBEDDING_MODEL || "qwen3-embedding:
|
|
179167
|
+
configuredModel: process.env.OLLAMA_EMBEDDING_MODEL || "qwen3-embedding:4b",
|
|
179117
179168
|
baseUrl: process.env.OLLAMA_BASE_URL || "http://localhost:11434"
|
|
179118
179169
|
};
|
|
179119
179170
|
}, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@massa-ai/tools-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"author": "luizgmassa",
|
|
5
5
|
"description": "massa-ai REST API server - Semantic code search, memory, and context compression",
|
|
6
6
|
"type": "module",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"test": "bun scripts/run-tests-isolated.ts"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@massa-ai/core": "^1.
|
|
25
|
-
"@massa-ai/shared": "^1.
|
|
24
|
+
"@massa-ai/core": "^1.33.0",
|
|
25
|
+
"@massa-ai/shared": "^1.33.0",
|
|
26
26
|
"elysia": "^1.2.25",
|
|
27
27
|
"@elysiajs/swagger": "^1.2.0",
|
|
28
28
|
"@elysiajs/cors": "^1.2.0",
|