@agntk/core 0.3.1 → 0.3.2
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/LICENSE +22 -0
- package/dist/config/defaults.js +3 -3
- package/dist/config/defaults.js.map +1 -1
- package/dist/models.d.ts +4 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +52 -6
- package/dist/models.js.map +1 -1
- package/dist/provider-resolver.d.ts +4 -0
- package/dist/provider-resolver.d.ts.map +1 -1
- package/dist/provider-resolver.js +51 -15
- package/dist/provider-resolver.js.map +1 -1
- package/dist/system-detect.d.ts +34 -12
- package/dist/system-detect.d.ts.map +1 -1
- package/dist/system-detect.js +154 -29
- package/dist/system-detect.js.map +1 -1
- package/package.json +13 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Phoenixrr2113
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/dist/config/defaults.js
CHANGED
|
@@ -15,9 +15,9 @@ export const DEFAULT_MODELS = {
|
|
|
15
15
|
},
|
|
16
16
|
ollama: {
|
|
17
17
|
fast: 'qwen3:8b',
|
|
18
|
-
standard: 'qwen3:
|
|
19
|
-
reasoning: 'qwen3:
|
|
20
|
-
powerful: 'qwen3:
|
|
18
|
+
standard: 'qwen3-coder:30b',
|
|
19
|
+
reasoning: 'qwen3-coder:30b',
|
|
20
|
+
powerful: 'qwen3.5:35b',
|
|
21
21
|
},
|
|
22
22
|
openai: {
|
|
23
23
|
fast: 'gpt-4o-mini',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/config/defaults.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,MAAM,CAAC,MAAM,gBAAgB,GAAa,YAAY,CAAC;AAEvD,MAAM,CAAC,MAAM,cAAc,GAAgD;IACzE,UAAU,EAAE;QACV,IAAI,EAAE,oBAAoB;QAC1B,QAAQ,EAAE,+BAA+B;QACzC,SAAS,EAAE,sBAAsB;QACjC,QAAQ,EAAE,cAAc;KACzB;IACD,MAAM,EAAE;QACN,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/config/defaults.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,MAAM,CAAC,MAAM,gBAAgB,GAAa,YAAY,CAAC;AAEvD,MAAM,CAAC,MAAM,cAAc,GAAgD;IACzE,UAAU,EAAE;QACV,IAAI,EAAE,oBAAoB;QAC1B,QAAQ,EAAE,+BAA+B;QACzC,SAAS,EAAE,sBAAsB;QACjC,QAAQ,EAAE,cAAc;KACzB;IACD,MAAM,EAAE;QACN,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,iBAAiB;QAC3B,SAAS,EAAE,iBAAiB;QAC5B,QAAQ,EAAE,aAAa;KACxB;IACD,MAAM,EAAE;QACN,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAE,QAAQ;QAClB,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,QAAQ;KACnB;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,gCAAgC;QACtC,QAAQ,EAAE,cAAc;QACxB,SAAS,EAAE,cAAc;QACzB,QAAQ,EAAE,YAAY;KACvB;IACD,YAAY,EAAE;QACZ,IAAI,EAAE,cAAc;QACpB,QAAQ,EAAE,cAAc;QACxB,SAAS,EAAE,cAAc;QACzB,QAAQ,EAAE,cAAc;KACzB;CACF,CAAC;AAEF,+EAA+E;AAC/E,yBAAyB;AACzB,+EAA+E;AAE/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC"}
|
package/dist/models.d.ts
CHANGED
|
@@ -20,6 +20,10 @@ export interface ResolvedProvider {
|
|
|
20
20
|
powerful: string;
|
|
21
21
|
reason: string;
|
|
22
22
|
};
|
|
23
|
+
/** Models actually installed in Ollama (for validating env overrides) */
|
|
24
|
+
ollamaInstalledModels?: string[];
|
|
25
|
+
/** When Ollama was skipped despite running, explains why (for CLI display) */
|
|
26
|
+
ollamaSkipReason?: string;
|
|
23
27
|
}
|
|
24
28
|
/**
|
|
25
29
|
* Set the resolved provider. Called once by the CLI after running the cascade.
|
package/dist/models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAA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,CAAC;IACjB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,sBAA2B,GAAG,aAAa,CA+ChF"}
|
package/dist/models.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
8
8
|
import { createLogger } from '@agntk/logger';
|
|
9
9
|
import { getModelForTier, getConfig, DEFAULT_MODELS, DEFAULT_PROVIDER } from './config/index.js';
|
|
10
|
+
import { isUsableSize } from './system-detect.js';
|
|
10
11
|
const log = createLogger('@agntk/core:models');
|
|
11
12
|
const PROVIDER_CONFIGS = {
|
|
12
13
|
openrouter: {
|
|
@@ -16,7 +17,9 @@ const PROVIDER_CONFIGS = {
|
|
|
16
17
|
},
|
|
17
18
|
ollama: {
|
|
18
19
|
name: 'ollama',
|
|
19
|
-
|
|
20
|
+
// OLLAMA_BASE_URL may be the root (http://localhost:11434) or have /api or /v1 —
|
|
21
|
+
// normalize to always end with /v1 for the OpenAI-compatible endpoint.
|
|
22
|
+
baseURL: ((process.env['OLLAMA_BASE_URL'] || 'http://localhost:11434').replace(/\/(api|v1)\/?$/, '')) + '/v1',
|
|
20
23
|
apiKeyEnv: 'OLLAMA_API_KEY', // Ollama typically doesn't need a key, but support it
|
|
21
24
|
},
|
|
22
25
|
openai: {
|
|
@@ -123,10 +126,27 @@ function createTierModel(tier) {
|
|
|
123
126
|
// 1. Use resolved provider if available (new zero-config path)
|
|
124
127
|
if (_resolvedProvider) {
|
|
125
128
|
const providerName = _resolvedProvider.provider;
|
|
126
|
-
// For Ollama: check env override → hardware-detected models → static defaults
|
|
127
129
|
const ollamaRecommended = _resolvedProvider.ollamaModels;
|
|
130
|
+
// For Ollama: env overrides must pass quality gate AND be installed.
|
|
131
|
+
let ollamaEnvModel;
|
|
132
|
+
if (providerName === 'ollama') {
|
|
133
|
+
const envVal = getOllamaEnvModel(tier);
|
|
134
|
+
const installed = _resolvedProvider.ollamaInstalledModels;
|
|
135
|
+
const isInstalled = (m) => !installed || installed.some((i) => i.startsWith(m.toLowerCase()));
|
|
136
|
+
if (envVal && isUsableSize(envVal) && isInstalled(envVal)) {
|
|
137
|
+
ollamaEnvModel = envVal;
|
|
138
|
+
}
|
|
139
|
+
else if (envVal) {
|
|
140
|
+
const reasons = [];
|
|
141
|
+
if (!isUsableSize(envVal))
|
|
142
|
+
reasons.push('too small (need 8b+)');
|
|
143
|
+
if (!isInstalled(envVal))
|
|
144
|
+
reasons.push('not installed');
|
|
145
|
+
log.warn(`Ignoring OLLAMA_${tier.toUpperCase()}_MODEL=${envVal} (${reasons.join(', ')})`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
128
148
|
const modelName = getEnvModel(tier)
|
|
129
|
-
||
|
|
149
|
+
|| ollamaEnvModel
|
|
130
150
|
|| (providerName === 'ollama' && ollamaRecommended ? ollamaRecommended[tier] : undefined)
|
|
131
151
|
|| DEFAULT_MODELS[providerName]?.[tier]
|
|
132
152
|
|| DEFAULT_MODELS[DEFAULT_PROVIDER][tier];
|
|
@@ -168,9 +188,35 @@ export function resolveModel(options = {}) {
|
|
|
168
188
|
log.info('Resolving model (OpenRouter format)', { modelName });
|
|
169
189
|
return createModelForProvider('openrouter', modelName);
|
|
170
190
|
}
|
|
171
|
-
// Use tier-based selection from
|
|
172
|
-
const effectiveProvider = provider ?? config.models?.defaultProvider ??
|
|
173
|
-
|
|
191
|
+
// Use tier-based selection: resolved provider (from cascade) wins over config default
|
|
192
|
+
const effectiveProvider = provider ?? _resolvedProvider?.provider ?? config.models?.defaultProvider ?? DEFAULT_PROVIDER;
|
|
193
|
+
// For Ollama: hardware-detected recommendation takes priority over static defaults.
|
|
194
|
+
// Env overrides (OLLAMA_*_MODEL) can win if they pass both the quality gate AND
|
|
195
|
+
// are actually installed — otherwise we silently fall back to the recommendation.
|
|
196
|
+
let effectiveModel;
|
|
197
|
+
if (effectiveProvider === 'ollama' && _resolvedProvider?.ollamaModels) {
|
|
198
|
+
const ollamaEnvModel = getOllamaEnvModel(tier);
|
|
199
|
+
const installed = _resolvedProvider.ollamaInstalledModels;
|
|
200
|
+
const isInstalled = (m) => !installed || installed.some((i) => i.startsWith(m.toLowerCase()));
|
|
201
|
+
if (ollamaEnvModel && isUsableSize(ollamaEnvModel) && isInstalled(ollamaEnvModel)) {
|
|
202
|
+
effectiveModel = ollamaEnvModel;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
if (ollamaEnvModel) {
|
|
206
|
+
const reasons = [];
|
|
207
|
+
if (!isUsableSize(ollamaEnvModel))
|
|
208
|
+
reasons.push('too small (need 8b+)');
|
|
209
|
+
if (!isInstalled(ollamaEnvModel))
|
|
210
|
+
reasons.push('not installed');
|
|
211
|
+
log.warn(`Ignoring OLLAMA_${tier.toUpperCase()}_MODEL=${ollamaEnvModel} (${reasons.join(', ')})`);
|
|
212
|
+
}
|
|
213
|
+
effectiveModel = _resolvedProvider.ollamaModels[tier]
|
|
214
|
+
|| getModelForTier(tier, effectiveProvider);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
effectiveModel = getModelForTier(tier, effectiveProvider);
|
|
219
|
+
}
|
|
174
220
|
log.info('Resolving model (tier-based)', { tier, provider: effectiveProvider, model: effectiveModel });
|
|
175
221
|
return createModelForProvider(effectiveProvider, effectiveModel);
|
|
176
222
|
}
|
package/dist/models.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,cAAc,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AO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;gBAChE,GAAG,CAAC,IAAI,CAAC,mBAAmB,IAAI,CAAC,WAAW,EAAE,UAAU,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACpG,CAAC;YACD,cAAc,GAAG,iBAAiB,CAAC,YAAY,CAAC,IAAyG,CAAC;mBACrJ,eAAe,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;SAAM,CAAC;QACN,cAAc,GAAG,eAAe,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IAC5D,CAAC;IAED,GAAG,CAAC,IAAI,CAAC,8BAA8B,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;IACvG,OAAO,sBAAsB,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -16,6 +16,10 @@ export interface ResolvedProvider {
|
|
|
16
16
|
isFree: boolean;
|
|
17
17
|
/** When provider is 'ollama', hardware-aware model recommendations */
|
|
18
18
|
ollamaModels?: OllamaModelRecommendation;
|
|
19
|
+
/** When provider is 'ollama', the list of models actually installed */
|
|
20
|
+
ollamaInstalledModels?: string[];
|
|
21
|
+
/** When Ollama was skipped despite running, explains why (for CLI display) */
|
|
22
|
+
ollamaSkipReason?: string;
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
25
|
* Resolve the best available provider.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-resolver.d.ts","sourceRoot":"","sources":["../src/provider-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAuC,KAAK,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAQtG,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,MAAM,EAAE,OAAO,CAAC;IAChB,sEAAsE;IACtE,YAAY,CAAC,EAAE,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"provider-resolver.d.ts","sourceRoot":"","sources":["../src/provider-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAuC,KAAK,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAQtG,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,MAAM,EAAE,OAAO,CAAC;IAChB,sEAAsE;IACtE,YAAY,CAAC,EAAE,yBAAyB,CAAC;IACzC,uEAAuE;IACvE,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IACjC,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAoID;;;;;;;;GAQG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAiBjE;AASD;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAUrE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAGzC"}
|
|
@@ -28,6 +28,10 @@ function checkBYOK() {
|
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
30
|
// ============================================================================
|
|
31
|
+
// Ollama Skip Reason (set by probeOllama, read by getFreeTier)
|
|
32
|
+
// ============================================================================
|
|
33
|
+
let _ollamaSkipReason = null;
|
|
34
|
+
// ============================================================================
|
|
31
35
|
// Ollama Detection
|
|
32
36
|
// ============================================================================
|
|
33
37
|
/**
|
|
@@ -45,11 +49,16 @@ function checkOllamaExplicit() {
|
|
|
45
49
|
}
|
|
46
50
|
/**
|
|
47
51
|
* Probe Ollama at localhost:11434 with a fast health check.
|
|
48
|
-
* If Ollama is running
|
|
52
|
+
* If Ollama is running AND has at least one model pulled, detect system
|
|
53
|
+
* hardware and recommend the best available models.
|
|
49
54
|
* Returns within 500ms regardless of whether Ollama is running.
|
|
50
55
|
*/
|
|
51
56
|
async function probeOllama() {
|
|
52
|
-
|
|
57
|
+
// Strip trailing path segments (/api, /v1, etc.) — the probe needs the raw Ollama host.
|
|
58
|
+
// Users may set OLLAMA_BASE_URL to "http://localhost:11434/api" or "/v1" for the AI SDK,
|
|
59
|
+
// but the native Ollama API lives at the root (e.g. /api/tags, not /api/api/tags).
|
|
60
|
+
const rawUrl = process.env['OLLAMA_BASE_URL'] || 'http://localhost:11434';
|
|
61
|
+
const baseUrl = rawUrl.replace(/\/(api|v1)\/?$/, '');
|
|
53
62
|
const controller = new AbortController();
|
|
54
63
|
const timeout = setTimeout(() => controller.abort(), 500);
|
|
55
64
|
try {
|
|
@@ -58,19 +67,41 @@ async function probeOllama() {
|
|
|
58
67
|
method: 'GET',
|
|
59
68
|
});
|
|
60
69
|
clearTimeout(timeout);
|
|
61
|
-
if (response.ok)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
isFree: false,
|
|
70
|
-
ollamaModels: models,
|
|
71
|
-
};
|
|
70
|
+
if (!response.ok)
|
|
71
|
+
return null;
|
|
72
|
+
// Parse which models are actually installed
|
|
73
|
+
const data = (await response.json());
|
|
74
|
+
const installedModels = (data.models || []).map((m) => m.name.toLowerCase());
|
|
75
|
+
if (installedModels.length === 0) {
|
|
76
|
+
log.info('Ollama running but no models installed', { baseUrl });
|
|
77
|
+
return null;
|
|
72
78
|
}
|
|
73
|
-
|
|
79
|
+
// Detect hardware and recommend the best model from what's actually installed
|
|
80
|
+
const sysProfile = detectSystem();
|
|
81
|
+
const recommendation = recommendOllamaModels(sysProfile, installedModels);
|
|
82
|
+
// If no usable models found (all sub-8b, no cloud), skip Ollama
|
|
83
|
+
if (recommendation.noUsableModels) {
|
|
84
|
+
_ollamaSkipReason =
|
|
85
|
+
'Ollama running but no 8b+ model found.\n' +
|
|
86
|
+
' Run `ollama pull qwen3-coder:30b` for local, or `ollama pull qwen3-coder:480b-cloud` for cloud.\n' +
|
|
87
|
+
' Using free tier for now.';
|
|
88
|
+
log.info('Ollama skipped — no usable models', { baseUrl, installed: installedModels });
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
log.info('Ollama detected', {
|
|
92
|
+
baseUrl,
|
|
93
|
+
tier: recommendation.tier,
|
|
94
|
+
standard: recommendation.standard,
|
|
95
|
+
installed: installedModels,
|
|
96
|
+
reason: recommendation.reason,
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
provider: 'ollama',
|
|
100
|
+
source: `ollama (${baseUrl})`,
|
|
101
|
+
isFree: false,
|
|
102
|
+
ollamaModels: recommendation,
|
|
103
|
+
ollamaInstalledModels: installedModels,
|
|
104
|
+
};
|
|
74
105
|
}
|
|
75
106
|
catch {
|
|
76
107
|
clearTimeout(timeout);
|
|
@@ -83,7 +114,11 @@ async function probeOllama() {
|
|
|
83
114
|
// ============================================================================
|
|
84
115
|
function getFreeTier() {
|
|
85
116
|
log.info('Using agntk free tier');
|
|
86
|
-
|
|
117
|
+
const result = { provider: 'agntk-free', source: 'free tier (Cerebras)', isFree: true };
|
|
118
|
+
if (_ollamaSkipReason) {
|
|
119
|
+
result.ollamaSkipReason = _ollamaSkipReason;
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
87
122
|
}
|
|
88
123
|
// ============================================================================
|
|
89
124
|
// Main Cascade
|
|
@@ -98,6 +133,7 @@ function getFreeTier() {
|
|
|
98
133
|
* 4. Free tier fallback (sync, instant)
|
|
99
134
|
*/
|
|
100
135
|
export async function resolveProvider() {
|
|
136
|
+
_ollamaSkipReason = null;
|
|
101
137
|
// 1. BYOK — instant
|
|
102
138
|
const byok = checkBYOK();
|
|
103
139
|
if (byok)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-resolver.js","sourceRoot":"","sources":["../src/provider-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAkC,MAAM,iBAAiB,CAAC;AAEtG,MAAM,GAAG,GAAG,YAAY,CAAC,+BAA+B,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"provider-resolver.js","sourceRoot":"","sources":["../src/provider-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAkC,MAAM,iBAAiB,CAAC;AAEtG,MAAM,GAAG,GAAG,YAAY,CAAC,+BAA+B,CAAC,CAAC;AAqB1D,+EAA+E;AAC/E,iCAAiC;AACjC,+EAA+E;AAE/E,MAAM,SAAS,GAAG;IAChB,EAAE,GAAG,EAAE,oBAAoB,EAAE,QAAQ,EAAE,YAAY,EAAE;IACrD,EAAE,GAAG,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE;IAC7C,EAAE,GAAG,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,EAAE;CACzC,CAAC;AAEX,SAAS,SAAS;IAChB,KAAK,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,SAAS,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjC,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;YACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK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,KAAK,UAAU,mBAAmB;IACvC,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC;IAC1C,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC;IAE1C,cAAc,GAAG,eAAe,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;QAC5C,cAAc,GAAG,CAAC,CAAC;QACnB,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,cAAc,GAAG,IAAI,CAAC;IACtB,cAAc,GAAG,IAAI,CAAC;AACxB,CAAC"}
|
package/dist/system-detect.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview System hardware detection for automatic Ollama model selection.
|
|
3
3
|
*
|
|
4
|
-
* Detects available RAM/VRAM and selects the
|
|
5
|
-
*
|
|
4
|
+
* Detects available RAM/VRAM and selects the best model the system can
|
|
5
|
+
* comfortably run. Falls back conservatively — better to run a smaller
|
|
6
6
|
* model fast than a larger model that swaps to disk.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Supports both local models and Ollama cloud models (-cloud suffix).
|
|
9
|
+
* Cloud models are always preferred when available since they run on
|
|
10
|
+
* remote infrastructure regardless of local hardware.
|
|
11
|
+
*
|
|
12
|
+
* Memory thresholds (Q4_K_M quantization, local models):
|
|
13
|
+
* qwen3:8b ~5-6 GB → needs ≥8 GB total RAM
|
|
14
|
+
* qwen3-coder:30b ~17 GB → needs ≥24 GB total RAM (MoE, fast inference)
|
|
15
|
+
* qwen3.5:35b ~20 GB → needs ≥32 GB total RAM
|
|
12
16
|
*/
|
|
13
17
|
export interface SystemProfile {
|
|
14
18
|
/** Total system RAM in GB */
|
|
@@ -26,28 +30,46 @@ export type OllamaModelTier = 'small' | 'medium' | 'large';
|
|
|
26
30
|
export interface OllamaModelRecommendation {
|
|
27
31
|
/** Recommended tier */
|
|
28
32
|
tier: OllamaModelTier;
|
|
29
|
-
/** Model tag to pull/use
|
|
33
|
+
/** Model tag to pull/use for each agent tier */
|
|
30
34
|
fast: string;
|
|
31
35
|
standard: string;
|
|
32
36
|
reasoning: string;
|
|
33
37
|
powerful: string;
|
|
34
38
|
/** Human-readable reason */
|
|
35
39
|
reason: string;
|
|
40
|
+
/** True when installed models exist but none are usable (all < 8b, no cloud) */
|
|
41
|
+
noUsableModels?: boolean;
|
|
36
42
|
}
|
|
43
|
+
/** Cloud models run on remote infrastructure — always usable regardless of local hardware. */
|
|
44
|
+
export declare function isCloudModel(tag: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a model is large enough for reliable agent tool-calling.
|
|
47
|
+
* Models need >= 8b parameters. Cloud models are always usable.
|
|
48
|
+
* Unknown sizes (e.g. "deepseek-coder:latest") are assumed usable.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isUsableSize(tag: string): boolean;
|
|
37
51
|
/**
|
|
38
52
|
* Detect system hardware profile.
|
|
39
53
|
*/
|
|
40
54
|
export declare function detectSystem(): SystemProfile;
|
|
41
55
|
/**
|
|
42
|
-
* Select the best Ollama model tier based on system capabilities
|
|
56
|
+
* Select the best Ollama model tier based on system capabilities
|
|
57
|
+
* and (optionally) which models are actually installed.
|
|
58
|
+
*
|
|
59
|
+
* When installedModels is provided, the recommendation is constrained
|
|
60
|
+
* to models the user already has pulled — the best available model is
|
|
61
|
+
* used for every tier rather than recommending something that would 404.
|
|
62
|
+
*
|
|
63
|
+
* If only sub-8b models are installed (and no cloud models), sets
|
|
64
|
+
* `noUsableModels: true` so the caller can skip Ollama entirely.
|
|
43
65
|
*
|
|
44
|
-
*
|
|
66
|
+
* Hardware thresholds (usable memory for model weights):
|
|
45
67
|
* < 6 GB → too small, warn user
|
|
46
68
|
* 6-10 GB → small (qwen3:8b everywhere)
|
|
47
|
-
* 10-
|
|
48
|
-
*
|
|
69
|
+
* 10-20 GB → medium (qwen3-coder:30b for standard+)
|
|
70
|
+
* 20+ GB → large (qwen3.5:35b for reasoning/powerful)
|
|
49
71
|
*/
|
|
50
|
-
export declare function recommendOllamaModels(profile?: SystemProfile): OllamaModelRecommendation;
|
|
72
|
+
export declare function recommendOllamaModels(profile?: SystemProfile, installedModels?: string[]): OllamaModelRecommendation;
|
|
51
73
|
/**
|
|
52
74
|
* Check which models Ollama already has pulled.
|
|
53
75
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-detect.d.ts","sourceRoot":"","sources":["../src/system-detect.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"system-detect.d.ts","sourceRoot":"","sources":["../src/system-detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAYH,MAAM,WAAW,aAAa;IAC5B,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,cAAc,EAAE,OAAO,CAAC;IACxB,qCAAqC;IACrC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,yBAAyB;IACxC,uBAAuB;IACvB,IAAI,EAAE,eAAe,CAAC;IACtB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAMD,8FAA8F;AAC9F,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAGjD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMjD;AA2FD;;GAEG;AACH,wBAAgB,YAAY,IAAI,aAAa,CAuC5C;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,CAAC,EAAE,aAAa,EACvB,eAAe,CAAC,EAAE,MAAM,EAAE,GACzB,yBAAyB,CA4E3B;AAiCD;;GAEG;AACH,wBAAsB,eAAe,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAqBzE;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAKtF"}
|
package/dist/system-detect.js
CHANGED
|
@@ -1,20 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview System hardware detection for automatic Ollama model selection.
|
|
3
3
|
*
|
|
4
|
-
* Detects available RAM/VRAM and selects the
|
|
5
|
-
*
|
|
4
|
+
* Detects available RAM/VRAM and selects the best model the system can
|
|
5
|
+
* comfortably run. Falls back conservatively — better to run a smaller
|
|
6
6
|
* model fast than a larger model that swaps to disk.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Supports both local models and Ollama cloud models (-cloud suffix).
|
|
9
|
+
* Cloud models are always preferred when available since they run on
|
|
10
|
+
* remote infrastructure regardless of local hardware.
|
|
11
|
+
*
|
|
12
|
+
* Memory thresholds (Q4_K_M quantization, local models):
|
|
13
|
+
* qwen3:8b ~5-6 GB → needs ≥8 GB total RAM
|
|
14
|
+
* qwen3-coder:30b ~17 GB → needs ≥24 GB total RAM (MoE, fast inference)
|
|
15
|
+
* qwen3.5:35b ~20 GB → needs ≥32 GB total RAM
|
|
12
16
|
*/
|
|
13
17
|
import { createLogger } from '@agntk/logger';
|
|
14
18
|
import os from 'node:os';
|
|
15
19
|
import { execSync } from 'node:child_process';
|
|
16
20
|
const log = createLogger('@agntk/core:system-detect');
|
|
17
21
|
// ============================================================================
|
|
22
|
+
// Model Classification
|
|
23
|
+
// ============================================================================
|
|
24
|
+
/** Cloud models run on remote infrastructure — always usable regardless of local hardware. */
|
|
25
|
+
export function isCloudModel(tag) {
|
|
26
|
+
const lower = tag.toLowerCase();
|
|
27
|
+
return lower.includes('-cloud') || lower.endsWith(':cloud');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if a model is large enough for reliable agent tool-calling.
|
|
31
|
+
* Models need >= 8b parameters. Cloud models are always usable.
|
|
32
|
+
* Unknown sizes (e.g. "deepseek-coder:latest") are assumed usable.
|
|
33
|
+
*/
|
|
34
|
+
export function isUsableSize(tag) {
|
|
35
|
+
if (isCloudModel(tag))
|
|
36
|
+
return true;
|
|
37
|
+
// Parse size from tags like "qwen3:14b", "llama3.1:70b", "qwen3-coder:30b"
|
|
38
|
+
const match = tag.match(/(\d+(?:\.\d+)?)b/i);
|
|
39
|
+
if (!match)
|
|
40
|
+
return true; // unknown size → assume usable
|
|
41
|
+
return parseFloat(match[1]) >= 8;
|
|
42
|
+
}
|
|
43
|
+
// ============================================================================
|
|
18
44
|
// Model Tier Definitions
|
|
19
45
|
// ============================================================================
|
|
20
46
|
const MODEL_TIERS = {
|
|
@@ -28,18 +54,36 @@ const MODEL_TIERS = {
|
|
|
28
54
|
medium: {
|
|
29
55
|
tier: 'medium',
|
|
30
56
|
fast: 'qwen3:8b',
|
|
31
|
-
standard: 'qwen3:
|
|
32
|
-
reasoning: 'qwen3:
|
|
33
|
-
powerful: 'qwen3:
|
|
57
|
+
standard: 'qwen3-coder:30b',
|
|
58
|
+
reasoning: 'qwen3-coder:30b',
|
|
59
|
+
powerful: 'qwen3-coder:30b',
|
|
34
60
|
},
|
|
35
61
|
large: {
|
|
36
62
|
tier: 'large',
|
|
37
63
|
fast: 'qwen3:8b',
|
|
38
|
-
standard: 'qwen3:
|
|
39
|
-
reasoning: 'qwen3:
|
|
40
|
-
powerful: 'qwen3:
|
|
64
|
+
standard: 'qwen3-coder:30b',
|
|
65
|
+
reasoning: 'qwen3.5:35b',
|
|
66
|
+
powerful: 'qwen3.5:35b',
|
|
41
67
|
},
|
|
42
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Preferred models ordered from best to least preferred.
|
|
71
|
+
* Cloud models first (run on remote infra), then best local models.
|
|
72
|
+
*/
|
|
73
|
+
const MODEL_PREFERENCE = [
|
|
74
|
+
// Cloud (always top priority)
|
|
75
|
+
'qwen3-coder:480b-cloud',
|
|
76
|
+
'qwen3.5:cloud',
|
|
77
|
+
'qwen3.5:397b-cloud',
|
|
78
|
+
'gpt-oss:120b-cloud',
|
|
79
|
+
// Local (newest/best first)
|
|
80
|
+
'qwen3-coder:30b',
|
|
81
|
+
'qwen3.5:35b',
|
|
82
|
+
'qwen3.5:27b',
|
|
83
|
+
'qwen3:32b',
|
|
84
|
+
'qwen3:14b',
|
|
85
|
+
'qwen3:8b',
|
|
86
|
+
];
|
|
43
87
|
// ============================================================================
|
|
44
88
|
// System Detection
|
|
45
89
|
// ============================================================================
|
|
@@ -50,7 +94,10 @@ function detectAppleSilicon() {
|
|
|
50
94
|
if (os.platform() !== 'darwin')
|
|
51
95
|
return false;
|
|
52
96
|
try {
|
|
53
|
-
const brand = execSync('sysctl -n machdep.cpu.brand_string', {
|
|
97
|
+
const brand = execSync('sysctl -n machdep.cpu.brand_string', {
|
|
98
|
+
encoding: 'utf-8',
|
|
99
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
100
|
+
}).trim();
|
|
54
101
|
return brand.includes('Apple');
|
|
55
102
|
}
|
|
56
103
|
catch {
|
|
@@ -64,7 +111,7 @@ function detectAppleSilicon() {
|
|
|
64
111
|
*/
|
|
65
112
|
function detectNvidiaVRAM() {
|
|
66
113
|
try {
|
|
67
|
-
const output = execSync('nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits', { encoding: 'utf-8', timeout: 3000 }).trim();
|
|
114
|
+
const output = execSync('nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits', { encoding: 'utf-8', timeout: 3000, stdio: ['pipe', 'pipe', 'pipe'] }).trim();
|
|
68
115
|
// nvidia-smi returns MB, could have multiple GPUs — take the first
|
|
69
116
|
const mb = parseInt(output.split('\n')[0], 10);
|
|
70
117
|
if (!isNaN(mb) && mb > 0) {
|
|
@@ -120,40 +167,117 @@ export function detectSystem() {
|
|
|
120
167
|
// Model Recommendation
|
|
121
168
|
// ============================================================================
|
|
122
169
|
/**
|
|
123
|
-
* Select the best Ollama model tier based on system capabilities
|
|
170
|
+
* Select the best Ollama model tier based on system capabilities
|
|
171
|
+
* and (optionally) which models are actually installed.
|
|
172
|
+
*
|
|
173
|
+
* When installedModels is provided, the recommendation is constrained
|
|
174
|
+
* to models the user already has pulled — the best available model is
|
|
175
|
+
* used for every tier rather than recommending something that would 404.
|
|
124
176
|
*
|
|
125
|
-
*
|
|
177
|
+
* If only sub-8b models are installed (and no cloud models), sets
|
|
178
|
+
* `noUsableModels: true` so the caller can skip Ollama entirely.
|
|
179
|
+
*
|
|
180
|
+
* Hardware thresholds (usable memory for model weights):
|
|
126
181
|
* < 6 GB → too small, warn user
|
|
127
182
|
* 6-10 GB → small (qwen3:8b everywhere)
|
|
128
|
-
* 10-
|
|
129
|
-
*
|
|
183
|
+
* 10-20 GB → medium (qwen3-coder:30b for standard+)
|
|
184
|
+
* 20+ GB → large (qwen3.5:35b for reasoning/powerful)
|
|
130
185
|
*/
|
|
131
|
-
export function recommendOllamaModels(profile) {
|
|
186
|
+
export function recommendOllamaModels(profile, installedModels) {
|
|
132
187
|
const sys = profile || detectSystem();
|
|
133
188
|
const mem = sys.usableForModelsGb;
|
|
189
|
+
// Determine the hardware-ideal tier
|
|
190
|
+
let ideal;
|
|
134
191
|
if (mem < 4) {
|
|
135
192
|
log.warn('Very limited memory for local models', { usableGb: mem });
|
|
136
|
-
|
|
193
|
+
ideal = {
|
|
137
194
|
...MODEL_TIERS.small,
|
|
138
195
|
reason: `Only ${sys.totalRAMGb} GB RAM detected — qwen3:8b may be slow. Consider using the free tier instead.`,
|
|
139
196
|
};
|
|
140
197
|
}
|
|
141
|
-
if (mem < 10) {
|
|
142
|
-
|
|
198
|
+
else if (mem < 10) {
|
|
199
|
+
ideal = {
|
|
143
200
|
...MODEL_TIERS.small,
|
|
144
201
|
reason: `${sys.totalRAMGb} GB RAM → qwen3:8b (best fit for your hardware)`,
|
|
145
202
|
};
|
|
146
203
|
}
|
|
147
|
-
if (mem <
|
|
148
|
-
|
|
204
|
+
else if (mem < 20) {
|
|
205
|
+
ideal = {
|
|
149
206
|
...MODEL_TIERS.medium,
|
|
150
|
-
reason: `${sys.totalRAMGb} GB RAM → qwen3:
|
|
207
|
+
reason: `${sys.totalRAMGb} GB RAM → qwen3-coder:30b for standard tasks, qwen3:8b for fast tasks`,
|
|
151
208
|
};
|
|
152
209
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
210
|
+
else {
|
|
211
|
+
ideal = {
|
|
212
|
+
...MODEL_TIERS.large,
|
|
213
|
+
reason: `${sys.totalRAMGb} GB RAM → qwen3.5:35b for reasoning/powerful, qwen3-coder:30b for standard`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
// If we don't know what's installed, return the hardware-ideal recommendation
|
|
217
|
+
if (!installedModels || installedModels.length === 0) {
|
|
218
|
+
return ideal;
|
|
219
|
+
}
|
|
220
|
+
// Constrain to what's actually pulled — pick the best available model
|
|
221
|
+
const installed = new Set(installedModels.map((m) => m.toLowerCase()));
|
|
222
|
+
const bestAvailable = pickBestAvailable(installed);
|
|
223
|
+
if (!bestAvailable) {
|
|
224
|
+
// No usable models installed (all sub-8b, no cloud)
|
|
225
|
+
log.info('No usable models installed', { installed: [...installed] });
|
|
226
|
+
return {
|
|
227
|
+
...ideal,
|
|
228
|
+
noUsableModels: true,
|
|
229
|
+
reason: 'No usable models found (need 8b+ local or cloud model)',
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
// Clamp each tier to what's installed.
|
|
233
|
+
// Cloud models always win over local — they run on remote infrastructure
|
|
234
|
+
// so they're faster and more capable regardless of local hardware.
|
|
235
|
+
const bestIsCloud = isCloudModel(bestAvailable);
|
|
236
|
+
const clamp = (model) => {
|
|
237
|
+
if (bestIsCloud)
|
|
238
|
+
return bestAvailable;
|
|
239
|
+
const norm = model.toLowerCase();
|
|
240
|
+
if (installed.has(norm) || [...installed].some((m) => m.startsWith(norm))) {
|
|
241
|
+
return model;
|
|
242
|
+
}
|
|
243
|
+
return bestAvailable;
|
|
156
244
|
};
|
|
245
|
+
const result = {
|
|
246
|
+
tier: ideal.tier,
|
|
247
|
+
fast: clamp(ideal.fast),
|
|
248
|
+
standard: clamp(ideal.standard),
|
|
249
|
+
reasoning: clamp(ideal.reasoning),
|
|
250
|
+
powerful: clamp(ideal.powerful),
|
|
251
|
+
reason: '',
|
|
252
|
+
};
|
|
253
|
+
// Build reason showing what standard tier will actually use
|
|
254
|
+
const unique = [...new Set([result.fast, result.standard, result.reasoning, result.powerful])];
|
|
255
|
+
result.reason = `${sys.totalRAMGb} GB RAM → ${unique.join(', ')}`;
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Pick the best usable model from what's installed.
|
|
260
|
+
*
|
|
261
|
+
* Priority:
|
|
262
|
+
* 1. Preferred models in order (cloud first, then best local)
|
|
263
|
+
* 2. Any other installed model that passes isUsableSize()
|
|
264
|
+
* 3. null if nothing qualifies
|
|
265
|
+
*/
|
|
266
|
+
function pickBestAvailable(installed) {
|
|
267
|
+
// Check preferred models in order
|
|
268
|
+
for (const model of MODEL_PREFERENCE) {
|
|
269
|
+
if (installed.has(model) || [...installed].some((m) => m.startsWith(model))) {
|
|
270
|
+
return model;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
// Check for any other usable model (non-qwen, non-preferred but >= 8b or cloud)
|
|
274
|
+
for (const model of installed) {
|
|
275
|
+
if (isUsableSize(model)) {
|
|
276
|
+
return model;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// Nothing qualifies
|
|
280
|
+
return null;
|
|
157
281
|
}
|
|
158
282
|
// ============================================================================
|
|
159
283
|
// Ollama Model Availability
|
|
@@ -162,7 +286,8 @@ export function recommendOllamaModels(profile) {
|
|
|
162
286
|
* Check which models Ollama already has pulled.
|
|
163
287
|
*/
|
|
164
288
|
export async function getOllamaModels(baseUrl) {
|
|
165
|
-
const
|
|
289
|
+
const rawUrl = baseUrl || process.env['OLLAMA_BASE_URL'] || 'http://localhost:11434';
|
|
290
|
+
const url = rawUrl.replace(/\/(api|v1)\/?$/, '');
|
|
166
291
|
const controller = new AbortController();
|
|
167
292
|
const timeout = setTimeout(() => controller.abort(), 2000);
|
|
168
293
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-detect.js","sourceRoot":"","sources":["../src/system-detect.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"system-detect.js","sourceRoot":"","sources":["../src/system-detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,GAAG,GAAG,YAAY,CAAC,2BAA2B,CAAC,CAAC;AAmCtD,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E,8FAA8F;AAC9F,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IAChC,OAAO,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,QA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CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAyC,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAAC,MAAM,CAAC;QACP,YAAY,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,KAAa,EAAE,OAAgB;IAClE,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC;IAC9C,sEAAsE;IACtE,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IACvC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;AACpE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agntk/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Opinionated agent SDK extending AI SDK's ToolLoopAgent",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,24 +22,18 @@
|
|
|
22
22
|
"default": "./dist/advanced/index.js"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "tsc && node ../../scripts/fix-esm-imports.mjs ./dist",
|
|
27
|
-
"dev": "tsc --watch",
|
|
28
|
-
"test": "vitest",
|
|
29
|
-
"clean": "rm -rf dist"
|
|
30
|
-
},
|
|
31
25
|
"dependencies": {
|
|
32
|
-
"@agntk/logger": "workspace:*",
|
|
33
26
|
"@ai-sdk/openai-compatible": "^2.0.28",
|
|
34
27
|
"ai": "6.0.77",
|
|
35
28
|
"xstate": "^5.26.0",
|
|
36
|
-
"zod": "^3.25.76"
|
|
29
|
+
"zod": "^3.25.76",
|
|
30
|
+
"@agntk/logger": "0.2.0"
|
|
37
31
|
},
|
|
38
32
|
"devDependencies": {
|
|
39
|
-
"@agntk/config-typescript": "workspace:*",
|
|
40
33
|
"@types/node": "^20.17.19",
|
|
41
34
|
"typescript": "^5.7.3",
|
|
42
|
-
"vitest": "^3.2.3"
|
|
35
|
+
"vitest": "^3.2.3",
|
|
36
|
+
"@agntk/config-typescript": "0.1.0"
|
|
43
37
|
},
|
|
44
38
|
"peerDependencies": {
|
|
45
39
|
"@opentelemetry/sdk-trace-node": "*",
|
|
@@ -87,5 +81,11 @@
|
|
|
87
81
|
"workflow",
|
|
88
82
|
"durable"
|
|
89
83
|
],
|
|
90
|
-
"license": "MIT"
|
|
91
|
-
|
|
84
|
+
"license": "MIT",
|
|
85
|
+
"scripts": {
|
|
86
|
+
"build": "tsc && node ../../scripts/fix-esm-imports.mjs ./dist",
|
|
87
|
+
"dev": "tsc --watch",
|
|
88
|
+
"test": "vitest",
|
|
89
|
+
"clean": "rm -rf dist"
|
|
90
|
+
}
|
|
91
|
+
}
|