@axiom-lattice/core 2.1.102 → 2.1.103
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.d.mts +125 -2
- package/dist/index.d.ts +125 -2
- package/dist/index.js +280 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +270 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -7815,6 +7815,34 @@ function validateImageSize(sizeBytes) {
|
|
|
7815
7815
|
return null;
|
|
7816
7816
|
}
|
|
7817
7817
|
|
|
7818
|
+
// src/deep_agent_new/backends/audioUtils.ts
|
|
7819
|
+
var AUDIO_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
7820
|
+
".webm",
|
|
7821
|
+
".wav",
|
|
7822
|
+
".mp3",
|
|
7823
|
+
".m4a",
|
|
7824
|
+
".ogg",
|
|
7825
|
+
".flac",
|
|
7826
|
+
".aac",
|
|
7827
|
+
".wma",
|
|
7828
|
+
".opus",
|
|
7829
|
+
".amr"
|
|
7830
|
+
]);
|
|
7831
|
+
function isAudioFile(filePath) {
|
|
7832
|
+
const ext = filePath.toLowerCase().slice(filePath.lastIndexOf("."));
|
|
7833
|
+
return AUDIO_EXTENSIONS.has(ext);
|
|
7834
|
+
}
|
|
7835
|
+
function detectAudioFormat(filePath) {
|
|
7836
|
+
return filePath.toLowerCase().slice(filePath.lastIndexOf(".") + 1);
|
|
7837
|
+
}
|
|
7838
|
+
var MAX_AUDIO_SIZE = 25 * 1024 * 1024;
|
|
7839
|
+
function validateAudioSize(sizeBytes) {
|
|
7840
|
+
if (sizeBytes > MAX_AUDIO_SIZE) {
|
|
7841
|
+
return `Audio file too large (${(sizeBytes / 1024 / 1024).toFixed(1)}MB). Maximum is 25MB.`;
|
|
7842
|
+
}
|
|
7843
|
+
return null;
|
|
7844
|
+
}
|
|
7845
|
+
|
|
7818
7846
|
// src/deep_agent_new/backends/describeImage.ts
|
|
7819
7847
|
import { HumanMessage } from "@langchain/core/messages";
|
|
7820
7848
|
async function describeImage(options) {
|
|
@@ -7840,6 +7868,212 @@ async function describeImage(options) {
|
|
|
7840
7868
|
return result.content || "";
|
|
7841
7869
|
}
|
|
7842
7870
|
|
|
7871
|
+
// src/stt_model_lattice/STTModelLattice.ts
|
|
7872
|
+
import { OpenAIClient, toFile } from "@langchain/openai";
|
|
7873
|
+
var STTModelLattice = class {
|
|
7874
|
+
constructor(key4, config) {
|
|
7875
|
+
this.key = key4;
|
|
7876
|
+
this.config = config;
|
|
7877
|
+
this.client = this;
|
|
7878
|
+
const apiKey = config.apiKey || (config.apiKeyEnvName ? process.env[config.apiKeyEnvName] : void 0) || process.env.OPENAI_API_KEY || "";
|
|
7879
|
+
if (!apiKey) {
|
|
7880
|
+
throw new Error("No API key configured for STT. Set apiKey, apiKeyEnvName, or OPENAI_API_KEY.");
|
|
7881
|
+
}
|
|
7882
|
+
this.openaiClient = new OpenAIClient({
|
|
7883
|
+
apiKey,
|
|
7884
|
+
baseURL: config.baseURL,
|
|
7885
|
+
timeout: config.timeout || 3e4
|
|
7886
|
+
});
|
|
7887
|
+
}
|
|
7888
|
+
/**
|
|
7889
|
+
* Transcribe audio buffer to text.
|
|
7890
|
+
* Routes to whisper or chat API mode based on config.
|
|
7891
|
+
*/
|
|
7892
|
+
async transcribe(audio, format) {
|
|
7893
|
+
const mode = this.config.apiMode || "whisper";
|
|
7894
|
+
if (mode === "chat") {
|
|
7895
|
+
return this.transcribeViaChat(audio, format);
|
|
7896
|
+
}
|
|
7897
|
+
return this.transcribeViaWhisper(audio, format);
|
|
7898
|
+
}
|
|
7899
|
+
/**
|
|
7900
|
+
* Transcribe via OpenAI /v1/audio/transcriptions endpoint (multipart).
|
|
7901
|
+
*/
|
|
7902
|
+
async transcribeViaWhisper(audio, format) {
|
|
7903
|
+
const mimeType = formatToMimeType(format);
|
|
7904
|
+
const file = typeof File !== "undefined" ? new File([audio], `audio.${format}`, { type: mimeType }) : await toFile(audio, `audio.${format}`, { type: mimeType });
|
|
7905
|
+
const extra = this.config.extra || {};
|
|
7906
|
+
const response = await this.openaiClient.audio.transcriptions.create({
|
|
7907
|
+
file,
|
|
7908
|
+
model: this.config.model || "whisper-1",
|
|
7909
|
+
response_format: "verbose_json",
|
|
7910
|
+
...extra
|
|
7911
|
+
});
|
|
7912
|
+
const result = response;
|
|
7913
|
+
return {
|
|
7914
|
+
text: result.text,
|
|
7915
|
+
segments: result.segments?.map((s) => ({
|
|
7916
|
+
start: s.start,
|
|
7917
|
+
end: s.end,
|
|
7918
|
+
text: s.text
|
|
7919
|
+
})),
|
|
7920
|
+
confidence: result.segments ? result.segments.reduce((sum, s) => sum + Math.exp(s.avg_logprob ?? -Infinity), 0) / result.segments.length : void 0
|
|
7921
|
+
};
|
|
7922
|
+
}
|
|
7923
|
+
/**
|
|
7924
|
+
* Transcribe via OpenAI /v1/chat/completions with input_audio.
|
|
7925
|
+
* Used by Qwen3-ASR-Flash and similar audio-via-chat models.
|
|
7926
|
+
*/
|
|
7927
|
+
async transcribeViaChat(audio, format) {
|
|
7928
|
+
const mimeType = formatToMimeType(format);
|
|
7929
|
+
const dataUri = `data:${mimeType};base64,${audio.toString("base64")}`;
|
|
7930
|
+
const extra = this.config.extra || {};
|
|
7931
|
+
const response = await this.openaiClient.chat.completions.create({
|
|
7932
|
+
model: this.config.model || "qwen3-asr-flash",
|
|
7933
|
+
messages: [
|
|
7934
|
+
{
|
|
7935
|
+
role: "user",
|
|
7936
|
+
content: [
|
|
7937
|
+
{
|
|
7938
|
+
type: "input_audio",
|
|
7939
|
+
input_audio: {
|
|
7940
|
+
data: dataUri,
|
|
7941
|
+
format
|
|
7942
|
+
}
|
|
7943
|
+
}
|
|
7944
|
+
]
|
|
7945
|
+
}
|
|
7946
|
+
],
|
|
7947
|
+
...extra
|
|
7948
|
+
});
|
|
7949
|
+
const result = response;
|
|
7950
|
+
const text = result.choices?.[0]?.message?.content || "";
|
|
7951
|
+
return { text };
|
|
7952
|
+
}
|
|
7953
|
+
};
|
|
7954
|
+
function formatToMimeType(format) {
|
|
7955
|
+
const mimeTypes = {
|
|
7956
|
+
webm: "audio/webm",
|
|
7957
|
+
wav: "audio/wav",
|
|
7958
|
+
mp3: "audio/mpeg",
|
|
7959
|
+
m4a: "audio/mp4",
|
|
7960
|
+
ogg: "audio/ogg",
|
|
7961
|
+
flac: "audio/flac",
|
|
7962
|
+
aac: "audio/aac"
|
|
7963
|
+
};
|
|
7964
|
+
const lower = format.toLowerCase();
|
|
7965
|
+
if (!mimeTypes[lower]) {
|
|
7966
|
+
console.warn(`Unknown STT audio format "${format}", falling back to audio/webm`);
|
|
7967
|
+
}
|
|
7968
|
+
return mimeTypes[lower] || "audio/webm";
|
|
7969
|
+
}
|
|
7970
|
+
|
|
7971
|
+
// src/stt_model_lattice/STTModelLatticeManager.ts
|
|
7972
|
+
var STTModelLatticeManager = class _STTModelLatticeManager extends BaseLatticeManager {
|
|
7973
|
+
static getInstance() {
|
|
7974
|
+
if (!_STTModelLatticeManager._instance) {
|
|
7975
|
+
_STTModelLatticeManager._instance = new _STTModelLatticeManager();
|
|
7976
|
+
}
|
|
7977
|
+
return _STTModelLatticeManager._instance;
|
|
7978
|
+
}
|
|
7979
|
+
getLatticeType() {
|
|
7980
|
+
return "stt";
|
|
7981
|
+
}
|
|
7982
|
+
/**
|
|
7983
|
+
* Register an STT model lattice.
|
|
7984
|
+
* @param key - Lattice key name
|
|
7985
|
+
* @param config - STT provider configuration
|
|
7986
|
+
*/
|
|
7987
|
+
registerLattice(key4, config) {
|
|
7988
|
+
const client = new STTModelLattice(key4, config);
|
|
7989
|
+
const label = config.model || key4;
|
|
7990
|
+
const sttLattice = {
|
|
7991
|
+
key: key4,
|
|
7992
|
+
client,
|
|
7993
|
+
config,
|
|
7994
|
+
label
|
|
7995
|
+
};
|
|
7996
|
+
this.register(key4, sttLattice);
|
|
7997
|
+
}
|
|
7998
|
+
/**
|
|
7999
|
+
* Get an STT model lattice by key.
|
|
8000
|
+
*/
|
|
8001
|
+
getSTTModelLattice(key4) {
|
|
8002
|
+
const lattice = this.get(key4);
|
|
8003
|
+
if (!lattice) {
|
|
8004
|
+
throw new Error(`STTModelLattice "${key4}" not found`);
|
|
8005
|
+
}
|
|
8006
|
+
return lattice;
|
|
8007
|
+
}
|
|
8008
|
+
/**
|
|
8009
|
+
* Get STT client instance by key (default tenant).
|
|
8010
|
+
*/
|
|
8011
|
+
getSTTClient(key4) {
|
|
8012
|
+
return this.getSTTModelLattice(key4).client;
|
|
8013
|
+
}
|
|
8014
|
+
/**
|
|
8015
|
+
* Get STT client instance by key and tenant.
|
|
8016
|
+
* @param tenantId - Tenant ID for isolation
|
|
8017
|
+
* @param key - Lattice key name
|
|
8018
|
+
*/
|
|
8019
|
+
getSTTClientWithTenant(tenantId2, key4) {
|
|
8020
|
+
let lattice = this.getWithTenant(tenantId2, key4);
|
|
8021
|
+
if (!lattice && tenantId2 !== "default") {
|
|
8022
|
+
lattice = this.getWithTenant("default", key4);
|
|
8023
|
+
}
|
|
8024
|
+
if (!lattice) {
|
|
8025
|
+
throw new Error(`STTModelLattice "${key4}" not found for tenant "${tenantId2}"`);
|
|
8026
|
+
}
|
|
8027
|
+
return lattice.client;
|
|
8028
|
+
}
|
|
8029
|
+
/**
|
|
8030
|
+
* Get all registered STT models as info list.
|
|
8031
|
+
*/
|
|
8032
|
+
getAllSTTModelInfo() {
|
|
8033
|
+
return this.getAllLattices().map((l) => ({
|
|
8034
|
+
key: l.key,
|
|
8035
|
+
label: l.label,
|
|
8036
|
+
provider: l.config.provider || "openai-compatible",
|
|
8037
|
+
model: l.config.model || "unknown"
|
|
8038
|
+
}));
|
|
8039
|
+
}
|
|
8040
|
+
getAllLattices() {
|
|
8041
|
+
return this.getAll();
|
|
8042
|
+
}
|
|
8043
|
+
hasLattice(key4) {
|
|
8044
|
+
return this.has(key4);
|
|
8045
|
+
}
|
|
8046
|
+
removeLattice(key4) {
|
|
8047
|
+
return this.remove(key4);
|
|
8048
|
+
}
|
|
8049
|
+
clearLattices() {
|
|
8050
|
+
this.clear();
|
|
8051
|
+
}
|
|
8052
|
+
getLatticeCount() {
|
|
8053
|
+
return this.count();
|
|
8054
|
+
}
|
|
8055
|
+
getLatticeKeys() {
|
|
8056
|
+
return this.keys();
|
|
8057
|
+
}
|
|
8058
|
+
};
|
|
8059
|
+
var sttModelLatticeManager = STTModelLatticeManager.getInstance();
|
|
8060
|
+
var registerSTTModelLattice = (key4, config) => sttModelLatticeManager.registerLattice(key4, config);
|
|
8061
|
+
var getSTTModelLattice = (key4) => sttModelLatticeManager.getSTTModelLattice(key4);
|
|
8062
|
+
var getSTTClient = (key4) => sttModelLatticeManager.getSTTClient(key4);
|
|
8063
|
+
var getSTTClientWithTenant = (tenantId2, key4) => sttModelLatticeManager.getSTTClientWithTenant(tenantId2, key4);
|
|
8064
|
+
|
|
8065
|
+
// src/deep_agent_new/backends/transcribeAudio.ts
|
|
8066
|
+
async function transcribeAudio(options) {
|
|
8067
|
+
const { audioBuffer, format } = options;
|
|
8068
|
+
if (!sttModelLatticeManager.hasLattice("default")) {
|
|
8069
|
+
throw new Error(
|
|
8070
|
+
"No default STT model registered. Use registerSTTModelLattice('default', { ... }) first."
|
|
8071
|
+
);
|
|
8072
|
+
}
|
|
8073
|
+
const client = sttModelLatticeManager.getSTTClient("default");
|
|
8074
|
+
return await client.transcribe(audioBuffer, format);
|
|
8075
|
+
}
|
|
8076
|
+
|
|
7843
8077
|
// src/deep_agent_new/middleware/fs.ts
|
|
7844
8078
|
var FileDataSchema = z310.object({
|
|
7845
8079
|
content: z310.array(z310.string()),
|
|
@@ -7898,7 +8132,7 @@ Path conventions:
|
|
|
7898
8132
|
- glob: find files matching a pattern (e.g., "/project/**/*.py")
|
|
7899
8133
|
- grep: search for text within files`;
|
|
7900
8134
|
var LS_TOOL_DESCRIPTION = "List files and directories in a directory";
|
|
7901
|
-
var READ_FILE_TOOL_DESCRIPTION = "Read the contents of a file. For image files (png, jpg, gif, webp, bmp, svg), returns a visual description when the current model supports vision
|
|
8135
|
+
var READ_FILE_TOOL_DESCRIPTION = "Read the contents of a file. For image files (png, jpg, gif, webp, bmp, svg), returns a visual description when the current model supports vision; otherwise returns an error suggesting a vision-capable model. For audio files (webm, wav, mp3, m4a, ogg, flac, aac, wma, opus, amr), transcribes the content using the default STT model; if none is registered, returns an error with registration instructions.";
|
|
7902
8136
|
var WRITE_FILE_TOOL_DESCRIPTION = "Write content to a new file. Returns an error if the file already exists";
|
|
7903
8137
|
var EDIT_FILE_TOOL_DESCRIPTION = "Edit a file by replacing a specific string with a new string";
|
|
7904
8138
|
var GLOB_TOOL_DESCRIPTION = "Find files matching a glob pattern (e.g., '**/*.py' for all Python files)";
|
|
@@ -7983,6 +8217,34 @@ ${description}`;
|
|
|
7983
8217
|
\u8BFB\u53D6\u56FE\u7247\u5931\u8D25\uFF1A${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`;
|
|
7984
8218
|
}
|
|
7985
8219
|
}
|
|
8220
|
+
if (isAudioFile(file_path)) {
|
|
8221
|
+
if (!resolvedBackend.readBinary) {
|
|
8222
|
+
return `[Audio] ${file_path}
|
|
8223
|
+
The current backend does not support binary reading, unable to process audio.`;
|
|
8224
|
+
}
|
|
8225
|
+
try {
|
|
8226
|
+
const buffer2 = await resolvedBackend.readBinary(file_path);
|
|
8227
|
+
const sizeWarning = validateAudioSize(buffer2.length);
|
|
8228
|
+
if (sizeWarning) {
|
|
8229
|
+
return `[Audio] ${file_path}
|
|
8230
|
+
${sizeWarning}`;
|
|
8231
|
+
}
|
|
8232
|
+
const format = detectAudioFormat(file_path);
|
|
8233
|
+
const result = await transcribeAudio({ audioBuffer: buffer2, format });
|
|
8234
|
+
let output = `[Audio] ${file_path} (${format}, ${(buffer2.length / 1024).toFixed(1)}KB)`;
|
|
8235
|
+
if (result.confidence !== void 0) {
|
|
8236
|
+
output += `
|
|
8237
|
+
Confidence: ${(result.confidence * 100).toFixed(1)}%`;
|
|
8238
|
+
}
|
|
8239
|
+
output += `
|
|
8240
|
+
|
|
8241
|
+
${result.text}`;
|
|
8242
|
+
return output;
|
|
8243
|
+
} catch (error) {
|
|
8244
|
+
return `[Audio] ${file_path}
|
|
8245
|
+
Audio transcription failed: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
8246
|
+
}
|
|
8247
|
+
}
|
|
7986
8248
|
return await resolvedBackend.read(file_path, offset, limit);
|
|
7987
8249
|
},
|
|
7988
8250
|
{
|
|
@@ -27594,6 +27856,8 @@ export {
|
|
|
27594
27856
|
QueueMode,
|
|
27595
27857
|
RemoteSandboxInstance,
|
|
27596
27858
|
RemoteSandboxProvider,
|
|
27859
|
+
STTModelLattice,
|
|
27860
|
+
STTModelLatticeManager,
|
|
27597
27861
|
SandboxFilesystem,
|
|
27598
27862
|
SandboxLatticeManager,
|
|
27599
27863
|
SandboxSkillStore,
|
|
@@ -27699,6 +27963,9 @@ export {
|
|
|
27699
27963
|
getNextCronTime,
|
|
27700
27964
|
getOrCreateCollectionVectorStore,
|
|
27701
27965
|
getQueueLattice,
|
|
27966
|
+
getSTTClient,
|
|
27967
|
+
getSTTClientWithTenant,
|
|
27968
|
+
getSTTModelLattice,
|
|
27702
27969
|
getSandBoxManager,
|
|
27703
27970
|
getScheduleLattice,
|
|
27704
27971
|
getStoreLattice,
|
|
@@ -27742,6 +28009,7 @@ export {
|
|
|
27742
28009
|
registerLoggerLattice,
|
|
27743
28010
|
registerModelLattice,
|
|
27744
28011
|
registerQueueLattice,
|
|
28012
|
+
registerSTTModelLattice,
|
|
27745
28013
|
registerSandboxProviderType,
|
|
27746
28014
|
registerScheduleLattice,
|
|
27747
28015
|
registerStoreLattice,
|
|
@@ -27763,6 +28031,7 @@ export {
|
|
|
27763
28031
|
skillLatticeManager,
|
|
27764
28032
|
sqlDatabaseManager,
|
|
27765
28033
|
storeLatticeManager,
|
|
28034
|
+
sttModelLatticeManager,
|
|
27766
28035
|
toJsonSchema,
|
|
27767
28036
|
toSafeStateExpr,
|
|
27768
28037
|
toolLatticeManager,
|