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.
@@ -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;IAC3B,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;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC,YAAY,EAAE;QAC3B,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC,CAAC;IACH,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CAClD;AAED,MAAM,WAAW,cAAc;IAC7B,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;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAA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AAS,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.7",
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 { SmartRouter } from './router.js';
2
- export { ModelProfiler } from './profiles.js';
3
- export { SubAgentManager } from './sub-agent.js';
4
- export * from './types.js';
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 { ModelProfile, TaskCategory } from './types.js';
2
- import { readFile, writeFile } from 'node:fs/promises';
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import type { ModelProfile, TaskCategory } from "./types.js";
3
3
 
4
4
  export class ModelProfiler {
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
- this.profiles.set(profile.id, profile);
19
- }
20
- }
21
- } catch (error) {
22
- // If file doesn't exist, use default profiles
23
- console.warn(`Could not load profiles from ${path}:`, error);
24
- this.loadDefaultProfiles();
25
- }
26
- }
27
-
28
- /**
29
- * Sauvegarde les profiles vers un fichier JSON
30
- */
31
- async saveToFile(path: string): Promise<void> {
32
- const data = {
33
- profiles: Array.from(this.profiles.values())
34
- };
35
-
36
- await writeFile(path, JSON.stringify(data, null, 2), 'utf8');
37
- }
38
-
39
- /**
40
- * Ajoute un profile
41
- */
42
- addProfile(profile: ModelProfile): void {
43
- this.profiles.set(profile.id, profile);
44
- }
45
-
46
- /**
47
- * Retourne le meilleur modèle pour une tâche donnée
48
- */
49
- getBestForTask(category: TaskCategory): ModelProfile | null {
50
- const candidates = Array.from(this.profiles.values())
51
- .filter(profile => profile.strengths.includes(category))
52
- .sort((a, b) => {
53
- // Priority: quality > speed
54
- if (a.quality !== b.quality) {
55
- const qualityOrder = { high: 3, medium: 2, low: 1 };
56
- return qualityOrder[b.quality] - qualityOrder[a.quality];
57
- }
58
-
59
- if (a.speed !== b.speed) {
60
- const speedOrder = { fast: 3, medium: 2, slow: 1 };
61
- return speedOrder[b.speed] - speedOrder[a.speed];
62
- }
63
-
64
- return 0; // Equal priority
65
- });
66
-
67
- return candidates[0] || null;
68
- }
69
-
70
- /**
71
- * Charge les profiles par défaut des modèles Alibaba
72
- */
73
- private loadDefaultProfiles(): void {
74
- const defaultProfiles = this.getDefaultProfiles();
75
- this.profiles.clear();
76
-
77
- for (const profile of defaultProfiles) {
78
- this.profiles.set(profile.id, profile);
79
- }
80
- }
81
-
82
- /**
83
- * Returns empty default profiles.
84
- * Actual profiles should be populated from /phi-init or user configuration.
85
- * sigma-agents is provider-agnostic — no hardcoded model names.
86
- */
87
- getDefaultProfiles(): ModelProfile[] {
88
- return [];
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
+ }