@dexto/core 1.5.7 → 1.5.8
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/agent/DextoAgent.cjs +96 -5
- package/dist/agent/DextoAgent.d.ts +32 -7
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +96 -5
- package/dist/agent/schemas.cjs +5 -0
- package/dist/agent/schemas.d.ts +60 -21
- package/dist/agent/schemas.d.ts.map +1 -1
- package/dist/agent/schemas.js +5 -0
- package/dist/context/manager.cjs +1 -1
- package/dist/context/manager.js +1 -1
- package/dist/context/utils.cjs +69 -42
- package/dist/context/utils.d.ts.map +1 -1
- package/dist/context/utils.js +69 -42
- package/dist/events/index.cjs +4 -1
- package/dist/events/index.d.ts +37 -2
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +4 -1
- package/dist/index.browser.d.ts +1 -1
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/llm/curation-config.cjs +82 -0
- package/dist/llm/curation-config.d.ts +13 -0
- package/dist/llm/curation-config.d.ts.map +1 -0
- package/dist/llm/curation-config.js +59 -0
- package/dist/llm/curation.cjs +57 -0
- package/dist/llm/curation.d.ts +16 -0
- package/dist/llm/curation.d.ts.map +1 -0
- package/dist/llm/curation.js +34 -0
- package/dist/llm/errors.cjs +1 -1
- package/dist/llm/errors.d.ts +8 -8
- package/dist/llm/errors.js +1 -1
- package/dist/llm/executor/provider-options.cjs +1 -1
- package/dist/llm/executor/provider-options.js +1 -1
- package/dist/llm/executor/turn-executor.cjs +8 -2
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +8 -2
- package/dist/llm/index.cjs +14 -3
- package/dist/llm/index.d.ts +3 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +13 -2
- package/dist/llm/registry/auto-update.cjs +263 -0
- package/dist/llm/registry/auto-update.d.ts +27 -0
- package/dist/llm/registry/auto-update.d.ts.map +1 -0
- package/dist/llm/registry/auto-update.js +227 -0
- package/dist/llm/registry/index.cjs +806 -0
- package/dist/llm/{registry.d.ts → registry/index.d.ts} +19 -41
- package/dist/llm/registry/index.d.ts.map +1 -0
- package/dist/llm/registry/index.js +756 -0
- package/dist/llm/registry/models.generated.cjs +4861 -0
- package/dist/llm/registry/models.generated.d.ts +431 -0
- package/dist/llm/registry/models.generated.d.ts.map +1 -0
- package/dist/llm/registry/models.generated.js +4838 -0
- package/dist/llm/registry/models.manual.cjs +44 -0
- package/dist/llm/registry/models.manual.d.ts +22 -0
- package/dist/llm/registry/models.manual.d.ts.map +1 -0
- package/dist/llm/registry/models.manual.js +21 -0
- package/dist/llm/registry/sync.cjs +354 -0
- package/dist/llm/registry/sync.d.ts +41 -0
- package/dist/llm/registry/sync.d.ts.map +1 -0
- package/dist/llm/registry/sync.js +328 -0
- package/dist/llm/resolver.cjs +27 -18
- package/dist/llm/resolver.d.ts +1 -1
- package/dist/llm/resolver.d.ts.map +1 -1
- package/dist/llm/resolver.js +28 -20
- package/dist/llm/schemas.cjs +13 -1
- package/dist/llm/schemas.d.ts +23 -23
- package/dist/llm/schemas.d.ts.map +1 -1
- package/dist/llm/schemas.js +14 -1
- package/dist/llm/services/factory.cjs +4 -4
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +4 -4
- package/dist/llm/services/test-utils.integration.cjs +1 -1
- package/dist/llm/services/test-utils.integration.js +1 -1
- package/dist/llm/services/vercel.cjs +4 -1
- package/dist/llm/services/vercel.d.ts +1 -0
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +4 -1
- package/dist/llm/types.cjs +1 -1
- package/dist/llm/types.d.ts +1 -1
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/llm/types.js +1 -1
- package/dist/llm/validation.cjs +1 -1
- package/dist/llm/validation.js +1 -1
- package/dist/resources/handlers/filesystem-handler.cjs +25 -0
- package/dist/resources/handlers/filesystem-handler.d.ts +1 -0
- package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
- package/dist/resources/handlers/filesystem-handler.js +25 -0
- package/dist/session/chat-session.cjs +1 -1
- package/dist/session/chat-session.js +1 -1
- package/dist/session/message-queue.cjs +29 -5
- package/dist/session/message-queue.d.ts +3 -1
- package/dist/session/message-queue.d.ts.map +1 -1
- package/dist/session/message-queue.js +29 -5
- package/dist/session/session-manager.cjs +40 -3
- package/dist/session/session-manager.d.ts +3 -1
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +30 -3
- package/dist/session/types.d.ts +1 -0
- package/dist/session/types.d.ts.map +1 -1
- package/dist/tools/internal-tools/provider.d.ts +3 -1
- package/dist/tools/internal-tools/provider.d.ts.map +1 -1
- package/dist/tools/internal-tools/registry.d.ts +1 -1
- package/dist/tools/internal-tools/registry.d.ts.map +1 -1
- package/dist/tools/tool-call-metadata.cjs +75 -0
- package/dist/tools/tool-call-metadata.d.ts +16 -0
- package/dist/tools/tool-call-metadata.d.ts.map +1 -0
- package/dist/tools/tool-call-metadata.js +51 -0
- package/dist/tools/tool-manager.cjs +257 -30
- package/dist/tools/tool-manager.d.ts +43 -2
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +257 -30
- package/dist/utils/api-key-resolver.cjs +1 -1
- package/dist/utils/api-key-resolver.js +1 -1
- package/dist/utils/env.cjs +49 -0
- package/dist/utils/env.d.ts +4 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +24 -0
- package/dist/utils/index.cjs +3 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/service-initializer.cjs +17 -5
- package/dist/utils/service-initializer.d.ts +23 -4
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/dist/utils/service-initializer.js +17 -5
- package/package.json +6 -2
- package/dist/llm/registry.cjs +0 -2075
- package/dist/llm/registry.d.ts.map +0 -1
- package/dist/llm/registry.js +0 -2025
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import "../../chunk-PTJYTZNU.js";
|
|
2
|
+
import { promises as fs } from "node:fs";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { getDextoGlobalPath } from "../../utils/path.js";
|
|
6
|
+
import { logger as defaultLogger } from "../../logger/logger.js";
|
|
7
|
+
import { LLM_PROVIDERS } from "../types.js";
|
|
8
|
+
import { LLM_REGISTRY } from "./index.js";
|
|
9
|
+
import { buildModelsByProviderFromRemote } from "./sync.js";
|
|
10
|
+
const CACHE_SUBDIR = "cache";
|
|
11
|
+
const CACHE_FILENAME = "llm-registry-models.json";
|
|
12
|
+
const CACHE_SCHEMA_VERSION = 1;
|
|
13
|
+
const DEFAULT_TTL_MS = 1e3 * 60 * 60;
|
|
14
|
+
const MIN_REFRESH_INTERVAL_MS = 1e3 * 60 * 5;
|
|
15
|
+
const UPDATABLE_PROVIDERS = [
|
|
16
|
+
"openai",
|
|
17
|
+
"anthropic",
|
|
18
|
+
"google",
|
|
19
|
+
"groq",
|
|
20
|
+
"xai",
|
|
21
|
+
"cohere",
|
|
22
|
+
"minimax",
|
|
23
|
+
"glm",
|
|
24
|
+
"vertex",
|
|
25
|
+
"bedrock"
|
|
26
|
+
];
|
|
27
|
+
function truthyEnv(name) {
|
|
28
|
+
const v = process.env[name];
|
|
29
|
+
if (!v) return false;
|
|
30
|
+
return v === "1" || v === "true" || v === "yes" || v === "on";
|
|
31
|
+
}
|
|
32
|
+
function getTtlMs() {
|
|
33
|
+
const raw = process.env.DEXTO_LLM_REGISTRY_TTL_MS;
|
|
34
|
+
if (!raw) return DEFAULT_TTL_MS;
|
|
35
|
+
const n = Number(raw);
|
|
36
|
+
return Number.isFinite(n) && n > 0 ? n : DEFAULT_TTL_MS;
|
|
37
|
+
}
|
|
38
|
+
function getCachePath() {
|
|
39
|
+
return getDextoGlobalPath(CACHE_SUBDIR, CACHE_FILENAME);
|
|
40
|
+
}
|
|
41
|
+
function isModelInfo(value) {
|
|
42
|
+
if (typeof value !== "object" || value === null) return false;
|
|
43
|
+
const name = value.name;
|
|
44
|
+
return typeof name === "string" && name.trim() !== "";
|
|
45
|
+
}
|
|
46
|
+
function applyModelsByProvider(modelsByProvider) {
|
|
47
|
+
for (const provider of UPDATABLE_PROVIDERS) {
|
|
48
|
+
const incoming = modelsByProvider[provider] ?? [];
|
|
49
|
+
const existing = LLM_REGISTRY[provider].models ?? [];
|
|
50
|
+
const incomingByName = /* @__PURE__ */ new Map();
|
|
51
|
+
for (const m of incoming) {
|
|
52
|
+
incomingByName.set(m.name.toLowerCase(), m);
|
|
53
|
+
}
|
|
54
|
+
const existingDefault = existing.find((m) => m.default)?.name.toLowerCase();
|
|
55
|
+
const incomingDefault = incoming.find((m) => m.default)?.name.toLowerCase();
|
|
56
|
+
const merged = [];
|
|
57
|
+
const seen = /* @__PURE__ */ new Set();
|
|
58
|
+
for (const m of existing) {
|
|
59
|
+
const key = m.name.toLowerCase();
|
|
60
|
+
const updated = incomingByName.get(key);
|
|
61
|
+
if (!updated) {
|
|
62
|
+
merged.push(m);
|
|
63
|
+
} else {
|
|
64
|
+
const name = updated.name ?? m.name;
|
|
65
|
+
const maxInputTokens = typeof updated.maxInputTokens === "number" && updated.maxInputTokens > 0 ? updated.maxInputTokens : m.maxInputTokens;
|
|
66
|
+
const supportedFileTypes = Array.isArray(updated.supportedFileTypes) ? updated.supportedFileTypes : m.supportedFileTypes;
|
|
67
|
+
const displayName = updated.displayName ?? m.displayName;
|
|
68
|
+
const pricing = updated.pricing ?? m.pricing;
|
|
69
|
+
merged.push({
|
|
70
|
+
name,
|
|
71
|
+
maxInputTokens,
|
|
72
|
+
supportedFileTypes,
|
|
73
|
+
...displayName ? { displayName } : {},
|
|
74
|
+
...pricing ? { pricing } : {}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
seen.add(key);
|
|
78
|
+
}
|
|
79
|
+
const newModels = incoming.filter((m) => !seen.has(m.name.toLowerCase()));
|
|
80
|
+
newModels.sort((a, b) => a.name.localeCompare(b.name));
|
|
81
|
+
merged.push(...newModels);
|
|
82
|
+
const chosenDefault = incomingDefault ?? existingDefault ?? merged[0]?.name.toLowerCase();
|
|
83
|
+
const finalMerged = merged.map((m) => {
|
|
84
|
+
const copy = { ...m };
|
|
85
|
+
delete copy.default;
|
|
86
|
+
return copy;
|
|
87
|
+
});
|
|
88
|
+
if (chosenDefault) {
|
|
89
|
+
const idx = finalMerged.findIndex((m) => m.name.toLowerCase() === chosenDefault);
|
|
90
|
+
if (idx >= 0) {
|
|
91
|
+
finalMerged[idx] = { ...finalMerged[idx], default: true };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
LLM_REGISTRY[provider].models = finalMerged;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function normalizeModelsByProvider(raw) {
|
|
98
|
+
const out = {};
|
|
99
|
+
for (const p of LLM_PROVIDERS) {
|
|
100
|
+
const value = raw[p];
|
|
101
|
+
out[p] = Array.isArray(value) ? value.filter(isModelInfo) : [];
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
function tryLoadCacheFromDisk(log) {
|
|
106
|
+
const cachePath = getCachePath();
|
|
107
|
+
if (!existsSync(cachePath)) return null;
|
|
108
|
+
try {
|
|
109
|
+
const text = readFileSync(cachePath, "utf-8");
|
|
110
|
+
const parsed = JSON.parse(text);
|
|
111
|
+
if (parsed.schemaVersion !== CACHE_SCHEMA_VERSION) return null;
|
|
112
|
+
if (!parsed.fetchedAt || typeof parsed.fetchedAt !== "string") return null;
|
|
113
|
+
if (!parsed.modelsByProvider || typeof parsed.modelsByProvider !== "object") return null;
|
|
114
|
+
const fetchedAt = Date.parse(parsed.fetchedAt);
|
|
115
|
+
if (!Number.isFinite(fetchedAt)) return null;
|
|
116
|
+
const modelsByProvider = normalizeModelsByProvider(
|
|
117
|
+
parsed.modelsByProvider
|
|
118
|
+
);
|
|
119
|
+
return { fetchedAt, modelsByProvider };
|
|
120
|
+
} catch (e) {
|
|
121
|
+
log?.warn?.(
|
|
122
|
+
`Failed to load LLM registry cache (${cachePath}): ${e instanceof Error ? e.message : String(e)}`
|
|
123
|
+
);
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
let refreshPromise = null;
|
|
128
|
+
let lastRefreshAttemptAt = null;
|
|
129
|
+
let lastFetchedAt = null;
|
|
130
|
+
let lastSource = "snapshot";
|
|
131
|
+
let autoRefreshStarted = false;
|
|
132
|
+
function isFresh(now, fetchedAt, ttlMs) {
|
|
133
|
+
return now - fetchedAt < ttlMs;
|
|
134
|
+
}
|
|
135
|
+
function getLlmRegistryAutoUpdateStatus() {
|
|
136
|
+
const cachePath = getCachePath();
|
|
137
|
+
const fetchedAt = lastFetchedAt ? new Date(lastFetchedAt) : null;
|
|
138
|
+
const now = Date.now();
|
|
139
|
+
return {
|
|
140
|
+
cachePath,
|
|
141
|
+
lastFetchedAt: fetchedAt,
|
|
142
|
+
isFresh: lastFetchedAt ? isFresh(now, lastFetchedAt, getTtlMs()) : false,
|
|
143
|
+
source: lastSource
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function loadLlmRegistryCache(options) {
|
|
147
|
+
const cache = tryLoadCacheFromDisk(options?.logger);
|
|
148
|
+
if (!cache) return false;
|
|
149
|
+
applyModelsByProvider(cache.modelsByProvider);
|
|
150
|
+
lastFetchedAt = cache.fetchedAt;
|
|
151
|
+
lastSource = "cache";
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
async function writeCacheFile(cachePath, modelsByProvider) {
|
|
155
|
+
await fs.mkdir(path.dirname(cachePath), { recursive: true });
|
|
156
|
+
const payload = {
|
|
157
|
+
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
158
|
+
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
159
|
+
modelsByProvider
|
|
160
|
+
};
|
|
161
|
+
const tmpPath = `${cachePath}.tmp`;
|
|
162
|
+
await fs.writeFile(tmpPath, JSON.stringify(payload), "utf-8");
|
|
163
|
+
await fs.rename(tmpPath, cachePath);
|
|
164
|
+
}
|
|
165
|
+
async function refreshLlmRegistryCache(options) {
|
|
166
|
+
if (truthyEnv("DEXTO_LLM_REGISTRY_DISABLE_FETCH") || !options?.allowInTests && (process.env.NODE_ENV === "test" || truthyEnv("VITEST"))) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (refreshPromise && !options?.force) {
|
|
170
|
+
await refreshPromise;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const now = Date.now();
|
|
174
|
+
if (!options?.force && lastRefreshAttemptAt && now - lastRefreshAttemptAt < MIN_REFRESH_INTERVAL_MS) {
|
|
175
|
+
if (refreshPromise) await refreshPromise;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
lastRefreshAttemptAt = now;
|
|
179
|
+
const log = options?.logger ?? defaultLogger;
|
|
180
|
+
refreshPromise = (async () => {
|
|
181
|
+
const modelsByProvider = await buildModelsByProviderFromRemote({
|
|
182
|
+
userAgent: "dexto-llm-registry",
|
|
183
|
+
timeoutMs: 3e4
|
|
184
|
+
});
|
|
185
|
+
const cachePath = getCachePath();
|
|
186
|
+
await writeCacheFile(cachePath, modelsByProvider);
|
|
187
|
+
applyModelsByProvider(modelsByProvider);
|
|
188
|
+
lastFetchedAt = Date.now();
|
|
189
|
+
lastSource = "remote";
|
|
190
|
+
log?.debug?.(`Refreshed LLM registry cache (${cachePath})`);
|
|
191
|
+
})().catch((e) => {
|
|
192
|
+
log?.warn?.(
|
|
193
|
+
`Failed to refresh LLM registry cache: ${e instanceof Error ? e.message : String(e)}`
|
|
194
|
+
);
|
|
195
|
+
}).finally(() => {
|
|
196
|
+
refreshPromise = null;
|
|
197
|
+
});
|
|
198
|
+
await refreshPromise;
|
|
199
|
+
}
|
|
200
|
+
function startLlmRegistryAutoUpdate(options) {
|
|
201
|
+
if (autoRefreshStarted) return;
|
|
202
|
+
autoRefreshStarted = true;
|
|
203
|
+
const log = options?.logger ?? defaultLogger;
|
|
204
|
+
const loaded = loadLlmRegistryCache({ logger: log });
|
|
205
|
+
if (loaded) {
|
|
206
|
+
log?.debug?.(`Loaded LLM registry cache from disk (${getCachePath()})`);
|
|
207
|
+
}
|
|
208
|
+
if (options?.refreshOnStart !== false) {
|
|
209
|
+
void refreshLlmRegistryCache({ logger: log });
|
|
210
|
+
}
|
|
211
|
+
const timer = setInterval(
|
|
212
|
+
() => {
|
|
213
|
+
const ttlMs = getTtlMs();
|
|
214
|
+
const now = Date.now();
|
|
215
|
+
if (lastFetchedAt && isFresh(now, lastFetchedAt, ttlMs)) return;
|
|
216
|
+
void refreshLlmRegistryCache({ logger: log });
|
|
217
|
+
},
|
|
218
|
+
Math.min(getTtlMs(), DEFAULT_TTL_MS)
|
|
219
|
+
);
|
|
220
|
+
timer.unref?.();
|
|
221
|
+
}
|
|
222
|
+
export {
|
|
223
|
+
getLlmRegistryAutoUpdateStatus,
|
|
224
|
+
loadLlmRegistryCache,
|
|
225
|
+
refreshLlmRegistryCache,
|
|
226
|
+
startLlmRegistryAutoUpdate
|
|
227
|
+
};
|