botql 1.0.2 → 1.2.2

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/createBot.js ADDED
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * createBot.js — ponto de entrada do BotQL.
5
+ *
6
+ * Lê um ficheiro .sql (com suporte a IMPORT), cria o interpreter, liga os
7
+ * connectors reais das plataformas usadas via CONNECT, corre ON START e
8
+ * fica pronto a receber mensagens.
9
+ *
10
+ * Uso:
11
+ * node createBot.js caminho/para/bot.sql
12
+ *
13
+ * Uso programático:
14
+ * const { createBot } = require('./createBot.js');
15
+ * const bot = await createBot('bot.sql');
16
+ * await bot.receiveMessage('+244900000000', 'quero comprar');
17
+ */
18
+
19
+ const path = require('path');
20
+ const { BotQLInterpreter } = require('./botql.js');
21
+ const { ConnectorRegistry, attachConnectors } = require('./Connectors.js');
22
+ const { SQLiteDatabase } = require('./Database.js');
23
+ const { attachTerminalUI } = require('./Terminal.js');
24
+
25
+ /**
26
+ * @param {string} sqlFilePath Caminho do ficheiro .sql principal do bot.
27
+ * @param {object} options
28
+ * @param {string} [options.dbPath] Caminho do ficheiro .sqlite. Sem isto,
29
+ * usa MemoryDatabase (sem persistência), que é o omisso do interpreter.
30
+ * @param {string} [options.connectorsPath] Caminho alternativo para o JSON
31
+ * de connectors. Por omissão usa o Connectors.json ao lado deste ficheiro.
32
+ * @param {boolean} [options.autoStart] Corre ON START automaticamente (omissão: true).
33
+ * @param {boolean} [options.terminalUI] Liga o spinner de terminal (Terminal.js)
34
+ * ao onThinking/onReply/onForward/onSend que ainda não tiverem sido definidos
35
+ * pelos connectors reais (omissão: true). Só tem efeito em Node — em
36
+ * browser/WebView não faz nada.
37
+ */
38
+ async function createBot(sqlFilePath, options = {}) {
39
+ const interpreterOptions = {};
40
+ if (options.dbPath) {
41
+ interpreterOptions.db = new SQLiteDatabase(options.dbPath);
42
+ }
43
+
44
+ const bot = BotQLInterpreter.fromFile(sqlFilePath, interpreterOptions);
45
+
46
+ const registry = new ConnectorRegistry(
47
+ options.connectorsPath || path.join(__dirname, 'Connectors.json')
48
+ );
49
+ attachConnectors(bot, registry);
50
+
51
+ // Depois de attachConnectors, nunca antes: assim o spinner só preenche
52
+ // onReply/onForward/onSend quando NÃO há connector real ligado (ex: bot
53
+ // sem CONNECT nenhum, só a testar localmente) — com connector real, essas
54
+ // respostas já vão para a plataforma verdadeira, e o Terminal.js respeita
55
+ // isso e não lhes toca (ver Terminal.js, só substitui o que estiver null).
56
+ if (options.terminalUI !== false) {
57
+ attachTerminalUI(bot);
58
+ }
59
+
60
+ if (options.autoStart !== false) {
61
+ await bot.start();
62
+ }
63
+
64
+ return bot;
65
+ }
66
+
67
+ // Execução direta: node createBot.js caminho/bot.sql
68
+ if (require.main === module) {
69
+ const sqlFilePath = process.argv[2];
70
+ if (!sqlFilePath) {
71
+ console.error('Uso: node createBot.js caminho/para/bot.sql');
72
+ process.exit(1);
73
+ }
74
+
75
+ createBot(sqlFilePath)
76
+ .then((bot) => {
77
+ console.log(`BotQL: bot "${bot.botName || '(sem nome)'}" iniciado.`);
78
+ if (!bot.running) {
79
+ console.log('Aviso: o ficheiro não tem "RUN BOT" — o bot foi carregado mas não marcado como em execução.');
80
+ }
81
+ })
82
+ .catch((err) => {
83
+ console.error(err.message);
84
+ process.exit(1);
85
+ });
86
+ }
87
+
88
+ module.exports = { createBot };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "botql",
3
- "version": "1.0.2",
3
+ "version": "1.2.2",
4
4
  "description": "BotQL is a simple, SQL-inspired rules language for creating bots without writing traditional code.",
