@nahisaho/katashiro-orchestrator 1.0.1 → 1.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/consensus/ConsensusResearchEngine.d.ts +83 -0
- package/dist/consensus/ConsensusResearchEngine.d.ts.map +1 -0
- package/dist/consensus/ConsensusResearchEngine.js +397 -0
- package/dist/consensus/ConsensusResearchEngine.js.map +1 -0
- package/dist/consensus/ConsensusSelector.d.ts +63 -0
- package/dist/consensus/ConsensusSelector.d.ts.map +1 -0
- package/dist/consensus/ConsensusSelector.js +124 -0
- package/dist/consensus/ConsensusSelector.js.map +1 -0
- package/dist/consensus/ReportScorer.d.ts +81 -0
- package/dist/consensus/ReportScorer.d.ts.map +1 -0
- package/dist/consensus/ReportScorer.js +292 -0
- package/dist/consensus/ReportScorer.js.map +1 -0
- package/dist/consensus/ResearchAgent.d.ts +137 -0
- package/dist/consensus/ResearchAgent.d.ts.map +1 -0
- package/dist/consensus/ResearchAgent.js +319 -0
- package/dist/consensus/ResearchAgent.js.map +1 -0
- package/dist/consensus/index.d.ts +19 -0
- package/dist/consensus/index.d.ts.map +1 -0
- package/dist/consensus/index.js +35 -0
- package/dist/consensus/index.js.map +1 -0
- package/dist/consensus/types.d.ts +343 -0
- package/dist/consensus/types.d.ts.map +1 -0
- package/dist/consensus/types.js +88 -0
- package/dist/consensus/types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* KATASHIRO v1.2.0 - ConsensusSelector
|
|
4
|
+
* 最良レポートの選択ロジックを担当
|
|
5
|
+
* @module @nahisaho/katashiro-orchestrator/consensus
|
|
6
|
+
* @version 1.2.0
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ConsensusSelector = void 0;
|
|
10
|
+
const types_1 = require("./types");
|
|
11
|
+
/**
|
|
12
|
+
* コンセンサスセレクター
|
|
13
|
+
* @requirement REQ-1.2.0-WFL-003
|
|
14
|
+
*/
|
|
15
|
+
class ConsensusSelector {
|
|
16
|
+
/**
|
|
17
|
+
* 最良レポートを選択
|
|
18
|
+
* @requirement REQ-1.2.0-WFL-003
|
|
19
|
+
* @param scores スコア配列
|
|
20
|
+
* @returns 選択結果
|
|
21
|
+
*/
|
|
22
|
+
select(scores) {
|
|
23
|
+
if (scores.length === 0) {
|
|
24
|
+
throw new types_1.ConsensusResearchError(types_1.ConsensusResearchErrorCode.SELECTION_ERROR, 'No reports to select from');
|
|
25
|
+
}
|
|
26
|
+
if (scores.length === 1) {
|
|
27
|
+
const onlyScore = scores[0];
|
|
28
|
+
return {
|
|
29
|
+
selectedReportId: onlyScore.reportId,
|
|
30
|
+
reason: 'Only one report available',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// 総合スコアでソート(降順)
|
|
34
|
+
const sorted = [...scores].sort((a, b) => b.totalScore - a.totalScore);
|
|
35
|
+
const best = sorted[0]; // 必ず存在(scores.length >= 2)
|
|
36
|
+
const secondBest = sorted[1]; // 必ず存在(scores.length >= 2)
|
|
37
|
+
// タイブレーカー: 同スコアの場合はconsistencyで判断
|
|
38
|
+
if (Math.abs(best.totalScore - secondBest.totalScore) < 0.01) {
|
|
39
|
+
const byConsistency = [...scores].sort((a, b) => b.consistencyScore - a.consistencyScore);
|
|
40
|
+
const topByConsistency = byConsistency[0];
|
|
41
|
+
return {
|
|
42
|
+
selectedReportId: topByConsistency.reportId,
|
|
43
|
+
reason: `Tie-breaker: highest consistency score (${topByConsistency.consistencyScore.toFixed(3)})`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
selectedReportId: best.reportId,
|
|
48
|
+
reason: this.generateReason(best, sorted.slice(1)),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 選択理由を生成
|
|
53
|
+
* @param selected 選択されたスコア
|
|
54
|
+
* @param others 他のスコア
|
|
55
|
+
* @returns 選択理由
|
|
56
|
+
*/
|
|
57
|
+
generateReason(selected, others) {
|
|
58
|
+
const avgOthers = others.reduce((sum, s) => sum + s.totalScore, 0) / others.length;
|
|
59
|
+
const margin = ((selected.totalScore - avgOthers) * 100).toFixed(1);
|
|
60
|
+
return (`Selected with total score ${selected.totalScore.toFixed(3)} ` +
|
|
61
|
+
`(+${margin}% vs average). ` +
|
|
62
|
+
`Consistency: ${selected.consistencyScore.toFixed(3)}, ` +
|
|
63
|
+
`Reliability: ${selected.reliabilityScore.toFixed(3)}, ` +
|
|
64
|
+
`Coverage: ${selected.coverageScore.toFixed(3)}. ` +
|
|
65
|
+
`Conflicts: ${selected.conflicts.length}`);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 選択結果の詳細分析を生成
|
|
69
|
+
* @param scores 全スコア
|
|
70
|
+
* @param selection 選択結果
|
|
71
|
+
* @returns 詳細分析
|
|
72
|
+
*/
|
|
73
|
+
analyzeSelection(scores, selection) {
|
|
74
|
+
const selected = scores.find((s) => s.reportId === selection.selectedReportId);
|
|
75
|
+
if (!selected) {
|
|
76
|
+
throw new types_1.ConsensusResearchError(types_1.ConsensusResearchErrorCode.SELECTION_ERROR, 'Selected report not found in scores');
|
|
77
|
+
}
|
|
78
|
+
const others = scores.filter((s) => s.reportId !== selection.selectedReportId);
|
|
79
|
+
const avgTotalScore = others.reduce((sum, s) => sum + s.totalScore, 0) / others.length;
|
|
80
|
+
const avgConsistency = others.reduce((sum, s) => sum + s.consistencyScore, 0) / others.length;
|
|
81
|
+
const avgReliability = others.reduce((sum, s) => sum + s.reliabilityScore, 0) / others.length;
|
|
82
|
+
const avgCoverage = others.reduce((sum, s) => sum + s.coverageScore, 0) / others.length;
|
|
83
|
+
return {
|
|
84
|
+
selectedReportId: selection.selectedReportId,
|
|
85
|
+
selectedScore: selected,
|
|
86
|
+
comparison: {
|
|
87
|
+
totalScoreDiff: selected.totalScore - avgTotalScore,
|
|
88
|
+
consistencyDiff: selected.consistencyScore - avgConsistency,
|
|
89
|
+
reliabilityDiff: selected.reliabilityScore - avgReliability,
|
|
90
|
+
coverageDiff: selected.coverageScore - avgCoverage,
|
|
91
|
+
},
|
|
92
|
+
ranking: scores
|
|
93
|
+
.map((s) => ({
|
|
94
|
+
reportId: s.reportId,
|
|
95
|
+
rank: scores.filter((o) => o.totalScore > s.totalScore).length + 1,
|
|
96
|
+
score: s.totalScore,
|
|
97
|
+
}))
|
|
98
|
+
.sort((a, b) => a.rank - b.rank),
|
|
99
|
+
confidence: this.calculateSelectionConfidence(selected, others),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 選択の信頼度を計算
|
|
104
|
+
*/
|
|
105
|
+
calculateSelectionConfidence(selected, others) {
|
|
106
|
+
if (others.length === 0)
|
|
107
|
+
return 1.0;
|
|
108
|
+
const maxOtherScore = Math.max(...others.map((s) => s.totalScore));
|
|
109
|
+
const scoreDiff = selected.totalScore - maxOtherScore;
|
|
110
|
+
// スコア差が大きいほど信頼度が高い
|
|
111
|
+
// 0.1以上の差で高信頼、0.01未満は低信頼
|
|
112
|
+
if (scoreDiff >= 0.1)
|
|
113
|
+
return 0.95;
|
|
114
|
+
if (scoreDiff >= 0.05)
|
|
115
|
+
return 0.8;
|
|
116
|
+
if (scoreDiff >= 0.02)
|
|
117
|
+
return 0.6;
|
|
118
|
+
if (scoreDiff >= 0.01)
|
|
119
|
+
return 0.4;
|
|
120
|
+
return 0.3; // 僅差
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.ConsensusSelector = ConsensusSelector;
|
|
124
|
+
//# sourceMappingURL=ConsensusSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConsensusSelector.js","sourceRoot":"","sources":["../../src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v1.2.0 - ReportScorer
|
|
3
|
+
* レポートのスコアリングと矛盾検出を担当
|
|
4
|
+
* @module @nahisaho/katashiro-orchestrator/consensus
|
|
5
|
+
* @version 1.2.0
|
|
6
|
+
*/
|
|
7
|
+
import { AgentReport, ReportScore, ConflictDetail, ScoringWeights } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* レポートスコアラー
|
|
10
|
+
* @requirement REQ-1.2.0-WFL-002
|
|
11
|
+
*/
|
|
12
|
+
export declare class ReportScorer {
|
|
13
|
+
private readonly conflictThreshold;
|
|
14
|
+
private readonly weights;
|
|
15
|
+
/**
|
|
16
|
+
* コンストラクタ
|
|
17
|
+
* @param conflictThreshold 矛盾許容閾値(デフォルト: 0.1)
|
|
18
|
+
* @param weights スコアリング重み
|
|
19
|
+
*/
|
|
20
|
+
constructor(conflictThreshold?: number, weights?: ScoringWeights);
|
|
21
|
+
/**
|
|
22
|
+
* 複数レポートをスコアリング
|
|
23
|
+
* @param reports エージェントレポート配列
|
|
24
|
+
* @returns スコア配列
|
|
25
|
+
*/
|
|
26
|
+
scoreReports(reports: AgentReport[]): ReportScore[];
|
|
27
|
+
/**
|
|
28
|
+
* 単一レポートをスコアリング
|
|
29
|
+
* @requirement REQ-1.2.0-WFL-002
|
|
30
|
+
* @param report 対象レポート
|
|
31
|
+
* @param allReports 全レポート(矛盾検出用)
|
|
32
|
+
* @returns スコア
|
|
33
|
+
*/
|
|
34
|
+
scoreReport(report: AgentReport, allReports: AgentReport[]): ReportScore;
|
|
35
|
+
/**
|
|
36
|
+
* 矛盾を検出
|
|
37
|
+
* @param report 対象レポート
|
|
38
|
+
* @param otherReports 他のレポート
|
|
39
|
+
* @returns 矛盾詳細配列
|
|
40
|
+
*/
|
|
41
|
+
detectConflicts(report: AgentReport, otherReports: AgentReport[]): ConflictDetail[];
|
|
42
|
+
/**
|
|
43
|
+
* 一貫性スコアを計算
|
|
44
|
+
* 矛盾の数と深刻度に基づいて減点
|
|
45
|
+
*/
|
|
46
|
+
private calculateConsistencyScore;
|
|
47
|
+
/**
|
|
48
|
+
* ソース信頼性スコアを計算
|
|
49
|
+
*/
|
|
50
|
+
private calculateReliabilityScore;
|
|
51
|
+
/**
|
|
52
|
+
* カバレッジスコアを計算
|
|
53
|
+
* レポートの情報網羅度を評価
|
|
54
|
+
*/
|
|
55
|
+
private calculateCoverageScore;
|
|
56
|
+
/**
|
|
57
|
+
* コンテンツ長を正規化
|
|
58
|
+
*/
|
|
59
|
+
private normalizeContentLength;
|
|
60
|
+
/**
|
|
61
|
+
* エンティティ多様性を推定
|
|
62
|
+
*/
|
|
63
|
+
private estimateEntityDiversity;
|
|
64
|
+
/**
|
|
65
|
+
* 未検証ステートメントをカウント
|
|
66
|
+
*/
|
|
67
|
+
private countUnverifiedStatements;
|
|
68
|
+
/**
|
|
69
|
+
* ステートメントを抽出
|
|
70
|
+
*/
|
|
71
|
+
private extractStatements;
|
|
72
|
+
/**
|
|
73
|
+
* ステートメント間の矛盾を検出
|
|
74
|
+
*/
|
|
75
|
+
private detectStatementConflict;
|
|
76
|
+
/**
|
|
77
|
+
* キーワードを抽出
|
|
78
|
+
*/
|
|
79
|
+
private extractKeywords;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=ReportScorer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReportScorer.d.ts","sourceRoot":"","sources":["../../src/consensus/ReportScorer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,WAAW,EACX,WAAW,EACX,cAAc,EAEd,cAAc,EAEf,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IAEzC;;;;OAIG;gBAED,iBAAiB,GAAE,MAAY,EAC/B,OAAO,GAAE,cAAwC;IAMnD;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE;IAInD;;;;;;OAMG;IACH,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,WAAW;IAoCxE;;;;;OAKG;IACH,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,cAAc,EAAE;IAyBnF;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAgBjC;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAQjC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAwB9B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAO9B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAmB/B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAiBjC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAkBzB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAyE/B;;OAEG;IACH,OAAO,CAAC,eAAe;CAwBxB"}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* KATASHIRO v1.2.0 - ReportScorer
|
|
4
|
+
* レポートのスコアリングと矛盾検出を担当
|
|
5
|
+
* @module @nahisaho/katashiro-orchestrator/consensus
|
|
6
|
+
* @version 1.2.0
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ReportScorer = void 0;
|
|
10
|
+
const types_1 = require("./types");
|
|
11
|
+
/**
|
|
12
|
+
* レポートスコアラー
|
|
13
|
+
* @requirement REQ-1.2.0-WFL-002
|
|
14
|
+
*/
|
|
15
|
+
class ReportScorer {
|
|
16
|
+
conflictThreshold;
|
|
17
|
+
weights;
|
|
18
|
+
/**
|
|
19
|
+
* コンストラクタ
|
|
20
|
+
* @param conflictThreshold 矛盾許容閾値(デフォルト: 0.1)
|
|
21
|
+
* @param weights スコアリング重み
|
|
22
|
+
*/
|
|
23
|
+
constructor(conflictThreshold = 0.1, weights = types_1.DEFAULT_SCORING_WEIGHTS) {
|
|
24
|
+
this.conflictThreshold = conflictThreshold;
|
|
25
|
+
this.weights = weights;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 複数レポートをスコアリング
|
|
29
|
+
* @param reports エージェントレポート配列
|
|
30
|
+
* @returns スコア配列
|
|
31
|
+
*/
|
|
32
|
+
scoreReports(reports) {
|
|
33
|
+
return reports.map((report) => this.scoreReport(report, reports));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 単一レポートをスコアリング
|
|
37
|
+
* @requirement REQ-1.2.0-WFL-002
|
|
38
|
+
* @param report 対象レポート
|
|
39
|
+
* @param allReports 全レポート(矛盾検出用)
|
|
40
|
+
* @returns スコア
|
|
41
|
+
*/
|
|
42
|
+
scoreReport(report, allReports) {
|
|
43
|
+
// 1. 矛盾検出
|
|
44
|
+
const otherReports = allReports.filter((r) => r.reportId !== report.reportId);
|
|
45
|
+
const conflicts = this.detectConflicts(report, otherReports);
|
|
46
|
+
// 2. 一貫性スコア(矛盾が少ないほど高い)
|
|
47
|
+
const consistencyScore = this.calculateConsistencyScore(report, conflicts);
|
|
48
|
+
// 3. ソース信頼性スコア
|
|
49
|
+
const reliabilityScore = this.calculateReliabilityScore(report.sources);
|
|
50
|
+
// 4. カバレッジスコア
|
|
51
|
+
const coverageScore = this.calculateCoverageScore(report);
|
|
52
|
+
// 5. 総合スコア計算
|
|
53
|
+
// Score = (ConsistencyScore * 0.5) + (ReliabilityScore * 0.3) + (CoverageScore * 0.2)
|
|
54
|
+
const totalScore = consistencyScore * this.weights.consistency +
|
|
55
|
+
reliabilityScore * this.weights.reliability +
|
|
56
|
+
coverageScore * this.weights.coverage;
|
|
57
|
+
// 6. ソースURL一覧を抽出
|
|
58
|
+
const sourceUrls = report.sources.map((s) => s.url);
|
|
59
|
+
return {
|
|
60
|
+
reportId: report.reportId,
|
|
61
|
+
consistencyScore,
|
|
62
|
+
reliabilityScore,
|
|
63
|
+
coverageScore,
|
|
64
|
+
totalScore,
|
|
65
|
+
conflicts,
|
|
66
|
+
unverifiedCount: this.countUnverifiedStatements(report),
|
|
67
|
+
sourceUrls,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 矛盾を検出
|
|
72
|
+
* @param report 対象レポート
|
|
73
|
+
* @param otherReports 他のレポート
|
|
74
|
+
* @returns 矛盾詳細配列
|
|
75
|
+
*/
|
|
76
|
+
detectConflicts(report, otherReports) {
|
|
77
|
+
const conflicts = [];
|
|
78
|
+
const statements = this.extractStatements(report.content);
|
|
79
|
+
for (const otherReport of otherReports) {
|
|
80
|
+
const otherStatements = this.extractStatements(otherReport.content);
|
|
81
|
+
for (const stmt of statements) {
|
|
82
|
+
for (const otherStmt of otherStatements) {
|
|
83
|
+
const conflict = this.detectStatementConflict(stmt, report, otherStmt, otherReport);
|
|
84
|
+
if (conflict && conflict.confidence >= this.conflictThreshold) {
|
|
85
|
+
conflicts.push(conflict);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return conflicts;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 一貫性スコアを計算
|
|
94
|
+
* 矛盾の数と深刻度に基づいて減点
|
|
95
|
+
*/
|
|
96
|
+
calculateConsistencyScore(_report, conflicts) {
|
|
97
|
+
if (conflicts.length === 0)
|
|
98
|
+
return 1.0;
|
|
99
|
+
// 深刻度に応じた減点
|
|
100
|
+
const totalPenalty = conflicts.reduce((sum, c) => {
|
|
101
|
+
const severityWeight = c.severity / 5; // 1-5 → 0.2-1.0
|
|
102
|
+
const confidenceWeight = c.confidence;
|
|
103
|
+
return sum + severityWeight * confidenceWeight * 0.1;
|
|
104
|
+
}, 0);
|
|
105
|
+
return Math.max(0, 1.0 - totalPenalty);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* ソース信頼性スコアを計算
|
|
109
|
+
*/
|
|
110
|
+
calculateReliabilityScore(sources) {
|
|
111
|
+
if (sources.length === 0)
|
|
112
|
+
return 0;
|
|
113
|
+
const avgReliability = sources.reduce((sum, s) => sum + (s.reliabilityScore || 0.5), 0) / sources.length;
|
|
114
|
+
return avgReliability;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* カバレッジスコアを計算
|
|
118
|
+
* レポートの情報網羅度を評価
|
|
119
|
+
*/
|
|
120
|
+
calculateCoverageScore(report) {
|
|
121
|
+
const content = report.content;
|
|
122
|
+
// 評価基準
|
|
123
|
+
const metrics = {
|
|
124
|
+
// ソース数(多いほど良い、最大10で1.0)
|
|
125
|
+
sourceCount: Math.min(report.sources.length / 10, 1.0),
|
|
126
|
+
// コンテンツ長(適度な長さが良い、2000-5000文字で最高)
|
|
127
|
+
contentLength: this.normalizeContentLength(content.length),
|
|
128
|
+
// セクション数(構造化されているほど良い)
|
|
129
|
+
sectionCount: (content.match(/^#{1,3}\s/gm) || []).length / 10,
|
|
130
|
+
// エンティティ多様性(人名、組織名、日付などの種類)
|
|
131
|
+
entityDiversity: this.estimateEntityDiversity(content),
|
|
132
|
+
};
|
|
133
|
+
// 重み付き平均
|
|
134
|
+
return (metrics.sourceCount * 0.3 +
|
|
135
|
+
metrics.contentLength * 0.2 +
|
|
136
|
+
metrics.sectionCount * 0.2 +
|
|
137
|
+
metrics.entityDiversity * 0.3);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* コンテンツ長を正規化
|
|
141
|
+
*/
|
|
142
|
+
normalizeContentLength(length) {
|
|
143
|
+
if (length < 1000)
|
|
144
|
+
return length / 1000;
|
|
145
|
+
if (length <= 5000)
|
|
146
|
+
return 1.0;
|
|
147
|
+
if (length <= 10000)
|
|
148
|
+
return 1.0 - (length - 5000) / 10000;
|
|
149
|
+
return 0.5;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* エンティティ多様性を推定
|
|
153
|
+
*/
|
|
154
|
+
estimateEntityDiversity(content) {
|
|
155
|
+
const patterns = [
|
|
156
|
+
/\d{4}年/g, // 年
|
|
157
|
+
/[A-Z][a-z]+/g, // 固有名詞(英語)
|
|
158
|
+
/「[^」]+」/g, // 引用
|
|
159
|
+
/https?:\/\/[^\s]+/g, // URL
|
|
160
|
+
];
|
|
161
|
+
let diversityScore = 0;
|
|
162
|
+
for (const pattern of patterns) {
|
|
163
|
+
const matches = content.match(pattern);
|
|
164
|
+
if (matches && matches.length > 0) {
|
|
165
|
+
diversityScore += Math.min(matches.length / 5, 0.25);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return Math.min(diversityScore, 1.0);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* 未検証ステートメントをカウント
|
|
172
|
+
*/
|
|
173
|
+
countUnverifiedStatements(report) {
|
|
174
|
+
const unverifiedPatterns = [
|
|
175
|
+
/\[要検証\]/g,
|
|
176
|
+
/\[未確認\]/g,
|
|
177
|
+
/\[unverified\]/gi,
|
|
178
|
+
/(要確認)/g,
|
|
179
|
+
];
|
|
180
|
+
let count = 0;
|
|
181
|
+
for (const pattern of unverifiedPatterns) {
|
|
182
|
+
const matches = report.content.match(pattern);
|
|
183
|
+
if (matches)
|
|
184
|
+
count += matches.length;
|
|
185
|
+
}
|
|
186
|
+
return count;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* ステートメントを抽出
|
|
190
|
+
*/
|
|
191
|
+
extractStatements(content) {
|
|
192
|
+
// 文単位で分割
|
|
193
|
+
const sentences = content
|
|
194
|
+
.split(/[。.!?!?]/)
|
|
195
|
+
.map((s) => s.trim())
|
|
196
|
+
.filter((s) => s.length > 10);
|
|
197
|
+
// 数値や日付を含む事実ステートメントを優先
|
|
198
|
+
const factualStatements = sentences.filter((s) => /\d+/.test(s) || // 数値を含む
|
|
199
|
+
/年|月|日/.test(s) || // 日付を含む
|
|
200
|
+
/は|である|された|される/.test(s) // 断定表現
|
|
201
|
+
);
|
|
202
|
+
return factualStatements.slice(0, 50); // 最大50件
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* ステートメント間の矛盾を検出
|
|
206
|
+
*/
|
|
207
|
+
detectStatementConflict(stmt1, report1, stmt2, report2) {
|
|
208
|
+
// 類似度が高いが内容が矛盾するケースを検出
|
|
209
|
+
// 1. キーワード類似度チェック
|
|
210
|
+
const keywords1 = this.extractKeywords(stmt1);
|
|
211
|
+
const keywords2 = this.extractKeywords(stmt2);
|
|
212
|
+
const commonKeywords = keywords1.filter((k) => keywords2.includes(k));
|
|
213
|
+
// 共通キーワードが少なければ関連性なし
|
|
214
|
+
if (commonKeywords.length < 2)
|
|
215
|
+
return null;
|
|
216
|
+
// 2. 数値の矛盾チェック
|
|
217
|
+
const numbers1 = stmt1.match(/\d+(?:\.\d+)?/g) || [];
|
|
218
|
+
const numbers2 = stmt2.match(/\d+(?:\.\d+)?/g) || [];
|
|
219
|
+
if (numbers1.length > 0 && numbers2.length > 0) {
|
|
220
|
+
// 同じ文脈で異なる数値
|
|
221
|
+
const hasConflictingNumbers = numbers1.some((n1) => numbers2.some((n2) => n1 !== n2 && Math.abs(parseFloat(n1) - parseFloat(n2)) > 0.1));
|
|
222
|
+
if (hasConflictingNumbers && commonKeywords.length >= 2) {
|
|
223
|
+
return {
|
|
224
|
+
conflictId: `conflict-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
225
|
+
type: 'inconsistency',
|
|
226
|
+
statement1: {
|
|
227
|
+
text: stmt1,
|
|
228
|
+
source: report1.sources[0]?.url || 'unknown',
|
|
229
|
+
reportId: report1.reportId,
|
|
230
|
+
},
|
|
231
|
+
statement2: {
|
|
232
|
+
text: stmt2,
|
|
233
|
+
source: report2.sources[0]?.url || 'unknown',
|
|
234
|
+
reportId: report2.reportId,
|
|
235
|
+
},
|
|
236
|
+
severity: 3,
|
|
237
|
+
confidence: 0.6 + commonKeywords.length * 0.1,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// 3. 否定表現の矛盾チェック
|
|
242
|
+
const negatives = ['ない', 'なかった', 'ではない', 'not', 'no', '否定'];
|
|
243
|
+
const hasNegative1 = negatives.some((n) => stmt1.includes(n));
|
|
244
|
+
const hasNegative2 = negatives.some((n) => stmt2.includes(n));
|
|
245
|
+
if (hasNegative1 !== hasNegative2 && commonKeywords.length >= 3) {
|
|
246
|
+
return {
|
|
247
|
+
conflictId: `conflict-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
248
|
+
type: 'contradiction',
|
|
249
|
+
statement1: {
|
|
250
|
+
text: stmt1,
|
|
251
|
+
source: report1.sources[0]?.url || 'unknown',
|
|
252
|
+
reportId: report1.reportId,
|
|
253
|
+
},
|
|
254
|
+
statement2: {
|
|
255
|
+
text: stmt2,
|
|
256
|
+
source: report2.sources[0]?.url || 'unknown',
|
|
257
|
+
reportId: report2.reportId,
|
|
258
|
+
},
|
|
259
|
+
severity: 4,
|
|
260
|
+
confidence: 0.5 + commonKeywords.length * 0.1,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* キーワードを抽出
|
|
267
|
+
*/
|
|
268
|
+
extractKeywords(text) {
|
|
269
|
+
// 日本語の名詞っぽいものを抽出(簡易版)
|
|
270
|
+
const words = text
|
|
271
|
+
.replace(/[。、!?「」()\[\]【】]/g, ' ')
|
|
272
|
+
.split(/\s+/)
|
|
273
|
+
.filter((w) => w.length >= 2);
|
|
274
|
+
// ストップワード除去
|
|
275
|
+
const stopWords = [
|
|
276
|
+
'これ',
|
|
277
|
+
'それ',
|
|
278
|
+
'あれ',
|
|
279
|
+
'この',
|
|
280
|
+
'その',
|
|
281
|
+
'ある',
|
|
282
|
+
'いる',
|
|
283
|
+
'する',
|
|
284
|
+
'なる',
|
|
285
|
+
'れる',
|
|
286
|
+
'られる',
|
|
287
|
+
];
|
|
288
|
+
return words.filter((w) => !stopWords.includes(w));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
exports.ReportScorer = ReportScorer;
|
|
292
|
+
//# sourceMappingURL=ReportScorer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReportScorer.js","sourceRoot":"","sources":["../../src/consensus/ReportScorer.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mCAOiB;AAEjB;;;GAGG;AACH,MAAa,YAAY;IACN,iBAAiB,CAAS;IAC1B,OAAO,CAAiB;IAEzC;;;;OAIG;IACH,YACE,oBAA4B,GAAG,EAC/B,UAA0B,+BAAuB;QAEjD,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,OAAsB;QACjC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,MAAmB,EAAE,UAAyB;QACxD,UAAU;QACV,MAAM,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9E,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAE7D,wBAAwB;QACxB,MAAM,gBAAgB,GAAG,IAAI,CAAC,yBAAyB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAE3E,eAAe;QACf,MAAM,gBAAgB,GAAG,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAExE,cAAc;QACd,MAAM,aAAa,GAAG,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAE1D,aAAa;QACb,sF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AAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,SAAS;oBAC5C,QAAQ,EAAE,OAAO,CAAC,QAAQ;iBAC3B;gBACD,QAAQ,EAAE,CAAC;gBACX,UAAU,EAAE,GAAG,GAAG,cAAc,CAAC,MAAM,GAAG,GAAG;aAC9C,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACK,eAAe,CAAC,IAAY;QAClC,sBAAsB;QACtB,MAAM,KAAK,GAAG,IAAI;aACf,OAAO,CAAC,mBAAmB,EAAE,GAAG,CAAC;aACjC,KAAK,CAAC,KAAK,CAAC;aACZ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;QAEhC,YAAY;QACZ,MAAM,SAAS,GAAG;YAChB,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,KAAK;SACN,CAAC;QAEF,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;CACF;AA/UD,oCA+UC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KATASHIRO v1.2.0 - ResearchAgent
|
|
3
|
+
* リサーチパイプラインを実行するエージェント
|
|
4
|
+
* @module @nahisaho/katashiro-orchestrator/consensus
|
|
5
|
+
* @version 1.2.0
|
|
6
|
+
*/
|
|
7
|
+
import { AgentReport, AgentStrategy, IterationContext } from './types';
|
|
8
|
+
interface SearchResult {
|
|
9
|
+
url: string;
|
|
10
|
+
title: string;
|
|
11
|
+
snippet?: string;
|
|
12
|
+
}
|
|
13
|
+
interface ScrapedContent {
|
|
14
|
+
url: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
content: string;
|
|
17
|
+
}
|
|
18
|
+
interface TextAnalysis {
|
|
19
|
+
keywords: string[];
|
|
20
|
+
complexity: number;
|
|
21
|
+
sentiment?: {
|
|
22
|
+
score: number;
|
|
23
|
+
label: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface ExtractedEntities {
|
|
27
|
+
persons: string[];
|
|
28
|
+
organizations: string[];
|
|
29
|
+
locations: string[];
|
|
30
|
+
all: Array<{
|
|
31
|
+
text: string;
|
|
32
|
+
type: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 依存性注入用インターフェース
|
|
37
|
+
*/
|
|
38
|
+
export interface ResearchAgentDependencies {
|
|
39
|
+
searchClient: {
|
|
40
|
+
search: (query: string, options?: {
|
|
41
|
+
maxResults?: number;
|
|
42
|
+
}) => Promise<SearchResult[]>;
|
|
43
|
+
};
|
|
44
|
+
scraper: {
|
|
45
|
+
scrape: (url: string) => Promise<{
|
|
46
|
+
ok: true;
|
|
47
|
+
value: ScrapedContent;
|
|
48
|
+
} | {
|
|
49
|
+
ok: false;
|
|
50
|
+
error: Error;
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
53
|
+
analyzer: {
|
|
54
|
+
analyze: (text: string) => Promise<TextAnalysis>;
|
|
55
|
+
};
|
|
56
|
+
extractor: {
|
|
57
|
+
extract: (text: string) => Promise<ExtractedEntities>;
|
|
58
|
+
};
|
|
59
|
+
reportGenerator: {
|
|
60
|
+
generate: (config: {
|
|
61
|
+
title: string;
|
|
62
|
+
sections: Array<{
|
|
63
|
+
heading: string;
|
|
64
|
+
content: string;
|
|
65
|
+
}>;
|
|
66
|
+
format: string;
|
|
67
|
+
}) => Promise<string>;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* リサーチエージェント
|
|
72
|
+
* @requirement REQ-1.2.0-AGT-001, REQ-1.2.0-AGT-002
|
|
73
|
+
*/
|
|
74
|
+
export declare class ResearchAgent {
|
|
75
|
+
private readonly _agentId;
|
|
76
|
+
private readonly _strategy;
|
|
77
|
+
private readonly deps;
|
|
78
|
+
/**
|
|
79
|
+
* コンストラクタ
|
|
80
|
+
* @param agentId エージェントID
|
|
81
|
+
* @param strategy エージェント戦略
|
|
82
|
+
* @param deps 依存性
|
|
83
|
+
*/
|
|
84
|
+
constructor(agentId: number, deps: ResearchAgentDependencies, strategy?: AgentStrategy);
|
|
85
|
+
/**
|
|
86
|
+
* エージェントIDを取得
|
|
87
|
+
*/
|
|
88
|
+
get agentId(): number;
|
|
89
|
+
/**
|
|
90
|
+
* 戦略を取得
|
|
91
|
+
*/
|
|
92
|
+
get strategy(): AgentStrategy;
|
|
93
|
+
/**
|
|
94
|
+
* リサーチパイプラインを実行
|
|
95
|
+
* @requirement REQ-1.2.0-AGT-001
|
|
96
|
+
* @param context イテレーションコンテキスト
|
|
97
|
+
* @returns エージェントレポート
|
|
98
|
+
*/
|
|
99
|
+
execute(context: IterationContext): Promise<AgentReport>;
|
|
100
|
+
/**
|
|
101
|
+
* エージェント戦略に基づいて検索クエリを構築
|
|
102
|
+
* @requirement REQ-1.2.0-AGT-002
|
|
103
|
+
*/
|
|
104
|
+
private buildSearchQuery;
|
|
105
|
+
/**
|
|
106
|
+
* 検索を実行
|
|
107
|
+
*/
|
|
108
|
+
private search;
|
|
109
|
+
/**
|
|
110
|
+
* URLリストをスクレイピング
|
|
111
|
+
*/
|
|
112
|
+
private scrape;
|
|
113
|
+
/**
|
|
114
|
+
* コンテンツを分析
|
|
115
|
+
*/
|
|
116
|
+
private analyze;
|
|
117
|
+
/**
|
|
118
|
+
* エンティティを抽出
|
|
119
|
+
*/
|
|
120
|
+
private extractEntities;
|
|
121
|
+
/**
|
|
122
|
+
* レポートを生成
|
|
123
|
+
*/
|
|
124
|
+
private generateReport;
|
|
125
|
+
/**
|
|
126
|
+
* ソースURLから信頼性スコアを推定
|
|
127
|
+
* @requirement REQ-1.2.0-WFL-002
|
|
128
|
+
*/
|
|
129
|
+
private estimateSourceReliability;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* デフォルト依存性を作成するファクトリ
|
|
133
|
+
* 実際のKATASHIROモジュールを使用
|
|
134
|
+
*/
|
|
135
|
+
export declare function createDefaultDependencies(): ResearchAgentDependencies;
|
|
136
|
+
export {};
|
|
137
|
+
//# sourceMappingURL=ResearchAgent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResearchAgent.d.ts","sourceRoot":"","sources":["../../src/consensus/ResearchAgent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,WAAW,EACX,aAAa,EACb,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AAGjB,UAAU,YAAY;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,cAAc;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,YAAY;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC9C;AAED,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,GAAG,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE;QACZ,MAAM,EAAE,CAAC,KAAK,EAAE,MAA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