@metatell/bot-cli 0.0.6 → 0.0.7

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,192 +1,112 @@
1
- "use strict";
2
1
  /**
3
2
  * Interactive mode command with rich commands support
4
3
  */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- var __generator = (this && this.__generator) || function (thisArg, body) {
15
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
16
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
17
- function verb(n) { return function (v) { return step([n, v]); }; }
18
- function step(op) {
19
- if (f) throw new TypeError("Generator is already executing.");
20
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
21
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
22
- if (y = 0, t) op = [op[0] & 2, t.value];
23
- switch (op[0]) {
24
- case 0: case 1: t = op; break;
25
- case 4: _.label++; return { value: op[1], done: false };
26
- case 5: _.label++; y = op[1]; op = [0]; continue;
27
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
28
- default:
29
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
30
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
31
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
32
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
33
- if (t[2]) _.ops.pop();
34
- _.trys.pop(); continue;
4
+ import { createInterface } from 'node:readline';
5
+ import { createMetatellClient } from '@metatell/bot-sdk';
6
+ import { CommandParser } from '../utils/commands.js';
7
+ import { parseUrl } from '../utils/url.js';
8
+ export async function startInteractiveMode(url, options) {
9
+ console.log('Starting interactive mode...');
10
+ try {
11
+ const { serverUrl, roomId } = parseUrl(url);
12
+ const client = createMetatellClient({
13
+ serverUrl,
14
+ roomId,
15
+ token: options.token || process.env.METATELL_TOKEN || '',
16
+ username: options.name || 'MetatellCLI',
17
+ debug: options.debug,
18
+ });
19
+ // Event handlers
20
+ client.on('connected', () => {
21
+ console.log('[Connected]');
22
+ });
23
+ client.on('disconnected', (reason) => {
24
+ console.log('[Disconnected]', reason || 'Connection closed');
25
+ });
26
+ // chat-messageイベントを使用して、より詳細なメッセージ情報を取得
27
+ client.on('chat-message', (message) => {
28
+ const mentionInfo = message.mention ? ` (mentions @${message.mention.name})` : '';
29
+ console.log(`[Chat] ${message.from.name}: ${message.text}${mentionInfo}`);
30
+ // デバッグ情報
31
+ if (options.debug) {
32
+ console.log(`[Debug] Sender ID: ${message.from.id}`);
35
33
  }
36
- op = body.call(thisArg, _);
37
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
38
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
39
- }
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.startInteractiveMode = startInteractiveMode;
43
- var node_readline_1 = require("node:readline");
44
- var bot_sdk_1 = require("@metatell/bot-sdk");
45
- var commands_js_1 = require("../utils/commands.js");
46
- var url_js_1 = require("../utils/url.js");
47
- function startInteractiveMode(url, options) {
48
- return __awaiter(this, void 0, void 0, function () {
49
- var _a, serverUrl, roomId, client_1, botInfo_1, rl_1, parser_1, error_1;
50
- var _this = this;
51
- return __generator(this, function (_b) {
52
- switch (_b.label) {
53
- case 0:
54
- console.log('Starting interactive mode...');
55
- _b.label = 1;
56
- case 1:
57
- _b.trys.push([1, 4, , 5]);
58
- _a = (0, url_js_1.parseUrl)(url), serverUrl = _a.serverUrl, roomId = _a.roomId;
59
- client_1 = (0, bot_sdk_1.createMetatellClient)({
60
- serverUrl: serverUrl,
61
- roomId: roomId,
62
- token: options.token || process.env.METATELL_TOKEN || '',
63
- username: options.name || 'MetatellCLI',
64
- debug: options.debug,
65
- });
66
- // Event handlers
67
- client_1.on('connected', function () {
68
- console.log('[Connected]');
69
- });
70
- client_1.on('disconnected', function (reason) {
71
- console.log('[Disconnected]', reason || 'Connection closed');
72
- });
73
- // chat-messageイベントを使用して、より詳細なメッセージ情報を取得
74
- client_1.on('chat-message', function (message) {
75
- var mentionInfo = message.mention ? " (mentions @".concat(message.mention.name, ")") : '';
76
- console.log("[Chat] ".concat(message.from.name, ": ").concat(message.text).concat(mentionInfo));
77
- // デバッグ情報
78
- if (options.debug) {
79
- console.log("[Debug] Sender ID: ".concat(message.from.id));
80
- }
81
- });
82
- return [4 /*yield*/, client_1.getInfo()];
83
- case 2:
84
- botInfo_1 = _b.sent();
85
- client_1.chat.onMessage(function (event) { return __awaiter(_this, void 0, void 0, function () {
86
- return __generator(this, function (_a) {
87
- if (event.mention && event.mention.sessionId === botInfo_1.sessionId) {
88
- console.log("[Mentioned by ".concat(event.from.name, "] ").concat(event.text));
89
- // 自動的に返信
90
- event.reply("Hello ".concat(event.from.name, "! You said: \"").concat(event.text, "\"")).catch(function (err) {
91
- console.error('[Error replying]', err);
92
- });
93
- }
94
- return [2 /*return*/];
95
- });
96
- }); });
97
- client_1.on('user-join', function (user) {
98
- console.log('[User joined]', user.name || 'Anonymous', "(".concat(user.id, ")"));
99
- });
100
- client_1.on('user-leave', function (user) {
101
- console.log('[User left]', user.name || 'Anonymous', "(".concat(user.id, ")"));
102
- });
103
- return [4 /*yield*/, client_1.connect()];
104
- case 3:
105
- _b.sent();
106
- console.log('Connected to room:', roomId);
107
- console.log('Session ID:', client_1.getSessionId());
108
- console.log('Commands: /help for list of commands');
109
- console.log('Type messages to send, or "quit" to exit\n');
110
- rl_1 = (0, node_readline_1.createInterface)({
111
- input: process.stdin,
112
- output: process.stdout,
113
- prompt: '> ',
114
- });
115
- parser_1 = new commands_js_1.CommandParser();
116
- rl_1.on('line', function (line) { return __awaiter(_this, void 0, void 0, function () {
117
- var input, result, error_2, error_3;
118
- return __generator(this, function (_a) {
119
- switch (_a.label) {
120
- case 0:
121
- input = line.trim();
122
- // 特殊なキーワードのみ特別扱い
123
- if (input === 'quit' || input === 'exit') {
124
- rl_1.close();
125
- return [2 /*return*/];
126
- }
127
- if (!input.startsWith('/')) return [3 /*break*/, 5];
128
- _a.label = 1;
129
- case 1:
130
- _a.trys.push([1, 3, , 4]);
131
- return [4 /*yield*/, parser_1.execute(input, client_1)];
132
- case 2:
133
- result = _a.sent();
134
- if (!result.success) {
135
- console.error('[Error]', result.message);
136
- }
137
- return [3 /*break*/, 4];
138
- case 3:
139
- error_2 = _a.sent();
140
- console.error('[Error]', error_2 instanceof Error ? error_2.message : 'Command failed');
141
- return [3 /*break*/, 4];
142
- case 4: return [3 /*break*/, 9];
143
- case 5:
144
- if (!input) return [3 /*break*/, 9];
145
- _a.label = 6;
146
- case 6:
147
- _a.trys.push([6, 8, , 9]);
148
- return [4 /*yield*/, client_1.chat.send(input)];
149
- case 7:
150
- _a.sent();
151
- console.log("[Sent] ".concat(input));
152
- return [3 /*break*/, 9];
153
- case 8:
154
- error_3 = _a.sent();
155
- console.error('[Error sending message]', error_3);
156
- return [3 /*break*/, 9];
157
- case 9:
158
- rl_1.prompt();
159
- return [2 /*return*/];
160
- }
161
- });
162
- }); });
163
- rl_1.on('close', function () { return __awaiter(_this, void 0, void 0, function () {
164
- return __generator(this, function (_a) {
165
- switch (_a.label) {
166
- case 0:
167
- console.log('\nShutting down...');
168
- return [4 /*yield*/, client_1.disconnect()];
169
- case 1:
170
- _a.sent();
171
- process.exit(0);
172
- return [2 /*return*/];
173
- }
174
- });
175
- }); });
176
- // Show initial prompt
177
- rl_1.prompt();
178
- // Handle process termination
179
- process.on('SIGINT', function () {
180
- rl_1.close();
181
- });
182
- return [3 /*break*/, 5];
183
- case 4:
184
- error_1 = _b.sent();
185
- console.error('Failed to start interactive mode:', error_1);
186
- process.exit(1);
187
- return [3 /*break*/, 5];
188
- case 5: return [2 /*return*/];
34
+ });
35
+ // メッセージハンドラーを設定(メンションのみ反応)
36
+ const botInfo = await client.getInfo();
37
+ client.chat.onMessage(async (event) => {
38
+ if (event.mention && event.mention.sessionId === botInfo.sessionId) {
39
+ console.log(`[Mentioned by ${event.from.name}] ${event.text}`);
40
+ // 自動的に返信
41
+ event.reply(`Hello ${event.from.name}! You said: "${event.text}"`).catch((err) => {
42
+ console.error('[Error replying]', err);
43
+ });
44
+ }
45
+ });
46
+ client.on('user-join', (user) => {
47
+ console.log('[User joined]', user.name || 'Anonymous', `(${user.id})`);
48
+ });
49
+ client.on('user-leave', (user) => {
50
+ console.log('[User left]', user.name || 'Anonymous', `(${user.id})`);
51
+ });
52
+ await client.connect();
53
+ console.log('Connected to room:', roomId);
54
+ console.log('Session ID:', client.getSessionId());
55
+ console.log('Commands: /help for list of commands');
56
+ console.log('Type messages to send, or "quit" to exit\n');
57
+ // Setup readline interface
58
+ const rl = createInterface({
59
+ input: process.stdin,
60
+ output: process.stdout,
61
+ prompt: '> ',
62
+ });
63
+ // Command parser
64
+ const parser = new CommandParser();
65
+ rl.on('line', async (line) => {
66
+ const input = line.trim();
67
+ // 特殊なキーワードのみ特別扱い
68
+ if (input === 'quit' || input === 'exit') {
69
+ rl.close();
70
+ return;
71
+ }
72
+ // /で始まる場合のみコマンドとして処理
73
+ if (input.startsWith('/')) {
74
+ try {
75
+ const result = await parser.execute(input, client);
76
+ if (!result.success) {
77
+ console.error('[Error]', result.message);
78
+ }
79
+ }
80
+ catch (error) {
81
+ console.error('[Error]', error instanceof Error ? error.message : 'Command failed');
82
+ }
83
+ }
84
+ else if (input) {
85
+ // それ以外はすべてメッセージとして送信
86
+ try {
87
+ await client.chat.send(input);
88
+ console.log(`[Sent] ${input}`);
89
+ }
90
+ catch (error) {
91
+ console.error('[Error sending message]', error);
92
+ }
189
93
  }
94
+ rl.prompt();
190
95
  });
191
- });
96
+ rl.on('close', async () => {
97
+ console.log('\nShutting down...');
98
+ await client.disconnect();
99
+ process.exit(0);
100
+ });
101
+ // Show initial prompt
102
+ rl.prompt();
103
+ // Handle process termination
104
+ process.on('SIGINT', () => {
105
+ rl.close();
106
+ });
107
+ }
108
+ catch (error) {
109
+ console.error('Failed to start interactive mode:', error);
110
+ process.exit(1);
111
+ }
192
112
  }
package/dist/index.js CHANGED
@@ -1,12 +1,6 @@
1
- "use strict";
2
1
  /**
3
2
  * Main exports for @metatell/cli
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.startInteractiveMode = exports.inspectCommand = exports.connectCommand = void 0;
7
- var connect_js_1 = require("./commands/connect.js");
8
- Object.defineProperty(exports, "connectCommand", { enumerable: true, get: function () { return connect_js_1.connectCommand; } });
9
- var inspect_js_1 = require("./commands/inspect.js");
10
- Object.defineProperty(exports, "inspectCommand", { enumerable: true, get: function () { return inspect_js_1.inspectCommand; } });
11
- var interactive_js_1 = require("./commands/interactive.js");
12
- Object.defineProperty(exports, "startInteractiveMode", { enumerable: true, get: function () { return interactive_js_1.startInteractiveMode; } });
4
+ export { connectCommand } from './commands/connect.js';
5
+ export { inspectCommand } from './commands/inspect.js';
6
+ export { startInteractiveMode } from './commands/interactive.js';
package/dist/types.js CHANGED
@@ -1,5 +1,4 @@
1
- "use strict";
2
1
  /**
3
2
  * CLI type definitions
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
4
+ export {};