5
5
  "main": "botql.js",
6
6
  "browser": "botql.browser.js",
@@ -8,7 +8,7 @@
8
8
  "botql.js",
9
9
  "botql.browser.js",
10
10
  "botql-mode.js",
11
- "Bootstrap.js",
11
+ "createBot.js",
12
12
  "Parser.js",
13
13
  "Database.js",
14
14
  "RAG.js",
@@ -16,6 +16,7 @@
16
16
  "Connectors.js",
17
17
  "Connectors.json",
18
18
  "connectors/",
19
+ "Terminal.js",
19
20
  "README.md",
20
21
  "LICENSE"
21
22
  ],
package/Bootstrap.js DELETED
@@ -1,74 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Bootstrap.js — ponto de entrada do BotQL.
5
- *
6
- * Lê um ficheiro .sql (com suporte a IMPORT), cria o interpreter, liga os
7
- * connectors reais das plataformas usadas via CONNECT, corre ON START e
8
- * fica pronto a receber mensagens.
9
- *
10
- * Uso:
11
- * node Bootstrap.js caminho/para/bot.sql
12
- *
13
- * Uso programático:
14
- * const { bootstrap } = require('./Bootstrap.js');
15
- * const bot = await bootstrap('bot.sql');
16
- * await bot.receiveMessage('+244900000000', 'quero comprar');
17
- */
18
-
19
- const path = require('path');
20
- const { BotQLInterpreter } = require('./botql.js');
21
- const { ConnectorRegistry, attachConnectors } = require('./Connectors.js');
22
- const { SQLiteDatabase } = require('./Database.js');
23
-
24
- /**
25
- * @param {string} sqlFilePath Caminho do ficheiro .sql principal do bot.
26
- * @param {object} options
27
- * @param {string} [options.dbPath] Caminho do ficheiro .sqlite. Sem isto,
28
- * usa MemoryDatabase (sem persistência), que é o omisso do interpreter.
29
- * @param {string} [options.connectorsPath] Caminho alternativo para o JSON
30
- * de connectors. Por omissão usa o Connectors.json ao lado deste ficheiro.
31
- * @param {boolean} [options.autoStart] Corre ON START automaticamente (omissão: true).
32
- */
33
- async function bootstrap(sqlFilePath, options = {}) {
34
- const interpreterOptions = {};
35
- if (options.dbPath) {
36
- interpreterOptions.db = new SQLiteDatabase(options.dbPath);
37
- }
38
-
39
- const bot = BotQLInterpreter.fromFile(sqlFilePath, interpreterOptions);
40
-
41
- const registry = new ConnectorRegistry(
42
- options.connectorsPath || path.join(__dirname, 'Connectors.json')
43
- );
44
- attachConnectors(bot, registry);
45
-
46
- if (options.autoStart !== false) {
47
- await bot.start();
48
- }
49
-
50
- return bot;
51
- }
52
-
53
- // Execução direta: node Bootstrap.js caminho/bot.sql
54
- if (require.main === module) {
55
- const sqlFilePath = process.argv[2];
56
- if (!sqlFilePath) {
57
- console.error('Uso: node Bootstrap.js caminho/para/bot.sql');
58
- process.exit(1);
59
- }
60
-
61
- bootstrap(sqlFilePath)
62
- .then((bot) => {
63
- console.log(`BotQL: bot "${bot.botName || '(sem nome)'}" iniciado.`);
64
- if (!bot.running) {
65
- console.log('Aviso: o ficheiro não tem "RUN BOT" — o bot foi carregado mas não marcado como em execução.');
66
- }
67
- })
68
- .catch((err) => {
69
- console.error(err.message);
70
- process.exit(1);
71
- });
72
- }
73
-
74
- module.exports = { bootstrap };