polygram 0.24.1 → 0.25.1

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/polygram.js CHANGED
@@ -50,7 +50,9 @@ const { extractAssistantText } = require('@shumkov/orchestra');
50
50
  // and reused by createChannelsToolDispatcher inside main() — Claude replies
51
51
  // containing code blocks or HTML-style tags aren't split mid-element by the
52
52
  // size cap.
53
- const { createChannelsToolDispatcher, buildAllowedRoots } = require('./lib/process/channels-tool-dispatcher');
53
+ const {
54
+ createChannelsToolDispatcher, buildAllowedRoots,
55
+ } = require('./lib/process/channels-tool-dispatcher');
54
56
  const { createTmuxRunner } = require('@shumkov/orchestra');
55
57
  const { sweepTmuxOrphans } = require('@shumkov/orchestra').orphanSweep;
56
58
  // rc.42: autosteer-buffer module deleted. Native SDK priority push
@@ -122,12 +124,12 @@ const {
122
124
  isRichCapabilityErrorExplicit, isRichMessageFieldRejection, stripMediaMarkdown,
123
125
  } = require('./lib/telegram/rich');
124
126
  const {
125
- createRichMediaResolver,
127
+ makeRichMediaResolver,
128
+ makeReplyMediaWiring,
126
129
  createMediaDeliveryContext,
127
130
  createMediaFileIdCache,
128
131
  collectMediaRescueEntries,
129
- PHOTO_UPLOAD_CEILING,
130
- OTHER_MEDIA_UPLOAD_CEILING,
132
+ MAX_MEDIA_PER_MESSAGE,
131
133
  } = require('./lib/telegram/rich-media');
132
134
  const { createRichEditor } = require('./lib/telegram/rich-edit');
133
135
  const { createRichCapabilityLatch } = require('./lib/telegram/rich-capability-latch');
@@ -1307,22 +1309,25 @@ async function handleMessage(sessionKey, chatId, msg, bot) {
1307
1309
  sessionKey,
1308
1310
  sessionCwd: _mediaTopicCfg.cwd || chatConfig.cwd || null,
1309
1311
  });
