@vellumai/assistant 0.10.3-dev.202606291939.024f27f → 0.10.3-dev.202606292136.ce8bf33
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/bun.lock +31 -0
- package/package.json +4 -1
- package/src/__tests__/skill-docs-sync-guard.test.ts +34 -0
- package/src/config/bundled-skills/AGENTS.md +11 -0
- package/src/messaging/providers/__tests__/transport-dispatch.test.ts +1 -0
- package/src/messaging/providers/telegram-bot/api.ts +17 -3
- package/src/messaging/providers/telegram-bot/render.test.ts +146 -0
- package/src/messaging/providers/telegram-bot/render.ts +292 -0
- package/src/messaging/providers/telegram-bot/send.test.ts +197 -0
- package/src/messaging/providers/telegram-bot/send.ts +69 -1
- package/src/messaging/providers/telegram-bot/transport.ts +10 -1
package/bun.lock
CHANGED
|
@@ -29,8 +29,10 @@
|
|
|
29
29
|
"diff": "8.0.4",
|
|
30
30
|
"dotenv": "17.3.1",
|
|
31
31
|
"drizzle-orm": "0.45.2",
|
|
32
|
+
"hast-util-to-html": "9.0.5",
|
|
32
33
|
"jszip": "3.10.1",
|
|
33
34
|
"marked": "18.0.0",
|
|
35
|
+
"mdast-util-to-hast": "13.2.1",
|
|
34
36
|
"minimatch": "10.2.4",
|
|
35
37
|
"openai": "6.29.0",
|
|
36
38
|
"pino": "9.14.0",
|
|
@@ -55,6 +57,7 @@
|
|
|
55
57
|
"devDependencies": {
|
|
56
58
|
"@microsoft/api-extractor": "7.58.8",
|
|
57
59
|
"@types/bun": "1.3.10",
|
|
60
|
+
"@types/hast": "3.0.4",
|
|
58
61
|
"@types/mdast": "4.0.4",
|
|
59
62
|
"@types/node": "25.5.0",
|
|
60
63
|
"@types/semver": "7.5.8",
|
|
@@ -422,6 +425,8 @@
|
|
|
422
425
|
|
|
423
426
|
"@types/estree": ["@types/estree@1.0.9", "", {}, "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg=="],
|
|
424
427
|
|
|
428
|
+
"@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="],
|
|
429
|
+
|
|
425
430
|
"@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="],
|
|
426
431
|
|
|
427
432
|
"@types/mdast": ["@types/mdast@4.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA=="],
|
|
@@ -484,6 +489,8 @@
|
|
|
484
489
|
|
|
485
490
|
"@typescript/native-preview-win32-x64": ["@typescript/native-preview-win32-x64@7.0.0-dev.20260624.1", "", { "os": "win32", "cpu": "x64" }, "sha512-WaZ+ue63NgB2j/lqjirfevh/TqcsCxSqnKhGGiRnlxHyYIBcoq+x7KngyEnyGIaywJE1PcFeXA+2EMSIPlSEiQ=="],
|
|
486
491
|
|
|
492
|
+
"@ungap/structured-clone": ["@ungap/structured-clone@1.3.2", "", {}, "sha512-5jsZFwgR5rTdKwidH9Qmat75RKwqfpKlWWB1frDkljN127mwqBu8K0PYo7/hFpF03IEJpfVPpCQDY/eDx3iHvA=="],
|
|
493
|
+
|
|
487
494
|
"@vellumai/ces-client": ["@vellumai/ces-client@file:../packages/ces-client", { "dependencies": { "@vellumai/service-contracts": "file:../service-contracts" }, "devDependencies": { "@types/bun": "1.2.4", "typescript": "5.7.3" } }],
|
|
488
495
|
|
|
489
496
|
"@vellumai/credential-storage": ["@vellumai/credential-storage@file:../packages/credential-storage", { "devDependencies": { "@types/bun": "1.3.10", "typescript": "5.9.3" } }],
|
|
@@ -584,6 +591,10 @@
|
|
|
584
591
|
|
|
585
592
|
"character-entities": ["character-entities@2.0.2", "", {}, "sha512-shx7oQ0Awen/BRIdkjkvz54PnEEI/EjwXDSIZp86/KKdbafHh1Df/RYGBhn4hbe2+uKC9FnT5UCEdyPz3ai9hQ=="],
|
|
586
593
|
|
|
594
|
+
"character-entities-html4": ["character-entities-html4@2.1.0", "", {}, "sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA=="],
|
|
595
|
+
|
|
596
|
+
"character-entities-legacy": ["character-entities-legacy@3.0.0", "", {}, "sha512-RpPp0asT/6ufRm//AJVwpViZbGM/MkjQFxJccQRHmISF/22NBtsHqAWmL+/pmkPWoIUJdWyeVleTl1wydHATVQ=="],
|
|
597
|
+
|
|
587
598
|
"cjs-module-lexer": ["cjs-module-lexer@2.2.0", "", {}, "sha512-4bHTS2YuzUvtoLjdy+98ykbNB5jS0+07EvFNXerqZQJ89F7DI6ET7OQo/HJuW6K0aVsKA9hj9/RVb2kQVOrPDQ=="],
|
|
588
599
|
|
|
589
600
|
"cli-cursor": ["cli-cursor@3.1.0", "", { "dependencies": { "restore-cursor": "^3.1.0" } }, "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw=="],
|
|
@@ -598,6 +609,8 @@
|
|
|
598
609
|
|
|
599
610
|
"colorette": ["colorette@2.0.20", "", {}, "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w=="],
|
|
600
611
|
|
|
612
|
+
"comma-separated-tokens": ["comma-separated-tokens@2.0.3", "", {}, "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg=="],
|
|
613
|
+
|
|
601
614
|
"commander": ["commander@13.1.0", "", {}, "sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw=="],
|
|
602
615
|
|
|
603
616
|
"commondir": ["commondir@1.0.1", "", {}, "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg=="],
|
|
@@ -818,10 +831,16 @@
|
|
|
818
831
|
|
|
819
832
|
"hasown": ["hasown@2.0.4", "", { "dependencies": { "function-bind": "^1.1.2" } }, "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A=="],
|
|
820
833
|
|
|
834
|
+
"hast-util-to-html": ["hast-util-to-html@9.0.5", "", { "dependencies": { "@types/hast": "^3.0.0", "@types/unist": "^3.0.0", "ccount": "^2.0.0", "comma-separated-tokens": "^2.0.0", "hast-util-whitespace": "^3.0.0", "html-void-elements": "^3.0.0", "mdast-util-to-hast": "^13.0.0", "property-information": "^7.0.0", "space-separated-tokens": "^2.0.0", "stringify-entities": "^4.0.0", "zwitch": "^2.0.4" } }, "sha512-OguPdidb+fbHQSU4Q4ZiLKnzWo8Wwsf5bZfbvu7//a9oTYoqD/fWpe96NuHkoS9h0ccGOTe0C4NGXdtS0iObOw=="],
|
|
835
|
+
|
|
836
|
+
"hast-util-whitespace": ["hast-util-whitespace@3.0.0", "", { "dependencies": { "@types/hast": "^3.0.0" } }, "sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw=="],
|
|
837
|
+
|
|
821
838
|
"help-me": ["help-me@5.0.0", "", {}, "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg=="],
|
|
822
839
|
|
|
823
840
|
"hono": ["hono@4.12.25", "", {}, "sha512-2NFaIyNVgJmBs/ecmtGzlmluTFs5cHEWGTdu0t1HBwYzoGXOL5nUQBRMXsXWla5i4KkG//QMzVP88m1+I3fdAQ=="],
|
|
824
841
|
|
|
842
|
+
"html-void-elements": ["html-void-elements@3.0.0", "", {}, "sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg=="],
|
|
843
|
+
|
|
825
844
|
"http-errors": ["http-errors@2.0.1", "", { "dependencies": { "depd": "~2.0.0", "inherits": "~2.0.4", "setprototypeof": "~1.2.0", "statuses": "~2.0.2", "toidentifier": "~1.0.1" } }, "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ=="],
|
|
826
845
|
|
|
827
846
|
"https-proxy-agent": ["https-proxy-agent@7.0.6", "", { "dependencies": { "agent-base": "^7.1.2", "debug": "4" } }, "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw=="],
|
|
@@ -948,6 +967,8 @@
|
|
|
948
967
|
|
|
949
968
|
"mdast-util-phrasing": ["mdast-util-phrasing@4.1.0", "", { "dependencies": { "@types/mdast": "^4.0.0", "unist-util-is": "^6.0.0" } }, "sha512-TqICwyvJJpBwvGAMZjj4J2n0X8QWp21b9l0o7eXyVJ25YNWYbJDVIyD1bZXE6WtV6RmKJVYmQAKWa0zWOABz2w=="],
|
|
950
969
|
|
|
970
|
+
"mdast-util-to-hast": ["mdast-util-to-hast@13.2.1", "", { "dependencies": { "@types/hast": "^3.0.0", "@types/mdast": "^4.0.0", "@ungap/structured-clone": "^1.0.0", "devlop": "^1.0.0", "micromark-util-sanitize-uri": "^2.0.0", "trim-lines": "^3.0.0", "unist-util-position": "^5.0.0", "unist-util-visit": "^5.0.0", "vfile": "^6.0.0" } }, "sha512-cctsq2wp5vTsLIcaymblUriiTcZd0CwWtCbLvrOzYCDZoWyMNV8sZ7krj09FSnsiJi3WVsHLM4k6Dq/yaPyCXA=="],
|
|
971
|
+
|
|
951
972
|
"mdast-util-to-markdown": ["mdast-util-to-markdown@2.1.2", "", { "dependencies": { "@types/mdast": "^4.0.0", "@types/unist": "^3.0.0", "longest-streak": "^3.0.0", "mdast-util-phrasing": "^4.0.0", "mdast-util-to-string": "^4.0.0", "micromark-util-classify-character": "^2.0.0", "micromark-util-decode-string": "^2.0.0", "unist-util-visit": "^5.0.0", "zwitch": "^2.0.0" } }, "sha512-xj68wMTvGXVOKonmog6LwyJKrYXZPvlwabaryTjLh9LuvovB/KAH+kvi8Gjj+7rJjsFi23nkUxRQv1KqSroMqA=="],
|
|
952
973
|
|
|
953
974
|
"mdast-util-to-string": ["mdast-util-to-string@4.0.0", "", { "dependencies": { "@types/mdast": "^4.0.0" } }, "sha512-0H44vDimn51F0YwvxSJSm0eCDOJTRlmN0R1yBh4HLj9wiV1Dn0QoXGbvFAWj2hSItVTlCmBF1hqKlIyUBVFLPg=="],
|
|
@@ -1138,6 +1159,8 @@
|
|
|
1138
1159
|
|
|
1139
1160
|
"process-warning": ["process-warning@5.0.0", "", {}, "sha512-a39t9ApHNx2L4+HBnQKqxxHNs1r7KF+Intd8Q/g1bUh6q0WIp9voPXJ/x0j+ZL45KF1pJd9+q2jLIRMfvEshkA=="],
|
|
1140
1161
|
|
|
1162
|
+
"property-information": ["property-information@7.2.0", "", {}, "sha512-IAtzIB6sUiWaJYrX9smp3V46pBGbBeLFRGdh25kg1334VcBlD8HzhPeNIWQH9zhGmo2itIe25EHt9dQP7G5hmg=="],
|
|
1163
|
+
|
|
1141
1164
|
"protobufjs": ["protobufjs@7.6.4", "", { "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", "@protobufjs/codegen": "^2.0.5", "@protobufjs/eventemitter": "^1.1.1", "@protobufjs/fetch": "^1.1.1", "@protobufjs/float": "^1.0.2", "@protobufjs/path": "^1.1.2", "@protobufjs/pool": "^1.1.0", "@protobufjs/utf8": "^1.1.1", "@types/node": ">=13.7.0", "long": "^5.3.2" } }, "sha512-RJJPTTpvFfHcWLkIa2JFWK4XvtSzS0yEWDmunqHXli1h3JlkbcQZXDZdcWxv+JK3Xsl5/UFDPZ0iGm7DAengYw=="],
|
|
1142
1165
|
|
|
1143
1166
|
"proxy-addr": ["proxy-addr@2.0.7", "", { "dependencies": { "forwarded": "0.2.0", "ipaddr.js": "1.9.1" } }, "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg=="],
|
|
@@ -1248,6 +1271,8 @@
|
|
|
1248
1271
|
|
|
1249
1272
|
"source-map-support": ["source-map-support@0.5.21", "", { "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" } }, "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w=="],
|
|
1250
1273
|
|
|
1274
|
+
"space-separated-tokens": ["space-separated-tokens@2.0.2", "", {}, "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q=="],
|
|
1275
|
+
|
|
1251
1276
|
"split2": ["split2@4.2.0", "", {}, "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg=="],
|
|
1252
1277
|
|
|
1253
1278
|
"sprintf-js": ["sprintf-js@1.0.3", "", {}, "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g=="],
|
|
@@ -1264,6 +1289,8 @@
|
|
|
1264
1289
|
|
|
1265
1290
|
"string_decoder": ["string_decoder@1.1.1", "", { "dependencies": { "safe-buffer": "~5.1.0" } }, "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg=="],
|
|
1266
1291
|
|
|
1292
|
+
"stringify-entities": ["stringify-entities@4.0.4", "", { "dependencies": { "character-entities-html4": "^2.0.0", "character-entities-legacy": "^3.0.0" } }, "sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg=="],
|
|
1293
|
+
|
|
1267
1294
|
"stringify-object": ["stringify-object@3.3.0", "", { "dependencies": { "get-own-enumerable-property-symbols": "^3.0.0", "is-obj": "^1.0.1", "is-regexp": "^1.0.0" } }, "sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw=="],
|
|
1268
1295
|
|
|
1269
1296
|
"strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="],
|
|
@@ -1296,6 +1323,8 @@
|
|
|
1296
1323
|
|
|
1297
1324
|
"toidentifier": ["toidentifier@1.0.1", "", {}, "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="],
|
|
1298
1325
|
|
|
1326
|
+
"trim-lines": ["trim-lines@3.0.1", "", {}, "sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg=="],
|
|
1327
|
+
|
|
1299
1328
|
"trough": ["trough@2.2.0", "", {}, "sha512-tmMpK00BjZiUyVyvrBK7knerNgmgvcV/KLVyuma/SC+TQN167GrMRciANTz09+k3zW8L8t60jWO1GpfkZdjTaw=="],
|
|
1300
1329
|
|
|
1301
1330
|
"ts-algebra": ["ts-algebra@2.0.0", "", {}, "sha512-FPAhNPFMrkwz76P7cdjdmiShwMynZYN6SgOujD1urY4oNm80Ou9oMdmbR45LotcKOXoy7wSmHkRFE6Mxbrhefw=="],
|
|
@@ -1328,6 +1357,8 @@
|
|
|
1328
1357
|
|
|
1329
1358
|
"unist-util-is": ["unist-util-is@6.0.1", "", { "dependencies": { "@types/unist": "^3.0.0" } }, "sha512-LsiILbtBETkDz8I9p1dQ0uyRUWuaQzd/cuEeS1hoRSyW5E5XGmTzlwY1OrNzzakGowI9Dr/I8HVaw4hTtnxy8g=="],
|
|
1330
1359
|
|
|
1360
|
+
"unist-util-position": ["unist-util-position@5.0.0", "", { "dependencies": { "@types/unist": "^3.0.0" } }, "sha512-fucsC7HjXvkB5R3kTCO7kUjRdrS0BJt3M/FPxmHMBOm8JQi2BsHAHFsy27E0EolP8rp0NzXsJ+jNPyDWvOJZPA=="],
|
|
1361
|
+
|
|
1331
1362
|
"unist-util-stringify-position": ["unist-util-stringify-position@4.0.0", "", { "dependencies": { "@types/unist": "^3.0.0" } }, "sha512-0ASV06AAoKCDkS2+xw5RXJywruurpbC4JZSm7nr7MOt1ojAzvyyaO+UxZf18j8FCF6kmzCZKcAgN/yu2gm2XgQ=="],
|
|
1332
1363
|
|
|
1333
1364
|
"unist-util-visit": ["unist-util-visit@5.1.0", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-is": "^6.0.0", "unist-util-visit-parents": "^6.0.0" } }, "sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg=="],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vellumai/assistant",
|
|
3
|
-
"version": "0.10.3-dev.
|
|
3
|
+
"version": "0.10.3-dev.202606292136.ce8bf33",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -58,8 +58,10 @@
|
|
|
58
58
|
"diff": "8.0.4",
|
|
59
59
|
"dotenv": "17.3.1",
|
|
60
60
|
"drizzle-orm": "0.45.2",
|
|
61
|
+
"hast-util-to-html": "9.0.5",
|
|
61
62
|
"jszip": "3.10.1",
|
|
62
63
|
"marked": "18.0.0",
|
|
64
|
+
"mdast-util-to-hast": "13.2.1",
|
|
63
65
|
"minimatch": "10.2.4",
|
|
64
66
|
"openai": "6.29.0",
|
|
65
67
|
"pino": "9.14.0",
|
|
@@ -107,6 +109,7 @@
|
|
|
107
109
|
"devDependencies": {
|
|
108
110
|
"@microsoft/api-extractor": "7.58.8",
|
|
109
111
|
"@types/bun": "1.3.10",
|
|
112
|
+
"@types/hast": "3.0.4",
|
|
110
113
|
"@types/mdast": "4.0.4",
|
|
111
114
|
"@types/node": "25.5.0",
|
|
112
115
|
"@types/semver": "7.5.8",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { describe, expect, test } from "bun:test";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Guard for skill ↔ public-docs drift. A bundled skill's SKILL.md is the
|
|
8
|
+
* behavioral source of truth; its public reference page lives in a separate
|
|
9
|
+
* repo (vellum-assistant-platform, https://www.vellum.ai/docs/skills-reference).
|
|
10
|
+
* `scripts/check-skill-docs-sync.ts` fingerprints each documented SKILL.md so a
|
|
11
|
+
* behavior change can't land without the author reconciling the docs page and
|
|
12
|
+
* re-recording the fingerprint.
|
|
13
|
+
*
|
|
14
|
+
* This guard runs that check. On failure, the script's output names the skills
|
|
15
|
+
* whose SKILL.md drifted and the docs page to update — read it, fix the docs,
|
|
16
|
+
* then run `bun run scripts/check-skill-docs-sync.ts --write`.
|
|
17
|
+
*/
|
|
18
|
+
describe("skill ↔ public-docs sync", () => {
|
|
19
|
+
test("documented SKILL.md files match their recorded fingerprint", () => {
|
|
20
|
+
const repoRoot = resolve(
|
|
21
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
22
|
+
"../../..",
|
|
23
|
+
);
|
|
24
|
+
const result = spawnSync(
|
|
25
|
+
process.execPath,
|
|
26
|
+
["run", "scripts/check-skill-docs-sync.ts"],
|
|
27
|
+
{ cwd: repoRoot, encoding: "utf8" },
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const output = `${result.stdout ?? ""}${result.stderr ?? ""}`;
|
|
31
|
+
expect(output, output).not.toBe("");
|
|
32
|
+
expect(result.status, output).toBe(0);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -32,3 +32,14 @@ You can regenerate the full registry with:
|
|
|
32
32
|
```sh
|
|
33
33
|
bun run scripts/generate-bundled-tool-registry.ts
|
|
34
34
|
```
|
|
35
|
+
|
|
36
|
+
## Keeping public docs in sync
|
|
37
|
+
|
|
38
|
+
A bundled skill's `SKILL.md` is its behavioral source of truth. Skills with a public reference page (`https://www.vellum.ai/docs/skills-reference/<slug>`, authored in the **vellum-assistant-platform** repo) are fingerprinted in `scripts/skill-docs-sync.manifest.json` and enforced by `skill-docs-sync-guard.test.ts`.
|
|
39
|
+
|
|
40
|
+
When you change a documented skill's `SKILL.md`, the guard fails until you reconcile it:
|
|
41
|
+
|
|
42
|
+
1. Review the named docs page and update it if the behavior changed.
|
|
43
|
+
2. Re-record the fingerprint to acknowledge it: `bun run scripts/check-skill-docs-sync.ts --write`.
|
|
44
|
+
|
|
45
|
+
The fingerprint bump is the acknowledgement — even a trivial wording edit requires one. When a bundled skill **gains** a public docs page, add an entry to the manifest.
|
|
@@ -21,6 +21,7 @@ const slack = {
|
|
|
21
21
|
};
|
|
22
22
|
const telegram = {
|
|
23
23
|
sendTelegramReply: mock((..._args: unknown[]) => Promise.resolve()),
|
|
24
|
+
sendTelegramRichReply: mock((..._args: unknown[]) => Promise.resolve()),
|
|
24
25
|
sendTelegramTypingIndicator: mock((..._args: unknown[]) => Promise.resolve()),
|
|
25
26
|
sendTelegramAttachments: mock((..._args: unknown[]) =>
|
|
26
27
|
Promise.resolve({ allFailed: false, failureCount: 0 }),
|
|
@@ -24,10 +24,24 @@ const TELEGRAM_DEFAULT_TIMEOUT_MS = 15_000;
|
|
|
24
24
|
// Error types
|
|
25
25
|
// ---------------------------------------------------------------------------
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* A Telegram Bot API call that returned a non-retryable client error (a 4xx
|
|
29
|
+
* with `ok: false`). The request itself is the problem — the chat, the method,
|
|
30
|
+
* or the payload — so retrying the same call is pointless. `description` carries
|
|
31
|
+
* Telegram's human-readable error text when present.
|
|
32
|
+
*
|
|
33
|
+
* Callers branch on this type to degrade gracefully: e.g. a rejected
|
|
34
|
+
* `sendRichMessage` falls back to a plain-text `sendMessage`. Branch on the
|
|
35
|
+
* type, not on `error_code` — the docs warn the numeric code is "subject to
|
|
36
|
+
* change" (https://core.telegram.org/bots/api#making-requests).
|
|
37
|
+
*/
|
|
38
|
+
export class TelegramNonRetryableError extends Error {
|
|
39
|
+
readonly description: string | undefined;
|
|
40
|
+
|
|
41
|
+
constructor(message: string, description?: string) {
|
|
29
42
|
super(message);
|
|
30
43
|
this.name = "TelegramNonRetryableError";
|
|
44
|
+
this.description = description;
|
|
31
45
|
}
|
|
32
46
|
}
|
|
33
47
|
|
|
@@ -132,7 +146,7 @@ async function retryableFetch<T>(
|
|
|
132
146
|
? `Telegram ${method} failed with status ${response.status}: ${redactBotTokens(body)}`
|
|
133
147
|
: `Telegram ${method} failed with status ${response.status}`;
|
|
134
148
|
|
|
135
|
-
throw new TelegramNonRetryableError(message);
|
|
149
|
+
throw new TelegramNonRetryableError(message, description);
|
|
136
150
|
}
|
|
137
151
|
|
|
138
152
|
if (isRetryable(response.status)) {
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { renderTelegramHtml } from "./render.js";
|
|
4
|
+
|
|
5
|
+
// Expected values are derived from Telegram's documented Rich HTML vocabulary
|
|
6
|
+
// (https://core.telegram.org/bots/api#rich-html-style), not from the renderer's
|
|
7
|
+
// output. Notable doc-grounded choices:
|
|
8
|
+
// - `<strong>`/`<em>`/`<del>` are listed as supported alongside `<b>`/`<i>`/
|
|
9
|
+
// `<s>`, so the serializer's defaults need no remapping.
|
|
10
|
+
// - Character references are numeric (`&`) because Telegram supports all
|
|
11
|
+
// numeric references but only 13 named ones; numeric is unambiguously safe.
|
|
12
|
+
// - `<img src>` is a supported tag, but only as a standalone media block, so
|
|
13
|
+
// an image-only paragraph is unwrapped from its `<p>`.
|
|
14
|
+
describe("renderTelegramHtml", () => {
|
|
15
|
+
test("returns undefined for empty or whitespace-only input", () => {
|
|
16
|
+
expect(renderTelegramHtml("")).toBeUndefined();
|
|
17
|
+
expect(renderTelegramHtml(" \n\t ")).toBeUndefined();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("wraps a plain paragraph", () => {
|
|
21
|
+
expect(renderTelegramHtml("Hello world")).toBe("<p>Hello world</p>");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("maps headings to h1-h6", () => {
|
|
25
|
+
expect(renderTelegramHtml("# A")).toBe("<h1>A</h1>");
|
|
26
|
+
expect(renderTelegramHtml("###### F")).toBe("<h6>F</h6>");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("maps inline emphasis to Telegram's supported tags", () => {
|
|
30
|
+
expect(renderTelegramHtml("**b** _i_ ~~d~~ `c`")).toBe(
|
|
31
|
+
"<p><strong>b</strong> <em>i</em> <del>d</del> <code>c</code></p>",
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("renders links with a numeric-escaped href", () => {
|
|
36
|
+
expect(renderTelegramHtml("[text](https://x.test/?a=1&b=2)")).toBe(
|
|
37
|
+
'<p><a href="https://x.test/?a=1&b=2">text</a></p>',
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("renders fenced code with a language class and escaped body", () => {
|
|
42
|
+
expect(renderTelegramHtml("```ts\nconst a = 1 < 2;\n```")).toBe(
|
|
43
|
+
'<pre><code class="language-ts">const a = 1 < 2;</code></pre>',
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("renders a no-language code block as a bare pre", () => {
|
|
48
|
+
expect(renderTelegramHtml("```\nplain\n```")).toBe("<pre>plain</pre>");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("renders bullet and ordered lists", () => {
|
|
52
|
+
expect(renderTelegramHtml("- one\n- two")).toBe(
|
|
53
|
+
"<ul><li>one</li><li>two</li></ul>",
|
|
54
|
+
);
|
|
55
|
+
expect(renderTelegramHtml("3. a\n4. b")).toBe(
|
|
56
|
+
'<ol start="3"><li>a</li><li>b</li></ol>',
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("renders GFM task lists with bare checkbox inputs", () => {
|
|
61
|
+
// Telegram's documented form is `<input type="checkbox" checked>` with no
|
|
62
|
+
// `disabled` attribute and no list classes.
|
|
63
|
+
expect(renderTelegramHtml("- [x] done\n- [ ] todo")).toBe(
|
|
64
|
+
'<ul><li><input type="checkbox" checked>done</li>' +
|
|
65
|
+
'<li><input type="checkbox">todo</li></ul>',
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("renders a nested list inside a list item", () => {
|
|
70
|
+
expect(renderTelegramHtml("- a\n - b")).toBe(
|
|
71
|
+
"<ul><li>a<ul><li>b</li></ul></li></ul>",
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("renders a GFM table without thead/tbody wrappers", () => {
|
|
76
|
+
const html = renderTelegramHtml("| H1 | H2 |\n| :- | -: |\n| a | b |");
|
|
77
|
+
expect(html).toBe(
|
|
78
|
+
"<table>" +
|
|
79
|
+
'<tr><th align="left">H1</th><th align="right">H2</th></tr>' +
|
|
80
|
+
'<tr><td align="left">a</td><td align="right">b</td></tr>' +
|
|
81
|
+
"</table>",
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("renders blockquotes, preserving paragraph structure", () => {
|
|
86
|
+
expect(renderTelegramHtml("> quoted")).toBe(
|
|
87
|
+
"<blockquote><p>quoted</p></blockquote>",
|
|
88
|
+
);
|
|
89
|
+
expect(renderTelegramHtml("> line one\n>\n> line two")).toBe(
|
|
90
|
+
"<blockquote><p>line one</p><p>line two</p></blockquote>",
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("renders a thematic break", () => {
|
|
95
|
+
expect(renderTelegramHtml("---")).toBe("<hr>");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("renders a standalone image as a top-level media block", () => {
|
|
99
|
+
// Telegram accepts `<img>` only as a standalone media block, never nested
|
|
100
|
+
// in a `<p>`, so the serializer's `<p><img></p>` wrapper is removed.
|
|
101
|
+
expect(renderTelegramHtml("")).toBe(
|
|
102
|
+
'<img src="https://x.test/i.png" alt="alt text">',
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("keeps an image inline when it shares a paragraph with text", () => {
|
|
107
|
+
// A paragraph mixing prose and an image keeps its `<p>` so the surrounding
|
|
108
|
+
// text is not orphaned; only image-only paragraphs are unwrapped.
|
|
109
|
+
expect(renderTelegramHtml("see  here")).toBe(
|
|
110
|
+
'<p>see <img src="https://x.test/i.png" alt="a"> here</p>',
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("preserves significant whitespace between inline elements in a list item", () => {
|
|
115
|
+
// The space between adjacent inline nodes is content, not layout, so it must
|
|
116
|
+
// survive: `Status: ready`, never `Status:ready`.
|
|
117
|
+
expect(renderTelegramHtml("- **Status:** _ready_")).toBe(
|
|
118
|
+
"<ul><li><strong>Status:</strong> <em>ready</em></li></ul>",
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Fidelity: characters that Telegram's Rich *Markdown* dialect reinterprets
|
|
123
|
+
// ($ math, == highlight, || spoiler, < HTML) must survive as literal text in
|
|
124
|
+
// HTML mode rather than triggering those extensions.
|
|
125
|
+
test("keeps Telegram Rich-Markdown-only syntax literal", () => {
|
|
126
|
+
expect(renderTelegramHtml("Pay $100 to $200")).toBe(
|
|
127
|
+
"<p>Pay $100 to $200</p>",
|
|
128
|
+
);
|
|
129
|
+
expect(renderTelegramHtml("a ==hi== b")).toBe("<p>a ==hi== b</p>");
|
|
130
|
+
expect(renderTelegramHtml("a ||spoiler|| b")).toBe(
|
|
131
|
+
"<p>a ||spoiler|| b</p>",
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("escapes raw HTML so it renders verbatim", () => {
|
|
136
|
+
expect(renderTelegramHtml("a <b>not bold</b> z")).toBe(
|
|
137
|
+
"<p>a <b>not bold</b> z</p>",
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("emits numeric references for the characters HTML must escape", () => {
|
|
142
|
+
// Only `&` and `<` require escaping in element text; `>`, `"`, and `'` are
|
|
143
|
+
// left literal. Escaped characters use numeric references.
|
|
144
|
+
expect(renderTelegramHtml(`& < > " '`)).toBe(`<p>& < > " '</p>`);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram rich-message rendering: canonical mdast → Telegram rich HTML.
|
|
3
|
+
*
|
|
4
|
+
* The channel-neutral parse (markdown → mdast) lives in `messaging/content`;
|
|
5
|
+
* this module is Telegram's "how". Telegram Bot API 10.1 rich messages accept
|
|
6
|
+
* an `html` field whose text content is literal — so `$100`, `==x==`, `||y||`,
|
|
7
|
+
* and `<` render exactly as the agent wrote them. The sibling `markdown` field
|
|
8
|
+
* is a GFM *superset* that would instead reinterpret those as math, highlight,
|
|
9
|
+
* spoiler, and inline HTML, silently changing content.
|
|
10
|
+
*
|
|
11
|
+
* Rendering goes through the standard unified pipeline — `mdast-util-to-hast`
|
|
12
|
+
* then `hast-util-to-html` — so HTML escaping and serialization are owned by the
|
|
13
|
+
* maintained serializer rather than hand-written. `telegramizeHast` then applies
|
|
14
|
+
* the few documented places where Telegram's vocabulary differs from generic
|
|
15
|
+
* HTML:
|
|
16
|
+
* - tables use `<tr>` directly, with no `<thead>`/`<tbody>` wrappers;
|
|
17
|
+
* - task-list items use a bare `<input type="checkbox">` — no `disabled`
|
|
18
|
+
* attribute and no list classes;
|
|
19
|
+
* - a code block without a language is a bare `<pre>`; a language is carried
|
|
20
|
+
* on a nested `<code class="language-…">`;
|
|
21
|
+
* - images are standalone media blocks, so an image-only paragraph is
|
|
22
|
+
* unwrapped (`<p><img></p>` → `<img>`) rather than nested inside `<p>`.
|
|
23
|
+
*
|
|
24
|
+
* `useNamedReferences: false` emits numeric character references. Telegram
|
|
25
|
+
* supports every numeric reference but only a fixed set of 13 named entities,
|
|
26
|
+
* and its docs are ambiguous about whether `"` is among them, so numeric
|
|
27
|
+
* references are the unambiguously-safe choice.
|
|
28
|
+
*
|
|
29
|
+
* Verified against the official Bot API docs:
|
|
30
|
+
* https://core.telegram.org/bots/api#rich-html-style
|
|
31
|
+
* https://core.telegram.org/bots/api#inputrichmessage
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import type { Element, ElementContent, Root, RootContent } from "hast";
|
|
35
|
+
import { toHtml } from "hast-util-to-html";
|
|
36
|
+
import { toHast } from "mdast-util-to-hast";
|
|
37
|
+
|
|
38
|
+
import { parseMarkdown } from "../../content/parse.js";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Render markdown / plain text into a Telegram rich-message HTML string, or
|
|
42
|
+
* `undefined` when there is no renderable content so callers can skip the rich
|
|
43
|
+
* path entirely.
|
|
44
|
+
*/
|
|
45
|
+
export function renderTelegramHtml(text: string): string | undefined {
|
|
46
|
+
if (!text || text.trim().length === 0) return undefined;
|
|
47
|
+
|
|
48
|
+
const hast = toHast(parseMarkdown(text), {
|
|
49
|
+
handlers: {
|
|
50
|
+
// remark-gfm parses literal `<tag>` markup the agent typed as `html`
|
|
51
|
+
// nodes. Agent-authored HTML is not executed as Telegram markup; emitting
|
|
52
|
+
// it as text makes the serializer escape it so it renders verbatim — the
|
|
53
|
+
// same outcome as the web client, which parses with remark-gfm and no
|
|
54
|
+
// `rehype-raw`.
|
|
55
|
+
html: (_state, node: { value: string }) => ({
|
|
56
|
+
type: "text",
|
|
57
|
+
value: node.value,
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// `toHast` is typed to return any hast node, but a root input always yields a
|
|
63
|
+
// root; the guard narrows the type without changing behaviour.
|
|
64
|
+
if (hast.type !== "root") return undefined;
|
|
65
|
+
|
|
66
|
+
telegramizeHast(hast);
|
|
67
|
+
|
|
68
|
+
const html = toHtml(hast, {
|
|
69
|
+
characterReferences: { useNamedReferences: false },
|
|
70
|
+
});
|
|
71
|
+
return html.length > 0 ? html : undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// Telegram-specific hast adjustments
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Block-level tags in the generic HTML the serializer produces. Whitespace that
|
|
80
|
+
* only separates block-level siblings is layout-insignificant; whitespace
|
|
81
|
+
* between inline content (text, `<strong>`, `<em>`, `<a>`, …) is meaningful and
|
|
82
|
+
* must be preserved.
|
|
83
|
+
*/
|
|
84
|
+
const BLOCK_TAGS = new Set([
|
|
85
|
+
"blockquote",
|
|
86
|
+
"details",
|
|
87
|
+
"figure",
|
|
88
|
+
"figcaption",
|
|
89
|
+
"h1",
|
|
90
|
+
"h2",
|
|
91
|
+
"h3",
|
|
92
|
+
"h4",
|
|
93
|
+
"h5",
|
|
94
|
+
"h6",
|
|
95
|
+
"hr",
|
|
96
|
+
"li",
|
|
97
|
+
"ol",
|
|
98
|
+
"p",
|
|
99
|
+
"pre",
|
|
100
|
+
"summary",
|
|
101
|
+
"table",
|
|
102
|
+
"tbody",
|
|
103
|
+
"td",
|
|
104
|
+
"th",
|
|
105
|
+
"thead",
|
|
106
|
+
"tr",
|
|
107
|
+
"ul",
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
/** Tags whose text content is preformatted, so whitespace is always significant. */
|
|
111
|
+
const PREFORMATTED_TAGS = new Set(["pre", "code"]);
|
|
112
|
+
|
|
113
|
+
function telegramizeHast(root: Root): void {
|
|
114
|
+
processNode(root);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function processNode(node: Root | Element): void {
|
|
118
|
+
for (const child of node.children) {
|
|
119
|
+
if (child.type === "element") processNode(child);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (node.type === "element") {
|
|
123
|
+
switch (node.tagName) {
|
|
124
|
+
case "table":
|
|
125
|
+
unwrapTableSections(node);
|
|
126
|
+
break;
|
|
127
|
+
case "pre":
|
|
128
|
+
normalizeCodeBlock(node);
|
|
129
|
+
break;
|
|
130
|
+
case "input":
|
|
131
|
+
if (node.properties) delete node.properties.disabled;
|
|
132
|
+
break;
|
|
133
|
+
case "ul":
|
|
134
|
+
case "ol":
|
|
135
|
+
stripTaskListClasses(node);
|
|
136
|
+
break;
|
|
137
|
+
case "li":
|
|
138
|
+
stripTaskListClasses(node);
|
|
139
|
+
normalizeTaskItemSpacing(node);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
unwrapImageParagraphs(node);
|
|
145
|
+
stripStructuralWhitespace(node);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Lift `<tr>` rows out of `<thead>`/`<tbody>`, which Telegram does not support. */
|
|
149
|
+
function unwrapTableSections(table: Element): void {
|
|
150
|
+
const rows: ElementContent[] = [];
|
|
151
|
+
for (const child of table.children) {
|
|
152
|
+
if (
|
|
153
|
+
child.type === "element" &&
|
|
154
|
+
(child.tagName === "thead" || child.tagName === "tbody")
|
|
155
|
+
) {
|
|
156
|
+
rows.push(...child.children);
|
|
157
|
+
} else {
|
|
158
|
+
rows.push(child);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
table.children = rows;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function normalizeCodeBlock(pre: Element): void {
|
|
165
|
+
const code = pre.children.find(
|
|
166
|
+
(child): child is Element =>
|
|
167
|
+
child.type === "element" && child.tagName === "code",
|
|
168
|
+
);
|
|
169
|
+
if (!code) return;
|
|
170
|
+
|
|
171
|
+
const last = code.children[code.children.length - 1];
|
|
172
|
+
if (last?.type === "text" && last.value.endsWith("\n")) {
|
|
173
|
+
last.value = last.value.slice(0, -1);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const className = code.properties?.className;
|
|
177
|
+
const hasLanguage =
|
|
178
|
+
Array.isArray(className) &&
|
|
179
|
+
className.some(
|
|
180
|
+
(name) => typeof name === "string" && name.startsWith("language-"),
|
|
181
|
+
);
|
|
182
|
+
// A bare code block has no language to carry, so the `<code>` wrapper is
|
|
183
|
+
// dropped — Telegram renders fixed-width text from `<pre>` alone and only
|
|
184
|
+
// honours a language on a nested `<code>`.
|
|
185
|
+
if (!hasLanguage) {
|
|
186
|
+
pre.children = code.children;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function stripTaskListClasses(element: Element): void {
|
|
191
|
+
const className = element.properties?.className;
|
|
192
|
+
if (!Array.isArray(className) || !element.properties) return;
|
|
193
|
+
const kept = className.filter(
|
|
194
|
+
(name) => name !== "contains-task-list" && name !== "task-list-item",
|
|
195
|
+
);
|
|
196
|
+
if (kept.length > 0) {
|
|
197
|
+
element.properties.className = kept;
|
|
198
|
+
} else {
|
|
199
|
+
delete element.properties.className;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Drop the whitespace that GFM inserts between a task-list checkbox and its
|
|
205
|
+
* label. Telegram's documented checklist form places the label directly after
|
|
206
|
+
* the input (`<input type="checkbox" checked>Checked checkbox`), so the leading
|
|
207
|
+
* space is removed to match.
|
|
208
|
+
*/
|
|
209
|
+
function normalizeTaskItemSpacing(li: Element): void {
|
|
210
|
+
const [first, second] = li.children;
|
|
211
|
+
if (
|
|
212
|
+
first?.type === "element" &&
|
|
213
|
+
first.tagName === "input" &&
|
|
214
|
+
first.properties?.type === "checkbox" &&
|
|
215
|
+
second?.type === "text" &&
|
|
216
|
+
second.value.trim().length === 0
|
|
217
|
+
) {
|
|
218
|
+
li.children.splice(1, 1);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Lift the `<img>` out of an image-only paragraph. Telegram's rich HTML treats
|
|
224
|
+
* images as standalone media blocks and does not accept `<img>` nested inside a
|
|
225
|
+
* `<p>`; the generic serializer wraps a standalone Markdown image in `<p>`, so
|
|
226
|
+
* an `<p><img></p>` is flattened to a top-level `<img>`. A paragraph that mixes
|
|
227
|
+
* an image with text is left intact — its surrounding prose still needs `<p>`.
|
|
228
|
+
*/
|
|
229
|
+
function unwrapImageParagraphs(node: Root | Element): void {
|
|
230
|
+
const lifted: Array<RootContent | ElementContent> = [];
|
|
231
|
+
for (const child of node.children) {
|
|
232
|
+
if (
|
|
233
|
+
child.type === "element" &&
|
|
234
|
+
child.tagName === "p" &&
|
|
235
|
+
isImageOnlyParagraph(child)
|
|
236
|
+
) {
|
|
237
|
+
for (const grandchild of child.children) {
|
|
238
|
+
if (grandchild.type === "element" && grandchild.tagName === "img") {
|
|
239
|
+
lifted.push(grandchild);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
lifted.push(child);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
node.children = lifted as Element["children"];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function isImageOnlyParagraph(paragraph: Element): boolean {
|
|
250
|
+
let hasImage = false;
|
|
251
|
+
for (const child of paragraph.children) {
|
|
252
|
+
if (child.type === "text") {
|
|
253
|
+
if (child.value.trim().length > 0) return false;
|
|
254
|
+
} else if (child.type === "element" && child.tagName === "img") {
|
|
255
|
+
hasImage = true;
|
|
256
|
+
} else {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return hasImage;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Remove whitespace-only text nodes that merely separate block-level siblings —
|
|
265
|
+
* the generic serializer inserts newlines between block elements, but Telegram
|
|
266
|
+
* renders those source newlines as literal text. Whitespace flanked by inline
|
|
267
|
+
* content on both sides (e.g. the space in `<strong>x</strong> <em>y</em>`) is
|
|
268
|
+
* meaningful and preserved, and preformatted (`<pre>`/`<code>`) whitespace is
|
|
269
|
+
* always left untouched.
|
|
270
|
+
*/
|
|
271
|
+
function stripStructuralWhitespace(node: Root | Element): void {
|
|
272
|
+
if (node.type === "element" && PREFORMATTED_TAGS.has(node.tagName)) return;
|
|
273
|
+
|
|
274
|
+
const children = node.children;
|
|
275
|
+
node.children = children.filter((child, index) => {
|
|
276
|
+
if (child.type !== "text" || child.value.trim().length > 0) return true;
|
|
277
|
+
const prev = children[index - 1];
|
|
278
|
+
const next = children[index + 1];
|
|
279
|
+
return (
|
|
280
|
+
prev !== undefined &&
|
|
281
|
+
next !== undefined &&
|
|
282
|
+
isInlineContent(prev) &&
|
|
283
|
+
isInlineContent(next)
|
|
284
|
+
);
|
|
285
|
+
}) as Element["children"];
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function isInlineContent(node: RootContent | ElementContent): boolean {
|
|
289
|
+
if (node.type === "text") return node.value.trim().length > 0;
|
|
290
|
+
if (node.type === "element") return !BLOCK_TAGS.has(node.tagName);
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ApprovalUIMetadata,
|
|
5
|
+
ChannelReplyPayload,
|
|
6
|
+
} from "@vellumai/gateway-client";
|
|
7
|
+
|
|
8
|
+
import type { CallbackContext } from "../channel-transport.js";
|
|
9
|
+
|
|
10
|
+
// Derive the mock signature from the real export so the test cannot drift from
|
|
11
|
+
// the production call signature.
|
|
12
|
+
type CallTelegramBotApi = typeof import("./api.js").callTelegramBotApi;
|
|
13
|
+
|
|
14
|
+
const callTelegramBotApiMock = mock<CallTelegramBotApi>(
|
|
15
|
+
async () => ({}) as never,
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
mock.module("../../../util/logger.js", () => ({
|
|
19
|
+
getLogger: () =>
|
|
20
|
+
new Proxy({} as Record<string, unknown>, {
|
|
21
|
+
get: () => () => {},
|
|
22
|
+
}),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
mock.module("./api.js", () => ({
|
|
26
|
+
callTelegramBotApi: (method: string, body: Record<string, unknown>) =>
|
|
27
|
+
callTelegramBotApiMock(method, body),
|
|
28
|
+
callTelegramBotApiMultipart: async () => ({}),
|
|
29
|
+
TelegramNonRetryableError: class TelegramNonRetryableError extends Error {
|
|
30
|
+
readonly description: string | undefined;
|
|
31
|
+
constructor(message: string, description?: string) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "TelegramNonRetryableError";
|
|
34
|
+
this.description = description;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
const { TelegramNonRetryableError } = await import("./api.js");
|
|
40
|
+
const { sendTelegramRichReply } = await import("./send.js");
|
|
41
|
+
const { telegramTransport } = await import("./transport.js");
|
|
42
|
+
|
|
43
|
+
const approval: ApprovalUIMetadata = {
|
|
44
|
+
requestId: "req-1",
|
|
45
|
+
plainTextFallback: "Approve?",
|
|
46
|
+
actions: [
|
|
47
|
+
{ id: "approve", label: "Approve" },
|
|
48
|
+
{ id: "deny", label: "Deny" },
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const expectedKeyboard = {
|
|
53
|
+
inline_keyboard: [
|
|
54
|
+
[{ text: "Approve", callback_data: "apr:req-1:approve" }],
|
|
55
|
+
[{ text: "Deny", callback_data: "apr:req-1:deny" }],
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const callsTo = (method: string) =>
|
|
60
|
+
callTelegramBotApiMock.mock.calls.filter((call) => call[0] === method);
|
|
61
|
+
|
|
62
|
+
beforeEach(() => {
|
|
63
|
+
callTelegramBotApiMock.mockReset();
|
|
64
|
+
callTelegramBotApiMock.mockImplementation(async () => ({}) as never);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("sendTelegramRichReply", () => {
|
|
68
|
+
test("renders markdown to HTML and sends it via the nested rich_message object", async () => {
|
|
69
|
+
await sendTelegramRichReply("123", "# Heading\n\n| a | b |\n| - | - |");
|
|
70
|
+
|
|
71
|
+
expect(callsTo("sendRichMessage")).toHaveLength(1);
|
|
72
|
+
expect(callsTo("sendMessage")).toHaveLength(0);
|
|
73
|
+
expect(callTelegramBotApiMock).toHaveBeenCalledWith("sendRichMessage", {
|
|
74
|
+
chat_id: "123",
|
|
75
|
+
rich_message: {
|
|
76
|
+
html: "<h1>Heading</h1><table><tr><th>a</th><th>b</th></tr></table>",
|
|
77
|
+
skip_entity_detection: true,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("escapes Telegram Rich-Markdown-only syntax so it renders as written", async () => {
|
|
83
|
+
// `$…$` math, `==highlight==`, `||spoiler||`, and literal `<` are Telegram
|
|
84
|
+
// Rich Markdown extensions; HTML mode keeps them literal.
|
|
85
|
+
await sendTelegramRichReply("123", "$100 to $200 ==x== ||y|| <b>");
|
|
86
|
+
|
|
87
|
+
const [, body] = callsTo("sendRichMessage")[0] ?? [];
|
|
88
|
+
const html = (body?.rich_message as { html: string }).html;
|
|
89
|
+
// The Rich-Markdown extensions survive verbatim, and the angle brackets are
|
|
90
|
+
// escaped rather than emitted as a live <b> tag. (render.test.ts pins the
|
|
91
|
+
// exact character-reference form.)
|
|
92
|
+
expect(html).toContain("$100 to $200 ==x== ||y||");
|
|
93
|
+
expect(html).not.toContain("<b>");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("attaches the approval inline keyboard as reply_markup on the rich send", async () => {
|
|
97
|
+
await sendTelegramRichReply("123", "Please approve", approval);
|
|
98
|
+
|
|
99
|
+
expect(callTelegramBotApiMock).toHaveBeenCalledWith("sendRichMessage", {
|
|
100
|
+
chat_id: "123",
|
|
101
|
+
rich_message: {
|
|
102
|
+
html: "<p>Please approve</p>",
|
|
103
|
+
skip_entity_detection: true,
|
|
104
|
+
},
|
|
105
|
+
reply_markup: expectedKeyboard,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("falls back to plain sendMessage when the rich send is rejected", async () => {
|
|
110
|
+
callTelegramBotApiMock.mockImplementationOnce(async () => {
|
|
111
|
+
throw new TelegramNonRetryableError(
|
|
112
|
+
"Telegram sendRichMessage failed: BLOCK_LIMIT_EXCEEDED",
|
|
113
|
+
"BLOCK_LIMIT_EXCEEDED",
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
await sendTelegramRichReply("123", "Too rich for this server");
|
|
118
|
+
|
|
119
|
+
// One rejected rich attempt, then one plain-text retry — the user still
|
|
120
|
+
// receives the message.
|
|
121
|
+
expect(callsTo("sendRichMessage")).toHaveLength(1);
|
|
122
|
+
expect(callsTo("sendMessage")).toHaveLength(1);
|
|
123
|
+
expect(callTelegramBotApiMock).toHaveBeenNthCalledWith(2, "sendMessage", {
|
|
124
|
+
chat_id: "123",
|
|
125
|
+
text: "Too rich for this server",
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("preserves the approval keyboard when falling back to plain text", async () => {
|
|
130
|
+
callTelegramBotApiMock.mockImplementationOnce(async () => {
|
|
131
|
+
throw new TelegramNonRetryableError("rejected", "rejected");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
await sendTelegramRichReply("123", "Please approve", approval);
|
|
135
|
+
|
|
136
|
+
expect(callsTo("sendMessage")).toHaveLength(1);
|
|
137
|
+
expect(callTelegramBotApiMock).toHaveBeenNthCalledWith(2, "sendMessage", {
|
|
138
|
+
chat_id: "123",
|
|
139
|
+
text: "Please approve",
|
|
140
|
+
reply_markup: expectedKeyboard,
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("propagates non-client errors without a plain-text retry", async () => {
|
|
145
|
+
callTelegramBotApiMock.mockImplementationOnce(async () => {
|
|
146
|
+
throw new Error("network down");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
await expect(sendTelegramRichReply("123", "Hello")).rejects.toThrow(
|
|
150
|
+
"network down",
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
expect(callsTo("sendRichMessage")).toHaveLength(1);
|
|
154
|
+
expect(callsTo("sendMessage")).toHaveLength(0);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe("telegramTransport.deliver routing", () => {
|
|
159
|
+
const ctx: CallbackContext = { callbackUrl: "/deliver/telegram", params: {} };
|
|
160
|
+
|
|
161
|
+
function payload(
|
|
162
|
+
overrides: Partial<ChannelReplyPayload>,
|
|
163
|
+
): ChannelReplyPayload {
|
|
164
|
+
return {
|
|
165
|
+
chatId: "123",
|
|
166
|
+
text: "hello",
|
|
167
|
+
...overrides,
|
|
168
|
+
} as ChannelReplyPayload;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
test("routes to the rich send when useBlocks is set", async () => {
|
|
172
|
+
await telegramTransport.deliver(ctx, payload({ useBlocks: true }));
|
|
173
|
+
|
|
174
|
+
expect(callsTo("sendRichMessage")).toHaveLength(1);
|
|
175
|
+
expect(callsTo("sendMessage")).toHaveLength(0);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("stays on the plain send when useBlocks is absent", async () => {
|
|
179
|
+
await telegramTransport.deliver(ctx, payload({ useBlocks: false }));
|
|
180
|
+
|
|
181
|
+
expect(callsTo("sendRichMessage")).toHaveLength(0);
|
|
182
|
+
expect(callsTo("sendMessage")).toHaveLength(1);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("forwards approval metadata through the rich path", async () => {
|
|
186
|
+
await telegramTransport.deliver(
|
|
187
|
+
ctx,
|
|
188
|
+
payload({ useBlocks: true, approval } as Partial<ChannelReplyPayload>),
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
expect(callTelegramBotApiMock).toHaveBeenCalledWith("sendRichMessage", {
|
|
192
|
+
chat_id: "123",
|
|
193
|
+
rich_message: { html: "<p>hello</p>", skip_entity_detection: true },
|
|
194
|
+
reply_markup: expectedKeyboard,
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
@@ -10,7 +10,12 @@ import type { ApprovalUIMetadata } from "@vellumai/gateway-client";
|
|
|
10
10
|
import { getAttachmentContent } from "../../../persistence/attachments-store.js";
|
|
11
11
|
import type { RuntimeAttachmentMetadata } from "../../../runtime/http-types.js";
|
|
12
12
|
import { getLogger } from "../../../util/logger.js";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
callTelegramBotApi,
|
|
15
|
+
callTelegramBotApiMultipart,
|
|
16
|
+
TelegramNonRetryableError,
|
|
17
|
+
} from "./api.js";
|
|
18
|
+
import { renderTelegramHtml } from "./render.js";
|
|
14
19
|
|
|
15
20
|
const log = getLogger("telegram-send");
|
|
16
21
|
|
|
@@ -114,6 +119,69 @@ export async function sendTelegramReply(
|
|
|
114
119
|
log.debug({ chatId, chunks: chunks.length }, "Telegram reply sent");
|
|
115
120
|
}
|
|
116
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Send a Telegram reply as a rich message (Bot API 10.1) so tables, headings,
|
|
124
|
+
* code, and quotes render natively. On a non-retryable rejection of the rich
|
|
125
|
+
* send, fall back to the plain-text `sendTelegramReply` so the user still
|
|
126
|
+
* receives the message.
|
|
127
|
+
*
|
|
128
|
+
* The canonical reply markdown is rendered to Telegram rich HTML (see
|
|
129
|
+
* `render.ts`) and sent via `InputRichMessage.html`. HTML mode keeps text
|
|
130
|
+
* content literal, so canonical GFM that overlaps Telegram's Rich *Markdown*
|
|
131
|
+
* extensions (`$…$` math, `==highlight==`, `||spoiler||`) renders exactly as
|
|
132
|
+
* written instead of being reinterpreted. `skip_entity_detection` is set
|
|
133
|
+
* because the canonical parser already turns bare URLs and e-mails into links;
|
|
134
|
+
* leaving Telegram's auto-detection on would additionally linkify cashtags,
|
|
135
|
+
* hashtags, mentions, phone numbers, and bank-card-like digit runs that GFM
|
|
136
|
+
* treats as plain text.
|
|
137
|
+
*
|
|
138
|
+
* Old clients degrade the display client-side; the send itself does not fail on
|
|
139
|
+
* recipient version, so the only fallback trigger is a request-level rejection
|
|
140
|
+
* (content over Telegram's documented rich-message limits, or a Bot API server
|
|
141
|
+
* predating 10.1). The plain path splits at `TELEGRAM_MAX_MESSAGE_LEN`, so it
|
|
142
|
+
* also covers the rare oversize case the single-shot rich send cannot.
|
|
143
|
+
*
|
|
144
|
+
* Wire shapes verified against the official Bot API docs:
|
|
145
|
+
* - sendRichMessage: https://core.telegram.org/bots/api#sendrichmessage
|
|
146
|
+
* - InputRichMessage: https://core.telegram.org/bots/api#inputrichmessage
|
|
147
|
+
* - Rich HTML: https://core.telegram.org/bots/api#rich-message-formatting-options
|
|
148
|
+
*/
|
|
149
|
+
export async function sendTelegramRichReply(
|
|
150
|
+
chatId: string,
|
|
151
|
+
markdown: string,
|
|
152
|
+
approval?: ApprovalUIMetadata,
|
|
153
|
+
): Promise<void> {
|
|
154
|
+
const html = renderTelegramHtml(markdown);
|
|
155
|
+
if (html === undefined) {
|
|
156
|
+
// No renderable rich content — send as plain text.
|
|
157
|
+
await sendTelegramReply(chatId, markdown, approval);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const payload: Record<string, unknown> = {
|
|
162
|
+
chat_id: chatId,
|
|
163
|
+
rich_message: { html, skip_entity_detection: true },
|
|
164
|
+
};
|
|
165
|
+
if (approval) {
|
|
166
|
+
payload.reply_markup = buildInlineKeyboard(approval);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
await callTelegramBotApi("sendRichMessage", payload);
|
|
171
|
+
log.debug({ chatId }, "Telegram rich message sent");
|
|
172
|
+
} catch (err) {
|
|
173
|
+
if (err instanceof TelegramNonRetryableError) {
|
|
174
|
+
log.warn(
|
|
175
|
+
{ chatId, description: err.description },
|
|
176
|
+
"Telegram rejected rich message; falling back to plain text",
|
|
177
|
+
);
|
|
178
|
+
await sendTelegramReply(chatId, markdown, approval);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
throw err;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
117
185
|
export type TelegramAttachmentResult = {
|
|
118
186
|
allFailed: boolean;
|
|
119
187
|
failureCount: number;
|
|
@@ -5,6 +5,7 @@ import type { ChannelTransport } from "../channel-transport.js";
|
|
|
5
5
|
import {
|
|
6
6
|
sendTelegramAttachments,
|
|
7
7
|
sendTelegramReply,
|
|
8
|
+
sendTelegramRichReply,
|
|
8
9
|
sendTelegramTypingIndicator,
|
|
9
10
|
} from "./send.js";
|
|
10
11
|
|
|
@@ -17,7 +18,15 @@ export const telegramTransport: ChannelTransport = {
|
|
|
17
18
|
const { chatId, text, attachments, approval } = payload;
|
|
18
19
|
|
|
19
20
|
if (text) {
|
|
20
|
-
|
|
21
|
+
// `useBlocks` is the channel-neutral "render richly" intent set by the
|
|
22
|
+
// delivery layer; the Telegram adapter honors it by forwarding markdown
|
|
23
|
+
// to `sendRichMessage`, degrading to plain text otherwise (and on any
|
|
24
|
+
// rich-send rejection).
|
|
25
|
+
if (payload.useBlocks) {
|
|
26
|
+
await sendTelegramRichReply(chatId, text, approval);
|
|
27
|
+
} else {
|
|
28
|
+
await sendTelegramReply(chatId, text, approval);
|
|
29
|
+
}
|
|
21
30
|
} else if (approval) {
|
|
22
31
|
await sendTelegramReply(
|
|
23
32
|
chatId,
|