bazilion 0.2.1 → 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.
- package/dist/cli.js +372 -22
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +18460 -1801
- package/dist/daemon.js.map +1 -1
- package/dist/migrations/0003_agent_telegram.sql +40 -0
- package/dist/migrations/0004_agent_mirror_mode.sql +17 -0
- package/dist/migrations/0005_group_topic_name_format.sql +15 -0
- package/dist/migrations/0006_telegram_acl.sql +18 -0
- package/dist/worker.js +43 -3
- package/dist/worker.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
-- Telegram integration columns. Step 1 of the docs/telegram.md plan adds the
|
|
2
|
+
-- schema only; the bot singleton, polling loop, and routing helpers land in
|
|
3
|
+
-- subsequent steps. None of these columns are populated yet — they sit empty
|
|
4
|
+
-- until the live bot in Step 2 starts persisting topic ids on first traffic.
|
|
5
|
+
--
|
|
6
|
+
-- agents.telegram_topic_id — forum-topic message_thread_id; one topic per
|
|
7
|
+
-- agent. Partial unique index below allows
|
|
8
|
+
-- multiple NULLs (unbound agents) but enforces
|
|
9
|
+
-- one-to-one once an id is written.
|
|
10
|
+
-- agents.telegram_topic_name_locked — sticky bit set when a human renames the
|
|
11
|
+
-- topic in Telegram; once set, bazilion stops
|
|
12
|
+
-- propagating agent/group renames to that topic.
|
|
13
|
+
-- agents.telegram_icon_emoji — per-agent override of the profile-derived
|
|
14
|
+
-- custom-emoji sticker id. Lookup at topic
|
|
15
|
+
-- creation: agents.* → profiles.* → null.
|
|
16
|
+
-- Survives topic delete + recreate, unlike
|
|
17
|
+
-- a customization that only lived in Telegram.
|
|
18
|
+
-- groups.telegram_icon_color — Telegram's 6-color enum slot allocated to
|
|
19
|
+
-- this group on first-traffic. Red is reserved
|
|
20
|
+
-- for the service chat, so groups round-robin
|
|
21
|
+
-- over the remaining 5.
|
|
22
|
+
-- profiles.telegram_icon_emoji — curated default sticker id from
|
|
23
|
+
-- getForumTopicIconStickers, per built-in
|
|
24
|
+
-- profile. Seeded for built-ins, NULL for
|
|
25
|
+
-- custom profiles (which render color-only).
|
|
26
|
+
|
|
27
|
+
ALTER TABLE agents ADD COLUMN telegram_topic_id INTEGER;
|
|
28
|
+
ALTER TABLE agents ADD COLUMN telegram_topic_name_locked INTEGER NOT NULL DEFAULT 0;
|
|
29
|
+
ALTER TABLE agents ADD COLUMN telegram_icon_emoji TEXT;
|
|
30
|
+
|
|
31
|
+
ALTER TABLE groups ADD COLUMN telegram_icon_color INTEGER;
|
|
32
|
+
|
|
33
|
+
ALTER TABLE profiles ADD COLUMN telegram_icon_emoji TEXT;
|
|
34
|
+
|
|
35
|
+
-- Partial unique index: enforces one-to-one mapping between agents and topic
|
|
36
|
+
-- ids without blocking many unbound agents (SQLite treats NULLs as distinct
|
|
37
|
+
-- in unique indexes, but being explicit avoids surprise if that ever changes).
|
|
38
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_agents_telegram_topic_id
|
|
39
|
+
ON agents(telegram_topic_id)
|
|
40
|
+
WHERE telegram_topic_id IS NOT NULL;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- Per-agent Telegram outbound-mirror verbosity.
|
|
2
|
+
--
|
|
3
|
+
-- 'minimal' (default): mirror only the assistant's final message text to
|
|
4
|
+
-- the agent's bound forum topic. Cleanest conversation
|
|
5
|
+
-- feel; what most operators want.
|
|
6
|
+
-- 'verbose': also mirror short tool-call summary lines so the
|
|
7
|
+
-- topic shows the agent's reasoning steps. Helpful
|
|
8
|
+
-- while iterating on a misbehaving agent; noisy in
|
|
9
|
+
-- steady state.
|
|
10
|
+
--
|
|
11
|
+
-- The column has no effect on agents without a bound topic. Step 6 picks
|
|
12
|
+
-- the value up when materializing each ChatFrame; Step 7's CLI + web UI
|
|
13
|
+
-- surfaces let operators flip it per-agent.
|
|
14
|
+
|
|
15
|
+
ALTER TABLE agents
|
|
16
|
+
ADD COLUMN telegram_mirror_mode TEXT NOT NULL DEFAULT 'minimal'
|
|
17
|
+
CHECK (telegram_mirror_mode IN ('minimal','verbose'));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Per-group Telegram forum-topic name template.
|
|
2
|
+
--
|
|
3
|
+
-- NULL (default): bazilion composes topic names the built-in way — bare
|
|
4
|
+
-- agent.name for the `default` group, "<group.slug> › <agent.name>" for every
|
|
5
|
+
-- other group (see lib/telegram/naming.ts:topicNameFor).
|
|
6
|
+
-- Non-NULL: an explicit template rendered with the tokens {agent.name},
|
|
7
|
+
-- {group.name}, {group.slug}. Must contain {agent.name} so each agent in the
|
|
8
|
+
-- group still gets a distinct topic title. Validated on write
|
|
9
|
+
-- (lib/telegram/naming.ts:validateTopicNameFormat).
|
|
10
|
+
--
|
|
11
|
+
-- Changing the template re-renders every bound, non-locked topic in the group
|
|
12
|
+
-- via editForumTopic (lib/telegram/topic-rename.ts:syncGroupTopicNames). Topics
|
|
13
|
+
-- a human has renamed (telegram_topic_name_locked = 1) are left untouched.
|
|
14
|
+
|
|
15
|
+
ALTER TABLE groups ADD COLUMN telegram_topic_name_format TEXT;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- Per-user Telegram allowlist (Phase 7).
|
|
2
|
+
--
|
|
3
|
+
-- Bootstrap model: TOFU (trust-on-first-use). While this table is empty the
|
|
4
|
+
-- bot is open; the first user to message it is auto-added as 'owner' and
|
|
5
|
+
-- enforcement begins immediately after. Scope: FLAT — an allowlisted user can
|
|
6
|
+
-- do everything (commands + agent chat); anyone not on the list is ignored.
|
|
7
|
+
--
|
|
8
|
+
-- role: 'owner' can manage the allowlist (/allow, /deny) and cannot be removed;
|
|
9
|
+
-- 'member' can use the bot but not manage who else can. At least one owner must
|
|
10
|
+
-- always remain (enforced in the repo + routes).
|
|
11
|
+
|
|
12
|
+
CREATE TABLE IF NOT EXISTS telegram_allowed_users (
|
|
13
|
+
user_id INTEGER PRIMARY KEY,
|
|
14
|
+
username TEXT,
|
|
15
|
+
label TEXT,
|
|
16
|
+
role TEXT NOT NULL DEFAULT 'member' CHECK (role IN ('owner','member')),
|
|
17
|
+
added_at INTEGER NOT NULL
|
|
18
|
+
);
|
package/dist/worker.js
CHANGED
|
@@ -418,6 +418,36 @@ var SERVICES = [
|
|
|
418
418
|
placeholder: "https://searxng.example.com"
|
|
419
419
|
}
|
|
420
420
|
]
|
|
421
|
+
},
|
|
422
|
+
// --- External integrations (chat bridges, etc) ---
|
|
423
|
+
// Each integration has its own dedicated /config/integrations/* page with
|
|
424
|
+
// workflow-specific UI (preflight health, setup wizard, …). The fields
|
|
425
|
+
// here exist so the keys are allowlisted in the config/secrets stores and
|
|
426
|
+
// surfaced through the generic `PUT /api/config/fields/:envVar` endpoint.
|
|
427
|
+
// Daemon-managed internal state keys (watermarks, derived topic ids) live
|
|
428
|
+
// in repos/config.ts:INTERNAL_CONFIG_KEYS instead, since the user never
|
|
429
|
+
// edits them.
|
|
430
|
+
{
|
|
431
|
+
id: "telegram",
|
|
432
|
+
displayName: "Telegram",
|
|
433
|
+
category: "integration",
|
|
434
|
+
hint: "Forum-supergroup bot for talking to your agents from a phone",
|
|
435
|
+
fields: [
|
|
436
|
+
{
|
|
437
|
+
envVar: "TELEGRAM_BOT_TOKEN",
|
|
438
|
+
kind: "secret",
|
|
439
|
+
label: "Bot token",
|
|
440
|
+
placeholder: "1234567890:ABC...",
|
|
441
|
+
description: "Get one from @BotFather \u2192 /newbot. Disable Privacy Mode in Bot Settings."
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
envVar: "TELEGRAM_CHAT_ID",
|
|
445
|
+
kind: "config",
|
|
446
|
+
label: "Supergroup chat ID",
|
|
447
|
+
placeholder: "-1001234567890",
|
|
448
|
+
description: "Numeric id of the forum-enabled supergroup the bot is admin in."
|
|
449
|
+
}
|
|
450
|
+
]
|
|
421
451
|
}
|
|
422
452
|
];
|
|
423
453
|
var FIELD_INDEX = (() => {
|
|
@@ -431,9 +461,19 @@ var FIELD_INDEX = (() => {
|
|
|
431
461
|
})();
|
|
432
462
|
|
|
433
463
|
// ../daemon/src/core/repos/config.ts
|
|
434
|
-
var
|
|
435
|
-
|
|
436
|
-
|
|
464
|
+
var INTERNAL_CONFIG_KEYS = [
|
|
465
|
+
// Telegram (step 2+): polling watermark + derived topic/message ids.
|
|
466
|
+
"TELEGRAM_LAST_UPDATE_ID",
|
|
467
|
+
"TELEGRAM_SERVICE_TOPIC_ID",
|
|
468
|
+
"TELEGRAM_DIRECTORY_MESSAGE_ID",
|
|
469
|
+
// Phase 5: proposed new chat id after a migrate_to_chat_id event, pending
|
|
470
|
+
// operator confirmation via POST /api/config/telegram/reconnect.
|
|
471
|
+
"TELEGRAM_MIGRATED_CHAT_ID"
|
|
472
|
+
];
|
|
473
|
+
var CONFIG_KEYS = [
|
|
474
|
+
...SERVICES.flatMap((s) => s.fields.filter((f) => f.kind === "config").map((f) => f.envVar)),
|
|
475
|
+
...INTERNAL_CONFIG_KEYS
|
|
476
|
+
];
|
|
437
477
|
var CONFIG_KEY_SET = new Set(CONFIG_KEYS);
|
|
438
478
|
|
|
439
479
|
// ../daemon/src/core/repos/messages.ts
|