1310
- const maxMediaOverride = resolveMaxFileOverride(config, chatId, threadId);
1311
- const resolveRichMedia = createRichMediaResolver({
1312
+ // Same shared factory the reply-tool path uses, so the two trust boundaries
1313
+ // are one piece of code. This path keeps its wider per-message ceiling: it
1314
+ // is the interactive streamer, not the reply tool, so `files:` fan-out
1315
+ // parity does not apply to it.
1316
+ const resolveRichMedia = makeRichMediaResolver({
1312
1317
  allowedRoots: mediaAllowedRoots,
1318
+ chatId,
1319
+ threadId,
1320
+ config,
1313
1321
  fileIdCache: richMediaFileIdCache,
1314
- maxPhotoBytes: Math.min(
1315
- PHOTO_UPLOAD_CEILING,
1316
- maxMediaOverride ?? PHOTO_UPLOAD_CEILING,
1317
- ),
1318
- maxOtherMediaBytes: Math.min(
1319
- OTHER_MEDIA_UPLOAD_CEILING,
1320
- maxMediaOverride ?? OTHER_MEDIA_UPLOAD_CEILING,
1321
- ),
1322
- allowUrlMedia: !config.bot?.apiRoot,
1323
- logEvent: (kind, detail) => logEvent(kind, {
1324
- chat_id: chatId, thread_id: threadId, bot: BOT_NAME, ...detail,
1325
- }),
1322
+ // Closed on every server, not only self-hosted ones. A self-hosted Bot API
1323
+ // server fetching the URL is an SSRF surface; the cloud API fetching it is
1324
+ // an exfiltration beacon that leaves no trace on this host and bypasses
1325
+ // any egress control on it. Neither display hint teaches URL media, so
1326
+ // nothing legitimate authors it.
1327
+ allowUrlMedia: false,
1328
+ maxMediaPerMessage: MAX_MEDIA_PER_MESSAGE,
1329
+ logEvent,
1330
+ botName: BOT_NAME,
1326
1331
  });
1327
1332
  const toRichPayload = (text, opts) => {
1328
1333
  if (richKnownUnsupported || !resolveRichTextEnabled(config, chatId, threadId)) return null;
@@ -3606,6 +3611,15 @@ async function main() {
3606
3611
  persistBubbleText,
3607
3612
  logger: console,
3608
3613
  botName: BOT_NAME,
3614
+ // A consumed reply is finalized by the streamer, which resolves media
3615
+ // against the interactive path's roots and ceilings rather than this
3616
+ // call's. Rather than let the same reply obey different rules depending
3617
+ // on whether a preview happened to be live, media renders only where
3618
+ // the reply tool's own gates apply — here it degrades to its caption,
3619
+ // exactly as it does on any other path that cannot upload it.
3620
+ projectConsumedText: (text, { chatId, threadId }) => (
3621
+ resolveRichTextEnabled(config, chatId, threadId) ? stripMediaMarkdown(text) : text
3622
+ ),
3609
3623
  }),
3610
3624
  // Injected rather than imported by the dispatcher: rich-media.js requires
3611
3625
  // the dispatcher module, so the reverse direction would be a require cycle.
@@ -3615,6 +3629,19 @@ async function main() {
3615
3629
  isRichTextEnabled: (chatId, threadId) => resolveRichTextEnabled(config, chatId, threadId),
3616
3630
  getRichKnownUnsupported: () => richSendKnownUnsupported,
3617
3631
  redactError: redactBotToken,
3632
+ // Media for one reply. The envelope itself (no URL media, the `files:`
3633
+ // fan-out ceiling, the shared stat) lives in rich-media.js so it is
3634
+ // pinned by behavior rather than by this literal — nothing executes
3635
+ // this file. `allowedRoots` arrives per call from the dispatcher, which
3636
+ // computed it once and validates `files:` against that very array, so a
3637
+ // path the reply tool may upload is exactly a path image syntax may
3638
+ // upload.
3639
+ makeMediaWiring: makeReplyMediaWiring({
3640
+ config,
3641
+ fileIdCache: richMediaFileIdCache,
3642
+ logEvent,
3643
+ botName: BOT_NAME,
3644
+ }),
3618
3645
  }),
3619
3646
  ]);
3620
3647
 
@@ -3685,10 +3712,24 @@ async function main() {
3685
3712
  // CliProcess. Without it, cli chats lose the Telegram table/markdown display rules.
3686
3713
  // A resolver (not a static string) so each cli-backed chat gets its own richText
3687
3714
  // state — orchestra's factory calls this per spawn with the spawning chat/topic.
3688
- // No inline-media guidance: replies here are delivered by the reply tool, which
3689
- // renders rich text on media-stripped input, so an image would reach the user as
3690
- // its caption and nothing else.
3691
- displayHint: (chatId, threadId) => buildPolygramDisplayHint(resolveRichTextEnabled(config, chatId, threadId)),
3715
+ // inlineMedia: the reply tool renders media blocks, so the syntax the hint
3716
+ // teaches is syntax this backend delivers. The guidance is per-path for
3717
+ // exactly that reason — it is the throttle on how much media agents
3718
+ // author, and it may only be on where delivery can honor it.
3719
+ //
3720
+ // Enabling it with the code, rather than staging it behind a separate
3721
+ // switch, is deliberate: the RELEASE is the throttle. Media ships only
3722
+ // after the text-only rich path has soaked in production, so a chat that
3723
+ // turns richText on gets code and guidance in the same instant by design.
3724
+ //
3725
+ // The hint also describes media in a chat whose send capability has since
3726
+ // latched off, where replies degrade to plain text and captions. Accepted:
3727
+ // the latch is process-lifetime and rare, and the alternative — rebuilding
3728
+ // the system prompt on a capability change — would respawn live sessions.
3729
+ displayHint: (chatId, threadId) => buildPolygramDisplayHint(
3730
+ resolveRichTextEnabled(config, chatId, threadId),
3731
+ { inlineMedia: true },
3732
+ ),
3692
3733
  // Backend-default outbound cap fallback (per-spawn buildSpawnContext override
3693
3734
  // normally supersedes this; kept so any context-less spawn still gets the backend
3694
3735
  // default rather than orchestra's neutral 100MB).