@cuylabs/agent-core 0.8.0 → 0.9.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/{builder-UpOWQMW3.d.ts → builder-BgZ_j4Vs.d.ts} +2 -1
- package/dist/{chunk-RZITT45F.js → chunk-4QFNWPIF.js} +4 -4
- package/dist/{chunk-BFM2YHNM.js → chunk-5ARZJWD2.js} +74 -37
- package/dist/{chunk-KUVSERLJ.js → chunk-DXFBQMXP.js} +5 -2
- package/dist/{chunk-CAA7FHIH.js → chunk-EKR6PKXU.js} +0 -100
- package/dist/{chunk-IVUJDISU.js → chunk-GFTW23FV.js} +5 -14
- package/dist/{chunk-7VKQ4WPB.js → chunk-H3FUYU52.js} +11 -3
- package/dist/chunk-I6PKJ7XQ.js +292 -0
- package/dist/chunk-IYWQOJMQ.js +102 -0
- package/dist/{chunk-4BDA7DQY.js → chunk-J4QDGZIA.js} +19 -3
- package/dist/{chunk-7MUFEN4K.js → chunk-JLXG2SH7.js} +349 -3
- package/dist/{chunk-YSLSEQ6B.js → chunk-MAZ5DY5B.js} +18 -30
- package/dist/{chunk-P6YF7USR.js → chunk-MHKK374K.js} +12 -11
- package/dist/{chunk-VBWWUHWI.js → chunk-OFDKHNCX.js} +4 -1
- package/dist/{chunk-YUUJK53A.js → chunk-RKEW5WXI.js} +1 -1
- package/dist/{chunk-LRHOS4ZN.js → chunk-SPILYYDF.js} +3 -2
- package/dist/{chunk-RFEKJKTO.js → chunk-UDCZ673N.js} +321 -275
- package/dist/{chunk-BDBZ3SLK.js → chunk-UHCJEM2E.js} +39 -2
- package/dist/chunk-WGZAPU6N.js +929 -0
- package/dist/{chunk-N6HWIEEA.js → chunk-WKHDSSXG.js} +140 -23
- package/dist/index-BCqEGzBj.d.ts +251 -0
- package/dist/{index-CWSchSql.d.ts → index-DQuTZ8xL.d.ts} +290 -13
- package/dist/index.d.ts +23 -29
- package/dist/index.js +776 -490
- package/dist/{errors → inference/errors}/index.d.ts +2 -2
- package/dist/{errors → inference/errors}/index.js +1 -1
- package/dist/inference/index.d.ts +10 -9
- package/dist/inference/index.js +34 -8
- package/dist/middleware/index.d.ts +5 -4
- package/dist/middleware/index.js +3 -3
- package/dist/models/index.d.ts +18 -16
- package/dist/models/index.js +47 -11
- package/dist/models/reasoning/index.d.ts +4 -0
- package/dist/{reasoning → models/reasoning}/index.js +2 -3
- package/dist/plugin/index.d.ts +414 -0
- package/dist/plugin/index.js +32 -0
- package/dist/presets/index.d.ts +3 -3
- package/dist/presets/index.js +7 -5
- package/dist/prompt/index.d.ts +6 -5
- package/dist/prompt/index.js +3 -2
- package/dist/runner-CI-XeR16.d.ts +91 -0
- package/dist/runtime/index.d.ts +7 -6
- package/dist/runtime/index.js +6 -7
- package/dist/safety/index.d.ts +1 -1
- package/dist/safety/index.js +1 -1
- package/dist/{session-manager-B_CWGTsl.d.ts → session-manager-KbYt2WUh.d.ts} +8 -0
- package/dist/signal/index.js +1 -1
- package/dist/skill/index.d.ts +2 -2
- package/dist/skill/index.js +3 -3
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.js +1 -1
- package/dist/sub-agent/index.d.ts +10 -9
- package/dist/sub-agent/index.js +21 -4
- package/dist/tool/index.d.ts +19 -5
- package/dist/tool/index.js +2 -2
- package/dist/{tool-BHbyUAy3.d.ts → tool-CZWN3KbO.d.ts} +1 -10
- package/dist/{tool-DLXAR9Ce.d.ts → tool-DkhSCV2Y.d.ts} +1 -1
- package/dist/tracking/index.d.ts +1 -1
- package/dist/tracking/index.js +1 -1
- package/dist/{types-KKDrdU9Y.d.ts → types-BlOKk-Bb.d.ts} +9 -4
- package/dist/{types-BnpEOYV-.d.ts → types-BlZwmnuW.d.ts} +1 -1
- package/dist/{runner-e2YRcUoX.d.ts → types-DTSkxakL.d.ts} +3 -138
- package/dist/{types-QKHHQLLq.d.ts → types-DmDwi2zI.d.ts} +7 -4
- package/package.json +15 -9
- package/dist/chunk-DWYX7ASF.js +0 -26
- package/dist/chunk-SQU2AJHO.js +0 -305
- package/dist/reasoning/index.d.ts +0 -116
- package/dist/types-QA4WhEfz.d.ts +0 -138
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as PromptConfig, P as PromptBuildContext, c as PromptSection, e as ModelFamily } from './types-DTSkxakL.js';
|
|
2
2
|
import { S as SkillRegistry } from './registry-DwYqsQkX.js';
|
|
3
|
+
import { M as MiddlewareRunner } from './runner-CI-XeR16.js';
|
|
3
4
|
|
|
4
5
|
interface PromptSectionPreview {
|
|
5
6
|
id: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/errors/classify.ts
|
|
1
|
+
// src/inference/errors/classify.ts
|
|
2
2
|
function isRetryableCategory(category) {
|
|
3
3
|
switch (category) {
|
|
4
4
|
case "rate_limit":
|
|
@@ -80,7 +80,7 @@ function parseRetryDelay(headers) {
|
|
|
80
80
|
return void 0;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
// src/errors/extract.ts
|
|
83
|
+
// src/inference/errors/extract.ts
|
|
84
84
|
function extractFromAISDKError(error) {
|
|
85
85
|
const result = {};
|
|
86
86
|
const anyError = error;
|
|
@@ -111,7 +111,7 @@ function extractFromAISDKError(error) {
|
|
|
111
111
|
return result;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
// src/errors/llm-error.ts
|
|
114
|
+
// src/inference/errors/llm-error.ts
|
|
115
115
|
var LLMError = class _LLMError extends Error {
|
|
116
116
|
category;
|
|
117
117
|
status;
|
|
@@ -171,7 +171,7 @@ var LLMError = class _LLMError extends Error {
|
|
|
171
171
|
}
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
-
// src/errors/utils.ts
|
|
174
|
+
// src/inference/errors/utils.ts
|
|
175
175
|
function isRetryable(error) {
|
|
176
176
|
if (error instanceof LLMError) {
|
|
177
177
|
return error.isRetryable;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/safety/
|
|
1
|
+
// src/safety/risk.ts
|
|
2
2
|
var DEFAULT_TOOL_RISKS = {
|
|
3
3
|
read: "safe",
|
|
4
4
|
read_file: "safe",
|
|
@@ -31,7 +31,7 @@ function getToolRisk(tool, customRisks) {
|
|
|
31
31
|
return "moderate";
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// src/safety/
|
|
34
|
+
// src/safety/errors.ts
|
|
35
35
|
var ApprovalDeniedError = class extends Error {
|
|
36
36
|
constructor(tool, args, message) {
|
|
37
37
|
super(message || `Operation denied: ${tool}`);
|
|
@@ -49,10 +49,35 @@ var ApprovalTimeoutError = class extends Error {
|
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
// src/safety/
|
|
52
|
+
// src/safety/patterns.ts
|
|
53
53
|
function matchApprovalPattern(pattern, value) {
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
if (pattern.length > 500) return false;
|
|
55
|
+
const p = pattern.toLowerCase();
|
|
56
|
+
const v = value.toLowerCase();
|
|
57
|
+
let pi = 0;
|
|
58
|
+
let vi = 0;
|
|
59
|
+
let starPi = -1;
|
|
60
|
+
let starVi = -1;
|
|
61
|
+
while (vi < v.length) {
|
|
62
|
+
if (pi < p.length && (p[pi] === "?" || p[pi] === v[vi])) {
|
|
63
|
+
pi++;
|
|
64
|
+
vi++;
|
|
65
|
+
} else if (pi < p.length && p[pi] === "*") {
|
|
66
|
+
starPi = pi;
|
|
67
|
+
starVi = vi;
|
|
68
|
+
pi++;
|
|
69
|
+
} else if (starPi !== -1) {
|
|
70
|
+
pi = starPi + 1;
|
|
71
|
+
starVi++;
|
|
72
|
+
vi = starVi;
|
|
73
|
+
} else {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
while (pi < p.length && p[pi] === "*") {
|
|
78
|
+
pi++;
|
|
79
|
+
}
|
|
80
|
+
return pi === p.length;
|
|
56
81
|
}
|
|
57
82
|
function extractApprovalPatterns(tool, args) {
|
|
58
83
|
if (!args || typeof args !== "object") {
|
|
@@ -101,13 +126,15 @@ function describeApprovalOperation(tool, args) {
|
|
|
101
126
|
return `Search for: ${record.pattern}`;
|
|
102
127
|
case "glob":
|
|
103
128
|
return `Find files: ${record.pattern}`;
|
|
104
|
-
default:
|
|
105
|
-
|
|
129
|
+
default: {
|
|
130
|
+
const json = JSON.stringify(args);
|
|
131
|
+
const truncated = json.length > 50 ? `${json.slice(0, 50)}...` : json;
|
|
132
|
+
return `${tool}(${truncated})`;
|
|
133
|
+
}
|
|
106
134
|
}
|
|
107
135
|
}
|
|
108
136
|
|
|
109
|
-
// src/safety/
|
|
110
|
-
var requestCounter = 0;
|
|
137
|
+
// src/safety/handler.ts
|
|
111
138
|
function findMatchingRule(rules, tool, patterns) {
|
|
112
139
|
for (let index = rules.length - 1; index >= 0; index--) {
|
|
113
140
|
const rule = rules[index];
|
|
@@ -127,8 +154,10 @@ function createApprovalHandler(config = {}) {
|
|
|
127
154
|
timeout = 5 * 60 * 1e3,
|
|
128
155
|
onRequest
|
|
129
156
|
} = config;
|
|
157
|
+
let requestCounter = 0;
|
|
158
|
+
const initialRuleCount = config.rules?.length ?? 0;
|
|
130
159
|
const rules = [...config.rules ?? []];
|
|
131
|
-
const
|
|
160
|
+
const activeRequests = /* @__PURE__ */ new Set();
|
|
132
161
|
async function request(sessionId, tool, args, customRisks) {
|
|
133
162
|
const risk = getToolRisk(tool, customRisks);
|
|
134
163
|
const patterns = extractApprovalPatterns(tool, args);
|
|
@@ -166,35 +195,43 @@ function createApprovalHandler(config = {}) {
|
|
|
166
195
|
patterns,
|
|
167
196
|
timestamp: Date.now()
|
|
168
197
|
};
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
198
|
+
const ac = new AbortController();
|
|
199
|
+
activeRequests.add(ac);
|
|
200
|
+
let timeoutId;
|
|
201
|
+
try {
|
|
202
|
+
const action = await Promise.race([
|
|
203
|
+
onRequest(requestData),
|
|
204
|
+
new Promise((_, reject) => {
|
|
205
|
+
timeoutId = setTimeout(() => {
|
|
206
|
+
reject(new ApprovalTimeoutError(tool, timeout));
|
|
207
|
+
}, timeout);
|
|
208
|
+
ac.signal.addEventListener("abort", () => {
|
|
209
|
+
clearTimeout(timeoutId);
|
|
210
|
+
reject(new Error("Cancelled"));
|
|
211
|
+
}, { once: true });
|
|
212
|
+
})
|
|
213
|
+
]);
|
|
214
|
+
switch (action) {
|
|
215
|
+
case "allow":
|
|
216
|
+
return;
|
|
217
|
+
case "deny":
|
|
218
|
+
throw new ApprovalDeniedError(tool, args);
|
|
219
|
+
case "remember":
|
|
220
|
+
for (const pattern of patterns) {
|
|
221
|
+
rules.push({ pattern, tool, action: "allow" });
|
|
222
|
+
}
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
} finally {
|
|
226
|
+
clearTimeout(timeoutId);
|
|
227
|
+
activeRequests.delete(ac);
|
|
191
228
|
}
|
|
192
229
|
}
|
|
193
|
-
function cancelAll(
|
|
194
|
-
for (const
|
|
195
|
-
|
|
196
|
-
pending.delete(id);
|
|
230
|
+
function cancelAll(_reason) {
|
|
231
|
+
for (const ac of activeRequests) {
|
|
232
|
+
ac.abort();
|
|
197
233
|
}
|
|
234
|
+
activeRequests.clear();
|
|
198
235
|
}
|
|
199
236
|
function addRule(rule) {
|
|
200
237
|
rules.push(rule);
|
|
@@ -203,7 +240,7 @@ function createApprovalHandler(config = {}) {
|
|
|
203
240
|
return rules;
|
|
204
241
|
}
|
|
205
242
|
function clearSessionRules() {
|
|
206
|
-
rules.
|
|
243
|
+
rules.splice(initialRuleCount);
|
|
207
244
|
}
|
|
208
245
|
return {
|
|
209
246
|
request,
|
|
@@ -10,9 +10,12 @@ var LocalSignal = class {
|
|
|
10
10
|
set = /* @__PURE__ */ new Set();
|
|
11
11
|
this.typed.set(type, set);
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
const wrapped = (event) => {
|
|
14
|
+
handler(event);
|
|
15
|
+
};
|
|
16
|
+
set.add(wrapped);
|
|
14
17
|
return () => {
|
|
15
|
-
set.delete(
|
|
18
|
+
set.delete(wrapped);
|
|
16
19
|
if (set.size === 0) this.typed.delete(type);
|
|
17
20
|
};
|
|
18
21
|
}
|
|
@@ -1,99 +1,3 @@
|
|
|
1
|
-
// src/presets/patterns.ts
|
|
2
|
-
function globToRegex(pattern) {
|
|
3
|
-
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
4
|
-
return new RegExp(`^${escaped}$`, "i");
|
|
5
|
-
}
|
|
6
|
-
function matchesPatterns(id, patterns) {
|
|
7
|
-
return patterns.some((pattern) => globToRegex(pattern).test(id));
|
|
8
|
-
}
|
|
9
|
-
function filterTools(tools, options) {
|
|
10
|
-
const allowPatterns = options.allow ?? [];
|
|
11
|
-
const denyPatterns = options.deny ?? [];
|
|
12
|
-
return tools.filter((tool) => {
|
|
13
|
-
const matchesAllow = allowPatterns.length === 0 || matchesPatterns(tool.id, allowPatterns);
|
|
14
|
-
if (!matchesAllow) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
const matchesDeny = denyPatterns.length > 0 && matchesPatterns(tool.id, denyPatterns);
|
|
18
|
-
if (matchesDeny && allowPatterns.length === 0) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/presets/apply.ts
|
|
26
|
-
function applyPreset(preset, availableTools, baseSystemPrompt) {
|
|
27
|
-
const tools = filterTools(availableTools, {
|
|
28
|
-
allow: preset.allowTools,
|
|
29
|
-
deny: preset.denyTools
|
|
30
|
-
});
|
|
31
|
-
let systemPrompt = preset.systemPrompt;
|
|
32
|
-
if (systemPrompt && baseSystemPrompt) {
|
|
33
|
-
systemPrompt = systemPrompt.replace("{basePrompt}", baseSystemPrompt);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
name: preset.name,
|
|
37
|
-
systemPrompt,
|
|
38
|
-
tools: tools.length > 0 ? tools : void 0,
|
|
39
|
-
temperature: preset.temperature,
|
|
40
|
-
maxSteps: preset.maxSteps,
|
|
41
|
-
reasoningLevel: preset.reasoningLevel,
|
|
42
|
-
model: preset.model
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function mergePresets(...presets) {
|
|
46
|
-
if (presets.length === 0) {
|
|
47
|
-
throw new Error("mergePresets requires at least one preset");
|
|
48
|
-
}
|
|
49
|
-
if (presets.length === 1) {
|
|
50
|
-
return presets[0];
|
|
51
|
-
}
|
|
52
|
-
const [first, ...rest] = presets;
|
|
53
|
-
const allAllow = [];
|
|
54
|
-
const allDeny = [];
|
|
55
|
-
for (const preset of presets) {
|
|
56
|
-
if (preset.allowTools?.length) {
|
|
57
|
-
allAllow.push(preset.allowTools);
|
|
58
|
-
}
|
|
59
|
-
if (preset.denyTools?.length) {
|
|
60
|
-
allDeny.push(...preset.denyTools);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const combinedAllow = allAllow.length > 0 ? allAllow.reduce(
|
|
64
|
-
(left, right) => left.length <= right.length ? left : right
|
|
65
|
-
) : void 0;
|
|
66
|
-
return {
|
|
67
|
-
name: presets.map((preset) => preset.name).join("+"),
|
|
68
|
-
description: presets.map((preset) => preset.description).join(" | "),
|
|
69
|
-
allowTools: combinedAllow,
|
|
70
|
-
denyTools: allDeny.length > 0 ? [...new Set(allDeny)] : void 0,
|
|
71
|
-
systemPrompt: rest.reduce(
|
|
72
|
-
(value, preset) => preset.systemPrompt ?? value,
|
|
73
|
-
first.systemPrompt
|
|
74
|
-
),
|
|
75
|
-
temperature: rest.reduce(
|
|
76
|
-
(value, preset) => preset.temperature ?? value,
|
|
77
|
-
first.temperature
|
|
78
|
-
),
|
|
79
|
-
maxSteps: rest.reduce(
|
|
80
|
-
(value, preset) => preset.maxSteps ?? value,
|
|
81
|
-
first.maxSteps
|
|
82
|
-
),
|
|
83
|
-
reasoningLevel: rest.reduce(
|
|
84
|
-
(value, preset) => preset.reasoningLevel ?? value,
|
|
85
|
-
first.reasoningLevel
|
|
86
|
-
),
|
|
87
|
-
model: rest.reduce((value, preset) => preset.model ?? value, first.model)
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function createPreset(options) {
|
|
91
|
-
return {
|
|
92
|
-
description: options.description ?? `Custom preset: ${options.name}`,
|
|
93
|
-
...options
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
1
|
// src/presets/builtins.ts
|
|
98
2
|
var explore = {
|
|
99
3
|
name: "explore",
|
|
@@ -265,10 +169,6 @@ var Presets = {
|
|
|
265
169
|
};
|
|
266
170
|
|
|
267
171
|
export {
|
|
268
|
-
filterTools,
|
|
269
|
-
applyPreset,
|
|
270
|
-
mergePresets,
|
|
271
|
-
createPreset,
|
|
272
172
|
explore,
|
|
273
173
|
plan,
|
|
274
174
|
review,
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createSkillRegistry,
|
|
3
3
|
emptySkillRegistry
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-SPILYYDF.js";
|
|
5
|
+
import {
|
|
6
|
+
extractModelId,
|
|
7
|
+
extractProvider
|
|
8
|
+
} from "./chunk-I6PKJ7XQ.js";
|
|
5
9
|
|
|
6
10
|
// src/prompt/templates.ts
|
|
7
|
-
function extractModelId(model) {
|
|
8
|
-
if (typeof model === "string") return model;
|
|
9
|
-
if (typeof model === "object" && model !== null && "modelId" in model) {
|
|
10
|
-
return String(model.modelId);
|
|
11
|
-
}
|
|
12
|
-
return void 0;
|
|
13
|
-
}
|
|
14
|
-
function extractProvider(model) {
|
|
15
|
-
if (typeof model === "object" && model !== null && "provider" in model) {
|
|
16
|
-
return String(model.provider);
|
|
17
|
-
}
|
|
18
|
-
return void 0;
|
|
19
|
-
}
|
|
20
11
|
function detectModelFamily(model) {
|
|
21
12
|
const provider = extractProvider(model);
|
|
22
13
|
const modelId = extractModelId(model);
|
|
@@ -21,7 +21,7 @@ async function executeAgentToolCall(options) {
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
async () => {
|
|
24
|
-
const initialized = await options.tool.init({ cwd: options.cwd });
|
|
24
|
+
const initialized = options.initialized ?? await options.tool.init({ cwd: options.cwd });
|
|
25
25
|
const ctx = {
|
|
26
26
|
cwd: options.cwd,
|
|
27
27
|
abort: options.abort,
|
|
@@ -61,9 +61,17 @@ async function executeAgentToolCall(options) {
|
|
|
61
61
|
result,
|
|
62
62
|
ctx
|
|
63
63
|
);
|
|
64
|
-
return {
|
|
64
|
+
return {
|
|
65
|
+
output: transformed.output,
|
|
66
|
+
title: transformed.title,
|
|
67
|
+
metadata: transformed.metadata
|
|
68
|
+
};
|
|
65
69
|
}
|
|
66
|
-
return {
|
|
70
|
+
return {
|
|
71
|
+
output: result.output,
|
|
72
|
+
title: result.title,
|
|
73
|
+
metadata: result.metadata
|
|
74
|
+
};
|
|
67
75
|
}
|
|
68
76
|
);
|
|
69
77
|
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
// src/models/types.ts
|
|
2
|
+
var SourcePriority = /* @__PURE__ */ ((SourcePriority2) => {
|
|
3
|
+
SourcePriority2[SourcePriority2["UserConfig"] = 0] = "UserConfig";
|
|
4
|
+
SourcePriority2[SourcePriority2["LocalCache"] = 1] = "LocalCache";
|
|
5
|
+
SourcePriority2[SourcePriority2["BundledData"] = 2] = "BundledData";
|
|
6
|
+
SourcePriority2[SourcePriority2["PatternMatch"] = 3] = "PatternMatch";
|
|
7
|
+
SourcePriority2[SourcePriority2["RemoteAPI"] = 4] = "RemoteAPI";
|
|
8
|
+
return SourcePriority2;
|
|
9
|
+
})(SourcePriority || {});
|
|
10
|
+
var DEFAULT_RESOLVER_OPTIONS = {
|
|
11
|
+
enableRemoteFetch: false,
|
|
12
|
+
remoteApiUrl: "https://models.dev",
|
|
13
|
+
cachePath: ".agent-core/cache",
|
|
14
|
+
cacheTtlMs: 60 * 60 * 1e3,
|
|
15
|
+
// 1 hour
|
|
16
|
+
networkTimeoutMs: 10 * 1e3,
|
|
17
|
+
// 10 seconds
|
|
18
|
+
modelOverrides: {}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/models/profiles.ts
|
|
22
|
+
var REASONING_PATTERNS = [
|
|
23
|
+
// OpenAI o-series
|
|
24
|
+
{
|
|
25
|
+
pattern: /^o[134]-?(mini|pro|preview)?$/i,
|
|
26
|
+
provider: "openai",
|
|
27
|
+
capabilities: { reasoning: true, toolCalling: true },
|
|
28
|
+
compatibility: { supportsReasoningEffort: true, thinkingFormat: "openai" },
|
|
29
|
+
confidence: 0.95
|
|
30
|
+
},
|
|
31
|
+
// OpenAI GPT-5.x
|
|
32
|
+
{
|
|
33
|
+
pattern: /gpt-?5(\.\d)?/i,
|
|
34
|
+
provider: "openai",
|
|
35
|
+
capabilities: { reasoning: true, toolCalling: true },
|
|
36
|
+
compatibility: { supportsReasoningEffort: true, thinkingFormat: "openai" },
|
|
37
|
+
confidence: 0.9
|
|
38
|
+
},
|
|
39
|
+
// DeepSeek R1 variants
|
|
40
|
+
{
|
|
41
|
+
pattern: /deepseek[_-]?r1|r1[_-]distill/i,
|
|
42
|
+
capabilities: { reasoning: true, toolCalling: false },
|
|
43
|
+
confidence: 0.95
|
|
44
|
+
},
|
|
45
|
+
// Anthropic Claude with thinking
|
|
46
|
+
{
|
|
47
|
+
pattern: /claude.*thinking|thinking.*claude/i,
|
|
48
|
+
provider: "anthropic",
|
|
49
|
+
capabilities: { reasoning: true, toolCalling: true },
|
|
50
|
+
compatibility: { thinkingFormat: "anthropic" },
|
|
51
|
+
confidence: 0.9
|
|
52
|
+
},
|
|
53
|
+
// Claude 4.x series (reasoning capable)
|
|
54
|
+
{
|
|
55
|
+
pattern: /claude[_-]?(opus|sonnet)[_-]?4/i,
|
|
56
|
+
provider: "anthropic",
|
|
57
|
+
capabilities: { reasoning: true, toolCalling: true },
|
|
58
|
+
compatibility: { thinkingFormat: "anthropic" },
|
|
59
|
+
confidence: 0.85
|
|
60
|
+
},
|
|
61
|
+
// Gemini thinking models
|
|
62
|
+
{
|
|
63
|
+
pattern: /gemini.*thinking|gemini[_-]?2\.5[_-]?pro/i,
|
|
64
|
+
provider: "google",
|
|
65
|
+
capabilities: { reasoning: true, toolCalling: true },
|
|
66
|
+
compatibility: { thinkingFormat: "google" },
|
|
67
|
+
confidence: 0.85
|
|
68
|
+
},
|
|
69
|
+
// Gemini 3.x (future-proofing)
|
|
70
|
+
{
|
|
71
|
+
pattern: /gemini[_-]?3/i,
|
|
72
|
+
provider: "google",
|
|
73
|
+
capabilities: { reasoning: true, toolCalling: true },
|
|
74
|
+
compatibility: { thinkingFormat: "google" },
|
|
75
|
+
confidence: 0.8
|
|
76
|
+
},
|
|
77
|
+
// Grok reasoning models
|
|
78
|
+
{
|
|
79
|
+
pattern: /grok[_-]?\d[_-]?(mini|reasoning)/i,
|
|
80
|
+
provider: "xai",
|
|
81
|
+
capabilities: { reasoning: true, toolCalling: true },
|
|
82
|
+
confidence: 0.85
|
|
83
|
+
},
|
|
84
|
+
// Qwen thinking models
|
|
85
|
+
{
|
|
86
|
+
pattern: /qwen.*thinking|qwen3/i,
|
|
87
|
+
capabilities: { reasoning: true, toolCalling: true },
|
|
88
|
+
confidence: 0.8
|
|
89
|
+
},
|
|
90
|
+
// Generic reasoning/thinking in name
|
|
91
|
+
{
|
|
92
|
+
pattern: /reasoning|thinking/i,
|
|
93
|
+
capabilities: { reasoning: true },
|
|
94
|
+
confidence: 0.7
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
var PROVIDER_PATTERNS = [
|
|
98
|
+
{ pattern: /^(gpt|o[134]|chatgpt|davinci)/i, provider: "openai" },
|
|
99
|
+
{ pattern: /^claude/i, provider: "anthropic" },
|
|
100
|
+
{ pattern: /^gemini|^palm/i, provider: "google" },
|
|
101
|
+
{ pattern: /^grok/i, provider: "xai" },
|
|
102
|
+
{ pattern: /^deepseek/i, provider: "deepseek" },
|
|
103
|
+
{ pattern: /^mistral|^mixtral|codestral/i, provider: "mistral" },
|
|
104
|
+
{ pattern: /^llama/i, provider: "meta" },
|
|
105
|
+
{ pattern: /^qwen/i, provider: "alibaba" },
|
|
106
|
+
{ pattern: /^command/i, provider: "cohere" }
|
|
107
|
+
];
|
|
108
|
+
var CONTEXT_WINDOW_PROFILES = [
|
|
109
|
+
// Anthropic Claude 4.x — 200k
|
|
110
|
+
{ pattern: /claude[_-]?(opus|sonnet)[_-]?4/i, tokens: 2e5 },
|
|
111
|
+
// Anthropic Claude 3.5 — 200k
|
|
112
|
+
{ pattern: /claude[_-]?3[._-]?5/i, tokens: 2e5 },
|
|
113
|
+
// Anthropic Claude 3 Opus/Sonnet/Haiku — 200k
|
|
114
|
+
{ pattern: /claude[_-]?3/i, tokens: 2e5 },
|
|
115
|
+
// Anthropic Claude 2 — 100k
|
|
116
|
+
{ pattern: /claude[_-]?2/i, tokens: 1e5 },
|
|
117
|
+
// OpenAI o-series (o1, o3, o4) — 200k
|
|
118
|
+
{ pattern: /^o[134]-?(mini|pro|preview)?$/i, tokens: 2e5 },
|
|
119
|
+
// OpenAI GPT-5.x — 1M
|
|
120
|
+
{ pattern: /gpt-?5/i, tokens: 1e6 },
|
|
121
|
+
// OpenAI GPT-4o — 128k
|
|
122
|
+
{ pattern: /gpt-?4o/i, tokens: 128e3 },
|
|
123
|
+
// OpenAI GPT-4 turbo — 128k
|
|
124
|
+
{ pattern: /gpt-?4[_-]?turbo/i, tokens: 128e3 },
|
|
125
|
+
// OpenAI GPT-4 — 8k (original)
|
|
126
|
+
{ pattern: /gpt-?4(?!o|[_-]?turbo)/i, tokens: 8192 },
|
|
127
|
+
// OpenAI GPT-3.5 turbo — 16k
|
|
128
|
+
{ pattern: /gpt-?3[._-]?5/i, tokens: 16384 },
|
|
129
|
+
// Google Gemini 2.5 Pro — 1M
|
|
130
|
+
{ pattern: /gemini[_-]?2[._-]?5[_-]?pro/i, tokens: 1e6 },
|
|
131
|
+
// Google Gemini 2.x Flash — 1M
|
|
132
|
+
{ pattern: /gemini[_-]?2.*flash/i, tokens: 1e6 },
|
|
133
|
+
// Google Gemini 2.x Pro — 1M
|
|
134
|
+
{ pattern: /gemini[_-]?2[._-]?\d?[_-]?pro/i, tokens: 1e6 },
|
|
135
|
+
// Google Gemini 1.5 Pro/Flash — 1M
|
|
136
|
+
{ pattern: /gemini[_-]?1[._-]?5/i, tokens: 1e6 },
|
|
137
|
+
// xAI Grok 3+ — 128k
|
|
138
|
+
{ pattern: /grok[_-]?\d/i, tokens: 128e3 },
|
|
139
|
+
// Mistral Large — 128k
|
|
140
|
+
{ pattern: /mistral[_-]?large/i, tokens: 128e3 },
|
|
141
|
+
// Mistral Medium — 32k
|
|
142
|
+
{ pattern: /mistral[_-]?medium/i, tokens: 32768 },
|
|
143
|
+
// Codestral — 256k
|
|
144
|
+
{ pattern: /codestral/i, tokens: 256e3 },
|
|
145
|
+
// Mistral generic — 32k
|
|
146
|
+
{ pattern: /mistral|mixtral/i, tokens: 32768 },
|
|
147
|
+
// DeepSeek R1/V3 — 128k
|
|
148
|
+
{ pattern: /deepseek/i, tokens: 128e3 },
|
|
149
|
+
// Qwen 3 — 128k
|
|
150
|
+
{ pattern: /qwen/i, tokens: 128e3 },
|
|
151
|
+
// Meta Llama 3 — 128k
|
|
152
|
+
{ pattern: /llama[_-]?3/i, tokens: 128e3 },
|
|
153
|
+
// Cohere Command R+ — 128k
|
|
154
|
+
{ pattern: /command[_-]?r/i, tokens: 128e3 }
|
|
155
|
+
];
|
|
156
|
+
function inferContextWindow(modelId) {
|
|
157
|
+
const normalized = modelId.toLowerCase();
|
|
158
|
+
for (const { pattern, tokens } of CONTEXT_WINDOW_PROFILES) {
|
|
159
|
+
if (pattern.test(normalized)) {
|
|
160
|
+
return tokens;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return void 0;
|
|
164
|
+
}
|
|
165
|
+
function inferProvider(modelId) {
|
|
166
|
+
const normalized = modelId.toLowerCase();
|
|
167
|
+
for (const { pattern, provider } of PROVIDER_PATTERNS) {
|
|
168
|
+
if (pattern.test(normalized)) {
|
|
169
|
+
return provider;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (modelId.includes("/")) {
|
|
173
|
+
return modelId.split("/")[0];
|
|
174
|
+
}
|
|
175
|
+
return void 0;
|
|
176
|
+
}
|
|
177
|
+
function matchPatterns(modelId, providerHint) {
|
|
178
|
+
const normalized = modelId.toLowerCase();
|
|
179
|
+
for (const rule of REASONING_PATTERNS) {
|
|
180
|
+
if (rule.provider && providerHint && rule.provider !== providerHint) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const matches = typeof rule.pattern === "string" ? normalized.includes(rule.pattern.toLowerCase()) : rule.pattern.test(normalized);
|
|
184
|
+
if (matches) {
|
|
185
|
+
return { rule, confidence: rule.confidence };
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return void 0;
|
|
189
|
+
}
|
|
190
|
+
function createDefaultCapabilities() {
|
|
191
|
+
return {
|
|
192
|
+
reasoning: false,
|
|
193
|
+
toolCalling: true,
|
|
194
|
+
temperature: true,
|
|
195
|
+
attachments: false,
|
|
196
|
+
streaming: true,
|
|
197
|
+
inputModalities: ["text"],
|
|
198
|
+
outputModalities: ["text"]
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
var PatternCapabilitySource = class {
|
|
202
|
+
priority = 3 /* PatternMatch */;
|
|
203
|
+
name = "Pattern Matching";
|
|
204
|
+
async lookup(modelId, providerHint) {
|
|
205
|
+
const provider = providerHint || inferProvider(modelId);
|
|
206
|
+
const match = matchPatterns(modelId, provider);
|
|
207
|
+
const baseCapabilities = createDefaultCapabilities();
|
|
208
|
+
if (match) {
|
|
209
|
+
const entry = {
|
|
210
|
+
id: modelId,
|
|
211
|
+
name: modelId,
|
|
212
|
+
provider: match.rule.provider || provider || "unknown",
|
|
213
|
+
capabilities: {
|
|
214
|
+
...baseCapabilities,
|
|
215
|
+
...match.rule.capabilities,
|
|
216
|
+
contextWindow: inferContextWindow(modelId)
|
|
217
|
+
},
|
|
218
|
+
compatibility: match.rule.compatibility
|
|
219
|
+
};
|
|
220
|
+
return {
|
|
221
|
+
entry,
|
|
222
|
+
source: this.priority,
|
|
223
|
+
confident: match.confidence > 0.8
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
entry: {
|
|
228
|
+
id: modelId,
|
|
229
|
+
name: modelId,
|
|
230
|
+
provider: provider || "unknown",
|
|
231
|
+
capabilities: {
|
|
232
|
+
...baseCapabilities,
|
|
233
|
+
contextWindow: inferContextWindow(modelId)
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
source: this.priority,
|
|
237
|
+
confident: false
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
async isAvailable() {
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
function likelySupportsReasoning(modelId) {
|
|
245
|
+
const match = matchPatterns(modelId);
|
|
246
|
+
return match !== void 0 && match.rule.capabilities.reasoning === true;
|
|
247
|
+
}
|
|
248
|
+
function getProviderCompatibility(modelId, provider) {
|
|
249
|
+
const match = matchPatterns(modelId, provider);
|
|
250
|
+
return match?.rule.compatibility;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/models/identifiers.ts
|
|
254
|
+
function getModelId(model) {
|
|
255
|
+
if (typeof model === "string") return model;
|
|
256
|
+
if (typeof model === "object" && model !== null && "modelId" in model) {
|
|
257
|
+
return String(model.modelId);
|
|
258
|
+
}
|
|
259
|
+
return String(model);
|
|
260
|
+
}
|
|
261
|
+
function getProviderId(model) {
|
|
262
|
+
if (typeof model === "string") {
|
|
263
|
+
if (model.includes("/")) {
|
|
264
|
+
return model.split("/")[0];
|
|
265
|
+
}
|
|
266
|
+
return void 0;
|
|
267
|
+
}
|
|
268
|
+
if (typeof model === "object" && model !== null && "provider" in model) {
|
|
269
|
+
const provider = String(model.provider);
|
|
270
|
+
return provider.split(".")[0];
|
|
271
|
+
}
|
|
272
|
+
return void 0;
|
|
273
|
+
}
|
|
274
|
+
var extractModelId = getModelId;
|
|
275
|
+
function extractProvider(model) {
|
|
276
|
+
const provider = getProviderId(model);
|
|
277
|
+
return provider ?? inferProvider(getModelId(model));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export {
|
|
281
|
+
SourcePriority,
|
|
282
|
+
DEFAULT_RESOLVER_OPTIONS,
|
|
283
|
+
inferContextWindow,
|
|
284
|
+
inferProvider,
|
|
285
|
+
PatternCapabilitySource,
|
|
286
|
+
likelySupportsReasoning,
|
|
287
|
+
getProviderCompatibility,
|
|
288
|
+
getModelId,
|
|
289
|
+
getProviderId,
|
|
290
|
+
extractModelId,
|
|
291
|
+
extractProvider
|
|
292
|
+
};
|