sigma-agents 0.1.10 → 0.2.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/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +0 -26
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/src/types.ts +0 -28
- package/dist/profiles.d.ts +0 -37
- package/dist/profiles.d.ts.map +0 -1
- package/dist/profiles.js +0 -119
- package/dist/profiles.js.map +0 -1
- package/dist/sub-agent.d.ts +0 -42
- package/dist/sub-agent.d.ts.map +0 -1
- package/dist/sub-agent.js +0 -138
- package/dist/sub-agent.js.map +0 -1
- package/src/profiles.ts +0 -131
- package/src/sub-agent.ts +0 -155
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,12 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
var profiles_js_1 = require("./profiles.js");
|
|
19
|
-
Object.defineProperty(exports, "ModelProfiler", { enumerable: true, get: function () { return profiles_js_1.ModelProfiler; } });
|
|
17
|
+
exports.SmartRouter = void 0;
|
|
20
18
|
var router_js_1 = require("./router.js");
|
|
21
19
|
Object.defineProperty(exports, "SmartRouter", { enumerable: true, get: function () { return router_js_1.SmartRouter; } });
|
|
22
|
-
var sub_agent_js_1 = require("./sub-agent.js");
|
|
23
|
-
Object.defineProperty(exports, "SubAgentManager", { enumerable: true, get: function () { return sub_agent_js_1.SubAgentManager; } });
|
|
24
20
|
__exportStar(require("./types.js"), exports);
|
|
25
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCAA0C;AAAjC,wGAAA,WAAW,OAAA;AACpB,6CAA2B"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
export type TaskCategory = "code" | "debug" | "explore" | "plan" | "test" | "review" | "general";
|
|
2
|
-
export interface ModelProfile {
|
|
3
|
-
id: string;
|
|
4
|
-
provider: string;
|
|
5
|
-
speed: "fast" | "medium" | "slow";
|
|
6
|
-
quality: "high" | "medium" | "low";
|
|
7
|
-
strengths: TaskCategory[];
|
|
8
|
-
maxTokens: number;
|
|
9
|
-
supportsTools: boolean;
|
|
10
|
-
}
|
|
11
2
|
export interface RoutingConfig {
|
|
12
3
|
routes: Record<TaskCategory, {
|
|
13
4
|
preferredModel: string;
|
|
@@ -20,21 +11,4 @@ export interface RoutingConfig {
|
|
|
20
11
|
agent: string | null;
|
|
21
12
|
};
|
|
22
13
|
}
|
|
23
|
-
export interface SubAgentConfig {
|
|
24
|
-
name: string;
|
|
25
|
-
description: string;
|
|
26
|
-
model: string;
|
|
27
|
-
tools: string[];
|
|
28
|
-
systemPrompt: string;
|
|
29
|
-
maxTokens?: number;
|
|
30
|
-
}
|
|
31
|
-
export interface SubAgentResult {
|
|
32
|
-
agentName: string;
|
|
33
|
-
model: string;
|
|
34
|
-
output: string;
|
|
35
|
-
tokensUsed: number;
|
|
36
|
-
durationMs: number;
|
|
37
|
-
success: boolean;
|
|
38
|
-
error?: string;
|
|
39
|
-
}
|
|
40
14
|
//# sourceMappingURL=types.d.ts.map
|
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,
|
|
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,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"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
export type TaskCategory = "code" | "debug" | "explore" | "plan" | "test" | "review" | "general";
|
|
2
2
|
|
|
3
|
-
export interface ModelProfile {
|
|
4
|
-
id: string;
|
|
5
|
-
provider: string;
|
|
6
|
-
speed: "fast" | "medium" | "slow";
|
|
7
|
-
quality: "high" | "medium" | "low";
|
|
8
|
-
strengths: TaskCategory[];
|
|
9
|
-
maxTokens: number;
|
|
10
|
-
supportsTools: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
3
|
export interface RoutingConfig {
|
|
14
4
|
routes: Record<
|
|
15
5
|
TaskCategory,
|
|
@@ -23,21 +13,3 @@ export interface RoutingConfig {
|
|
|
23
13
|
default: { model: string; agent: string | null };
|
|
24
14
|
}
|
|
25
15
|
|
|
26
|
-
export interface SubAgentConfig {
|
|
27
|
-
name: string;
|
|
28
|
-
description: string;
|
|
29
|
-
model: string;
|
|
30
|
-
tools: string[];
|
|
31
|
-
systemPrompt: string;
|
|
32
|
-
maxTokens?: number;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface SubAgentResult {
|
|
36
|
-
agentName: string;
|
|
37
|
-
model: string;
|
|
38
|
-
output: string;
|
|
39
|
-
tokensUsed: number;
|
|
40
|
-
durationMs: number;
|
|
41
|
-
success: boolean;
|
|
42
|
-
error?: string;
|
|
43
|
-
}
|
package/dist/profiles.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { ModelProfile, TaskCategory } from "./types.js";
|
|
2
|
-
export declare class ModelProfiler {
|
|
3
|
-
profiles: Map<string, ModelProfile>;
|
|
4
|
-
/**
|
|
5
|
-
* Charge les profiles depuis un fichier JSON
|
|
6
|
-
*/
|
|
7
|
-
loadFromFile(path: string): Promise<void>;
|
|
8
|
-
/**
|
|
9
|
-
* Sauvegarde les profiles vers un fichier JSON
|
|
10
|
-
*/
|
|
11
|
-
saveToFile(path: string): Promise<void>;
|
|
12
|
-
/**
|
|
13
|
-
* Ajoute un profile
|
|
14
|
-
*/
|
|
15
|
-
addProfile(profile: ModelProfile): void;
|
|
16
|
-
/**
|
|
17
|
-
* Retourne le meilleur modèle pour une tâche donnée
|
|
18
|
-
*/
|
|
19
|
-
getBestForTask(category: TaskCategory): ModelProfile | null;
|
|
20
|
-
/**
|
|
21
|
-
* Charge les profiles par défaut des modèles Alibaba
|
|
22
|
-
*/
|
|
23
|
-
private loadDefaultProfiles;
|
|
24
|
-
/**
|
|
25
|
-
* Valide la forme d'un profile chargé depuis un JSON non fiable.
|
|
26
|
-
* Empêche les entrées sans id (qui s'écraseraient sous la clé undefined)
|
|
27
|
-
* et les champs malformés qui feraient planter getBestForTask.
|
|
28
|
-
*/
|
|
29
|
-
static isValidProfile(profile: unknown): profile is ModelProfile;
|
|
30
|
-
/**
|
|
31
|
-
* Returns empty default profiles.
|
|
32
|
-
* Actual profiles should be populated from /phi-init or user configuration.
|
|
33
|
-
* sigma-agents is provider-agnostic — no hardcoded model names.
|
|
34
|
-
*/
|
|
35
|
-
getDefaultProfiles(): ModelProfile[];
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=profiles.d.ts.map
|
package/dist/profiles.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE7D,qBAAa,aAAa;IAClB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAa;IAEvD;;OAEG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB/C;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7C;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAIvC;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY,GAAG,IAAI;IAqB3D;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,YAAY;IA6BhE;;;;OAIG;IACH,kBAAkB,IAAI,YAAY,EAAE;CAGpC"}
|
package/dist/profiles.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelProfiler = void 0;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
class ModelProfiler {
|
|
6
|
-
profiles = new Map();
|
|
7
|
-
/**
|
|
8
|
-
* Charge les profiles depuis un fichier JSON
|
|
9
|
-
*/
|
|
10
|
-
async loadFromFile(path) {
|
|
11
|
-
try {
|
|
12
|
-
const content = await (0, promises_1.readFile)(path, "utf8");
|
|
13
|
-
const data = JSON.parse(content);
|
|
14
|
-
if (Array.isArray(data.profiles)) {
|
|
15
|
-
this.profiles.clear();
|
|
16
|
-
for (const profile of data.profiles) {
|
|
17
|
-
if (!ModelProfiler.isValidProfile(profile)) {
|
|
18
|
-
console.warn("Skipping invalid profile entry");
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
this.profiles.set(profile.id, profile);
|
|
22
|
-
}
|
|
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.code !== "ENOENT") {
|
|
29
|
-
console.warn(`Could not load profiles from ${path}:`, error);
|
|
30
|
-
}
|
|
31
|
-
this.loadDefaultProfiles();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Sauvegarde les profiles vers un fichier JSON
|
|
36
|
-
*/
|
|
37
|
-
async saveToFile(path) {
|
|
38
|
-
const data = {
|
|
39
|
-
profiles: Array.from(this.profiles.values()),
|
|
40
|
-
};
|
|
41
|
-
await (0, promises_1.writeFile)(path, JSON.stringify(data, null, 2), "utf8");
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Ajoute un profile
|
|
45
|
-
*/
|
|
46
|
-
addProfile(profile) {
|
|
47
|
-
this.profiles.set(profile.id, profile);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Retourne le meilleur modèle pour une tâche donnée
|
|
51
|
-
*/
|
|
52
|
-
getBestForTask(category) {
|
|
53
|
-
const candidates = Array.from(this.profiles.values())
|
|
54
|
-
.filter((profile) => profile.strengths.includes(category))
|
|
55
|
-
.sort((a, b) => {
|
|
56
|
-
// Priority: quality > speed
|
|
57
|
-
if (a.quality !== b.quality) {
|
|
58
|
-
const qualityOrder = { high: 3, medium: 2, low: 1 };
|
|
59
|
-
return qualityOrder[b.quality] - qualityOrder[a.quality];
|
|
60
|
-
}
|
|
61
|
-
if (a.speed !== b.speed) {
|
|
62
|
-
const speedOrder = { fast: 3, medium: 2, slow: 1 };
|
|
63
|
-
return speedOrder[b.speed] - speedOrder[a.speed];
|
|
64
|
-
}
|
|
65
|
-
return 0; // Equal priority
|
|
66
|
-
});
|
|
67
|
-
return candidates[0] || null;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Charge les profiles par défaut des modèles Alibaba
|
|
71
|
-
*/
|
|
72
|
-
loadDefaultProfiles() {
|
|
73
|
-
const defaultProfiles = this.getDefaultProfiles();
|
|
74
|
-
this.profiles.clear();
|
|
75
|
-
for (const profile of defaultProfiles) {
|
|
76
|
-
this.profiles.set(profile.id, profile);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Valide la forme d'un profile chargé depuis un JSON non fiable.
|
|
81
|
-
* Empêche les entrées sans id (qui s'écraseraient sous la clé undefined)
|
|
82
|
-
* et les champs malformés qui feraient planter getBestForTask.
|
|
83
|
-
*/
|
|
84
|
-
static isValidProfile(profile) {
|
|
85
|
-
if (typeof profile !== "object" || profile === null) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
const p = profile;
|
|
89
|
-
if (typeof p.id !== "string" || p.id.length === 0) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
if (typeof p.provider !== "string") {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
if (p.speed !== "fast" && p.speed !== "medium" && p.speed !== "slow") {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
if (p.quality !== "high" && p.quality !== "medium" && p.quality !== "low") {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
if (!Array.isArray(p.strengths) || !p.strengths.every((s) => typeof s === "string")) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
if (typeof p.maxTokens !== "number" || typeof p.supportsTools !== "boolean") {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Returns empty default profiles.
|
|
111
|
-
* Actual profiles should be populated from /phi-init or user configuration.
|
|
112
|
-
* sigma-agents is provider-agnostic — no hardcoded model names.
|
|
113
|
-
*/
|
|
114
|
-
getDefaultProfiles() {
|
|
115
|
-
return [];
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
exports.ModelProfiler = ModelProfiler;
|
|
119
|
-
//# sourceMappingURL=profiles.js.map
|
package/dist/profiles.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":";;;AAAA,+CAAuD;AAGvD,MAAa,aAAa;IAClB,QAAQ,GAA8B,IAAI,GAAG,EAAE,CAAC;IAEvD;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,IAAY;QAC9B,IAAI,CAAC;YACJ,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAEjC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAClC,IA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from "./types.js";
|
|
2
|
-
export declare class SubAgentManager {
|
|
3
|
-
private agents;
|
|
4
|
-
/**
|
|
5
|
-
* Charge les définitions d'agents depuis un répertoire
|
|
6
|
-
* Les fichiers .md doivent avoir un frontmatter YAML
|
|
7
|
-
*/
|
|
8
|
-
loadAgentDefinitions(agentsDir: string): Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* Retourne la liste des agents disponibles
|
|
11
|
-
*/
|
|
12
|
-
getAvailableAgents(): SubAgentConfig[];
|
|
13
|
-
/**
|
|
14
|
-
* Construit la commande CLI pour spawner un sous-agent phi
|
|
15
|
-
*/
|
|
16
|
-
createCommand(agent: SubAgentConfig, task: string): string[];
|
|
17
|
-
/**
|
|
18
|
-
* Parse un fichier markdown avec frontmatter YAML
|
|
19
|
-
* Format attendu :
|
|
20
|
-
* ---
|
|
21
|
-
* name: agent-name
|
|
22
|
-
* description: Agent description
|
|
23
|
-
* model: model-name
|
|
24
|
-
* tools: [tool1, tool2]
|
|
25
|
-
* maxTokens: 4096
|
|
26
|
-
* ---
|
|
27
|
-
*
|
|
28
|
-
* # System Prompt
|
|
29
|
-
*
|
|
30
|
-
* Le contenu après le frontmatter devient le system prompt...
|
|
31
|
-
*/
|
|
32
|
-
parseAgentMarkdown(content: string): SubAgentConfig | null;
|
|
33
|
-
/**
|
|
34
|
-
* Récupère un agent par son nom
|
|
35
|
-
*/
|
|
36
|
-
getAgent(name: string): SubAgentConfig | null;
|
|
37
|
-
/**
|
|
38
|
-
* Vérifie si un agent existe
|
|
39
|
-
*/
|
|
40
|
-
hasAgent(name: string): boolean;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=sub-agent.d.ts.map
|
package/dist/sub-agent.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sub-agent.d.ts","sourceRoot":"","sources":["../src/sub-agent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,qBAAa,eAAe;IAC3B,OAAO,CAAC,MAAM,CAA0C;IAExD;;;OAGG;IACG,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB5D;;OAEG;IACH,kBAAkB,IAAI,cAAc,EAAE;IAItC;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAI5D;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IA4E1D;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAI7C;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAG/B"}
|
package/dist/sub-agent.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubAgentManager = void 0;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
class SubAgentManager {
|
|
7
|
-
agents = new Map();
|
|
8
|
-
/**
|
|
9
|
-
* Charge les définitions d'agents depuis un répertoire
|
|
10
|
-
* Les fichiers .md doivent avoir un frontmatter YAML
|
|
11
|
-
*/
|
|
12
|
-
async loadAgentDefinitions(agentsDir) {
|
|
13
|
-
try {
|
|
14
|
-
const files = await (0, promises_1.readdir)(agentsDir);
|
|
15
|
-
const mdFiles = files.filter((file) => file.endsWith(".md"));
|
|
16
|
-
this.agents.clear();
|
|
17
|
-
for (const file of mdFiles) {
|
|
18
|
-
try {
|
|
19
|
-
const filePath = (0, node_path_1.join)(agentsDir, file);
|
|
20
|
-
const content = await (0, promises_1.readFile)(filePath, "utf8");
|
|
21
|
-
const agent = this.parseAgentMarkdown(content);
|
|
22
|
-
if (agent) {
|
|
23
|
-
this.agents.set(agent.name, agent);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
console.warn(`Could not parse agent file ${file}:`, error);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
console.warn(`Could not load agent definitions from ${agentsDir}:`, error);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Retourne la liste des agents disponibles
|
|
37
|
-
*/
|
|
38
|
-
getAvailableAgents() {
|
|
39
|
-
return Array.from(this.agents.values());
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Construit la commande CLI pour spawner un sous-agent phi
|
|
43
|
-
*/
|
|
44
|
-
createCommand(agent, task) {
|
|
45
|
-
return ["phi", "--print", "--model", agent.model, "--no-session", "--system-prompt", agent.systemPrompt, task];
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Parse un fichier markdown avec frontmatter YAML
|
|
49
|
-
* Format attendu :
|
|
50
|
-
* ---
|
|
51
|
-
* name: agent-name
|
|
52
|
-
* description: Agent description
|
|
53
|
-
* model: model-name
|
|
54
|
-
* tools: [tool1, tool2]
|
|
55
|
-
* maxTokens: 4096
|
|
56
|
-
* ---
|
|
57
|
-
*
|
|
58
|
-
* # System Prompt
|
|
59
|
-
*
|
|
60
|
-
* Le contenu après le frontmatter devient le system prompt...
|
|
61
|
-
*/
|
|
62
|
-
parseAgentMarkdown(content) {
|
|
63
|
-
const lines = content.split(/\r?\n/);
|
|
64
|
-
if (!lines[0]?.startsWith("---")) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
// Trouver la fin du frontmatter
|
|
68
|
-
let frontmatterEnd = -1;
|
|
69
|
-
for (let i = 1; i < lines.length; i++) {
|
|
70
|
-
if (lines[i] === "---") {
|
|
71
|
-
frontmatterEnd = i;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (frontmatterEnd === -1) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
// Extraire et parser le frontmatter YAML
|
|
79
|
-
const frontmatterLines = lines.slice(1, frontmatterEnd);
|
|
80
|
-
const frontmatter = {};
|
|
81
|
-
for (const line of frontmatterLines) {
|
|
82
|
-
const trimmed = line.trim();
|
|
83
|
-
if (!trimmed || trimmed.startsWith("#"))
|
|
84
|
-
continue;
|
|
85
|
-
const colonIndex = trimmed.indexOf(":");
|
|
86
|
-
if (colonIndex === -1)
|
|
87
|
-
continue;
|
|
88
|
-
const key = trimmed.substring(0, colonIndex).trim();
|
|
89
|
-
const valueStr = trimmed.substring(colonIndex + 1).trim();
|
|
90
|
-
// Parser la valeur
|
|
91
|
-
let value = valueStr;
|
|
92
|
-
// Arrays (format: [item1, item2])
|
|
93
|
-
if (valueStr.startsWith("[") && valueStr.endsWith("]")) {
|
|
94
|
-
const arrayContent = valueStr.slice(1, -1);
|
|
95
|
-
value = arrayContent.split(",").map((item) => item.trim().replace(/['"]/g, ""));
|
|
96
|
-
}
|
|
97
|
-
// Numbers
|
|
98
|
-
else if (/^\d+$/.test(valueStr)) {
|
|
99
|
-
value = parseInt(valueStr, 10);
|
|
100
|
-
}
|
|
101
|
-
// Remove quotes from strings
|
|
102
|
-
else if ((valueStr.startsWith('"') && valueStr.endsWith('"')) ||
|
|
103
|
-
(valueStr.startsWith("'") && valueStr.endsWith("'"))) {
|
|
104
|
-
value = valueStr.slice(1, -1);
|
|
105
|
-
}
|
|
106
|
-
frontmatter[key] = value;
|
|
107
|
-
}
|
|
108
|
-
// Extract system prompt (content after frontmatter)
|
|
109
|
-
const systemPromptLines = lines.slice(frontmatterEnd + 1);
|
|
110
|
-
const systemPrompt = systemPromptLines.join("\n").trim();
|
|
111
|
-
// Valider les champs requis
|
|
112
|
-
if (!frontmatter.name || !frontmatter.model || !systemPrompt) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
name: frontmatter.name,
|
|
117
|
-
description: frontmatter.description || "",
|
|
118
|
-
model: frontmatter.model,
|
|
119
|
-
tools: Array.isArray(frontmatter.tools) ? frontmatter.tools : [],
|
|
120
|
-
systemPrompt,
|
|
121
|
-
maxTokens: frontmatter.maxTokens || undefined,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Récupère un agent par son nom
|
|
126
|
-
*/
|
|
127
|
-
getAgent(name) {
|
|
128
|
-
return this.agents.get(name) || null;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Vérifie si un agent existe
|
|
132
|
-
*/
|
|
133
|
-
hasAgent(name) {
|
|
134
|
-
return this.agents.has(name);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.SubAgentManager = SubAgentManager;
|
|
138
|
-
//# sourceMappingURL=sub-agent.js.map
|
package/dist/sub-agent.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sub-agent.js","sourceRoot":"","sources":["../src/sub-agent.ts"],"names":[],"mappings":";;;AAAA,+CAAqD;AACrD,yCAAiC;AAGjC,MAAa,eAAe;IACnB,MAAM,GAAgC,IAAI,GAAG,EAAE,CAAC;IAExD;;;OAGG;IACH,KAAK,CAAC,oBAAoB,CAAC,SAAiB;QAC3C,IAAI,CAAC;YACJ,MAAM,KAAK,GAAG,MAAM,IAAA,kBAAO,EAAC,SAAS,CAAC,CAAC;YACvC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;YAE7D,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAEpB,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;gBAC5B,IAAI,CAAC;oBACJ,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC;oBACvC,MAAM,OAAO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AAY;YACZ,SAAS,EAAE,WAAW,CAAC,SAAS,IAAI,SAAS;SAC7C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;CACD;AAtJD,0CAsJC"}
|
package/src/profiles.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import type { ModelProfile, TaskCategory } from "./types.js";
|
|
3
|
-
|
|
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
|
-
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
|
-
}
|
package/src/sub-agent.ts
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { readdir, readFile } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import type { SubAgentConfig } from "./types.js";
|
|
4
|
-
|
|
5
|
-
export class SubAgentManager {
|
|
6
|
-
private agents: Map<string, SubAgentConfig> = new Map();
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Charge les définitions d'agents depuis un répertoire
|
|
10
|
-
* Les fichiers .md doivent avoir un frontmatter YAML
|
|
11
|
-
*/
|
|
12
|
-
async loadAgentDefinitions(agentsDir: string): Promise<void> {
|
|
13
|
-
try {
|
|
14
|
-
const files = await readdir(agentsDir);
|
|
15
|
-
const mdFiles = files.filter((file) => file.endsWith(".md"));
|
|
16
|
-
|
|
17
|
-
this.agents.clear();
|
|
18
|
-
|
|
19
|
-
for (const file of mdFiles) {
|
|
20
|
-
try {
|
|
21
|
-
const filePath = join(agentsDir, file);
|
|
22
|
-
const content = await readFile(filePath, "utf8");
|
|
23
|
-
const agent = this.parseAgentMarkdown(content);
|
|
24
|
-
|
|
25
|
-
if (agent) {
|
|
26
|
-
this.agents.set(agent.name, agent);
|
|
27
|
-
}
|
|
28
|
-
} catch (error) {
|
|
29
|
-
console.warn(`Could not parse agent file ${file}:`, error);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.warn(`Could not load agent definitions from ${agentsDir}:`, error);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Retourne la liste des agents disponibles
|
|
39
|
-
*/
|
|
40
|
-
getAvailableAgents(): SubAgentConfig[] {
|
|
41
|
-
return Array.from(this.agents.values());
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Construit la commande CLI pour spawner un sous-agent phi
|
|
46
|
-
*/
|
|
47
|
-
createCommand(agent: SubAgentConfig, task: string): string[] {
|
|
48
|
-
return ["phi", "--print", "--model", agent.model, "--no-session", "--system-prompt", agent.systemPrompt, task];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Parse un fichier markdown avec frontmatter YAML
|
|
53
|
-
* Format attendu :
|
|
54
|
-
* ---
|
|
55
|
-
* name: agent-name
|
|
56
|
-
* description: Agent description
|
|
57
|
-
* model: model-name
|
|
58
|
-
* tools: [tool1, tool2]
|
|
59
|
-
* maxTokens: 4096
|
|
60
|
-
* ---
|
|
61
|
-
*
|
|
62
|
-
* # System Prompt
|
|
63
|
-
*
|
|
64
|
-
* Le contenu après le frontmatter devient le system prompt...
|
|
65
|
-
*/
|
|
66
|
-
parseAgentMarkdown(content: string): SubAgentConfig | null {
|
|
67
|
-
const lines = content.split(/\r?\n/);
|
|
68
|
-
|
|
69
|
-
if (!lines[0]?.startsWith("---")) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Trouver la fin du frontmatter
|
|
74
|
-
let frontmatterEnd = -1;
|
|
75
|
-
for (let i = 1; i < lines.length; i++) {
|
|
76
|
-
if (lines[i] === "---") {
|
|
77
|
-
frontmatterEnd = i;
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (frontmatterEnd === -1) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Extraire et parser le frontmatter YAML
|
|
87
|
-
const frontmatterLines = lines.slice(1, frontmatterEnd);
|
|
88
|
-
const frontmatter: any = {};
|
|
89
|
-
|
|
90
|
-
for (const line of frontmatterLines) {
|
|
91
|
-
const trimmed = line.trim();
|
|
92
|
-
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
93
|
-
|
|
94
|
-
const colonIndex = trimmed.indexOf(":");
|
|
95
|
-
if (colonIndex === -1) continue;
|
|
96
|
-
|
|
97
|
-
const key = trimmed.substring(0, colonIndex).trim();
|
|
98
|
-
const valueStr = trimmed.substring(colonIndex + 1).trim();
|
|
99
|
-
|
|
100
|
-
// Parser la valeur
|
|
101
|
-
let value: any = valueStr;
|
|
102
|
-
|
|
103
|
-
// Arrays (format: [item1, item2])
|
|
104
|
-
if (valueStr.startsWith("[") && valueStr.endsWith("]")) {
|
|
105
|
-
const arrayContent = valueStr.slice(1, -1);
|
|
106
|
-
value = arrayContent.split(",").map((item) => item.trim().replace(/['"]/g, ""));
|
|
107
|
-
}
|
|
108
|
-
// Numbers
|
|
109
|
-
else if (/^\d+$/.test(valueStr)) {
|
|
110
|
-
value = parseInt(valueStr, 10);
|
|
111
|
-
}
|
|
112
|
-
// Remove quotes from strings
|
|
113
|
-
else if (
|
|
114
|
-
(valueStr.startsWith('"') && valueStr.endsWith('"')) ||
|
|
115
|
-
(valueStr.startsWith("'") && valueStr.endsWith("'"))
|
|
116
|
-
) {
|
|
117
|
-
value = valueStr.slice(1, -1);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
frontmatter[key] = value;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Extract system prompt (content after frontmatter)
|
|
124
|
-
const systemPromptLines = lines.slice(frontmatterEnd + 1);
|
|
125
|
-
const systemPrompt = systemPromptLines.join("\n").trim();
|
|
126
|
-
|
|
127
|
-
// Valider les champs requis
|
|
128
|
-
if (!frontmatter.name || !frontmatter.model || !systemPrompt) {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
name: frontmatter.name,
|
|
134
|
-
description: frontmatter.description || "",
|
|
135
|
-
model: frontmatter.model,
|
|
136
|
-
tools: Array.isArray(frontmatter.tools) ? frontmatter.tools : [],
|
|
137
|
-
systemPrompt,
|
|
138
|
-
maxTokens: frontmatter.maxTokens || undefined,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Récupère un agent par son nom
|
|
144
|
-
*/
|
|
145
|
-
getAgent(name: string): SubAgentConfig | null {
|
|
146
|
-
return this.agents.get(name) || null;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Vérifie si un agent existe
|
|
151
|
-
*/
|
|
152
|
-
hasAgent(name: string): boolean {
|
|
153
|
-
return this.agents.has(name);
|
|
154
|
-
}
|
|
155
|
-
}
|