aranea-sdk-cli 0.1.4 → 0.3.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.
@@ -0,0 +1,374 @@
1
+ "use strict";
2
+ /**
3
+ * knowledge コマンド - ナレッジベース管理
4
+ *
5
+ * Usage:
6
+ * aranea-sdk knowledge add --title "..." --content "..." --category guide
7
+ * aranea-sdk knowledge search --query "state report"
8
+ * aranea-sdk knowledge list --category api
9
+ * aranea-sdk knowledge get --id <id>
10
+ *
11
+ * @see doc/APPS/araneaSDK/headDesign/20_ARANEA_METATRON_ARCHITECTURE.md
12
+ */
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ var __importDefault = (this && this.__importDefault) || function (mod) {
47
+ return (mod && mod.__esModule) ? mod : { "default": mod };
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.knowledgeCommand = void 0;
51
+ const commander_1 = require("commander");
52
+ const chalk_1 = __importDefault(require("chalk"));
53
+ const ora_1 = __importDefault(require("ora"));
54
+ const axios_1 = __importDefault(require("axios"));
55
+ const fs = __importStar(require("fs"));
56
+ const path = __importStar(require("path"));
57
+ // ============================================================================
58
+ // Config
59
+ // ============================================================================
60
+ const KNOWLEDGE_API_BASE = 'https://asia-northeast1-mobesorder.cloudfunctions.net/araneaSDK_knowledgeManagement';
61
+ // カテゴリ定義
62
+ const CATEGORIES = ['api', 'guide', 'code', 'reference', 'incident', 'tip'];
63
+ // ============================================================================
64
+ // Helper Functions
65
+ // ============================================================================
66
+ /**
67
+ * Firebase Auth トークンを環境変数から取得
68
+ */
69
+ function getAuthToken() {
70
+ return process.env.ARANEA_AUTH_TOKEN || process.env.FIREBASE_AUTH_TOKEN || null;
71
+ }
72
+ /**
73
+ * API呼び出し(Callable形式)
74
+ */
75
+ async function callKnowledgeAPI(action, params, token) {
76
+ const response = await axios_1.default.post(KNOWLEDGE_API_BASE, { data: { action, ...params } }, {
77
+ headers: {
78
+ 'Content-Type': 'application/json',
79
+ Authorization: `Bearer ${token}`,
80
+ },
81
+ });
82
+ if (response.data.error) {
83
+ throw new Error(response.data.error.message || response.data.error);
84
+ }
85
+ return response.data.result;
86
+ }
87
+ /**
88
+ * ナレッジエントリのフォーマット表示
89
+ */
90
+ function formatEntry(entry, detailed = false) {
91
+ const statusIcon = entry.status === 'published'
92
+ ? chalk_1.default.green('●')
93
+ : entry.status === 'draft'
94
+ ? chalk_1.default.yellow('○')
95
+ : chalk_1.default.gray('◌');
96
+ console.log(`${statusIcon} ${chalk_1.default.bold(entry.title)}`);
97
+ console.log(` ID: ${chalk_1.default.gray(entry.id)}`);
98
+ console.log(` Category: ${chalk_1.default.cyan(entry.category)} | Version: ${entry.version}`);
99
+ console.log(` Keywords: ${(entry.keywords || []).slice(0, 5).join(', ')}`);
100
+ if (entry.viewCount !== undefined || entry.usefulCount !== undefined) {
101
+ console.log(` Stats: 👁 ${entry.viewCount || 0} views | 👍 ${entry.usefulCount || 0} useful`);
102
+ }
103
+ if (detailed && entry.content) {
104
+ console.log('');
105
+ console.log(chalk_1.default.gray('─'.repeat(60)));
106
+ console.log(entry.content);
107
+ if (entry.codeExample) {
108
+ console.log('');
109
+ console.log(chalk_1.default.cyan('Code Example:'));
110
+ console.log(chalk_1.default.gray(entry.codeExample));
111
+ }
112
+ console.log(chalk_1.default.gray('─'.repeat(60)));
113
+ }
114
+ console.log('');
115
+ }
116
+ // ============================================================================
117
+ // Commands
118
+ // ============================================================================
119
+ exports.knowledgeCommand = new commander_1.Command('knowledge').description('AraneaMetatron ナレッジベース管理');
120
+ // knowledge add
121
+ exports.knowledgeCommand
122
+ .command('add')
123
+ .description('ナレッジエントリを追加')
124
+ .requiredOption('-t, --title <title>', 'タイトル')
125
+ .requiredOption('-c, --category <category>', `カテゴリ (${CATEGORIES.join('|')})`)
126
+ .option('--content <content>', '本文 (Markdown)')
127
+ .option('-f, --file <path>', 'ファイルから本文を読み込み')
128
+ .option('--code <code>', 'コードサンプル')
129
+ .option('--code-file <path>', 'ファイルからコードサンプルを読み込み')
130
+ .option('-k, --keywords <keywords>', 'キーワード (カンマ区切り)')
131
+ .option('--device-types <types>', '関連デバイスタイプ (カンマ区切り)')
132
+ .option('--status <status>', 'ステータス (draft|published)', 'draft')
133
+ .option('--token <token>', '認証トークン')
134
+ .action(async (options) => {
135
+ try {
136
+ console.log(chalk_1.default.bold('\n=== Knowledge Add ===\n'));
137
+ // 認証トークン
138
+ const token = options.token || getAuthToken();
139
+ if (!token) {
140
+ console.error(chalk_1.default.red('❌ 認証トークンが必要です。--token または ARANEA_AUTH_TOKEN 環境変数を設定'));
141
+ process.exit(1);
142
+ }
143
+ // カテゴリ検証
144
+ if (!CATEGORIES.includes(options.category)) {
145
+ console.error(chalk_1.default.red(`❌ 無効なカテゴリ: ${options.category}`));
146
+ console.error(` 有効なカテゴリ: ${CATEGORIES.join(', ')}`);
147
+ process.exit(1);
148
+ }
149
+ // 本文取得
150
+ let content = options.content || '';
151
+ if (options.file) {
152
+ const filePath = path.resolve(options.file);
153
+ if (!fs.existsSync(filePath)) {
154
+ console.error(chalk_1.default.red(`❌ ファイルが見つかりません: ${filePath}`));
155
+ process.exit(1);
156
+ }
157
+ content = fs.readFileSync(filePath, 'utf-8');
158
+ }
159
+ if (!content) {
160
+ console.error(chalk_1.default.red('❌ --content または --file で本文を指定してください'));
161
+ process.exit(1);
162
+ }
163
+ // コードサンプル取得
164
+ let codeExample = options.code;
165
+ if (options.codeFile) {
166
+ const codePath = path.resolve(options.codeFile);
167
+ if (fs.existsSync(codePath)) {
168
+ codeExample = fs.readFileSync(codePath, 'utf-8');
169
+ }
170
+ }
171
+ // キーワード解析
172
+ const keywords = options.keywords
173
+ ? options.keywords.split(',').map((k) => k.trim())
174
+ : [];
175
+ const deviceTypes = options.deviceTypes
176
+ ? options.deviceTypes.split(',').map((t) => t.trim())
177
+ : [];
178
+ const spinner = (0, ora_1.default)('ナレッジ追加中...').start();
179
+ const result = await callKnowledgeAPI('create', {
180
+ data: {
181
+ title: options.title,
182
+ category: options.category,
183
+ content,
184
+ codeExample,
185
+ keywords,
186
+ relatedDeviceTypes: deviceTypes,
187
+ status: options.status,
188
+ },
189
+ }, token);
190
+ spinner.stop();
191
+ if (result.success) {
192
+ console.log(chalk_1.default.green('✓ ナレッジエントリを追加しました'));
193
+ console.log(` ID: ${result.id}`);
194
+ console.log(` Title: ${options.title}`);
195
+ console.log(` Category: ${options.category}`);
196
+ console.log(` Status: ${options.status}`);
197
+ }
198
+ else {
199
+ console.log(chalk_1.default.red(`✗ 追加失敗: ${result.error}`));
200
+ }
201
+ }
202
+ catch (error) {
203
+ console.error(chalk_1.default.red(`エラー: ${error.message}`));
204
+ process.exit(1);
205
+ }
206
+ });
207
+ // knowledge search
208
+ exports.knowledgeCommand
209
+ .command('search')
210
+ .description('ナレッジを検索')
211
+ .requiredOption('-q, --query <query>', '検索クエリ')
212
+ .option('-c, --category <category>', 'カテゴリフィルタ')
213
+ .option('-l, --limit <limit>', '結果数', '10')
214
+ .option('--token <token>', '認証トークン')
215
+ .action(async (options) => {
216
+ try {
217
+ console.log(chalk_1.default.bold('\n=== Knowledge Search ===\n'));
218
+ const token = options.token || getAuthToken();
219
+ if (!token) {
220
+ console.error(chalk_1.default.red('❌ 認証トークンが必要です'));
221
+ process.exit(1);
222
+ }
223
+ const spinner = (0, ora_1.default)(`"${options.query}" を検索中...`).start();
224
+ const result = await callKnowledgeAPI('search', {
225
+ query: options.query,
226
+ category: options.category,
227
+ limit: parseInt(options.limit, 10),
228
+ }, token);
229
+ spinner.stop();
230
+ if (result.success && result.data) {
231
+ const entries = Array.isArray(result.data) ? result.data : [];
232
+ console.log(chalk_1.default.cyan(`${entries.length} 件見つかりました\n`));
233
+ for (const entry of entries) {
234
+ formatEntry(entry);
235
+ }
236
+ if (entries.length === 0) {
237
+ console.log(chalk_1.default.gray('検索結果がありません'));
238
+ }
239
+ }
240
+ else {
241
+ console.log(chalk_1.default.red(`✗ 検索失敗: ${result.error}`));
242
+ }
243
+ }
244
+ catch (error) {
245
+ console.error(chalk_1.default.red(`エラー: ${error.message}`));
246
+ process.exit(1);
247
+ }
248
+ });
249
+ // knowledge list
250
+ exports.knowledgeCommand
251
+ .command('list')
252
+ .description('ナレッジ一覧を表示')
253
+ .option('-c, --category <category>', 'カテゴリフィルタ')
254
+ .option('-s, --status <status>', 'ステータスフィルタ (draft|published|archived)')
255
+ .option('-l, --limit <limit>', '表示数', '20')
256
+ .option('--token <token>', '認証トークン')
257
+ .action(async (options) => {
258
+ try {
259
+ console.log(chalk_1.default.bold('\n=== Knowledge List ===\n'));
260
+ const token = options.token || getAuthToken();
261
+ if (!token) {
262
+ console.error(chalk_1.default.red('❌ 認証トークンが必要です'));
263
+ process.exit(1);
264
+ }
265
+ const spinner = (0, ora_1.default)('ナレッジ一覧を取得中...').start();
266
+ const result = await callKnowledgeAPI('list', {
267
+ category: options.category,
268
+ status: options.status,
269
+ limit: parseInt(options.limit, 10),
270
+ }, token);
271
+ spinner.stop();
272
+ if (result.success && result.data) {
273
+ const entries = Array.isArray(result.data) ? result.data : [];
274
+ console.log(chalk_1.default.cyan(`${entries.length} 件\n`));
275
+ for (const entry of entries) {
276
+ formatEntry(entry);
277
+ }
278
+ if (entries.length === 0) {
279
+ console.log(chalk_1.default.gray('ナレッジエントリがありません'));
280
+ }
281
+ }
282
+ else {
283
+ console.log(chalk_1.default.red(`✗ 取得失敗: ${result.error}`));
284
+ }
285
+ }
286
+ catch (error) {
287
+ console.error(chalk_1.default.red(`エラー: ${error.message}`));
288
+ process.exit(1);
289
+ }
290
+ });
291
+ // knowledge get
292
+ exports.knowledgeCommand
293
+ .command('get')
294
+ .description('ナレッジエントリを取得')
295
+ .requiredOption('-i, --id <id>', 'エントリID')
296
+ .option('--token <token>', '認証トークン')
297
+ .action(async (options) => {
298
+ try {
299
+ console.log(chalk_1.default.bold('\n=== Knowledge Get ===\n'));
300
+ const token = options.token || getAuthToken();
301
+ if (!token) {
302
+ console.error(chalk_1.default.red('❌ 認証トークンが必要です'));
303
+ process.exit(1);
304
+ }
305
+ const spinner = (0, ora_1.default)('ナレッジを取得中...').start();
306
+ const result = await callKnowledgeAPI('get', { id: options.id }, token);
307
+ spinner.stop();
308
+ if (result.success && result.data) {
309
+ formatEntry(result.data, true);
310
+ }
311
+ else {
312
+ console.log(chalk_1.default.red(`✗ 取得失敗: ${result.error}`));
313
+ }
314
+ }
315
+ catch (error) {
316
+ console.error(chalk_1.default.red(`エラー: ${error.message}`));
317
+ process.exit(1);
318
+ }
319
+ });
320
+ // knowledge delete
321
+ exports.knowledgeCommand
322
+ .command('delete')
323
+ .description('ナレッジエントリを削除 (アーカイブ)')
324
+ .requiredOption('-i, --id <id>', 'エントリID')
325
+ .option('--token <token>', '認証トークン')
326
+ .option('-y, --yes', '確認をスキップ')
327
+ .action(async (options) => {
328
+ try {
329
+ console.log(chalk_1.default.bold('\n=== Knowledge Delete ===\n'));
330
+ const token = options.token || getAuthToken();
331
+ if (!token) {
332
+ console.error(chalk_1.default.red('❌ 認証トークンが必要です'));
333
+ process.exit(1);
334
+ }
335
+ if (!options.yes) {
336
+ console.log(chalk_1.default.yellow(`⚠ エントリ ${options.id} をアーカイブします`));
337
+ console.log(chalk_1.default.gray(' (--yes オプションで確認をスキップ)'));
338
+ // Note: In a real CLI, would use inquirer for confirmation
339
+ }
340
+ const spinner = (0, ora_1.default)('削除中...').start();
341
+ const result = await callKnowledgeAPI('delete', { id: options.id }, token);
342
+ spinner.stop();
343
+ if (result.success) {
344
+ console.log(chalk_1.default.green('✓ ナレッジエントリをアーカイブしました'));
345
+ }
346
+ else {
347
+ console.log(chalk_1.default.red(`✗ 削除失敗: ${result.error}`));
348
+ }
349
+ }
350
+ catch (error) {
351
+ console.error(chalk_1.default.red(`エラー: ${error.message}`));
352
+ process.exit(1);
353
+ }
354
+ });
355
+ // knowledge categories
356
+ exports.knowledgeCommand
357
+ .command('categories')
358
+ .description('利用可能なカテゴリ一覧')
359
+ .action(() => {
360
+ console.log(chalk_1.default.bold('\n=== Knowledge Categories ===\n'));
361
+ const categoryDescriptions = {
362
+ api: 'API仕様・エンドポイント',
363
+ guide: '実装ガイド・チュートリアル',
364
+ code: 'コードサンプル・スニペット',
365
+ reference: 'リファレンス・仕様書',
366
+ incident: 'インシデント・トラブルシューティング',
367
+ tip: 'Tips・ノウハウ',
368
+ };
369
+ for (const cat of CATEGORIES) {
370
+ console.log(` ${chalk_1.default.cyan(cat.padEnd(12))} ${categoryDescriptions[cat]}`);
371
+ }
372
+ console.log('');
373
+ });
374
+ exports.default = exports.knowledgeCommand;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * metatron コマンド - AraneaMetatron AI対話
3
+ *
4
+ * Usage:
5
+ * aranea-sdk metatron ask "State Reportの送信方法は?"
6
+ * aranea-sdk metatron chat # REPLモード
7
+ *
8
+ * @see doc/APPS/araneaSDK/headDesign/20_ARANEA_METATRON_ARCHITECTURE.md
9
+ */
10
+ import { Command } from 'commander';
11
+ export declare const metatronCommand: Command;
12
+ export default metatronCommand;
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ /**
3
+ * metatron コマンド - AraneaMetatron AI対話
4
+ *
5
+ * Usage:
6
+ * aranea-sdk metatron ask "State Reportの送信方法は?"
7
+ * aranea-sdk metatron chat # REPLモード
8
+ *
9
+ * @see doc/APPS/araneaSDK/headDesign/20_ARANEA_METATRON_ARCHITECTURE.md
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || (function () {
28
+ var ownKeys = function(o) {
29
+ ownKeys = Object.getOwnPropertyNames || function (o) {
30
+ var ar = [];
31
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
32
+ return ar;
33
+ };
34
+ return ownKeys(o);
35
+ };
36
+ return function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ })();
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.metatronCommand = void 0;
49
+ const commander_1 = require("commander");
50
+ const chalk_1 = __importDefault(require("chalk"));
51
+ const ora_1 = __importDefault(require("ora"));
52
+ const axios_1 = __importDefault(require("axios"));
53
+ const readline = __importStar(require("readline"));
54
+ // ============================================================================
55
+ // Config
56
+ // ============================================================================
57
+ const METATRON_API_BASE = 'https://asia-northeast1-mobesorder.cloudfunctions.net/araneaSDK_metatronQuery';
58
+ // ============================================================================
59
+ // Helper Functions
60
+ // ============================================================================
61
+ /**
62
+ * Firebase Auth トークンを環境変数から取得
63
+ */
64
+ function getAuthToken() {
65
+ return process.env.ARANEA_AUTH_TOKEN || process.env.FIREBASE_AUTH_TOKEN || null;
66
+ }
67
+ /**
68
+ * Metatron API呼び出し
69
+ */
70
+ async function queryMetatron(query, context, token) {
71
+ const response = await axios_1.default.post(METATRON_API_BASE, { data: { query, context } }, {
72
+ headers: {
73
+ 'Content-Type': 'application/json',
74
+ Authorization: `Bearer ${token}`,
75
+ },
76
+ timeout: 60000, // 60秒タイムアウト
77
+ });
78
+ if (response.data.error) {
79
+ throw new Error(response.data.error.message || response.data.error);
80
+ }
81
+ return response.data.result || response.data;
82
+ }
83
+ /**
84
+ * 回答をフォーマット表示
85
+ */
86
+ function formatAnswer(result) {
87
+ console.log('');
88
+ console.log(chalk_1.default.cyan('📝 Answer:'));
89
+ console.log(chalk_1.default.white(result.answer));
90
+ if (result.codeSnippet) {
91
+ console.log('');
92
+ console.log(chalk_1.default.cyan('💻 Code:'));
93
+ console.log(chalk_1.default.gray('─'.repeat(60)));
94
+ console.log(chalk_1.default.yellow(result.codeSnippet));
95
+ console.log(chalk_1.default.gray('─'.repeat(60)));
96
+ }
97
+ if (result.sources && result.sources.length > 0) {
98
+ console.log('');
99
+ console.log(chalk_1.default.gray(`📚 Sources: ${result.sources.join(', ')}`));
100
+ }
101
+ console.log('');
102
+ }
103
+ // ============================================================================
104
+ // Commands
105
+ // ============================================================================
106
+ exports.metatronCommand = new commander_1.Command('metatron').description('AraneaMetatron AI対話 - AraneaSDK専門アシスタント');
107
+ // metatron ask
108
+ exports.metatronCommand
109
+ .command('ask <question>')
110
+ .description('単発質問')
111
+ .option('--context <context>', 'コンテキスト', 'aranea_sdk_cli')
112
+ .option('--token <token>', '認証トークン')
113
+ .option('--raw', 'JSON出力')
114
+ .action(async (question, options) => {
115
+ try {
116
+ if (!options.raw) {
117
+ console.log(chalk_1.default.bold('\n=== AraneaMetatron ===\n'));
118
+ console.log(chalk_1.default.gray(`Q: ${question}`));
119
+ }
120
+ const token = options.token || getAuthToken();
121
+ if (!token) {
122
+ console.error(chalk_1.default.red('❌ 認証トークンが必要です。--token または ARANEA_AUTH_TOKEN 環境変数を設定'));
123
+ process.exit(1);
124
+ }
125
+ const spinner = options.raw ? null : (0, ora_1.default)('回答生成中...').start();
126
+ const result = await queryMetatron(question, options.context, token);
127
+ spinner?.stop();
128
+ if (options.raw) {
129
+ console.log(JSON.stringify(result, null, 2));
130
+ }
131
+ else {
132
+ formatAnswer(result);
133
+ }
134
+ }
135
+ catch (error) {
136
+ console.error(chalk_1.default.red(`エラー: ${error.message}`));
137
+ process.exit(1);
138
+ }
139
+ });
140
+ // metatron chat (REPL mode)
141
+ exports.metatronCommand
142
+ .command('chat')
143
+ .description('対話モード (REPL)')
144
+ .option('--context <context>', 'コンテキスト', 'aranea_sdk_cli')
145
+ .option('--token <token>', '認証トークン')
146
+ .action(async (options) => {
147
+ console.log(chalk_1.default.bold('\n=== AraneaMetatron Chat ===\n'));
148
+ console.log(chalk_1.default.gray('AraneaSDKについて質問してください。'));
149
+ console.log(chalk_1.default.gray('終了するには "exit" または Ctrl+C を入力\n'));
150
+ const token = options.token || getAuthToken();
151
+ if (!token) {
152
+ console.error(chalk_1.default.red('❌ 認証トークンが必要です。--token または ARANEA_AUTH_TOKEN 環境変数を設定'));
153
+ process.exit(1);
154
+ }
155
+ const rl = readline.createInterface({
156
+ input: process.stdin,
157
+ output: process.stdout,
158
+ });
159
+ const askQuestion = () => {
160
+ rl.question(chalk_1.default.cyan('You: '), async (input) => {
161
+ const query = input.trim();
162
+ if (query.toLowerCase() === 'exit' || query.toLowerCase() === 'quit') {
163
+ console.log(chalk_1.default.gray('\nさようなら!\n'));
164
+ rl.close();
165
+ process.exit(0);
166
+ }
167
+ if (!query) {
168
+ askQuestion();
169
+ return;
170
+ }
171
+ const spinner = (0, ora_1.default)('').start();
172
+ spinner.text = '';
173
+ try {
174
+ const result = await queryMetatron(query, options.context, token);
175
+ spinner.stop();
176
+ console.log('');
177
+ console.log(chalk_1.default.green('Metatron:'), result.answer);
178
+ if (result.codeSnippet) {
179
+ console.log('');
180
+ console.log(chalk_1.default.gray('```'));
181
+ console.log(chalk_1.default.yellow(result.codeSnippet));
182
+ console.log(chalk_1.default.gray('```'));
183
+ }
184
+ console.log('');
185
+ }
186
+ catch (error) {
187
+ spinner.stop();
188
+ console.log(chalk_1.default.red(`Error: ${error.message}`));
189
+ console.log('');
190
+ }
191
+ askQuestion();
192
+ });
193
+ };
194
+ askQuestion();
195
+ });
196
+ // metatron topics
197
+ exports.metatronCommand
198
+ .command('topics')
199
+ .description('対話可能なトピック一覧')
200
+ .action(() => {
201
+ console.log(chalk_1.default.bold('\n=== AraneaMetatron Topics ===\n'));
202
+ const topics = [
203
+ { topic: 'State Report API', example: 'State Reportの送信方法は?' },
204
+ { topic: 'デバイス登録', example: 'デバイス登録のフローを教えて' },
205
+ { topic: 'スキーマ設計', example: 'stateSchemaの設計ガイドは?' },
206
+ { topic: 'MQTT/コマンド', example: 'コマンド送信の仕組みは?' },
207
+ { topic: 'ESP32実装', example: 'ESP32のサンプルコードを見せて' },
208
+ { topic: 'デバイスタイプ', example: '利用可能なデバイスタイプは?' },
209
+ { topic: 'CelestialGlobe', example: 'トポロジーマップの使い方は?' },
210
+ { topic: 'トラブルシューティング', example: '認証エラーの対処法は?' },
211
+ ];
212
+ console.log(chalk_1.default.gray('以下のトピックについて質問できます:\n'));
213
+ for (const { topic, example } of topics) {
214
+ console.log(` ${chalk_1.default.cyan('●')} ${chalk_1.default.bold(topic)}`);
215
+ console.log(` ${chalk_1.default.gray('例:')} ${example}`);
216
+ console.log('');
217
+ }
218
+ console.log(chalk_1.default.gray('使用例:'));
219
+ console.log(chalk_1.default.white(' aranea-sdk metatron ask "State Reportの送信方法は?"'));
220
+ console.log(chalk_1.default.white(' aranea-sdk metatron chat'));
221
+ console.log('');
222
+ });
223
+ // metatron examples
224
+ exports.metatronCommand
225
+ .command('examples')
226
+ .description('質問例を表示')
227
+ .action(() => {
228
+ console.log(chalk_1.default.bold('\n=== AraneaMetatron Examples ===\n'));
229
+ const examples = [
230
+ // 基本的な質問
231
+ 'State Reportの送信方法は?',
232
+ 'デバイス登録に必要なパラメータは?',
233
+ 'CICとは何ですか?',
234
+ // 技術的な質問
235
+ 'stateSchemaにはどんなフィールドを定義できる?',
236
+ 'ESP32でHTTPS通信するサンプルコードは?',
237
+ 'MQTTコマンドの送信方法は?',
238
+ // トラブルシューティング
239
+ 'TID format errorの対処法は?',
240
+ 'CIC認証が失敗する原因は?',
241
+ 'BigQuery同期が失敗した時の対応は?',
242
+ // 運用
243
+ 'デバイスの状態を確認する方法は?',
244
+ 'CelestialGlobeでトポロジーを見る方法は?',
245
+ ];
246
+ console.log(chalk_1.default.gray('Metatronに質問できる例:\n'));
247
+ for (const example of examples) {
248
+ console.log(` ${chalk_1.default.cyan('•')} ${example}`);
249
+ }
250
+ console.log('');
251
+ console.log(chalk_1.default.gray('使用方法:'));
252
+ console.log(chalk_1.default.white(` aranea-sdk metatron ask "${examples[0]}"`));
253
+ console.log('');
254
+ });
255
+ exports.default = exports.metatronCommand;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * mqtt コマンド - MQTT/Pub/Sub コマンド発行・モニタリング
3
+ *
4
+ * P0 機能 (v0.2.x):
5
+ * aranea-sdk mqtt send-command --lacis-id <id> --type relay --params '{"channel":1,"state":true}'
6
+ * aranea-sdk mqtt monitor --lacis-id <id> --timeout 30
7
+ * aranea-sdk mqtt periodic --lacis-id <id> --type ping --interval 5 --count 10
8
+ *
9
+ * Cloud Pub/Sub経由でaraneaDeviceCommandエンドポイントを呼び出す
10
+ *
11
+ * @see doc/APPS/araneaSDK/headDesign/20_ARANEA_METATRON_ARCHITECTURE.md Section 12
12
+ * @see functions/src/araneaDevice/araneaDeviceCommand.ts
13
+ */
14
+ import { Command } from 'commander';
15
+ export declare const mqttCommand: Command;
16
+ export default mqttCommand;