@nahisaho/katashiro 2.1.0 → 2.1.1

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.
Files changed (2) hide show
  1. package/AGENTS.md +58 -3
  2. package/package.json +1 -1
package/AGENTS.md CHANGED
@@ -81,6 +81,59 @@ import {
81
81
  } from '@nahisaho/katashiro';
82
82
  ```
83
83
 
84
+ ### ⚠️ 重要: 戻り値の型について
85
+
86
+ KATASHIROのAPIには**2種類の戻り値パターン**があります。コード生成時は必ず区別してください。
87
+
88
+ #### 1. 直接値を返すAPI(`isOk()` 不要)
89
+
90
+ 以下のAPIは**直接値を返す**ため、`isOk()` を使用しません:
91
+
92
+ | API | 戻り値の型 | 使用例 |
93
+ |-----|-----------|-------|
94
+ | `WebSearchClient.search()` | `Promise<SearchResult[]>` | `const results = await client.search(query);` |
95
+ | `TextAnalyzer.analyze()` | `Promise<{ keywords, complexity, sentiment, ... }>` | `const analysis = await analyzer.analyze(text);` |
96
+ | `EntityExtractor.extract()` | `Promise<ExtractedEntities>` | `const entities = await extractor.extract(text);` |
97
+ | `SummaryGenerator.generate()` | `Promise<string>` | `const summary = await summarizer.generate(text);` |
98
+ | `ReportGenerator.generate()` | `Promise<string>` | `const report = await reportGen.generate(config);` |
99
+
100
+ ```typescript
101
+ // ✅ 正しい使い方
102
+ const results = await searchClient.search('AI');
103
+ console.log(`${results.length}件の結果`);
104
+
105
+ const analysis = await analyzer.analyze(text);
106
+ console.log(`キーワード: ${analysis.keywords.join(', ')}`);
107
+
108
+ const entities = await extractor.extract(text);
109
+ console.log(`${entities.all.length}個のエンティティ`);
110
+
111
+ const summary = await summarizer.generate(text);
112
+ console.log(`${summary.length}文字の要約`);
113
+ ```
114
+
115
+ #### 2. `Result<T, E>` を返すAPI(`isOk()` 必須)
116
+
117
+ 以下のAPIは**Result型を返す**ため、`isOk()` でチェックが必要です:
118
+
119
+ | API | 戻り値の型 | 使用例 |
120
+ |-----|-----------|-------|
121
+ | `WebScraper.scrape()` | `Promise<Result<ScrapedContent, Error>>` | `if (isOk(page)) { ... }` |
122
+
123
+ ```typescript
124
+ // ✅ 正しい使い方(Result型のみ isOk() を使用)
125
+ const page = await scraper.scrape(url);
126
+ if (isOk(page)) {
127
+ console.log(page.value.content); // .value でアンラップ
128
+ } else {
129
+ console.error(page.error); // .error でエラー取得
130
+ }
131
+
132
+ // ❌ 間違い(直接値を返すAPIに isOk() を使用)
133
+ const results = await searchClient.search('AI');
134
+ // if (isOk(results)) { ... } // エラー!results は配列
135
+ ```
136
+
84
137
  ---
85
138
 
86
139
  ## 📝 課題タイプ別の実装パターン
@@ -109,10 +162,12 @@ async function solveResearchProblem(topic: string) {
109
162
 
110
163
  // 4. エンティティ抽出
111
164
  const extractor = new EntityExtractor();
112
- const allEntities = [];
165
+ const allEntities: Entity[] = [];
113
166
  for (const content of contents) {
114
- const entities = await extractor.extract(content);
115
- allEntities.push(...entities);
167
+ const extracted = await extractor.extract(content);
168
+ // extract() は ExtractedEntities オブジェクトを返す
169
+ // extracted.persons, extracted.organizations, extracted.urls など
170
+ allEntities.push(...extracted.all); // all プロパティで全エンティティ配列にアクセス
116
171
  }
117
172
 
118
173
  // 5. 要約生成
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nahisaho/katashiro",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "KATASHIRO - VS Code Agent Mode向け情報収集・分析・生成システム(オールインワンパッケージ)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",