@massa-ai/tools-api 1.58.0 → 1.59.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.
Files changed (2) hide show
  1. package/dist/index.js +117 -26
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -444,10 +444,15 @@ function parseLmStudioModelList(body) {
444
444
  function inferenceProviderList() {
445
445
  return LOCAL_INFERENCE_IDS.map((id) => INFERENCE_PROVIDERS[id]);
446
446
  }
447
- var LOCAL_INFERENCE_IDS, INFERENCE_PROVIDERS;
447
+ var LOCAL_INFERENCE_IDS, INFERENCE_ROLE_DEFAULTS, INFERENCE_PROVIDERS;
448
448
  var init_inference_providers = __esm(() => {
449
449
  init_embedding_dimensions();
450
450
  LOCAL_INFERENCE_IDS = ["ollama", "lmstudio"];
451
+ INFERENCE_ROLE_DEFAULTS = {
452
+ embedding: { contextWindow: 8192 },
453
+ instruct: { contextWindow: 16384, temperature: 0.2 },
454
+ coding: { contextWindow: 32768, temperature: 0 }
455
+ };
451
456
  INFERENCE_PROVIDERS = {
452
457
  ollama: {
453
458
  id: "ollama",
@@ -459,6 +464,13 @@ var init_inference_providers = __esm(() => {
459
464
  dimensions: "OLLAMA_EMBEDDING_DIMENSIONS"
460
465
  },
461
466
  knownDimensions: KNOWN_EMBEDDING_DIMENSIONS,
467
+ defaultModels: {
468
+ embedding: "qwen3-embedding:0.6b",
469
+ instruct: "qwen3-vl:8b",
470
+ coding: "qwen2.5-coder:7b"
471
+ },
472
+ appliesContextPerRequest: true,
473
+ embedBatchSize: 64,
462
474
  supportsOllamaVersionProbe: true,
463
475
  injectsDisableThink: true,
464
476
  requiresChatCompletionsApi: false,
@@ -474,8 +486,16 @@ var init_inference_providers = __esm(() => {
474
486
  dimensions: "LMSTUDIO_EMBEDDING_DIMENSIONS"
475
487
  },
476
488
  knownDimensions: {
477
- "text-embedding-nomic-embed-text-v1.5": 768
489
+ "text-embedding-nomic-embed-text-v1.5": 768,
490
+ "text-embedding-qwen3-embedding-0.6b": 1024
491
+ },
492
+ defaultModels: {
493
+ embedding: "text-embedding-qwen3-embedding-0.6b",
494
+ instruct: "qwen3-vl-8b-instruct",
495
+ coding: "qwen2.5-coder-7b-instruct"
478
496
  },
497
+ appliesContextPerRequest: false,
498
+ embedBatchSize: 64,
479
499
  supportsOllamaVersionProbe: false,
480
500
  injectsDisableThink: false,
481
501
  requiresChatCompletionsApi: true,
@@ -490,6 +510,7 @@ var API_PROVIDER_IDS, EMBEDDING_PROVIDER_IDS, SCHEDULER_JOB_KINDS, MAX_MATCH_WOR
490
510
  var init_massa_ai_config = __esm(() => {
491
511
  init_xdg();
492
512
  init_inference_providers();
513
+ init_embedding_dimensions();
493
514
  API_PROVIDER_IDS = ["mistral", "openai", "google", "cohere"];
494
515
  EMBEDDING_PROVIDER_IDS = [
495
516
  ...LOCAL_INFERENCE_IDS,
@@ -556,9 +577,9 @@ var init_massa_ai_config = __esm(() => {
556
577
  },
557
578
  embedding: {
558
579
  provider: "ollama",
559
- model: "qwen3-embedding:4b",
580
+ model: INFERENCE_PROVIDERS.ollama.defaultModels.embedding,
560
581
  baseURL: "http://localhost:11434",
561
- dimensions: 2560
582
+ dimensions: knownEmbeddingDimensions(INFERENCE_PROVIDERS.ollama.defaultModels.embedding) ?? 768
562
583
  },
563
584
  compression: {
564
585
  defaultStrategy: "code_structure",
@@ -597,12 +618,15 @@ var init_massa_ai_config = __esm(() => {
597
618
  enabled: false,
598
619
  baseUrl: "http://localhost:11434/v1",
599
620
  apiKey: "ollama",
600
- model: "qwen2.5:7b-instruct",
601
- codeModel: "qwen2.5-coder:7b",
621
+ model: INFERENCE_PROVIDERS.ollama.defaultModels.instruct,
622
+ codeModel: INFERENCE_PROVIDERS.ollama.defaultModels.coding,
602
623
  temperature: 0.2,
603
624
  maxOutputTokens: 8000,
604
625
  timeoutMs: 90000,
605
- disableThink: true
626
+ disableThink: true,
627
+ contextWindow: INFERENCE_ROLE_DEFAULTS.instruct.contextWindow,
628
+ codeContextWindow: INFERENCE_ROLE_DEFAULTS.coding.contextWindow,
629
+ codeTemperature: INFERENCE_ROLE_DEFAULTS.coding.temperature
606
630
  },
607
631
  memory: {
608
632
  decay: {
@@ -1098,6 +1122,10 @@ function validatePartial(partial) {
1098
1122
  details.push("embedding.apiKey must be a string");
1099
1123
  if (e.dimensions !== undefined && !checkNumber(e.dimensions, 1))
1100
1124
  details.push("embedding.dimensions must be a positive number");
1125
+ if (e.contextWindow !== undefined && !checkNumber(e.contextWindow, 1))
1126
+ details.push("embedding.contextWindow must be a positive number");
1127
+ if (e.batchSize !== undefined && !checkNumber(e.batchSize, 1))
1128
+ details.push("embedding.batchSize must be a positive number");
1101
1129
  }
1102
1130
  if (partial.compression !== undefined) {
1103
1131
  const c = partial.compression;
@@ -1181,6 +1209,12 @@ function validatePartial(partial) {
1181
1209
  details.push("llm.timeoutMs must be a positive number");
1182
1210
  if (!checkBoolean(l.disableThink))
1183
1211
  details.push("llm.disableThink must be a boolean");
1212
+ if (!checkNumber(l.contextWindow, 1))
1213
+ details.push("llm.contextWindow must be a positive number");
1214
+ if (!checkNumber(l.codeContextWindow, 1))
1215
+ details.push("llm.codeContextWindow must be a positive number");
1216
+ if (!checkNumber(l.codeTemperature))
1217
+ details.push("llm.codeTemperature must be a number");
1184
1218
  }
1185
1219
  if (partial.memory !== undefined) {
1186
1220
  const m = partial.memory;
@@ -1619,6 +1653,13 @@ function getGlobalDataDir() {
1619
1653
  return fileConfig.dataDir;
1620
1654
  return path6.join(getConfigDir(), "data");
1621
1655
  }
1656
+ function activeInferenceProviderId() {
1657
+ const providerId = fileConfig.embedding?.provider;
1658
+ if (providerId && LOCAL_INFERENCE_IDS.includes(providerId)) {
1659
+ return providerId;
1660
+ }
1661
+ return "ollama";
1662
+ }
1622
1663
 
1623
1664
  class Config {
1624
1665
  config;
@@ -1755,11 +1796,12 @@ class Config {
1755
1796
  this.config[key] = value;
1756
1797
  }
1757
1798
  }
1758
- var DEFAULT_LLM_MODEL = "qwen2.5:7b-instruct", DEFAULT_LLM_CODE_MODEL = "qwen2.5-coder:7b", SCHEDULER_JOB_ENV, DEFAULT_ALLOWED_EXTENSIONS, fileConfig, fileCacheL1Bytes, fileCacheL2Bytes, resolvedDataDir, defaultConfig, config;
1799
+ var SCHEDULER_JOB_ENV, DEFAULT_ALLOWED_EXTENSIONS, fileConfig, DEFAULT_LLM_MODEL, DEFAULT_LLM_CODE_MODEL, fileCacheL1Bytes, fileCacheL2Bytes, resolvedDataDir, defaultConfig, config;
1759
1800
  var init_config = __esm(() => {
1760
1801
  init_env();
1761
1802
  init_config_loader();
1762
1803
  init_massa_ai_config();
1804
+ init_inference_providers();
1763
1805
  init_massa_ai_config();
1764
1806
  init_massa_ai_config();
1765
1807
  init_config_loader();
@@ -1830,6 +1872,8 @@ var init_config = __esm(() => {
1830
1872
  ".hs"
1831
1873
  ];
1832
1874
  fileConfig = loadConfigSafe();
1875
+ DEFAULT_LLM_MODEL = INFERENCE_PROVIDERS[activeInferenceProviderId()].defaultModels.instruct;
1876
+ DEFAULT_LLM_CODE_MODEL = INFERENCE_PROVIDERS[activeInferenceProviderId()].defaultModels.coding;
1833
1877
  fileCacheL1Bytes = fileConfig.cache?.l1MaxSizeMB ? fileConfig.cache.l1MaxSizeMB * 1024 * 1024 : undefined;
1834
1878
  fileCacheL2Bytes = fileConfig.cache?.l2MaxSizeMB ? fileConfig.cache.l2MaxSizeMB * 1024 * 1024 : undefined;
1835
1879
  resolvedDataDir = getGlobalDataDir();
@@ -1872,7 +1916,10 @@ var init_config = __esm(() => {
1872
1916
  temperature: envNum("MASSA_AI_LLM_TEMPERATURE", fileConfig.llm?.temperature ?? 0.2),
1873
1917
  maxOutputTokens: envNum("MASSA_AI_LLM_MAX_OUTPUT_TOKENS", fileConfig.llm?.maxOutputTokens ?? 8000),
1874
1918
  timeoutMs: envNum("MASSA_AI_LLM_TIMEOUT_MS", fileConfig.llm?.timeoutMs ?? 90000),
1875
- disableThink: envBool("MASSA_AI_LLM_DISABLE_THINK", fileConfig.llm?.disableThink ?? true)
1919
+ disableThink: envBool("MASSA_AI_LLM_DISABLE_THINK", fileConfig.llm?.disableThink ?? true),
1920
+ contextWindow: fileConfig.llm?.contextWindow ?? INFERENCE_ROLE_DEFAULTS.instruct.contextWindow,
1921
+ codeContextWindow: fileConfig.llm?.codeContextWindow ?? INFERENCE_ROLE_DEFAULTS.coding.contextWindow,
1922
+ codeTemperature: envNum("MASSA_AI_LLM_CODE_TEMPERATURE", fileConfig.llm?.codeTemperature ?? INFERENCE_ROLE_DEFAULTS.coding.temperature)
1876
1923
  },
1877
1924
  memory: {
1878
1925
  decay: {
@@ -52615,20 +52662,26 @@ function isLlmEnabled() {
52615
52662
  function _setLlmEnabledForTesting(flag) {
52616
52663
  testEnabledOverride = flag;
52617
52664
  }
52618
- function getLlmConfig(opts) {
52619
- const cfg = config.get("llm");
52620
- const role = opts?.modelRole ?? "instruct";
52621
- const model = role === "code" ? cfg?.codeModel ?? cfg?.model ?? DEFAULT_LLM_MODEL : cfg?.model ?? DEFAULT_LLM_MODEL;
52665
+ function _resolveLlmConfig(cfg, role, baseUrlOverride) {
52666
+ const baseUrl = baseUrlOverride ?? cfg?.baseUrl ?? INFERENCE_PROVIDERS.ollama.defaultLlmBaseUrl;
52667
+ const spec = resolveInferenceSpec(baseUrl);
52668
+ const model = role === "code" ? cfg?.codeModel ?? spec.defaultModels.coding : cfg?.model ?? spec.defaultModels.instruct;
52669
+ const temperature = role === "code" ? cfg?.codeTemperature ?? INFERENCE_ROLE_DEFAULTS.coding.temperature : cfg?.temperature ?? INFERENCE_ROLE_DEFAULTS.instruct.temperature;
52670
+ const contextWindow = role === "code" ? cfg?.codeContextWindow ?? INFERENCE_ROLE_DEFAULTS.coding.contextWindow : cfg?.contextWindow ?? INFERENCE_ROLE_DEFAULTS.instruct.contextWindow;
52622
52671
  return {
52623
- baseUrl: testBaseUrlOverride ?? cfg?.baseUrl ?? "http://localhost:11434/v1",
52624
- apiKey: cfg?.apiKey ?? "ollama",
52672
+ baseUrl,
52673
+ apiKey: cfg?.apiKey ?? spec.id,
52625
52674
  model,
52626
- temperature: cfg?.temperature ?? 0.2,
52675
+ temperature,
52676
+ contextWindow,
52627
52677
  maxOutputTokens: cfg?.maxOutputTokens ?? 8000,
52628
52678
  timeoutMs: cfg?.timeoutMs ?? 90000,
52629
- disableThink: cfg?.disableThink ?? true
52679
+ disableThink: cfg?.disableThink ?? spec.injectsDisableThink
52630
52680
  };
52631
52681
  }
52682
+ function getLlmConfig(opts) {
52683
+ return _resolveLlmConfig(config.get("llm"), opts?.modelRole ?? "instruct", testBaseUrlOverride);
52684
+ }
52632
52685
  function hostPort(url2) {
52633
52686
  try {
52634
52687
  const u = new URL(url2);
@@ -52672,12 +52725,34 @@ function _wrapFetchDisableThink(baseFetch) {
52672
52725
  };
52673
52726
  return wrapped;
52674
52727
  }
52728
+ function _wrapFetchContextWindow(baseFetch, contextWindow) {
52729
+ const wrapped = async (input, init) => {
52730
+ try {
52731
+ if (init?.body && typeof init.body === "string") {
52732
+ const parsed = JSON.parse(init.body);
52733
+ if (parsed && typeof parsed === "object") {
52734
+ parsed.options = { ...parsed.options, num_ctx: contextWindow };
52735
+ init = { ...init, body: JSON.stringify(parsed) };
52736
+ }
52737
+ }
52738
+ } catch {}
52739
+ return baseFetch(input, init);
52740
+ };
52741
+ return wrapped;
52742
+ }
52675
52743
  function buildProvider(llm) {
52676
52744
  const spec = resolveInferenceSpec(llm.baseUrl);
52745
+ let fetchImpl;
52746
+ if (spec.appliesContextPerRequest) {
52747
+ fetchImpl = _wrapFetchContextWindow(fetchImpl ?? globalThis.fetch, llm.contextWindow);
52748
+ }
52749
+ if (llm.disableThink && spec.injectsDisableThink) {
52750
+ fetchImpl = _wrapFetchDisableThink(fetchImpl ?? globalThis.fetch);
52751
+ }
52677
52752
  const openai2 = createOpenAI({
52678
52753
  baseURL: llm.baseUrl,
52679
52754
  apiKey: llm.apiKey,
52680
- ...llm.disableThink && spec.injectsDisableThink ? { fetch: _wrapFetchDisableThink(globalThis.fetch) } : {}
52755
+ ...fetchImpl ? { fetch: fetchImpl } : {}
52681
52756
  });
52682
52757
  return spec.requiresChatCompletionsApi ? openai2.chat(llm.model) : openai2(llm.model);
52683
52758
  }
@@ -95425,6 +95500,9 @@ var init_local_transformers = __esm(() => {
95425
95500
  });
95426
95501
 
95427
95502
  // ../../packages/core/dist/services/embeddings/provider.js
95503
+ function _resolveEmbedContextWindow(embeddingConfig) {
95504
+ return parsePositiveIntEnv(process.env.OLLAMA_EMBEDDING_NUM_CTX, embeddingConfig?.contextWindow ?? INFERENCE_ROLE_DEFAULTS.embedding.contextWindow);
95505
+ }
95428
95506
  function sleep(ms) {
95429
95507
  return new Promise((resolve4) => setTimeout(resolve4, ms));
95430
95508
  }
@@ -95467,7 +95545,7 @@ function createProvider(config3, providerId) {
95467
95545
  }
95468
95546
  return new AISDKEmbeddingProvider(config3, providerId);
95469
95547
  }
95470
- var OLLAMA_EMBED_NUM_CTX, DimensionMismatchError, AISDKEmbeddingProvider;
95548
+ var DimensionMismatchError, AISDKEmbeddingProvider;
95471
95549
  var init_provider = __esm(() => {
95472
95550
  init_dist6();
95473
95551
  init_dist7();
@@ -95479,8 +95557,8 @@ var init_provider = __esm(() => {
95479
95557
  init_rate_limiter2();
95480
95558
  init_dist();
95481
95559
  init_config();
95560
+ init_inference_providers();
95482
95561
  init_local_transformers();
95483
- OLLAMA_EMBED_NUM_CTX = parsePositiveIntEnv(process.env.OLLAMA_EMBEDDING_NUM_CTX, 8192);
95484
95562
  DimensionMismatchError = class DimensionMismatchError extends Error {
95485
95563
  providerId;
95486
95564
  expected;
@@ -95642,7 +95720,7 @@ var init_provider = __esm(() => {
95642
95720
  const response = await this.ollamaFetch("/api/embed", {
95643
95721
  model: this.model,
95644
95722
  input: inputText,
95645
- options: { num_ctx: OLLAMA_EMBED_NUM_CTX }
95723
+ options: { num_ctx: _resolveEmbedContextWindow(loadConfigSafe().embedding) }
95646
95724
  });
95647
95725
  if (!response.ok) {
95648
95726
  throw new Error(`Ollama API error: ${response.status} ${response.statusText}`);
@@ -95733,7 +95811,7 @@ var init_provider = __esm(() => {
95733
95811
  const response = await this.ollamaFetch("/api/embed", {
95734
95812
  model: this.model,
95735
95813
  input: texts.map((t2) => this.sanitizeText(this.truncateText(t2))),
95736
- options: { num_ctx: OLLAMA_EMBED_NUM_CTX }
95814
+ options: { num_ctx: _resolveEmbedContextWindow(loadConfigSafe().embedding) }
95737
95815
  });
95738
95816
  if (!response.ok) {
95739
95817
  throw new Error(`Ollama batch API error: ${response.status} ${response.statusText}`);
@@ -107020,7 +107098,7 @@ var init_config2 = __esm(() => {
107020
107098
  })(),
107021
107099
  ollama: (() => {
107022
107100
  const file3 = fileFor("ollama");
107023
- const model = process.env.OLLAMA_EMBEDDING_MODEL || file3?.model || "qwen3-embedding:4b";
107101
+ const model = process.env.OLLAMA_EMBEDDING_MODEL || file3?.model || INFERENCE_PROVIDERS.ollama.defaultModels.embedding;
107024
107102
  const rawEnvDimensions = Number(process.env.OLLAMA_EMBEDDING_DIMENSIONS);
107025
107103
  const envDimensions = Number.isInteger(rawEnvDimensions) && rawEnvDimensions > 0 ? rawEnvDimensions : undefined;
107026
107104
  const resolvedDimensions = resolveEmbeddingDimensions(model, file3?.dimensions, envDimensions);
@@ -107126,7 +107204,7 @@ var init_config2 = __esm(() => {
107126
107204
  })(),
107127
107205
  lmstudio: (() => {
107128
107206
  const file3 = fileFor("lmstudio");
107129
- const model = process.env.LMSTUDIO_EMBEDDING_MODEL || file3?.model || "text-embedding-nomic-embed-text-v1.5";
107207
+ const model = process.env.LMSTUDIO_EMBEDDING_MODEL || file3?.model || INFERENCE_PROVIDERS.lmstudio.defaultModels.embedding;
107130
107208
  return {
107131
107209
  provider: "custom",
107132
107210
  model,
@@ -109478,6 +109556,12 @@ var init_base_vector_store = __esm(() => {
109478
109556
  });
109479
109557
 
109480
109558
  // ../../packages/core/dist/data/vector/postgres-vector-store.js
109559
+ function _resolveEmbedBatchSize(embeddingConfig) {
109560
+ const providerId = embeddingConfig?.provider;
109561
+ const spec = providerId && LOCAL_INFERENCE_IDS.includes(providerId) ? INFERENCE_PROVIDERS[providerId] : INFERENCE_PROVIDERS.ollama;
109562
+ return embeddingConfig?.batchSize ?? spec.embedBatchSize;
109563
+ }
109564
+
109481
109565
  class PostgresVectorCollection {
109482
109566
  pool;
109483
109567
  name;
@@ -109590,6 +109674,8 @@ var init_postgres_vector_store = __esm(() => {
109590
109674
  init_base_vector_store();
109591
109675
  init_dist();
109592
109676
  init_dist();
109677
+ init_config();
109678
+ init_inference_providers();
109593
109679
  init_identity_guard_installer();
109594
109680
  PostgresVectorStore = class PostgresVectorStore extends BaseVectorStore {
109595
109681
  pool = null;
@@ -109815,7 +109901,7 @@ var init_postgres_vector_store = __esm(() => {
109815
109901
  if (documents.length === 0)
109816
109902
  return;
109817
109903
  const pool = await this.ensureInitialized();
109818
- const EMBED_SUB_BATCH_SIZE = 8;
109904
+ const EMBED_SUB_BATCH_SIZE = _resolveEmbedBatchSize(loadConfigSafe().embedding);
109819
109905
  let totalInserted = 0;
109820
109906
  let totalFailed = 0;
109821
109907
  for (let i = 0;i < documents.length; i += EMBED_SUB_BATCH_SIZE) {
@@ -181069,9 +181155,14 @@ var analyticsRoutes = new Elysia({ prefix: "/api/v1/analytics" }).post("/", asyn
181069
181155
 
181070
181156
  // src/routes/system.ts
181071
181157
  init_dist();
181158
+ init_config();
181159
+ init_inference_providers();
181072
181160
  import path37 from "path";
181073
181161
  import fs24 from "fs";
181074
181162
  import os9 from "os";
181163
+ function resolveConfiguredOllamaEmbeddingModel() {
181164
+ return process.env.OLLAMA_EMBEDDING_MODEL || loadRawUserConfig().embedding?.model || INFERENCE_PROVIDERS.ollama.defaultModels.embedding;
181165
+ }
181075
181166
  function databaseUrlParts() {
181076
181167
  const url2 = new URL(process.env.DATABASE_URL);
181077
181168
  return {
@@ -181185,7 +181276,7 @@ var systemRoutes = new Elysia({ prefix: "/api/v1/system" }).get("/info", async (
181185
181276
  return {
181186
181277
  ...ollamaStatus,
181187
181278
  models,
181188
- configuredModel: process.env.OLLAMA_EMBEDDING_MODEL || "qwen3-embedding:4b",
181279
+ configuredModel: resolveConfiguredOllamaEmbeddingModel(),
181189
181280
  baseUrl: process.env.OLLAMA_BASE_URL || "http://localhost:11434"
181190
181281
  };
181191
181282
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massa-ai/tools-api",
3
- "version": "1.58.0",
3
+ "version": "1.59.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.58.0",
25
- "@massa-ai/shared": "^1.58.0",
24
+ "@massa-ai/core": "^1.59.0",
25
+ "@massa-ai/shared": "^1.59.0",
26
26
  "elysia": "^1.2.25",
27
27
  "@elysiajs/swagger": "^1.2.0",
28
28
  "@elysiajs/cors": "^1.2.0",