shadok-ai 0.19.19 → 0.19.21
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/README.md +21 -5
- package/dist/config.d.ts +24 -11
- package/dist/config.js +20 -14
- package/dist/config.js.map +1 -1
- package/dist/server.js +13 -9
- package/dist/server.js.map +1 -1
- package/dist/telegram.d.ts +7 -1
- package/dist/telegram.js +99 -16
- package/dist/telegram.js.map +1 -1
- package/dist/tg-guests.d.ts +76 -5
- package/dist/tg-guests.js +87 -17
- package/dist/tg-guests.js.map +1 -1
- package/package.json +1 -1
- package/public/index.html +51 -24
package/dist/tg-guests.js
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
1
|
import { BOOTSTRAP_ADMIN } from "./accounts.js";
|
|
2
2
|
import { isolationRefusal } from "./capability.js";
|
|
3
3
|
import { viewerInGroup } from "./groups.js";
|
|
4
|
-
export const
|
|
4
|
+
export const TG_MODES = ["group", "group+dm", "dm-only"];
|
|
5
|
+
/** Anything unrecognised reads as `group` — the config file is hand-editable,
|
|
6
|
+
* and the classic mode is the one that changes nothing. */
|
|
7
|
+
export function normalizeTgMode(v) {
|
|
8
|
+
return TG_MODES.includes(v) ? v : "group";
|
|
9
|
+
}
|
|
10
|
+
/** The classic instance: a board group, and DMs for their one owner. */
|
|
11
|
+
export const GUEST_SETUP_OFF = { mode: "group", group: null, profile: null };
|
|
12
|
+
/**
|
|
13
|
+
* Does a stranger who writes to the bot get their own agent?
|
|
14
|
+
*
|
|
15
|
+
* The three fields are solidary: a mode that opens the door without a group and
|
|
16
|
+
* a profile to put the person in is a door to nowhere, so it reads as closed.
|
|
17
|
+
*/
|
|
18
|
+
export function guestsOpen(s) {
|
|
19
|
+
return normalizeTgMode(s.mode) !== "group" && !!s.group?.trim() && !!s.profile?.trim();
|
|
20
|
+
}
|
|
21
|
+
/** Is this the DM-only instance — no board, no `/setup`, no owner? */
|
|
22
|
+
export function dmOnly(s) {
|
|
23
|
+
return normalizeTgMode(s.mode) === "dm-only" && guestsOpen(s);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What a GROUP chat is told on a DM-only instance, or null when groups are
|
|
27
|
+
* open.
|
|
28
|
+
*
|
|
29
|
+
* It names no command and no internals: for whoever added the bot to their
|
|
30
|
+
* group, "it only works in private" is the whole truth they can act on.
|
|
31
|
+
*/
|
|
32
|
+
export function groupChatRefusal(s) {
|
|
33
|
+
return dmOnly(s) ? "⛔ I only work in private messages — send me a direct message instead." : null;
|
|
34
|
+
}
|
|
5
35
|
/**
|
|
6
36
|
* May this setup be saved? `null` = yes, else the reason, shown to the admin
|
|
7
37
|
* as-is.
|
|
8
38
|
*
|
|
9
|
-
*
|
|
39
|
+
* Going back to `group` is always allowed, deliberately: the way out must not
|
|
10
40
|
* be gated by the checks that guard the way in, or an operator who wants to
|
|
11
41
|
* close their bot would first have to repair a group someone deleted.
|
|
12
42
|
*
|
|
@@ -21,20 +51,25 @@ export const GUEST_SETUP_OFF = { on: false, group: null, profile: null };
|
|
|
21
51
|
*/
|
|
22
52
|
export function guestEnableRefusal(input) {
|
|
23
53
|
const { want } = input;
|
|
24
|
-
|
|
54
|
+
const wanted = normalizeTgMode(want.mode);
|
|
55
|
+
if (wanted === "group")
|
|
25
56
|
return null;
|
|
26
57
|
// A non-public group cannot even exist outside the privileged deployment, so
|
|
27
58
|
// there is nothing here that could hold a guest.
|
|
28
59
|
const capability = isolationRefusal(input.mode);
|
|
29
60
|
if (capability)
|
|
30
61
|
return capability;
|
|
31
|
-
//
|
|
32
|
-
// there is none — a stranger then gets the pairing refusal, not
|
|
33
|
-
// and that ordering is
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
62
|
+
// In `group+dm` the bot's DMs must already have an OWNER. `dmGate` answers
|
|
63
|
+
// `pair` while there is none — a stranger then gets the pairing refusal, not
|
|
64
|
+
// an agent — and that ordering is what stops the first person through an open
|
|
65
|
+
// door from claiming the bot. Without this check the panel would save a door
|
|
66
|
+
// that cannot open, and nothing anywhere would say so.
|
|
67
|
+
//
|
|
68
|
+
// `dm-only` is exempt because it removes the owner altogether: nobody pairs,
|
|
69
|
+
// so there is no claim left to lose. Requiring a pairing there would be the
|
|
70
|
+
// prerequisite that mode exists to delete.
|
|
71
|
+
if (wanted === "group+dm" && !input.hasOwner)
|
|
72
|
+
return "pair the bot's private messages first (Pair Telegram above), or choose “DMs only”: while the bot has an owner's DM to protect, guests are only recognised once it is paired";
|
|
38
73
|
const groupId = want.group?.trim();
|
|
39
74
|
if (!groupId)
|
|
40
75
|
return "choose the group guests' agents live in";
|
|
@@ -85,13 +120,21 @@ export function withInstanceMember(groups, groupId, member) {
|
|
|
85
120
|
};
|
|
86
121
|
});
|
|
87
122
|
}
|
|
88
|
-
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
123
|
+
/**
|
|
124
|
+
* Pure: a setup with its strings trimmed, and a mode that opens the door only
|
|
125
|
+
* with both halves present — the three fields are solidary, so a mode alone is
|
|
126
|
+
* never a door to nowhere.
|
|
127
|
+
*
|
|
128
|
+
* A half-written open mode falls back to `group` rather than to a closed
|
|
129
|
+
* version of itself: `dm-only` with nowhere to put people would otherwise be an
|
|
130
|
+
* instance that answers neither a group nor a DM, i.e. a bot that silently does
|
|
131
|
+
* nothing. The classic mode is the one that always works.
|
|
132
|
+
*/
|
|
91
133
|
export function normalizeGuestSetup(want) {
|
|
92
134
|
const group = want.group?.trim() || null;
|
|
93
135
|
const profile = want.profile?.trim() || null;
|
|
94
|
-
|
|
136
|
+
const mode = normalizeTgMode(want.mode);
|
|
137
|
+
return { mode: mode !== "group" && (!group || !profile) ? "group" : mode, group, profile };
|
|
95
138
|
}
|
|
96
139
|
/**
|
|
97
140
|
* The whole `PUT /telegram` guest decision, transport-free — the twin of
|
|
@@ -118,9 +161,9 @@ export function guestPatchFlow(input) {
|
|
|
118
161
|
return { ok: false, status: 400, error };
|
|
119
162
|
let groups = [...input.groups];
|
|
120
163
|
const old = input.previous.group?.trim() || null;
|
|
121
|
-
if (input.previous
|
|
164
|
+
if (guestsOpen(input.previous) && old && old !== want.group)
|
|
122
165
|
groups = withInstanceMember(groups, old, false);
|
|
123
|
-
if (want
|
|
166
|
+
if (guestsOpen(want) && want.group)
|
|
124
167
|
groups = withInstanceMember(groups, want.group, true);
|
|
125
168
|
else if (old)
|
|
126
169
|
groups = withInstanceMember(groups, old, false);
|
|
@@ -147,7 +190,7 @@ export function guestSpawnPlan(input) {
|
|
|
147
190
|
if (input.marker !== true || !input.fromBridge || input.resuming)
|
|
148
191
|
return { kind: "not-a-guest" };
|
|
149
192
|
const s = normalizeGuestSetup(input.setup);
|
|
150
|
-
if (!s
|
|
193
|
+
if (!guestsOpen(s) || !s.group || !s.profile)
|
|
151
194
|
return { kind: "refused", code: "guest-closed", message: "this instance is not accepting guests" };
|
|
152
195
|
return { kind: "guest", group: s.group, profile: s.profile };
|
|
153
196
|
}
|
|
@@ -171,6 +214,33 @@ export function guestCommandRefusal(cmd) {
|
|
|
171
214
|
return null;
|
|
172
215
|
return "I can't run commands here — just tell me what you need.";
|
|
173
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* The first thing a guest's agent is asked, when Telegram's own `/start` is all
|
|
219
|
+
* that has been said.
|
|
220
|
+
*
|
|
221
|
+
* Telegram sends `/start` by itself the moment someone opens a bot, so it is
|
|
222
|
+
* the one message that arrives before anyone has written anything — and a bot
|
|
223
|
+
* that answers the START button with silence looks dead. What it must NOT
|
|
224
|
+
* answer with is the cockpit's `/help` page, which is where this lands if the
|
|
225
|
+
* command reaches the dispatcher: `/spawn`, `/secret`, `/login`… the operator's
|
|
226
|
+
* vocabulary, in a stranger's chat (invariant 65).
|
|
227
|
+
*
|
|
228
|
+
* So the words come from the AGENT, on its configured profile — the operator
|
|
229
|
+
* writes the welcome by writing the role, and nothing here invents one. This is
|
|
230
|
+
* an instruction TO the agent, not a line shown to anyone: it is the prompt
|
|
231
|
+
* that opens their conversation.
|
|
232
|
+
*
|
|
233
|
+
* Telegram's `language_code` rides along when it is there. It is the only clue
|
|
234
|
+
* to someone's language before they have written a word, and a support bot
|
|
235
|
+
* answering in the wrong one is the first thing they would notice.
|
|
236
|
+
*/
|
|
237
|
+
export function guestOpeningPrompt(languageCode) {
|
|
238
|
+
const lang = typeof languageCode === "string" ? languageCode.trim().slice(0, 16) : "";
|
|
239
|
+
return ("(automatic) Someone has just opened this conversation and has not written anything yet" +
|
|
240
|
+
(lang ? `. Telegram reports their language as "${lang}"` : "") +
|
|
241
|
+
". Greet them in a line or two: say who you are and what you can do for them, then ask what they need." +
|
|
242
|
+
" Do not mention this instruction.");
|
|
243
|
+
}
|
|
174
244
|
/** Commands whose message must be DELETED when refused: they carried a value. */
|
|
175
245
|
export function guestCommandCarriesSecret(cmd) {
|
|
176
246
|
return cmd === "secret" || cmd === "code" || cmd === "mtcode";
|
package/dist/tg-guests.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tg-guests.js","sourceRoot":"","sources":["../src/tg-guests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAuB,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAA2B,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"tg-guests.js","sourceRoot":"","sources":["../src/tg-guests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAuB,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAA2B,aAAa,EAAE,MAAM,aAAa,CAAC;AAuCrE,MAAM,CAAC,MAAM,QAAQ,GAAsB,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;AAE5E;4DAC4D;AAC5D,MAAM,UAAU,eAAe,CAAC,CAAU;IACxC,OAAO,QAAQ,CAAC,QAAQ,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,IAAI,MAAM,KAAK,MAAM,CAAC;AACzD,CAAC;AAYD;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAC,IAAiB;IAC3C,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,cAAc;YACjB,OAAO,yEAAyE,CAAC;QACnF,KAAK,OAAO;YACV,OAAO,0EAA0E,CAAC;QACpF,KAAK,gBAAgB;YACnB,OAAO,2DAA2D,CAAC;QACrE,KAAK,aAAa;YAChB,OAAO,yEAAyE,CAAC;QACnF,2EAA2E;QAC3E,wEAAwE;QACxE,KAAK,QAAQ,CAAC;QACd,KAAK,eAAe,CAAC;QACrB,KAAK,eAAe;YAClB,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,sBAAsB,CACpC,CAAqF,EACrF,UAAyB;IAEzB,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IACrB,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3D,IAAI,UAAU,IAAI,CAAC,CAAC,KAAK,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC;IACtD,OAAO,CAAC,CAAC,MAAM,CAAC;AAClB,CAAC"}
|
package/package.json
CHANGED
package/public/index.html
CHANGED
|
@@ -4022,6 +4022,7 @@
|
|
|
4022
4022
|
<li>Send <code>/spawn <name></code> (or create a topic by hand): each topic is one agent, also visible here as a tab.</li>
|
|
4023
4023
|
</ol>
|
|
4024
4024
|
<p class="check-hint">Optional: list chat ids under <i>Allowed chats</i> so only they can reach the bot.</p>
|
|
4025
|
+
<p class="check-hint">Only want private messages? Steps 3 to 6 are not for you: pick <b>Open DMs only</b> under <i>Where the bot works</i> — no group, no pairing, and anyone who writes to the bot gets their own agent.</p>
|
|
4025
4026
|
</details>
|
|
4026
4027
|
<div class="tg-pair">
|
|
4027
4028
|
<button id="tgPair" title="Show a one-time code: only the Telegram account that enters it can bind the board group or own the bot's DMs">Pair Telegram</button>
|
|
@@ -4054,8 +4055,12 @@
|
|
|
4054
4055
|
</form>
|
|
4055
4056
|
</div>
|
|
4056
4057
|
<div class="field" id="tgGuestsField">
|
|
4057
|
-
<span class="label">
|
|
4058
|
-
<
|
|
4058
|
+
<span class="label">Where the bot works <span class="check-hint">— a board group, open private messages, or both</span></span>
|
|
4059
|
+
<select id="tgMode" style="width:100%" title="Open private messages give anyone who writes to the bot their own agent">
|
|
4060
|
+
<option value="group">Board group — private messages are yours alone</option>
|
|
4061
|
+
<option value="group+dm">Board group + open DMs — anyone who writes gets their own agent</option>
|
|
4062
|
+
<option value="dm-only">Open DMs only — no board group, nobody pairs</option>
|
|
4063
|
+
</select>
|
|
4059
4064
|
<div style="display:flex;gap:8px;flex-wrap:wrap">
|
|
4060
4065
|
<select id="tgGuestGroup" style="flex:1;min-width:160px" title="The restricted group their agents live in"></select>
|
|
4061
4066
|
<select id="tgGuestProfile" style="flex:1;min-width:160px" title="The profile their agents run on — this is what defines the job"></select>
|
|
@@ -16063,15 +16068,25 @@
|
|
|
16063
16068
|
tgAllowed = s.allowedChats.slice();
|
|
16064
16069
|
const dot = s.running && s.username ? "🟢" : s.tokenError ? "🟠" : "⚪";
|
|
16065
16070
|
const who = s.username ? s.username : s.hasToken ? "(token set)" : "no token";
|
|
16066
|
-
|
|
16071
|
+
// A DM-only instance has no board group and never will: saying "no group
|
|
16072
|
+
// bound" there would describe a step that is refused on purpose.
|
|
16073
|
+
const dmOnlyMode = (s.guests && s.guests.mode) === "dm-only";
|
|
16074
|
+
const grp = dmOnlyMode
|
|
16075
|
+
? " · private messages only"
|
|
16076
|
+
: s.boundGroup ? ` · group ${s.boundGroup.chatId}` : " · no group bound (pair it below)";
|
|
16067
16077
|
const err = s.tokenError ? ` — ${s.tokenError}` : "";
|
|
16068
16078
|
$("tgStatus").textContent = `${dot} ${who}${grp}${err}`;
|
|
16069
16079
|
$("tgUnbind").hidden = !s.boundGroup; // only offer unbind when a group is bound
|
|
16070
|
-
//
|
|
16071
|
-
//
|
|
16072
|
-
|
|
16080
|
+
// Nothing can redeem a code on a DM-only instance (`/setup` is refused
|
|
16081
|
+
// everywhere), so the button that issues one is not offered.
|
|
16082
|
+
$("tgPair").hidden = dmOnlyMode;
|
|
16083
|
+
if (dmOnlyMode) hidePairing();
|
|
16084
|
+
// The guide unfolds on its own until the setup is done (token + bound
|
|
16085
|
+
// group, or a mode that needs no group); once it is, it stays folded unless
|
|
16086
|
+
// opened — decided once per opening of the panel, so saving a token never
|
|
16087
|
+
// folds a guide the user is reading.
|
|
16073
16088
|
if (!$("tgGuide").dataset.auto) {
|
|
16074
|
-
$("tgGuide").open = !(s.hasToken && s.boundGroup);
|
|
16089
|
+
$("tgGuide").open = !(s.hasToken && (s.boundGroup || dmOnlyMode));
|
|
16075
16090
|
$("tgGuide").dataset.auto = "1";
|
|
16076
16091
|
}
|
|
16077
16092
|
$("tgEnabled").checked = s.enabled;
|
|
@@ -16092,13 +16107,13 @@
|
|
|
16092
16107
|
renderGuests(s);
|
|
16093
16108
|
}
|
|
16094
16109
|
|
|
16095
|
-
/**
|
|
16096
|
-
* on. The
|
|
16097
|
-
*
|
|
16110
|
+
/** Where the bot works: the mode, the group guests' agents live in, the
|
|
16111
|
+
* profile they run on. The three are solidary — the server refuses an open
|
|
16112
|
+
* mode with either picker missing, and the panel says so rather than looking
|
|
16098
16113
|
* saved. The group list comes from the server and is per-caller: a group you
|
|
16099
16114
|
* are not a member of is never in it. */
|
|
16100
16115
|
function renderGuests(s) {
|
|
16101
|
-
const g = s.guests || {
|
|
16116
|
+
const g = s.guests || { mode: "group", group: null, profile: null };
|
|
16102
16117
|
const groups = s.guestGroups || [];
|
|
16103
16118
|
const sel = (id, items, value, empty) => {
|
|
16104
16119
|
const el = $(id);
|
|
@@ -16124,16 +16139,27 @@
|
|
|
16124
16139
|
g.profile,
|
|
16125
16140
|
"pick a profile…",
|
|
16126
16141
|
);
|
|
16127
|
-
$("
|
|
16128
|
-
|
|
16129
|
-
//
|
|
16130
|
-
//
|
|
16131
|
-
|
|
16142
|
+
const mode = $("tgMode");
|
|
16143
|
+
mode.value = ["group", "group+dm", "dm-only"].includes(g.mode) ? g.mode : "group";
|
|
16144
|
+
// The prerequisites are stated on the options themselves rather than
|
|
16145
|
+
// discovered through a failed save: an open mode needs a restricted group
|
|
16146
|
+
// to put people in, and `group+dm` also needs the bot's DMs paired — with
|
|
16147
|
+
// no owner, a stranger is asked for a code instead of getting an agent.
|
|
16148
|
+
// "DMs only" is exempt: it removes the owner altogether.
|
|
16149
|
+
for (const o of mode.options) {
|
|
16150
|
+
o.disabled = (o.value !== "group" && !groups.length) || (o.value === "group+dm" && !s.dmOwned);
|
|
16151
|
+
}
|
|
16152
|
+
const WALL =
|
|
16153
|
+
"Their agents live in that group: it runs under its own Unix user, and only its members see those conversations — you included, from this cockpit. Anyone you add to the group can read them.";
|
|
16132
16154
|
$("tgGuestsNote").textContent = !groups.length
|
|
16133
16155
|
? "You need a restricted group first (Groups panel) — and that needs the privileged deployment. Only its members will ever see these conversations."
|
|
16134
|
-
:
|
|
16135
|
-
? "
|
|
16136
|
-
:
|
|
16156
|
+
: mode.value === "dm-only"
|
|
16157
|
+
? "No board group at all: a group that adds the bot is told it only works in private, and /setup is refused everywhere — nobody pairs, and your own chat with the bot becomes a guest conversation like anyone else's. " + WALL
|
|
16158
|
+
: mode.value === "group+dm"
|
|
16159
|
+
? WALL
|
|
16160
|
+
: s.dmOwned
|
|
16161
|
+
? "The classic setup, unchanged: the board group runs your agents, and the bot's private messages are yours alone. Pick the group and the profile other people's agents would use, then change the mode above."
|
|
16162
|
+
: "The classic setup, unchanged. Pair the bot's private messages first (Pair Telegram above) to add open DMs to it — or pick “Open DMs only”, where nobody pairs at all.";
|
|
16137
16163
|
}
|
|
16138
16164
|
// Pairing code: shown once, as issued — the server never returns it again.
|
|
16139
16165
|
let tgPairTimer = null;
|
|
@@ -16925,12 +16951,13 @@
|
|
|
16925
16951
|
$("telegramClose").addEventListener("click", () => { $("telegramOverlay").hidden = true; });
|
|
16926
16952
|
$("telegramOverlay").addEventListener("click", (e) => { if (e.target === $("telegramOverlay")) $("telegramOverlay").hidden = true; });
|
|
16927
16953
|
$("tgEnabled").addEventListener("change", (e) => putTelegram({ enabled: e.target.checked }));
|
|
16928
|
-
//
|
|
16929
|
-
// (no group, no profile, wrong nature
|
|
16930
|
-
//
|
|
16954
|
+
// Where the bot works. Re-reads the server's state whatever happens: a
|
|
16955
|
+
// refused mode (no group, no profile, wrong nature, DMs not paired) must
|
|
16956
|
+
// visibly bounce back to the classic one rather than leave the picker
|
|
16957
|
+
// showing a door that is shut.
|
|
16931
16958
|
async function saveGuests() {
|
|
16932
16959
|
const guests = {
|
|
16933
|
-
|
|
16960
|
+
mode: $("tgMode").value,
|
|
16934
16961
|
group: $("tgGuestGroup").value || null,
|
|
16935
16962
|
profile: $("tgGuestProfile").value || null,
|
|
16936
16963
|
};
|
|
@@ -16943,7 +16970,7 @@
|
|
|
16943
16970
|
if (!r.ok) alert(body.error || "update failed");
|
|
16944
16971
|
loadTelegram();
|
|
16945
16972
|
}
|
|
16946
|
-
for (const id of ["
|
|
16973
|
+
for (const id of ["tgMode", "tgGuestGroup", "tgGuestProfile"]) {
|
|
16947
16974
|
$(id).addEventListener("change", saveGuests);
|
|
16948
16975
|
}
|
|
16949
16976
|
$("tgTokenSave").addEventListener("click", () => {
|