sigma-agents 0.1.7 → 0.1.9
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.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/profiles.d.ts +7 -1
- package/dist/profiles.d.ts.map +1 -1
- package/dist/profiles.js +43 -6
- package/dist/profiles.js.map +1 -1
- package/dist/router.d.ts +6 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +163 -32
- package/dist/router.js.map +1 -1
- package/dist/sub-agent.d.ts +1 -1
- package/dist/sub-agent.d.ts.map +1 -1
- package/dist/sub-agent.js +13 -22
- package/dist/sub-agent.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -3
- package/src/index.ts +4 -4
- package/src/profiles.ts +129 -88
- package/src/router.ts +275 -136
- package/src/sub-agent.ts +153 -160
- package/src/types.ts +32 -29
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjG,MAAM,WAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjG,MAAM,WAAW,YAAY;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;IAClC,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACnC,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAE,MAAM,CACb,YAAY,EACZ;QACC,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;KACnB,CACD,CAAC;IACF,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACjD;AAED,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sigma-agents",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Intelligent sub-agent system with model routing for Phi Code",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"clean": "rm -rf dist"
|
|
9
|
+
"clean": "shx rm -rf dist",
|
|
10
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
11
|
+
"test": "node --test dist/test/*.test.js"
|
|
10
12
|
},
|
|
11
13
|
"dependencies": {},
|
|
12
14
|
"devDependencies": {
|
|
15
|
+
"shx": "^0.4.0",
|
|
13
16
|
"typescript": "^5.4.0"
|
|
14
17
|
},
|
|
15
18
|
"repository": {
|
|
@@ -29,4 +32,4 @@
|
|
|
29
32
|
"src",
|
|
30
33
|
"README.md"
|
|
31
34
|
]
|
|
32
|
-
}
|
|
35
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { SubAgentManager } from
|
|
4
|
-
export * from
|
|
1
|
+
export { ModelProfiler } from "./profiles.js";
|
|
2
|
+
export { SmartRouter } from "./router.js";
|
|
3
|
+
export { SubAgentManager } from "./sub-agent.js";
|
|
4
|
+
export * from "./types.js";
|
package/src/profiles.ts
CHANGED
|
@@ -1,90 +1,131 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import type { ModelProfile, TaskCategory } from "./types.js";
|
|
3
3
|
|
|
4
4
|
export class ModelProfiler {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
5
|
+
public profiles: Map<string, ModelProfile> = new Map();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Charge les profiles depuis un fichier JSON
|
|
9
|
+
*/
|
|
10
|
+
async loadFromFile(path: string): Promise<void> {
|
|
11
|
+
try {
|
|
12
|
+
const content = await readFile(path, "utf8");
|
|
13
|
+
const data = JSON.parse(content);
|
|
14
|
+
|
|
15
|
+
if (Array.isArray(data.profiles)) {
|
|
16
|
+
this.profiles.clear();
|
|
17
|
+
for (const profile of data.profiles) {
|
|
18
|
+
if (!ModelProfiler.isValidProfile(profile)) {
|
|
19
|
+
console.warn("Skipping invalid profile entry");
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
this.profiles.set(profile.id, profile);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
} catch (error) {
|
|
26
|
+
// Missing file is nominal: fall back to defaults silently.
|
|
27
|
+
// Only warn on real read/parse errors.
|
|
28
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
|
|
29
|
+
console.warn(`Could not load profiles from ${path}:`, error);
|
|
30
|
+
}
|
|
31
|
+
this.loadDefaultProfiles();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Sauvegarde les profiles vers un fichier JSON
|
|
37
|
+
*/
|
|
38
|
+
async saveToFile(path: string): Promise<void> {
|
|
39
|
+
const data = {
|
|
40
|
+
profiles: Array.from(this.profiles.values()),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
await writeFile(path, JSON.stringify(data, null, 2), "utf8");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Ajoute un profile
|
|
48
|
+
*/
|
|
49
|
+
addProfile(profile: ModelProfile): void {
|
|
50
|
+
this.profiles.set(profile.id, profile);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Retourne le meilleur modèle pour une tâche donnée
|
|
55
|
+
*/
|
|
56
|
+
getBestForTask(category: TaskCategory): ModelProfile | null {
|
|
57
|
+
const candidates = Array.from(this.profiles.values())
|
|
58
|
+
.filter((profile) => profile.strengths.includes(category))
|
|
59
|
+
.sort((a, b) => {
|
|
60
|
+
// Priority: quality > speed
|
|
61
|
+
if (a.quality !== b.quality) {
|
|
62
|
+
const qualityOrder = { high: 3, medium: 2, low: 1 };
|
|
63
|
+
return qualityOrder[b.quality] - qualityOrder[a.quality];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (a.speed !== b.speed) {
|
|
67
|
+
const speedOrder = { fast: 3, medium: 2, slow: 1 };
|
|
68
|
+
return speedOrder[b.speed] - speedOrder[a.speed];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return 0; // Equal priority
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return candidates[0] || null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Charge les profiles par défaut des modèles Alibaba
|
|
79
|
+
*/
|
|
80
|
+
private loadDefaultProfiles(): void {
|
|
81
|
+
const defaultProfiles = this.getDefaultProfiles();
|
|
82
|
+
this.profiles.clear();
|
|
83
|
+
|
|
84
|
+
for (const profile of defaultProfiles) {
|
|
85
|
+
this.profiles.set(profile.id, profile);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Valide la forme d'un profile chargé depuis un JSON non fiable.
|
|
91
|
+
* Empêche les entrées sans id (qui s'écraseraient sous la clé undefined)
|
|
92
|
+
* et les champs malformés qui feraient planter getBestForTask.
|
|
93
|
+
*/
|
|
94
|
+
static isValidProfile(profile: unknown): profile is ModelProfile {
|
|
95
|
+
if (typeof profile !== "object" || profile === null) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const p = profile as Record<string, unknown>;
|
|
100
|
+
|
|
101
|
+
if (typeof p.id !== "string" || p.id.length === 0) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (typeof p.provider !== "string") {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (p.speed !== "fast" && p.speed !== "medium" && p.speed !== "slow") {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (p.quality !== "high" && p.quality !== "medium" && p.quality !== "low") {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (!Array.isArray(p.strengths) || !p.strengths.every((s) => typeof s === "string")) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (typeof p.maxTokens !== "number" || typeof p.supportsTools !== "boolean") {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Returns empty default profiles.
|
|
125
|
+
* Actual profiles should be populated from /phi-init or user configuration.
|
|
126
|
+
* sigma-agents is provider-agnostic — no hardcoded model names.
|
|
127
|
+
*/
|
|
128
|
+
getDefaultProfiles(): ModelProfile[] {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
}
|