@theokit/gateway 0.19.0 → 0.20.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/CHANGELOG.md +7 -0
- package/README.md +45 -0
- package/dist/index.cjs +313 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +95 -1
- package/dist/index.d.ts +95 -1
- package/dist/index.js +309 -74
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Security } from '@theokit/sdk';
|
|
2
|
+
import { randomInt, randomUUID } from 'crypto';
|
|
3
|
+
import { readFileSync, mkdirSync, writeFileSync, renameSync } from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
2
5
|
|
|
3
6
|
// src/text/fence.ts
|
|
4
7
|
var MAY_FENCE = /^ {0,3}(?:`{3}|~{3})/m;
|
|
@@ -275,17 +278,17 @@ var BasePlatformAdapter = class _BasePlatformAdapter {
|
|
|
275
278
|
* `empty_text`, `not_connected`, then `invalid_channel` when `channel.valid` rejects the id.
|
|
276
279
|
* Returns the refusal, or `undefined` when the message may be sent.
|
|
277
280
|
*/
|
|
278
|
-
refuseUnsendable(out,
|
|
281
|
+
refuseUnsendable(out, check2) {
|
|
279
282
|
const refuse = (code, message) => ({
|
|
280
283
|
ok: false,
|
|
281
284
|
error: { code, message }
|
|
282
285
|
});
|
|
283
286
|
if (out.text.length === 0) return refuse("empty_text", "outbound text is empty");
|
|
284
|
-
if (!
|
|
285
|
-
return refuse("not_connected", `${
|
|
287
|
+
if (!check2.connected) {
|
|
288
|
+
return refuse("not_connected", `${check2.className}.connect() has not succeeded`);
|
|
286
289
|
}
|
|
287
|
-
if (
|
|
288
|
-
return refuse("invalid_channel",
|
|
290
|
+
if (check2.channel !== void 0 && !check2.channel.valid(out.channel.id)) {
|
|
291
|
+
return refuse("invalid_channel", check2.channel.message);
|
|
289
292
|
}
|
|
290
293
|
return void 0;
|
|
291
294
|
}
|
|
@@ -573,6 +576,54 @@ var GatewayConfigurationError = class extends Error {
|
|
|
573
576
|
}
|
|
574
577
|
};
|
|
575
578
|
|
|
579
|
+
// src/channel/config-from-env.ts
|
|
580
|
+
function readValue(env, name) {
|
|
581
|
+
const value = env[name]?.trim();
|
|
582
|
+
return value ? value : void 0;
|
|
583
|
+
}
|
|
584
|
+
function configFromEnv(descriptor, env, prefix = "") {
|
|
585
|
+
const config = {};
|
|
586
|
+
const missing = [];
|
|
587
|
+
const secrets = [];
|
|
588
|
+
for (const field of descriptor.config) {
|
|
589
|
+
if (field.env === void 0) continue;
|
|
590
|
+
const name = prefix + field.env;
|
|
591
|
+
const value = readValue(env, name);
|
|
592
|
+
if (value === void 0) {
|
|
593
|
+
if (field.required) missing.push(name);
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
config[field.key] = value;
|
|
597
|
+
recordSecret(field, value, secrets);
|
|
598
|
+
}
|
|
599
|
+
return { config, missing, secrets };
|
|
600
|
+
}
|
|
601
|
+
function recordSecret(field, value, secrets) {
|
|
602
|
+
if (field.secret && !secrets.includes(value)) secrets.push(value);
|
|
603
|
+
}
|
|
604
|
+
function mismatch(parent, variant, name) {
|
|
605
|
+
throw new GatewayConfigurationError("gateway", {
|
|
606
|
+
code: "platform_mismatch",
|
|
607
|
+
message: `channel ${parent.platform}: variant "${name}" reports platform ${variant.platform}`
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
function unknownVariant(descriptor, name) {
|
|
611
|
+
const valid = Object.keys(descriptor.variants ?? {});
|
|
612
|
+
const given = name === void 0 ? "(none given)" : `"${name}"`;
|
|
613
|
+
throw new GatewayConfigurationError("gateway", {
|
|
614
|
+
code: "unknown_channel_variant",
|
|
615
|
+
message: `channel ${descriptor.platform}: unknown variant ${given}; valid variants: ${valid.length > 0 ? valid.join(", ") : "(none)"}`
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
function selectVariant(descriptor, name) {
|
|
619
|
+
const variants = descriptor.variants ?? {};
|
|
620
|
+
if (name === void 0 && Object.keys(variants).length === 0) return descriptor;
|
|
621
|
+
const variant = name !== void 0 && Object.hasOwn(variants, name) ? variants[name] : void 0;
|
|
622
|
+
if (variant === void 0) return unknownVariant(descriptor, name);
|
|
623
|
+
if (variant.platform !== descriptor.platform) mismatch(descriptor, variant, name ?? "");
|
|
624
|
+
return variant;
|
|
625
|
+
}
|
|
626
|
+
|
|
576
627
|
// src/channel/create-channels.ts
|
|
577
628
|
function isAbsent(value) {
|
|
578
629
|
return value === void 0 || value === null || value === "";
|
|
@@ -696,72 +747,6 @@ var GatewayLifecycleError = class extends Error {
|
|
|
696
747
|
this.code = opts.code;
|
|
697
748
|
}
|
|
698
749
|
};
|
|
699
|
-
|
|
700
|
-
// src/hooks/chat-command.ts
|
|
701
|
-
var LEADING_MENTION = /^(?:<@[^>]+>|@\S+)\s+/;
|
|
702
|
-
var DEFAULT_PREFIXES = ["/"];
|
|
703
|
-
function matchPrefix(text, prefixes) {
|
|
704
|
-
let best;
|
|
705
|
-
for (const p of prefixes) {
|
|
706
|
-
if (p.length > 0 && text.startsWith(p) && (best === void 0 || p.length > best.length)) {
|
|
707
|
-
best = p;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
return best;
|
|
711
|
-
}
|
|
712
|
-
function parseChatCommand(text, options) {
|
|
713
|
-
const body = text.trim().replace(LEADING_MENTION, "");
|
|
714
|
-
const prefix = matchPrefix(body, options?.prefixes ?? DEFAULT_PREFIXES);
|
|
715
|
-
if (prefix === void 0) return void 0;
|
|
716
|
-
const rest = body.slice(prefix.length);
|
|
717
|
-
const m = /^([^\s@]+)(?:@\S+)?(?:\s+([\s\S]*))?$/.exec(rest);
|
|
718
|
-
if (!m?.[1]) return void 0;
|
|
719
|
-
return { name: m[1].toLowerCase(), arg: (m[2] ?? "").trim() };
|
|
720
|
-
}
|
|
721
|
-
function usageOf(c) {
|
|
722
|
-
return c.usage ?? `/${c.name}`;
|
|
723
|
-
}
|
|
724
|
-
function helpText(commands) {
|
|
725
|
-
return commands.map((c) => `${usageOf(c)} - ${c.description}`).join("\n");
|
|
726
|
-
}
|
|
727
|
-
function assertUnique(names) {
|
|
728
|
-
const seen = /* @__PURE__ */ new Set();
|
|
729
|
-
for (const raw of names) {
|
|
730
|
-
const name = raw.toLowerCase();
|
|
731
|
-
if (seen.has(name)) {
|
|
732
|
-
throw new GatewayConfigurationError("gateway", {
|
|
733
|
-
code: "duplicate_command",
|
|
734
|
-
message: `gateway: duplicate_command: ${raw}`,
|
|
735
|
-
detail: raw
|
|
736
|
-
});
|
|
737
|
-
}
|
|
738
|
-
seen.add(name);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
function badArity(c, arg) {
|
|
742
|
-
const mode = c.arg ?? "optional";
|
|
743
|
-
return mode === "none" && arg !== "" || mode === "required" && arg === "";
|
|
744
|
-
}
|
|
745
|
-
function commandHook(commands, options) {
|
|
746
|
-
const helpName = options?.helpCommand === void 0 ? "help" : options.helpCommand;
|
|
747
|
-
assertUnique([...commands.map((c) => c.name), ...helpName === false ? [] : [helpName]]);
|
|
748
|
-
const byName = new Map(commands.map((c) => [c.name.toLowerCase(), c]));
|
|
749
|
-
const help = helpText(commands);
|
|
750
|
-
return {
|
|
751
|
-
name: options?.name ?? "chat-commands",
|
|
752
|
-
async pre_inbound({ event }) {
|
|
753
|
-
const parsed = parseChatCommand(event.text);
|
|
754
|
-
if (!parsed) return void 0;
|
|
755
|
-
if (helpName !== false && parsed.name === helpName.toLowerCase()) {
|
|
756
|
-
return { block: true, message: help };
|
|
757
|
-
}
|
|
758
|
-
const command = byName.get(parsed.name);
|
|
759
|
-
if (!command) return void 0;
|
|
760
|
-
if (badArity(command, parsed.arg)) return { block: true, message: usageOf(command) };
|
|
761
|
-
return command.run(event, parsed.arg);
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
750
|
var UNCOVERED_TABLE = `gateway-qq \`appSecret\` :: a QQ Bot AppSecret, an opaque 32-character string with no prefix or fixed shape. It travels only to the access-token endpoint and into the webhook signature derivation; the adapter never logs it.
|
|
766
751
|
gateway-x \`clientSecret\`, \`refreshToken\`, \`bearerToken\` :: an X OAuth 2.0 client secret, a rotating refresh token and an app bearer token, opaque strings with no fixed prefix. They travel only to the X API in Authorization headers and the token request body, which the adapter never logs.
|
|
767
752
|
gateway-buzz \`token\` :: a Buzz bot token with no fixed shape this package could confirm. It travels only in Authorization headers, which the adapter never logs.
|
|
@@ -845,6 +830,256 @@ function maskSecrets(text, secrets) {
|
|
|
845
830
|
for (const secret of ordered) out = out.split(secret).join("[redacted]");
|
|
846
831
|
return out;
|
|
847
832
|
}
|
|
833
|
+
function senderKey(platform, senderId) {
|
|
834
|
+
return `${platform}:${platform === "email" ? senderId.toLowerCase() : senderId}`;
|
|
835
|
+
}
|
|
836
|
+
var TTL_MS = 36e5;
|
|
837
|
+
var FILE = "pairing.json";
|
|
838
|
+
function unreadable() {
|
|
839
|
+
return new GatewayConfigurationError("gateway", {
|
|
840
|
+
code: "pairing_store_unreadable",
|
|
841
|
+
message: "gateway: pairing_store_unreadable"
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
function load(path) {
|
|
845
|
+
let raw;
|
|
846
|
+
try {
|
|
847
|
+
raw = readFileSync(path, "utf8");
|
|
848
|
+
} catch (e) {
|
|
849
|
+
if (e.code === "ENOENT") return /* @__PURE__ */ new Set();
|
|
850
|
+
throw unreadable();
|
|
851
|
+
}
|
|
852
|
+
let parsed;
|
|
853
|
+
try {
|
|
854
|
+
parsed = JSON.parse(raw);
|
|
855
|
+
} catch {
|
|
856
|
+
throw unreadable();
|
|
857
|
+
}
|
|
858
|
+
const list = parsed?.paired;
|
|
859
|
+
if (!Array.isArray(list) || !list.every((x) => typeof x === "string")) throw unreadable();
|
|
860
|
+
return new Set(list);
|
|
861
|
+
}
|
|
862
|
+
function createFilePairingStore(options) {
|
|
863
|
+
const clock = options.clock ?? Date.now;
|
|
864
|
+
const random = options.random ?? randomInt;
|
|
865
|
+
const path = join(options.dir, FILE);
|
|
866
|
+
const paired = load(path);
|
|
867
|
+
const pending = /* @__PURE__ */ new Map();
|
|
868
|
+
let chain = Promise.resolve();
|
|
869
|
+
const prune = () => {
|
|
870
|
+
const now = clock();
|
|
871
|
+
for (const [code, p] of pending) if (p.expires <= now) pending.delete(code);
|
|
872
|
+
};
|
|
873
|
+
function persist(next) {
|
|
874
|
+
mkdirSync(options.dir, { recursive: true });
|
|
875
|
+
const tmp = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
876
|
+
writeFileSync(tmp, JSON.stringify({ paired: [...next].sort((a, b) => a.localeCompare(b)) }), {
|
|
877
|
+
mode: 384,
|
|
878
|
+
flag: "wx"
|
|
879
|
+
});
|
|
880
|
+
renameSync(tmp, path);
|
|
881
|
+
}
|
|
882
|
+
return {
|
|
883
|
+
issue(platform, senderId) {
|
|
884
|
+
prune();
|
|
885
|
+
for (const [code2, p] of pending) {
|
|
886
|
+
if (senderKey(p.platform, p.senderId) === senderKey(platform, senderId)) return code2;
|
|
887
|
+
}
|
|
888
|
+
let code;
|
|
889
|
+
do {
|
|
890
|
+
code = String(random(1e5, 1e6));
|
|
891
|
+
} while (pending.has(code));
|
|
892
|
+
pending.set(code, { platform, senderId, expires: clock() + TTL_MS });
|
|
893
|
+
return code;
|
|
894
|
+
},
|
|
895
|
+
approve(code) {
|
|
896
|
+
const run = async () => {
|
|
897
|
+
prune();
|
|
898
|
+
const p = pending.get(code);
|
|
899
|
+
if (!p) return { ok: false, reason: "unknown_or_expired" };
|
|
900
|
+
const next = new Set(paired);
|
|
901
|
+
next.add(senderKey(p.platform, p.senderId));
|
|
902
|
+
try {
|
|
903
|
+
persist(next);
|
|
904
|
+
} catch {
|
|
905
|
+
return { ok: false, reason: "write_failed" };
|
|
906
|
+
}
|
|
907
|
+
paired.add(senderKey(p.platform, p.senderId));
|
|
908
|
+
pending.delete(code);
|
|
909
|
+
return { ok: true, platform: p.platform, senderId: p.senderId };
|
|
910
|
+
};
|
|
911
|
+
const result = chain.then(run, run);
|
|
912
|
+
chain = result.catch(() => void 0);
|
|
913
|
+
return result;
|
|
914
|
+
},
|
|
915
|
+
isPaired(platform, senderId) {
|
|
916
|
+
return paired.has(senderKey(platform, senderId));
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// src/hooks/access-policy.ts
|
|
922
|
+
var SILENT = { block: true };
|
|
923
|
+
var DEFAULT_REFUSAL = "Sorry, you are not authorized to use this assistant.";
|
|
924
|
+
function normalize(key) {
|
|
925
|
+
const i = key.indexOf(":");
|
|
926
|
+
return i < 0 ? key : senderKey(key.slice(0, i), key.slice(i + 1));
|
|
927
|
+
}
|
|
928
|
+
function check(keys, isAuth) {
|
|
929
|
+
const out = /* @__PURE__ */ new Set();
|
|
930
|
+
for (const key of keys) {
|
|
931
|
+
const i = key.indexOf(":");
|
|
932
|
+
const platform = i < 0 ? key : key.slice(0, i);
|
|
933
|
+
if (!isAuth(platform)) {
|
|
934
|
+
throw new GatewayConfigurationError("gateway", {
|
|
935
|
+
code: "unauthenticated_owner",
|
|
936
|
+
message: `gateway: unauthenticated_owner: platform ${platform} does not authenticate the sender`,
|
|
937
|
+
detail: platform
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
out.add(normalize(key));
|
|
941
|
+
}
|
|
942
|
+
return out;
|
|
943
|
+
}
|
|
944
|
+
function createAccessPolicyHook(options) {
|
|
945
|
+
if (options.dm === "pairing" && !options.pairing) {
|
|
946
|
+
throw new GatewayConfigurationError("gateway", {
|
|
947
|
+
code: "pairing_store_required",
|
|
948
|
+
message: "gateway: pairing_store_required"
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
const owners = check(options.owners, options.isAuthenticated);
|
|
952
|
+
const allowed = check(options.allowed ?? /* @__PURE__ */ new Set(), options.isAuthenticated);
|
|
953
|
+
const clock = options.clock ?? Date.now;
|
|
954
|
+
const interval = options.refusalIntervalMs ?? 36e5;
|
|
955
|
+
const write = options.write ?? ((line) => process.stderr.write(`${line}
|
|
956
|
+
`));
|
|
957
|
+
const refusal = options.refusalText ?? DEFAULT_REFUSAL;
|
|
958
|
+
const store = options.pairing;
|
|
959
|
+
const refused2 = /* @__PURE__ */ new Map();
|
|
960
|
+
const mayRefuse = (key) => {
|
|
961
|
+
const now = clock();
|
|
962
|
+
for (const [k, t] of refused2) if (now - t >= interval) refused2.delete(k);
|
|
963
|
+
if (refused2.has(key)) return false;
|
|
964
|
+
refused2.set(key, now);
|
|
965
|
+
return true;
|
|
966
|
+
};
|
|
967
|
+
const pairingReply = (event) => {
|
|
968
|
+
const code = store.issue(event.platform, event.sender.id);
|
|
969
|
+
return {
|
|
970
|
+
block: true,
|
|
971
|
+
message: `Your pairing code is ${code}. Ask the owner to send /approve ${code}.`
|
|
972
|
+
};
|
|
973
|
+
};
|
|
974
|
+
const groupDecision = () => options.groups === "open" ? void 0 : SILENT;
|
|
975
|
+
const stranger = (event, key) => {
|
|
976
|
+
if (event.channel.type !== "dm") return groupDecision();
|
|
977
|
+
if (options.dm === "open") return void 0;
|
|
978
|
+
if (options.dm === "disabled" || !mayRefuse(key)) return SILENT;
|
|
979
|
+
if (options.dm === "allowlist") return { block: true, message: refusal };
|
|
980
|
+
return pairingReply(event);
|
|
981
|
+
};
|
|
982
|
+
const ownerMessage = async (text) => {
|
|
983
|
+
const m = /^\/approve\s+(\d{6})\s*$/.exec(text.trim());
|
|
984
|
+
if (!m?.[1]) return void 0;
|
|
985
|
+
if (!store) return { block: true, message: "Pairing is not enabled." };
|
|
986
|
+
const r = await store.approve(m[1]);
|
|
987
|
+
if (r.ok) return { block: true, message: "Paired." };
|
|
988
|
+
return {
|
|
989
|
+
block: true,
|
|
990
|
+
message: r.reason === "write_failed" ? "Saving the pairing failed. Check the storage and send the code again." : "Unknown or expired code."
|
|
991
|
+
};
|
|
992
|
+
};
|
|
993
|
+
const isPaired = (event) => store?.isPaired(event.platform, event.sender.id) === true;
|
|
994
|
+
const decide = async (event) => {
|
|
995
|
+
if (options.passThrough?.(event)) return void 0;
|
|
996
|
+
if (!options.isAuthenticated(event.platform)) return SILENT;
|
|
997
|
+
const key = senderKey(event.platform, event.sender.id);
|
|
998
|
+
if (owners.has(key)) return ownerMessage(event.text);
|
|
999
|
+
if (allowed.has(key) || isPaired(event)) return void 0;
|
|
1000
|
+
return stranger(event, key);
|
|
1001
|
+
};
|
|
1002
|
+
return {
|
|
1003
|
+
name: "access-policy",
|
|
1004
|
+
async pre_inbound({ event }) {
|
|
1005
|
+
try {
|
|
1006
|
+
return await decide(event);
|
|
1007
|
+
} catch (e) {
|
|
1008
|
+
try {
|
|
1009
|
+
write(`access-policy: hook failed: ${redactSecrets(e)}`);
|
|
1010
|
+
} catch {
|
|
1011
|
+
}
|
|
1012
|
+
return SILENT;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// src/hooks/chat-command.ts
|
|
1019
|
+
var LEADING_MENTION = /^(?:<@[^>]+>|@\S+)\s+/;
|
|
1020
|
+
var DEFAULT_PREFIXES = ["/"];
|
|
1021
|
+
function matchPrefix(text, prefixes) {
|
|
1022
|
+
let best;
|
|
1023
|
+
for (const p of prefixes) {
|
|
1024
|
+
if (p.length > 0 && text.startsWith(p) && (best === void 0 || p.length > best.length)) {
|
|
1025
|
+
best = p;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
return best;
|
|
1029
|
+
}
|
|
1030
|
+
function parseChatCommand(text, options) {
|
|
1031
|
+
const body = text.trim().replace(LEADING_MENTION, "");
|
|
1032
|
+
const prefix = matchPrefix(body, options?.prefixes ?? DEFAULT_PREFIXES);
|
|
1033
|
+
if (prefix === void 0) return void 0;
|
|
1034
|
+
const rest = body.slice(prefix.length);
|
|
1035
|
+
const m = /^([^\s@]+)(?:@\S+)?(?:\s+([\s\S]*))?$/.exec(rest);
|
|
1036
|
+
if (!m?.[1]) return void 0;
|
|
1037
|
+
return { name: m[1].toLowerCase(), arg: (m[2] ?? "").trim() };
|
|
1038
|
+
}
|
|
1039
|
+
function usageOf(c) {
|
|
1040
|
+
return c.usage ?? `/${c.name}`;
|
|
1041
|
+
}
|
|
1042
|
+
function helpText(commands) {
|
|
1043
|
+
return commands.map((c) => `${usageOf(c)} - ${c.description}`).join("\n");
|
|
1044
|
+
}
|
|
1045
|
+
function assertUnique(names) {
|
|
1046
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1047
|
+
for (const raw of names) {
|
|
1048
|
+
const name = raw.toLowerCase();
|
|
1049
|
+
if (seen.has(name)) {
|
|
1050
|
+
throw new GatewayConfigurationError("gateway", {
|
|
1051
|
+
code: "duplicate_command",
|
|
1052
|
+
message: `gateway: duplicate_command: ${raw}`,
|
|
1053
|
+
detail: raw
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
seen.add(name);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
function badArity(c, arg) {
|
|
1060
|
+
const mode = c.arg ?? "optional";
|
|
1061
|
+
return mode === "none" && arg !== "" || mode === "required" && arg === "";
|
|
1062
|
+
}
|
|
1063
|
+
function commandHook(commands, options) {
|
|
1064
|
+
const helpName = options?.helpCommand === void 0 ? "help" : options.helpCommand;
|
|
1065
|
+
assertUnique([...commands.map((c) => c.name), ...helpName === false ? [] : [helpName]]);
|
|
1066
|
+
const byName = new Map(commands.map((c) => [c.name.toLowerCase(), c]));
|
|
1067
|
+
const help = helpText(commands);
|
|
1068
|
+
return {
|
|
1069
|
+
name: options?.name ?? "chat-commands",
|
|
1070
|
+
async pre_inbound({ event }) {
|
|
1071
|
+
const parsed = parseChatCommand(event.text);
|
|
1072
|
+
if (!parsed) return void 0;
|
|
1073
|
+
if (helpName !== false && parsed.name === helpName.toLowerCase()) {
|
|
1074
|
+
return { block: true, message: help };
|
|
1075
|
+
}
|
|
1076
|
+
const command = byName.get(parsed.name);
|
|
1077
|
+
if (!command) return void 0;
|
|
1078
|
+
if (badArity(command, parsed.arg)) return { block: true, message: usageOf(command) };
|
|
1079
|
+
return command.run(event, parsed.arg);
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
848
1083
|
|
|
849
1084
|
// src/hooks/executor.ts
|
|
850
1085
|
var HOOK_PHASES = ["pre_inbound", "post_outbound", "on_error"];
|
|
@@ -1802,9 +2037,9 @@ function statusForDeliver(outcomes) {
|
|
|
1802
2037
|
}
|
|
1803
2038
|
|
|
1804
2039
|
// src/webhook/express-server.ts
|
|
1805
|
-
async function loadPeer(
|
|
2040
|
+
async function loadPeer(load2, onMissing) {
|
|
1806
2041
|
try {
|
|
1807
|
-
const mod = await
|
|
2042
|
+
const mod = await load2();
|
|
1808
2043
|
return mod.default ?? mod;
|
|
1809
2044
|
} catch {
|
|
1810
2045
|
onMissing();
|
|
@@ -2031,6 +2266,6 @@ async function dispatch(webhook, adapter, request) {
|
|
|
2031
2266
|
return runDefault(webhook, adapter, request);
|
|
2032
2267
|
}
|
|
2033
2268
|
|
|
2034
|
-
export { BasePlatformAdapter, CREDENTIAL_SHAPES, DEFAULT_WEBHOOK_MAX_BYTES, DeliveryRouter, GatewayConfigurationError, GatewayLifecycleError, GatewayRunner, HookExecutor, SeenIds, SessionRouter, WeixinAdapterBase, bindingStrategy, channelRendering, chunkByGrapheme, chunkText, commandHook, createAgentBindings, createChannels, createWebhookHandler, defaultStrategy, helpText, isAuthenticatedSender, listenerLifecycle, loadPeer, maskSecrets, maskShapes, parseChatCommand, parseFlatXml, rawBodyCapture, redactSecrets, scanFences, splitKeepingRows, statusForDeliver, toDialect, withMediaUnderstanding };
|
|
2269
|
+
export { BasePlatformAdapter, CREDENTIAL_SHAPES, DEFAULT_WEBHOOK_MAX_BYTES, DeliveryRouter, GatewayConfigurationError, GatewayLifecycleError, GatewayRunner, HookExecutor, SeenIds, SessionRouter, WeixinAdapterBase, bindingStrategy, channelRendering, chunkByGrapheme, chunkText, commandHook, configFromEnv, createAccessPolicyHook, createAgentBindings, createChannels, createFilePairingStore, createWebhookHandler, defaultStrategy, helpText, isAuthenticatedSender, listenerLifecycle, loadPeer, maskSecrets, maskShapes, parseChatCommand, parseFlatXml, rawBodyCapture, redactSecrets, scanFences, selectVariant, senderKey, splitKeepingRows, statusForDeliver, toDialect, withMediaUnderstanding };
|
|
2035
2270
|
//# sourceMappingURL=index.js.map
|
|
2036
2271
|
//# sourceMappingURL=index.js.map
|