@inline-openclaw/inline 0.0.22 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2695,7 +2695,7 @@ var require_commonjs = __commonJS((exports) => {
2695
2695
  } });
2696
2696
  });
2697
2697
 
2698
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/constants.js
2698
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/constants.js
2699
2699
  var require_constants = __commonJS((exports, module) => {
2700
2700
  var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
2701
2701
  var hasBlob = typeof Blob !== "undefined";
@@ -2715,7 +2715,7 @@ var require_constants = __commonJS((exports, module) => {
2715
2715
  };
2716
2716
  });
2717
2717
 
2718
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/buffer-util.js
2718
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/buffer-util.js
2719
2719
  var require_buffer_util = __commonJS((exports, module) => {
2720
2720
  var { EMPTY_BUFFER } = require_constants();
2721
2721
  var FastBuffer = Buffer[Symbol.species];
@@ -2793,7 +2793,7 @@ var require_buffer_util = __commonJS((exports, module) => {
2793
2793
  }
2794
2794
  });
2795
2795
 
2796
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/limiter.js
2796
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/limiter.js
2797
2797
  var require_limiter = __commonJS((exports, module) => {
2798
2798
  var kDone = Symbol("kDone");
2799
2799
  var kRun = Symbol("kRun");
@@ -2825,7 +2825,7 @@ var require_limiter = __commonJS((exports, module) => {
2825
2825
  module.exports = Limiter;
2826
2826
  });
2827
2827
 
2828
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js
2828
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/permessage-deflate.js
2829
2829
  var require_permessage_deflate = __commonJS((exports, module) => {
2830
2830
  var zlib = __require("zlib");
2831
2831
  var bufferUtil = require_buffer_util();
@@ -2841,11 +2841,11 @@ var require_permessage_deflate = __commonJS((exports, module) => {
2841
2841
  var zlibLimiter;
2842
2842
 
2843
2843
  class PerMessageDeflate {
2844
- constructor(options, isServer, maxPayload) {
2845
- this._maxPayload = maxPayload | 0;
2844
+ constructor(options) {
2846
2845
  this._options = options || {};
2847
2846
  this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
2848
- this._isServer = !!isServer;
2847
+ this._maxPayload = this._options.maxPayload | 0;
2848
+ this._isServer = !!this._options.isServer;
2849
2849
  this._deflate = null;
2850
2850
  this._inflate = null;
2851
2851
  this.params = null;
@@ -3089,7 +3089,7 @@ var require_permessage_deflate = __commonJS((exports, module) => {
3089
3089
  }
3090
3090
  });
3091
3091
 
3092
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/validation.js
3092
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/validation.js
3093
3093
  var require_validation = __commonJS((exports, module) => {
3094
3094
  var { isUtf8 } = __require("buffer");
3095
3095
  var { hasBlob } = require_constants();
@@ -3276,7 +3276,7 @@ var require_validation = __commonJS((exports, module) => {
3276
3276
  }
3277
3277
  });
3278
3278
 
3279
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/receiver.js
3279
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/receiver.js
3280
3280
  var require_receiver = __commonJS((exports, module) => {
3281
3281
  var { Writable } = __require("stream");
3282
3282
  var PerMessageDeflate = require_permessage_deflate();
@@ -3657,7 +3657,7 @@ var require_receiver = __commonJS((exports, module) => {
3657
3657
  module.exports = Receiver;
3658
3658
  });
3659
3659
 
3660
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/sender.js
3660
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/sender.js
3661
3661
  var require_sender = __commonJS((exports, module) => {
3662
3662
  var { Duplex } = __require("stream");
3663
3663
  var { randomFillSync } = __require("crypto");
@@ -4011,7 +4011,7 @@ var require_sender = __commonJS((exports, module) => {
4011
4011
  }
4012
4012
  });
4013
4013
 
4014
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/event-target.js
4014
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/event-target.js
4015
4015
  var require_event_target = __commonJS((exports, module) => {
4016
4016
  var { kForOnEventAttribute, kListener } = require_constants();
4017
4017
  var kCode = Symbol("kCode");
@@ -4162,7 +4162,7 @@ var require_event_target = __commonJS((exports, module) => {
4162
4162
  }
4163
4163
  });
4164
4164
 
4165
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/extension.js
4165
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/extension.js
4166
4166
  var require_extension = __commonJS((exports, module) => {
4167
4167
  var { tokenChars } = require_validation();
4168
4168
  function push(dest, name, elem) {
@@ -4327,7 +4327,7 @@ var require_extension = __commonJS((exports, module) => {
4327
4327
  module.exports = { format, parse };
4328
4328
  });
4329
4329
 
4330
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/websocket.js
4330
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/websocket.js
4331
4331
  var require_websocket = __commonJS((exports, module) => {
4332
4332
  var EventEmitter = __require("events");
4333
4333
  var https = __require("https");
@@ -4716,7 +4716,7 @@ var require_websocket = __commonJS((exports, module) => {
4716
4716
  } else {
4717
4717
  try {
4718
4718
  parsedUrl = new URL2(address);
4719
- } catch (e) {
4719
+ } catch {
4720
4720
  throw new SyntaxError(`Invalid URL: ${address}`);
4721
4721
  }
4722
4722
  }
@@ -4764,7 +4764,11 @@ var require_websocket = __commonJS((exports, module) => {
4764
4764
  opts.path = parsedUrl.pathname + parsedUrl.search;
4765
4765
  opts.timeout = opts.handshakeTimeout;
4766
4766
  if (opts.perMessageDeflate) {
4767
- perMessageDeflate = new PerMessageDeflate(opts.perMessageDeflate !== true ? opts.perMessageDeflate : {}, false, opts.maxPayload);
4767
+ perMessageDeflate = new PerMessageDeflate({
4768
+ ...opts.perMessageDeflate,
4769
+ isServer: false,
4770
+ maxPayload: opts.maxPayload
4771
+ });
4768
4772
  opts.headers["Sec-WebSocket-Extensions"] = format({
4769
4773
  [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
4770
4774
  });
@@ -5089,7 +5093,7 @@ var require_websocket = __commonJS((exports, module) => {
5089
5093
  }
5090
5094
  });
5091
5095
 
5092
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/stream.js
5096
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/stream.js
5093
5097
  var require_stream = __commonJS((exports, module) => {
5094
5098
  var WebSocket = require_websocket();
5095
5099
  var { Duplex } = __require("stream");
@@ -5192,7 +5196,7 @@ var require_stream = __commonJS((exports, module) => {
5192
5196
  module.exports = createWebSocketStream;
5193
5197
  });
5194
5198
 
5195
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/subprotocol.js
5199
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/subprotocol.js
5196
5200
  var require_subprotocol = __commonJS((exports, module) => {
5197
5201
  var { tokenChars } = require_validation();
5198
5202
  function parse(header) {
@@ -5237,7 +5241,7 @@ var require_subprotocol = __commonJS((exports, module) => {
5237
5241
  module.exports = { parse };
5238
5242
  });
5239
5243
 
5240
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/lib/websocket-server.js
5244
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/lib/websocket-server.js
5241
5245
  var require_websocket_server = __commonJS((exports, module) => {
5242
5246
  var EventEmitter = __require("events");
5243
5247
  var http = __require("http");
@@ -5410,7 +5414,11 @@ var require_websocket_server = __commonJS((exports, module) => {
5410
5414
  const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
5411
5415
  const extensions = {};
5412
5416
  if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
5413
- const perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, true, this.options.maxPayload);
5417
+ const perMessageDeflate = new PerMessageDeflate({
5418
+ ...this.options.perMessageDeflate,
5419
+ isServer: true,
5420
+ maxPayload: this.options.maxPayload
5421
+ });
5414
5422
  try {
5415
5423
  const offers = extension.parse(secWebSocketExtensions);
5416
5424
  if (offers[PerMessageDeflate.extensionName]) {
@@ -7358,7 +7366,8 @@ class Message$Type extends import_runtime4.MessageType {
7358
7366
  { no: 17, name: "send_mode", kind: "enum", opt: true, T: () => ["MessageSendMode", MessageSendMode] },
7359
7367
  { no: 18, name: "fwd_from", kind: "message", T: () => MessageFwdHeader },
7360
7368
  { no: 19, name: "replies", kind: "message", T: () => MessageReplies },
7361
- { no: 20, name: "actions", kind: "message", T: () => MessageActions }
7369
+ { no: 20, name: "actions", kind: "message", T: () => MessageActions },
7370
+ { no: 21, name: "rev", kind: "scalar", opt: true, T: 3, L: 0 }
7362
7371
  ]);
7363
7372
  }
7364
7373
  create(value) {
@@ -7440,6 +7449,9 @@ class Message$Type extends import_runtime4.MessageType {
7440
7449
  case 20:
7441
7450
  message.actions = MessageActions.internalBinaryRead(reader, reader.uint32(), options, message.actions);
7442
7451
  break;
7452
+ case 21:
7453
+ message.rev = reader.int64().toBigInt();
7454
+ break;
7443
7455
  default:
7444
7456
  let u = options.readUnknownField;
7445
7457
  if (u === "throw")
@@ -7494,6 +7506,8 @@ class Message$Type extends import_runtime4.MessageType {
7494
7506
  MessageReplies.internalBinaryWrite(message.replies, writer.tag(19, import_runtime.WireType.LengthDelimited).fork(), options).join();
7495
7507
  if (message.actions)
7496
7508
  MessageActions.internalBinaryWrite(message.actions, writer.tag(20, import_runtime.WireType.LengthDelimited).fork(), options).join();
7509
+ if (message.rev !== undefined)
7510
+ writer.tag(21, import_runtime.WireType.Varint).int64(message.rev);
7497
7511
  let u = options.writeUnknownFields;
7498
7512
  if (u !== false)
7499
7513
  (u == true ? import_runtime2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
@@ -12987,7 +13001,8 @@ class MessageTranslation$Type extends import_runtime4.MessageType {
12987
13001
  { no: 2, name: "language", kind: "scalar", T: 9 },
12988
13002
  { no: 3, name: "translation", kind: "scalar", T: 9 },
12989
13003
  { no: 4, name: "date", kind: "scalar", T: 3, L: 0 },
12990
- { no: 5, name: "entities", kind: "message", T: () => MessageEntities }
13004
+ { no: 5, name: "entities", kind: "message", T: () => MessageEntities },
13005
+ { no: 6, name: "msg_rev", kind: "scalar", T: 3, L: 0 }
12991
13006
  ]);
12992
13007
  }
12993
13008
  create(value) {
@@ -12996,6 +13011,7 @@ class MessageTranslation$Type extends import_runtime4.MessageType {
12996
13011
  message.language = "";
12997
13012
  message.translation = "";
12998
13013
  message.date = 0n;
13014
+ message.msgRev = 0n;
12999
13015
  if (value !== undefined)
13000
13016
  import_runtime3.reflectionMergePartial(this, message, value);
13001
13017
  return message;
@@ -13020,6 +13036,9 @@ class MessageTranslation$Type extends import_runtime4.MessageType {
13020
13036
  case 5:
13021
13037
  message.entities = MessageEntities.internalBinaryRead(reader, reader.uint32(), options, message.entities);
13022
13038
  break;
13039
+ case 6:
13040
+ message.msgRev = reader.int64().toBigInt();
13041
+ break;
13023
13042
  default:
13024
13043
  let u = options.readUnknownField;
13025
13044
  if (u === "throw")
@@ -13042,6 +13061,8 @@ class MessageTranslation$Type extends import_runtime4.MessageType {
13042
13061
  writer.tag(4, import_runtime.WireType.Varint).int64(message.date);
13043
13062
  if (message.entities)
13044
13063
  MessageEntities.internalBinaryWrite(message.entities, writer.tag(5, import_runtime.WireType.LengthDelimited).fork(), options).join();
13064
+ if (message.msgRev !== 0n)
13065
+ writer.tag(6, import_runtime.WireType.Varint).int64(message.msgRev);
13045
13066
  let u = options.writeUnknownFields;
13046
13067
  if (u !== false)
13047
13068
  (u == true ? import_runtime2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
@@ -18687,10 +18708,13 @@ class ProtocolClientError extends Error {
18687
18708
  }
18688
18709
  }
18689
18710
 
18690
- // ../../node_modules/.bun/ws@8.19.0/node_modules/ws/wrapper.mjs
18711
+ // ../../node_modules/.bun/ws@8.20.0/node_modules/ws/wrapper.mjs
18691
18712
  var import_stream = __toESM(require_stream(), 1);
18713
+ var import_extension = __toESM(require_extension(), 1);
18714
+ var import_permessage_deflate = __toESM(require_permessage_deflate(), 1);
18692
18715
  var import_receiver = __toESM(require_receiver(), 1);
18693
18716
  var import_sender = __toESM(require_sender(), 1);
18717
+ var import_subprotocol = __toESM(require_subprotocol(), 1);
18694
18718
  var import_websocket = __toESM(require_websocket(), 1);
18695
18719
  var import_websocket_server = __toESM(require_websocket_server(), 1);
18696
18720
 
@@ -33735,6 +33759,9 @@ var InlineActionsSchema = exports_external.object({
33735
33759
  pins: exports_external.boolean().optional(),
33736
33760
  permissions: exports_external.boolean().optional()
33737
33761
  }).strict();
33762
+ var InlineCapabilitiesSchema = exports_external.object({
33763
+ replyThreads: exports_external.boolean().optional()
33764
+ }).strict();
33738
33765
  var InlineGroupSchema = exports_external.object({
33739
33766
  requireMention: exports_external.boolean().optional(),
33740
33767
  systemPrompt: exports_external.string().optional(),
@@ -33751,6 +33778,7 @@ var InlineAccountSchemaBase = exports_external.object({
33751
33778
  baseUrl: exports_external.string().optional(),
33752
33779
  token: exports_external.string().optional(),
33753
33780
  tokenFile: exports_external.string().optional(),
33781
+ capabilities: InlineCapabilitiesSchema.optional(),
33754
33782
  dmPolicy: DmPolicySchema.optional().default("pairing"),
33755
33783
  allowFrom: exports_external.array(exports_external.string()).optional(),
33756
33784
  systemPrompt: exports_external.string().optional(),
@@ -33874,6 +33902,97 @@ async function resolveInlineToken(account) {
33874
33902
  return token;
33875
33903
  }
33876
33904
 
33905
+ // src/inline/reply-threads.ts
33906
+ var GET_CHAT_METHOD = typeof Method.GET_CHAT === "number" && Number.isInteger(Method.GET_CHAT) && Method.GET_CHAT > 0 ? Method.GET_CHAT : 25;
33907
+ var GET_CHAT_HISTORY_METHOD = typeof Method.GET_CHAT_HISTORY === "number" && Number.isInteger(Method.GET_CHAT_HISTORY) && Method.GET_CHAT_HISTORY > 0 ? Method.GET_CHAT_HISTORY : 5;
33908
+ var GET_MESSAGES_METHOD = typeof Method.GET_MESSAGES === "number" && Number.isInteger(Method.GET_MESSAGES) && Method.GET_MESSAGES > 0 ? Method.GET_MESSAGES : 38;
33909
+ function buildChatPeer(chatId) {
33910
+ return {
33911
+ type: {
33912
+ oneofKind: "chat",
33913
+ chat: { chatId }
33914
+ }
33915
+ };
33916
+ }
33917
+ function getInlineReplyThreadsCapabilityConfig(params) {
33918
+ const account = resolveInlineAccount({
33919
+ cfg: params.cfg,
33920
+ accountId: params.accountId ?? null
33921
+ });
33922
+ return {
33923
+ replyThreads: account.config.capabilities?.replyThreads === true
33924
+ };
33925
+ }
33926
+ function isInlineReplyThreadsEnabled(params) {
33927
+ return getInlineReplyThreadsCapabilityConfig(params).replyThreads;
33928
+ }
33929
+ function resolveInlineReplyThreadChatId(params) {
33930
+ if (!isInlineReplyThreadsEnabled({ cfg: params.cfg, accountId: params.accountId ?? null })) {
33931
+ return params.parentChatId;
33932
+ }
33933
+ if (params.parentChatId == null) {
33934
+ return null;
33935
+ }
33936
+ if (params.threadId == null) {
33937
+ return params.parentChatId;
33938
+ }
33939
+ const normalized = typeof params.threadId === "number" ? Number.isFinite(params.threadId) && Number.isInteger(params.threadId) && params.threadId >= 0 ? BigInt(params.threadId) : null : typeof params.threadId === "string" ? params.threadId.trim() ? (() => {
33940
+ try {
33941
+ return BigInt(params.threadId.trim());
33942
+ } catch {
33943
+ return null;
33944
+ }
33945
+ })() : null : null;
33946
+ return normalized ?? params.parentChatId;
33947
+ }
33948
+ async function loadInlineReplyThreadMetadata(params) {
33949
+ const result = await params.client.invokeRaw(GET_CHAT_METHOD, {
33950
+ oneofKind: "getChat",
33951
+ getChat: { peerId: buildChatPeer(params.chatId) }
33952
+ }).catch(() => null);
33953
+ if (result?.oneofKind !== "getChat") {
33954
+ return null;
33955
+ }
33956
+ const chat = result.getChat.chat;
33957
+ const parentChatId = chat?.parentChatId;
33958
+ if (parentChatId == null) {
33959
+ return null;
33960
+ }
33961
+ return {
33962
+ childChatId: chat?.id ?? params.chatId,
33963
+ parentChatId,
33964
+ parentMessageId: chat?.parentMessageId ?? null,
33965
+ title: chat?.title?.trim() || null
33966
+ };
33967
+ }
33968
+ async function loadInlineReplyThreadAnchorMessage(params) {
33969
+ const directResult = await params.client.invokeRaw(GET_MESSAGES_METHOD, {
33970
+ oneofKind: "getMessages",
33971
+ getMessages: {
33972
+ peerId: buildChatPeer(params.parentChatId),
33973
+ messageIds: [params.parentMessageId]
33974
+ }
33975
+ }).catch(() => null);
33976
+ if (directResult?.oneofKind === "getMessages") {
33977
+ const directTarget = (directResult.getMessages.messages ?? []).find((item) => item.id === params.parentMessageId) ?? null;
33978
+ if (directTarget) {
33979
+ return directTarget;
33980
+ }
33981
+ }
33982
+ const historyResult = await params.client.invokeRaw(GET_CHAT_HISTORY_METHOD, {
33983
+ oneofKind: "getChatHistory",
33984
+ getChatHistory: {
33985
+ peerId: buildChatPeer(params.parentChatId),
33986
+ offsetId: params.parentMessageId + 1n,
33987
+ limit: 8
33988
+ }
33989
+ }).catch(() => null);
33990
+ if (historyResult?.oneofKind !== "getChatHistory") {
33991
+ return null;
33992
+ }
33993
+ return (historyResult.getChatHistory.messages ?? []).find((item) => item.id === params.parentMessageId) ?? null;
33994
+ }
33995
+
33877
33996
  // src/inline/normalize.ts
33878
33997
  function normalizeInlineTarget(raw) {
33879
33998
  let normalized = raw.trim();
@@ -34534,11 +34653,12 @@ function bestPhotoSize(photo) {
34534
34653
  return best;
34535
34654
  }
34536
34655
  function messageMediaSummary(message) {
34537
- const media = message.media?.media;
34656
+ const mediaContainer = message.media;
34657
+ const media = mediaContainer && typeof mediaContainer === "object" ? "media" in mediaContainer && mediaContainer.media && typeof mediaContainer.media === "object" && "oneofKind" in mediaContainer.media ? mediaContainer.media : ("oneofKind" in mediaContainer) ? mediaContainer : null : null;
34538
34658
  if (!media)
34539
34659
  return null;
34540
34660
  if (media.oneofKind === "photo") {
34541
- const photo = media.photo.photo;
34661
+ const photo = media.photo?.photo;
34542
34662
  const bestSize = photo ? bestPhotoSize(photo) : { cdnUrl: null, width: null, height: null, sizeBytes: null };
34543
34663
  return {
34544
34664
  kind: "photo",
@@ -34550,7 +34670,7 @@ function messageMediaSummary(message) {
34550
34670
  };
34551
34671
  }
34552
34672
  if (media.oneofKind === "video") {
34553
- const video = media.video.video;
34673
+ const video = media.video?.video;
34554
34674
  return {
34555
34675
  kind: "video",
34556
34676
  id: video?.id?.toString() ?? null,
@@ -34562,7 +34682,7 @@ function messageMediaSummary(message) {
34562
34682
  };
34563
34683
  }
34564
34684
  if (media.oneofKind === "document") {
34565
- const document = media.document.document;
34685
+ const document = media.document?.document;
34566
34686
  return {
34567
34687
  kind: "document",
34568
34688
  id: document?.id?.toString() ?? null,
@@ -34572,6 +34692,17 @@ function messageMediaSummary(message) {
34572
34692
  sizeBytes: document?.size ?? null
34573
34693
  };
34574
34694
  }
34695
+ if (media.oneofKind === "voice") {
34696
+ const voice = media.voice?.voice;
34697
+ return {
34698
+ kind: "voice",
34699
+ id: voice?.id?.toString() ?? null,
34700
+ url: voice?.cdnUrl ?? null,
34701
+ mimeType: voice?.mimeType ?? null,
34702
+ sizeBytes: voice?.size ?? null,
34703
+ durationSeconds: voice?.duration ?? null
34704
+ };
34705
+ }
34575
34706
  return {
34576
34707
  kind: "nudge",
34577
34708
  id: null,
@@ -34715,6 +34846,9 @@ function formatMediaSummary(media) {
34715
34846
  if (media.kind === "video") {
34716
34847
  return media.url ? `video attachment: ${media.url}` : "video attachment";
34717
34848
  }
34849
+ if (media.kind === "voice") {
34850
+ return media.url ? `audio attachment: ${media.url}` : "audio attachment";
34851
+ }
34718
34852
  const label = media.fileName ? `document attachment (${media.fileName})` : "document attachment";
34719
34853
  return media.url ? `${label}: ${media.url}` : label;
34720
34854
  }
@@ -35041,7 +35175,7 @@ var REACTION_TARGET_LOOKUP_LIMIT = 8;
35041
35175
  var REPLY_TARGET_LOOKUP_LIMIT = 8;
35042
35176
  var ATTACHMENT_CONTEXT_LIMIT = 6;
35043
35177
  var DEFAULT_INLINE_MEDIA_MAX_BYTES = 300 * 1024 * 1024;
35044
- var GET_MESSAGES_METHOD = typeof Method.GET_MESSAGES === "number" && Number.isInteger(Method.GET_MESSAGES) && Method.GET_MESSAGES > 0 ? Method.GET_MESSAGES : null;
35178
+ var GET_MESSAGES_METHOD2 = typeof Method.GET_MESSAGES === "number" && Number.isInteger(Method.GET_MESSAGES) && Method.GET_MESSAGES > 0 ? Method.GET_MESSAGES : null;
35045
35179
  function normalizeAllowEntry(raw) {
35046
35180
  return raw.trim().replace(/^inline:/i, "").replace(/^user:/i, "");
35047
35181
  }
@@ -35265,7 +35399,7 @@ function rememberBotMessagesFromList(params) {
35265
35399
  }
35266
35400
  }
35267
35401
  }
35268
- function buildChatPeer(chatId) {
35402
+ function buildChatPeer2(chatId) {
35269
35403
  return {
35270
35404
  type: {
35271
35405
  oneofKind: "chat",
@@ -35277,7 +35411,7 @@ async function loadChatHistoryMessages(params) {
35277
35411
  const result = await params.client.invokeRaw(Method.GET_CHAT_HISTORY, {
35278
35412
  oneofKind: "getChatHistory",
35279
35413
  getChatHistory: {
35280
- peerId: buildChatPeer(params.chatId),
35414
+ peerId: buildChatPeer2(params.chatId),
35281
35415
  ...params.offsetId != null ? { offsetId: params.offsetId } : {},
35282
35416
  limit: params.limit
35283
35417
  }
@@ -35288,10 +35422,10 @@ async function loadChatHistoryMessages(params) {
35288
35422
  return result.getChatHistory.messages ?? [];
35289
35423
  }
35290
35424
  async function findChatMessageById(params) {
35291
- const directResult = GET_MESSAGES_METHOD == null ? null : await params.client.invokeRaw(GET_MESSAGES_METHOD, {
35425
+ const directResult = GET_MESSAGES_METHOD2 == null ? null : await params.client.invokeRaw(GET_MESSAGES_METHOD2, {
35292
35426
  oneofKind: "getMessages",
35293
35427
  getMessages: {
35294
- peerId: buildChatPeer(params.chatId),
35428
+ peerId: buildChatPeer2(params.chatId),
35295
35429
  messageIds: [params.messageId]
35296
35430
  }
35297
35431
  }).catch(() => null);
@@ -35416,6 +35550,89 @@ function mergeInboundHistoryEntries(params) {
35416
35550
  ...entry.timestamp != null ? { timestamp: entry.timestamp } : {}
35417
35551
  }));
35418
35552
  }
35553
+ function buildInlineHistoryEntryPayload(params) {
35554
+ const content = summarizeInlineMessageContent(params.message);
35555
+ const text = normalizeHistoryText(content.text);
35556
+ if (!text) {
35557
+ return {
35558
+ line: null,
35559
+ attachmentLine: null,
35560
+ entityLine: null,
35561
+ inboundEntry: null
35562
+ };
35563
+ }
35564
+ const label = resolveHistorySenderLabel({
35565
+ senderId: params.message.fromId,
35566
+ meId: params.meId,
35567
+ senderProfilesById: params.senderProfilesById
35568
+ });
35569
+ const replySuffix = params.message.replyToMsgId != null ? ` ->${String(params.message.replyToMsgId)}` : "";
35570
+ const messageId = params.syntheticMessageId ?? String(params.message.id);
35571
+ const attachmentText = normalizeHistoryText(content.attachmentText);
35572
+ const entityText = normalizeHistoryText(content.entityText);
35573
+ return {
35574
+ line: `#${String(params.message.id)}${replySuffix} ${label}: ${text}`,
35575
+ attachmentLine: attachmentText ? `#${String(params.message.id)}${replySuffix} ${label}: ${attachmentText}` : null,
35576
+ entityLine: entityText ? `#${String(params.message.id)}${replySuffix} ${label}: ${entityText}` : null,
35577
+ inboundEntry: {
35578
+ sender: label,
35579
+ body: text,
35580
+ ...params.message.date != null ? { timestamp: Number(params.message.date) * 1000 } : {},
35581
+ messageId
35582
+ }
35583
+ };
35584
+ }
35585
+ function appendInlineHistoryEntry(target, entry) {
35586
+ if (!entry.inboundEntry || !entry.line)
35587
+ return;
35588
+ target.inboundHistory.push(entry.inboundEntry);
35589
+ target.lines.push(entry.line);
35590
+ if (entry.attachmentLine) {
35591
+ target.attachmentLines.push(entry.attachmentLine);
35592
+ }
35593
+ if (entry.entityLine) {
35594
+ target.entityLines.push(entry.entityLine);
35595
+ }
35596
+ }
35597
+ function prependLabeledHistoryLine(params) {
35598
+ if (!params.line)
35599
+ return params.existing;
35600
+ const prefix = `${params.heading}
35601
+ `;
35602
+ const existingBody = params.existing?.startsWith(prefix) ? params.existing.slice(prefix.length) : params.existing;
35603
+ return existingBody ? `${prefix}${params.line}
35604
+ ${existingBody}` : `${prefix}${params.line}`;
35605
+ }
35606
+ function prependInlineReplyThreadAnchor(params) {
35607
+ const entry = buildInlineHistoryEntryPayload({
35608
+ message: params.anchorMessage,
35609
+ senderProfilesById: params.senderProfilesById,
35610
+ meId: params.meId,
35611
+ syntheticMessageId: `anchor:${String(params.parentChatId)}:${String(params.anchorMessage.id)}`
35612
+ });
35613
+ if (!entry.inboundEntry || !entry.line) {
35614
+ return params.historyContext;
35615
+ }
35616
+ return {
35617
+ ...params.historyContext,
35618
+ inboundHistory: [entry.inboundEntry, ...params.historyContext.inboundHistory],
35619
+ historyText: prependLabeledHistoryLine({
35620
+ existing: params.historyContext.historyText,
35621
+ heading: "Recent thread messages (oldest -> newest):",
35622
+ line: entry.line
35623
+ }),
35624
+ attachmentText: prependLabeledHistoryLine({
35625
+ existing: params.historyContext.attachmentText,
35626
+ heading: "Recent media/attachments:",
35627
+ line: entry.attachmentLine
35628
+ }),
35629
+ entityText: prependLabeledHistoryLine({
35630
+ existing: params.historyContext.entityText,
35631
+ heading: "Recent message entities:",
35632
+ line: entry.entityLine
35633
+ })
35634
+ };
35635
+ }
35419
35636
  function buildInlineBodyForAgent(params) {
35420
35637
  return [
35421
35638
  params.rawBody,
@@ -35461,6 +35678,8 @@ function buildInlineAttachmentPlaceholder(content) {
35461
35678
  return "<media:video>";
35462
35679
  case "document":
35463
35680
  return "<media:document>";
35681
+ case "voice":
35682
+ return "<media:audio>";
35464
35683
  default:
35465
35684
  return "";
35466
35685
  }
@@ -35519,6 +35738,34 @@ async function resolveInlineInboundMedia(params) {
35519
35738
  }
35520
35739
  return out;
35521
35740
  }
35741
+ async function resolveInlineInboundReplyThreadContext(params) {
35742
+ if (params.chatInfo.kind === "direct" || !params.replyThreadsEnabled) {
35743
+ return null;
35744
+ }
35745
+ const metadata = await loadInlineReplyThreadMetadata({
35746
+ client: params.client,
35747
+ chatId: params.chatId
35748
+ });
35749
+ if (!metadata) {
35750
+ return null;
35751
+ }
35752
+ const parentChatInfo = metadata.parentChatId === params.chatId ? params.chatInfo : await resolveChatInfo(params.client, params.chatCache, metadata.parentChatId).catch(() => ({
35753
+ kind: "group",
35754
+ title: null
35755
+ }));
35756
+ const anchorMessage = metadata.parentMessageId != null ? await loadInlineReplyThreadAnchorMessage({
35757
+ client: params.client,
35758
+ parentChatId: metadata.parentChatId,
35759
+ parentMessageId: metadata.parentMessageId
35760
+ }).catch(() => null) : null;
35761
+ return {
35762
+ childChatId: metadata.childChatId,
35763
+ parentChatId: metadata.parentChatId,
35764
+ parentChatTitle: parentChatInfo.title ?? null,
35765
+ threadLabel: metadata.title ?? params.chatInfo.title ?? null,
35766
+ anchorMessage
35767
+ };
35768
+ }
35522
35769
  async function buildHistoryContext2(params) {
35523
35770
  const cachedReplyToBot = params.replyToMsgId != null && hasBotMessageId(params.botMessageIdsByChat, params.chatId, params.replyToMsgId);
35524
35771
  let repliedToBot = cachedReplyToBot;
@@ -35555,31 +35802,16 @@ async function buildHistoryContext2(params) {
35555
35802
  replyToSenderId = String(item.fromId);
35556
35803
  repliedToBot = item.fromId === params.meId;
35557
35804
  }
35558
- const content = summarizeInlineMessageContent(item);
35559
- const text = normalizeHistoryText(content.text);
35560
- if (!text)
35561
- continue;
35562
- const label = resolveHistorySenderLabel({
35563
- senderId: item.fromId,
35564
- meId: params.meId,
35565
- senderProfilesById: params.senderProfilesById
35566
- });
35567
- inboundHistory.push({
35568
- sender: label,
35569
- body: text,
35570
- ...item.date != null ? { timestamp: Number(item.date) * 1000 } : {},
35571
- messageId: String(item.id)
35572
- });
35573
- const replySuffix = item.replyToMsgId != null ? ` ->${String(item.replyToMsgId)}` : "";
35574
- lines.push(`#${String(item.id)}${replySuffix} ${label}: ${text}`);
35575
- const attachmentText = normalizeHistoryText(content.attachmentText);
35576
- if (attachmentText) {
35577
- attachmentLines.push(`#${String(item.id)}${replySuffix} ${label}: ${attachmentText}`);
35578
- }
35579
- const entityText = normalizeHistoryText(content.entityText);
35580
- if (entityText) {
35581
- entityLines.push(`#${String(item.id)}${replySuffix} ${label}: ${entityText}`);
35582
- }
35805
+ appendInlineHistoryEntry({
35806
+ lines,
35807
+ attachmentLines,
35808
+ entityLines,
35809
+ inboundHistory
35810
+ }, buildInlineHistoryEntryPayload({
35811
+ message: item,
35812
+ senderProfilesById: params.senderProfilesById,
35813
+ meId: params.meId
35814
+ }));
35583
35815
  }
35584
35816
  }
35585
35817
  }
@@ -35711,6 +35943,7 @@ async function monitorInlineProvider(params) {
35711
35943
  const rawEvent = event;
35712
35944
  let msg;
35713
35945
  let rawBody = "";
35946
+ let currentContent = null;
35714
35947
  let currentAttachmentText = null;
35715
35948
  let currentEntityText = null;
35716
35949
  let reactionEvent = null;
@@ -35722,10 +35955,10 @@ async function monitorInlineProvider(params) {
35722
35955
  ...event.message,
35723
35956
  chatId: event.chatId
35724
35957
  };
35725
- const content = summarizeInlineMessageContent(msg);
35726
- rawBody = buildInlineInboundBodyText(content);
35727
- currentAttachmentText = content.attachmentText || null;
35728
- currentEntityText = content.entityText || null;
35958
+ currentContent = summarizeInlineMessageContent(msg);
35959
+ rawBody = buildInlineInboundBodyText(currentContent);
35960
+ currentAttachmentText = currentContent.attachmentText || null;
35961
+ currentEntityText = currentContent.entityText || null;
35729
35962
  if (!rawBody)
35730
35963
  continue;
35731
35964
  if (msg.out || msg.fromId === meId)
@@ -35837,6 +36070,19 @@ async function monitorInlineProvider(params) {
35837
36070
  statusSink?.({ lastError: `getChat failed: ${String(err)}` });
35838
36071
  }
35839
36072
  const isGroup = chatInfo.kind !== "direct";
36073
+ const replyThreadsEnabled = account.config.capabilities?.replyThreads === true || isInlineReplyThreadsEnabled({ cfg, accountId: account.accountId });
36074
+ const replyThreadContext = await resolveInlineInboundReplyThreadContext({
36075
+ replyThreadsEnabled,
36076
+ client,
36077
+ chatId,
36078
+ chatInfo,
36079
+ chatCache
36080
+ }).catch((err) => {
36081
+ statusSink?.({ lastError: `getChat (reply thread) failed: ${String(err)}` });
36082
+ return null;
36083
+ });
36084
+ const effectiveChatId = replyThreadContext?.parentChatId ?? chatId;
36085
+ const effectiveGroupTitle = replyThreadContext?.parentChatTitle ?? chatInfo.title ?? null;
35840
36086
  const senderId = String(msg.fromId);
35841
36087
  await hydrateChatParticipants(chatId);
35842
36088
  const senderProfile = senderProfilesById.get(senderId);
@@ -35988,7 +36234,7 @@ ${JSON.stringify(payload)}`;
35988
36234
  accountId: account.accountId,
35989
36235
  peer: {
35990
36236
  kind: isGroup ? "group" : "direct",
35991
- id: isGroup ? String(chatId) : senderId
36237
+ id: isGroup ? String(effectiveChatId) : senderId
35992
36238
  }
35993
36239
  });
35994
36240
  const mentionRegexes = core3.channel.mentions.buildMentionRegexes(cfg, route.agentId);
@@ -35996,7 +36242,7 @@ ${JSON.stringify(payload)}`;
35996
36242
  const patternMentioned = mentionRegexes.length ? core3.channel.mentions.matchesMentionPatterns(rawBody, mentionRegexes) : false;
35997
36243
  const wasMentioned = nativeMentioned || patternMentioned;
35998
36244
  const messageTimestamp = Number(msg.date) * 1000;
35999
- const groupHistoryKey = isGroup ? route.sessionKey : null;
36245
+ const groupHistoryKey = isGroup ? replyThreadContext ? `${route.sessionKey}:thread:${String(replyThreadContext.childChatId)}` : route.sessionKey : null;
36000
36246
  const pendingHistorySender = senderUsername ? `@${senderUsername}` : senderName ?? `user:${senderId}`;
36001
36247
  const historyLimit = resolveHistoryLimit({
36002
36248
  cfg,
@@ -36024,10 +36270,17 @@ ${JSON.stringify(payload)}`;
36024
36270
  replyToSenderId: null
36025
36271
  };
36026
36272
  });
36027
- const implicitMention = (reactionEvent != null || callbackActionEvent != null) && isGroup || isGroup && (account.config.replyToBotWithoutMention ?? false) && msg.replyToMsgId != null && historyContext.repliedToBot;
36273
+ const effectiveHistoryContext = replyThreadContext?.anchorMessage != null ? prependInlineReplyThreadAnchor({
36274
+ historyContext,
36275
+ anchorMessage: replyThreadContext.anchorMessage,
36276
+ parentChatId: replyThreadContext.parentChatId,
36277
+ senderProfilesById,
36278
+ meId
36279
+ }) : historyContext;
36280
+ const implicitMention = (reactionEvent != null || callbackActionEvent != null) && isGroup || isGroup && (account.config.replyToBotWithoutMention ?? false) && msg.replyToMsgId != null && effectiveHistoryContext.repliedToBot;
36028
36281
  const requireMention = isGroup ? resolveInlineGroupRequireMention({
36029
36282
  cfg,
36030
- groupId: String(chatId),
36283
+ groupId: String(effectiveChatId),
36031
36284
  accountId: account.accountId,
36032
36285
  requireMentionDefault: account.config.requireMention ?? false
36033
36286
  }) : false;
@@ -36043,13 +36296,14 @@ ${JSON.stringify(payload)}`;
36043
36296
  });
36044
36297
  if (isGroup && mentionGate.shouldSkip) {
36045
36298
  runtime2.log?.(`inline: drop group chat ${String(chatId)} (no mention)`);
36299
+ const pendingBody = normalizeHistoryText(currentContent?.text) ?? normalizeHistoryText(rawBody);
36046
36300
  recordPendingHistoryEntryIfEnabled({
36047
36301
  historyMap: groupPendingHistories,
36048
36302
  historyKey: groupHistoryKey ?? "",
36049
36303
  limit: historyLimit,
36050
- entry: groupHistoryKey && rawBody.trim() ? {
36304
+ entry: groupHistoryKey && pendingBody ? {
36051
36305
  sender: pendingHistorySender,
36052
- body: rawBody.trim(),
36306
+ body: pendingBody,
36053
36307
  timestamp: messageTimestamp || Date.now(),
36054
36308
  messageId: String(msg.id)
36055
36309
  } : null
@@ -36090,14 +36344,14 @@ ${JSON.stringify(payload)}`;
36090
36344
  ...log ? { log } : {}
36091
36345
  });
36092
36346
  const timestamp = messageTimestamp;
36093
- const fromLabel = isGroup ? `chat:${chatInfo.title ?? String(chatId)}` : `user:${senderId}`;
36347
+ const fromLabel = isGroup ? `chat:${effectiveGroupTitle ?? String(effectiveChatId)}` : `user:${senderId}`;
36094
36348
  const storePath = core3.channel.session.resolveStorePath(cfg.session?.store, { agentId: route.agentId });
36095
36349
  const envelopeOptions = core3.channel.reply.resolveEnvelopeFormatOptions(cfg);
36096
36350
  const previousTimestamp = core3.channel.session.readSessionUpdatedAt({ storePath, sessionKey: route.sessionKey });
36097
36351
  const combinedBody = [
36098
- historyContext.historyText,
36099
- historyContext.attachmentText,
36100
- historyContext.entityText,
36352
+ effectiveHistoryContext.historyText,
36353
+ effectiveHistoryContext.attachmentText,
36354
+ effectiveHistoryContext.entityText,
36101
36355
  INLINE_FORMATTING_NOTE,
36102
36356
  `Current message:
36103
36357
  ${rawBody}`,
@@ -36132,7 +36386,7 @@ ${currentEntityText}` : null
36132
36386
  });
36133
36387
  }
36134
36388
  const inboundHistory = isGroup && groupHistoryKey ? mergeInboundHistoryEntries({
36135
- historyContextEntries: historyContext.inboundHistory,
36389
+ historyContextEntries: effectiveHistoryContext.inboundHistory,
36136
36390
  pendingEntries: groupPendingHistories.get(groupHistoryKey) ?? [],
36137
36391
  limit: historyLimit
36138
36392
  }) : [];
@@ -36144,7 +36398,7 @@ ${currentEntityText}` : null
36144
36398
  const effectiveSurface = shouldUseTelegramSurfaceForModelCommands(normalizedCommandBody) ? "telegram" : CHANNEL_ID;
36145
36399
  const systemPrompt = resolveInlineSystemPrompt({
36146
36400
  account,
36147
- ...isGroup ? { groupId: String(chatId) } : {}
36401
+ ...isGroup ? { groupId: String(effectiveChatId) } : {}
36148
36402
  });
36149
36403
  const ctxPayload = core3.channel.reply.finalizeInboundContext({
36150
36404
  Body: body,
@@ -36152,22 +36406,25 @@ ${currentEntityText}` : null
36152
36406
  ...isGroup ? { InboundHistory: inboundHistory } : {},
36153
36407
  RawBody: rawBody,
36154
36408
  CommandBody: normalizedCommandBody,
36155
- From: isGroup ? `inline:chat:${String(chatId)}` : `inline:${senderId}`,
36156
- To: `inline:${String(chatId)}`,
36409
+ From: isGroup ? `inline:chat:${String(effectiveChatId)}` : `inline:${senderId}`,
36410
+ To: `inline:${String(effectiveChatId)}`,
36157
36411
  SessionKey: route.sessionKey,
36412
+ ...replyThreadContext ? { ParentSessionKey: route.sessionKey } : {},
36158
36413
  AccountId: route.accountId,
36159
36414
  ChatType: isGroup ? "group" : "direct",
36160
36415
  ConversationLabel: fromLabel,
36161
- ...isGroup ? { GroupSubject: chatInfo.title ?? String(chatId) } : {},
36416
+ ...isGroup ? { GroupSubject: effectiveGroupTitle ?? String(effectiveChatId) } : {},
36162
36417
  SenderId: senderId,
36163
36418
  ...senderName ? { SenderName: senderName } : {},
36164
36419
  ...senderUsername ? { SenderUsername: senderUsername } : {},
36165
36420
  Provider: CHANNEL_ID,
36166
36421
  Surface: effectiveSurface,
36167
36422
  MessageSid: String(msg.id),
36423
+ ...replyThreadContext ? { MessageThreadId: String(replyThreadContext.childChatId) } : {},
36424
+ ...replyThreadContext?.threadLabel ? { ThreadLabel: replyThreadContext.threadLabel } : {},
36168
36425
  ...msg.replyToMsgId != null ? { ReplyToId: String(msg.replyToMsgId) } : {},
36169
- ...historyContext.replyToSenderId != null ? { ReplyToSenderId: historyContext.replyToSenderId } : {},
36170
- ...msg.replyToMsgId != null ? { ReplyToWasBot: historyContext.repliedToBot } : {},
36426
+ ...effectiveHistoryContext.replyToSenderId != null ? { ReplyToSenderId: effectiveHistoryContext.replyToSenderId } : {},
36427
+ ...msg.replyToMsgId != null ? { ReplyToWasBot: effectiveHistoryContext.repliedToBot } : {},
36171
36428
  ...callbackActionEvent ? {
36172
36429
  MessageActionInteractionId: String(callbackActionEvent.interactionId),
36173
36430
  MessageActionId: callbackActionEvent.actionId,
@@ -36180,7 +36437,7 @@ ${currentEntityText}` : null
36180
36437
  CommandAuthorized: commandAuthorized,
36181
36438
  GroupSystemPrompt: systemPrompt,
36182
36439
  OriginatingChannel: CHANNEL_ID,
36183
- OriginatingTo: `inline:${String(chatId)}`
36440
+ OriginatingTo: `inline:${String(effectiveChatId)}`
36184
36441
  });
36185
36442
  await core3.channel.session.recordInboundSession({
36186
36443
  storePath,
@@ -36190,7 +36447,7 @@ ${currentEntityText}` : null
36190
36447
  updateLastRoute: {
36191
36448
  sessionKey: route.mainSessionKey,
36192
36449
  channel: CHANNEL_ID,
36193
- to: `inline:${String(chatId)}`,
36450
+ to: `inline:${String(effectiveChatId)}`,
36194
36451
  accountId: route.accountId
36195
36452
  }
36196
36453
  } : {},
@@ -36267,7 +36524,7 @@ ${currentEntityText}` : null
36267
36524
  oneofKind: "editMessage",
36268
36525
  editMessage: {
36269
36526
  messageId: editStreamState.messageId,
36270
- peerId: buildChatPeer(chatId),
36527
+ peerId: buildChatPeer2(chatId),
36271
36528
  text: nextText,
36272
36529
  parseMarkdown
36273
36530
  }
@@ -36341,7 +36598,7 @@ ${currentEntityText}` : null
36341
36598
  oneofKind: "editMessage",
36342
36599
  editMessage: {
36343
36600
  messageId: editStreamState.messageId,
36344
- peerId: buildChatPeer(chatId),
36601
+ peerId: buildChatPeer2(chatId),
36345
36602
  text: textForEdit,
36346
36603
  parseMarkdown,
36347
36604
  ...actions !== undefined ? { actions } : {}
@@ -36549,7 +36806,8 @@ for (const group of ACTION_GROUPS) {
36549
36806
  }
36550
36807
  }
36551
36808
  var SUPPORTED_ACTIONS = Array.from(ACTION_TO_GATE_KEY.keys());
36552
- var GET_MESSAGES_METHOD2 = typeof Method.GET_MESSAGES === "number" && Number.isInteger(Method.GET_MESSAGES) && Method.GET_MESSAGES > 0 ? Method.GET_MESSAGES : null;
36809
+ var GET_MESSAGES_METHOD3 = typeof Method.GET_MESSAGES === "number" && Number.isInteger(Method.GET_MESSAGES) && Method.GET_MESSAGES > 0 ? Method.GET_MESSAGES : null;
36810
+ var CREATE_SUBTHREAD_METHOD = typeof Method.CREATE_SUBTHREAD === "number" && Number.isInteger(Method.CREATE_SUBTHREAD) && Method.CREATE_SUBTHREAD > 0 ? Method.CREATE_SUBTHREAD : 43;
36553
36811
  var INLINE_ACTION_MAX_ROWS2 = 8;
36554
36812
  var INLINE_ACTION_MAX_PER_ROW2 = 8;
36555
36813
  function isRecord4(value) {
@@ -36890,7 +37148,7 @@ function resolveMessageSendTargetFromParams(params) {
36890
37148
  chatId: BigInt(normalized)
36891
37149
  };
36892
37150
  }
36893
- function buildChatPeer2(chatId) {
37151
+ function buildChatPeer3(chatId) {
36894
37152
  return {
36895
37153
  type: {
36896
37154
  oneofKind: "chat",
@@ -36979,10 +37237,10 @@ async function loadMessageReactions(params) {
36979
37237
  return Array.from(byEmoji.values());
36980
37238
  }
36981
37239
  async function findMessageById(params) {
36982
- const directResult = GET_MESSAGES_METHOD2 == null ? null : await params.client.invokeRaw(GET_MESSAGES_METHOD2, {
37240
+ const directResult = GET_MESSAGES_METHOD3 == null ? null : await params.client.invokeRaw(GET_MESSAGES_METHOD3, {
36983
37241
  oneofKind: "getMessages",
36984
37242
  getMessages: {
36985
- peerId: buildChatPeer2(params.chatId),
37243
+ peerId: buildChatPeer3(params.chatId),
36986
37244
  messageIds: [params.messageId]
36987
37245
  }
36988
37246
  }).catch(() => null);
@@ -36992,7 +37250,7 @@ async function findMessageById(params) {
36992
37250
  const result = await params.client.invokeRaw(Method.GET_CHAT_HISTORY, {
36993
37251
  oneofKind: "getChatHistory",
36994
37252
  getChatHistory: {
36995
- peerId: buildChatPeer2(params.chatId),
37253
+ peerId: buildChatPeer3(params.chatId),
36996
37254
  offsetId: params.messageId + 1n,
36997
37255
  limit: 8
36998
37256
  }
@@ -37066,7 +37324,7 @@ async function resolveSpaceIdFromParams(params) {
37066
37324
  const chatId = BigInt(normalizeChatId(chatTarget));
37067
37325
  const chatResult = await params.client.invokeRaw(Method.GET_CHAT, {
37068
37326
  oneofKind: "getChat",
37069
- getChat: { peerId: buildChatPeer2(chatId) }
37327
+ getChat: { peerId: buildChatPeer3(chatId) }
37070
37328
  });
37071
37329
  if (chatResult.oneofKind !== "getChat") {
37072
37330
  throw new Error(`inline action: expected getChat result, got ${String(chatResult.oneofKind)}`);
@@ -37236,11 +37494,35 @@ var inlineMessageActions = {
37236
37494
  }
37237
37495
  if (normalizedAction === "reply" || normalizedAction === "thread-reply") {
37238
37496
  const parseMarkdown = resolveInlineAccount({ cfg, accountId: accountId ?? null }).config.parseMarkdown ?? true;
37497
+ const replyThreadsEnabled = normalizedAction === "thread-reply" && isInlineReplyThreadsEnabled({ cfg, accountId: accountId ?? null });
37239
37498
  return await withInlineClient({
37240
37499
  cfg,
37241
37500
  accountId,
37242
37501
  fn: async (client) => {
37243
37502
  const actions = resolveInlineMessageActionsParam(params);
37503
+ if (replyThreadsEnabled) {
37504
+ const rawThreadId = readFlexibleId(params, "threadId") ?? readStringParam(params, "threadId");
37505
+ if (!rawThreadId) {
37506
+ throw new Error("inline thread-reply: threadId is required when reply threads are enabled");
37507
+ }
37508
+ const chatId2 = parseInlineId(rawThreadId, "threadId");
37509
+ const replyToMsgId2 = parseOptionalInlineId(readFlexibleId(params, "messageId") ?? readFlexibleId(params, "replyTo") ?? readFlexibleId(params, "replyToId") ?? readStringParam(params, "messageId") ?? readStringParam(params, "replyTo") ?? readStringParam(params, "replyToId"), "messageId");
37510
+ const text2 = readStringParam(params, "message") ?? readStringParam(params, "text", { required: true, allowEmpty: true });
37511
+ const sent2 = await client.sendMessage({
37512
+ chatId: chatId2,
37513
+ text: text2,
37514
+ ...actions !== undefined ? { actions } : {},
37515
+ ...replyToMsgId2 != null ? { replyToMsgId: replyToMsgId2 } : {},
37516
+ parseMarkdown
37517
+ });
37518
+ return jsonResult({
37519
+ ok: true,
37520
+ chatId: String(chatId2),
37521
+ threadId: String(chatId2),
37522
+ messageId: sent2.messageId != null ? String(sent2.messageId) : null,
37523
+ replyToId: replyToMsgId2 != null ? String(replyToMsgId2) : null
37524
+ });
37525
+ }
37244
37526
  const replyParams = normalizedAction === "thread-reply" && params.threadId != null && params.to == null && params.chatId == null && params.channelId == null ? { ...params, to: params.threadId } : params;
37245
37527
  const chatId = resolveChatIdFromParams(replyParams);
37246
37528
  const replyToMsgId = parseInlineId(readFlexibleId(replyParams, "messageId") ?? readFlexibleId(replyParams, "replyTo") ?? readFlexibleId(replyParams, "replyToId") ?? readStringParam(replyParams, "messageId") ?? readStringParam(replyParams, "replyTo") ?? readStringParam(replyParams, "replyToId", { required: true }), "messageId");
@@ -37279,7 +37561,7 @@ var inlineMessageActions = {
37279
37561
  oneofKind: "deleteReaction",
37280
37562
  deleteReaction: {
37281
37563
  emoji: emoji3,
37282
- peerId: buildChatPeer2(chatId),
37564
+ peerId: buildChatPeer3(chatId),
37283
37565
  messageId
37284
37566
  }
37285
37567
  });
@@ -37292,7 +37574,7 @@ var inlineMessageActions = {
37292
37574
  addReaction: {
37293
37575
  emoji: emoji3,
37294
37576
  messageId,
37295
- peerId: buildChatPeer2(chatId)
37577
+ peerId: buildChatPeer3(chatId)
37296
37578
  }
37297
37579
  });
37298
37580
  if (result.oneofKind !== "addReaction") {
@@ -37341,7 +37623,7 @@ var inlineMessageActions = {
37341
37623
  const result = await client.invokeRaw(Method.GET_CHAT_HISTORY, {
37342
37624
  oneofKind: "getChatHistory",
37343
37625
  getChatHistory: {
37344
- peerId: buildChatPeer2(chatId),
37626
+ peerId: buildChatPeer3(chatId),
37345
37627
  ...offsetId != null ? { offsetId } : {},
37346
37628
  limit
37347
37629
  }
@@ -37369,7 +37651,7 @@ var inlineMessageActions = {
37369
37651
  const result = await client.invokeRaw(Method.SEARCH_MESSAGES, {
37370
37652
  oneofKind: "searchMessages",
37371
37653
  searchMessages: {
37372
- peerId: buildChatPeer2(chatId),
37654
+ peerId: buildChatPeer3(chatId),
37373
37655
  queries: [query],
37374
37656
  limit,
37375
37657
  ...offsetId != null ? { offsetId } : {}
@@ -37401,7 +37683,7 @@ var inlineMessageActions = {
37401
37683
  oneofKind: "editMessage",
37402
37684
  editMessage: {
37403
37685
  messageId,
37404
- peerId: buildChatPeer2(chatId),
37686
+ peerId: buildChatPeer3(chatId),
37405
37687
  text,
37406
37688
  ...actions !== undefined ? { actions } : {},
37407
37689
  parseMarkdown
@@ -37422,7 +37704,7 @@ var inlineMessageActions = {
37422
37704
  const chatId = resolveChatIdFromParams(params);
37423
37705
  const result = await client.invokeRaw(Method.GET_CHAT, {
37424
37706
  oneofKind: "getChat",
37425
- getChat: { peerId: buildChatPeer2(chatId) }
37707
+ getChat: { peerId: buildChatPeer3(chatId) }
37426
37708
  });
37427
37709
  if (result.oneofKind !== "getChat") {
37428
37710
  throw new Error(`inline action: expected getChat result, got ${String(result.oneofKind)}`);
@@ -37501,6 +37783,7 @@ var inlineMessageActions = {
37501
37783
  });
37502
37784
  }
37503
37785
  if (normalizedAction === "channel-create" || normalizedAction === "thread-create") {
37786
+ const replyThreadsEnabled = normalizedAction === "thread-create" && isInlineReplyThreadsEnabled({ cfg, accountId: accountId ?? null });
37504
37787
  return await withInlineClient({
37505
37788
  cfg,
37506
37789
  accountId,
@@ -37523,6 +37806,33 @@ var inlineMessageActions = {
37523
37806
  values: participantRefs,
37524
37807
  label: "participant"
37525
37808
  });
37809
+ if (replyThreadsEnabled) {
37810
+ const parentChatId = resolveChatIdFromParams(params);
37811
+ const parentMessageId = parseOptionalInlineId(readFlexibleId(params, "parentMessageId") ?? readFlexibleId(params, "messageId") ?? readFlexibleId(params, "replyTo") ?? readFlexibleId(params, "replyToId") ?? readStringParam(params, "parentMessageId") ?? readStringParam(params, "messageId") ?? readStringParam(params, "replyTo") ?? readStringParam(params, "replyToId"), "parentMessageId");
37812
+ const result2 = await client.invokeRaw(CREATE_SUBTHREAD_METHOD, {
37813
+ oneofKind: "createSubthread",
37814
+ createSubthread: {
37815
+ parentChatId,
37816
+ ...parentMessageId != null ? { parentMessageId } : {},
37817
+ title,
37818
+ ...description ? { description } : {},
37819
+ ...emoji3 ? { emoji: emoji3 } : {},
37820
+ participants: dedupedParticipants.map((userId) => ({ userId }))
37821
+ }
37822
+ });
37823
+ if (result2.oneofKind !== "createSubthread") {
37824
+ throw new Error(`inline action: expected createSubthread result, got ${String(result2.oneofKind)}`);
37825
+ }
37826
+ return jsonResult(toJsonSafe({
37827
+ ok: true,
37828
+ title,
37829
+ parentChatId: String(parentChatId),
37830
+ parentMessageId: parentMessageId != null ? String(parentMessageId) : null,
37831
+ chat: result2.createSubthread.chat ?? null,
37832
+ dialog: result2.createSubthread.dialog ?? null,
37833
+ anchorMessage: result2.createSubthread.anchorMessage ?? null
37834
+ }));
37835
+ }
37526
37836
  const result = await client.invokeRaw(Method.CREATE_CHAT, {
37527
37837
  oneofKind: "createChat",
37528
37838
  createChat: {
@@ -37558,7 +37868,7 @@ var inlineMessageActions = {
37558
37868
  const result = await client.invokeRaw(Method.DELETE_CHAT, {
37559
37869
  oneofKind: "deleteChat",
37560
37870
  deleteChat: {
37561
- peerId: buildChatPeer2(chatId)
37871
+ peerId: buildChatPeer3(chatId)
37562
37872
  }
37563
37873
  });
37564
37874
  if (result.oneofKind !== "deleteChat") {
@@ -37768,7 +38078,7 @@ var inlineMessageActions = {
37768
38078
  const result = await client.invokeRaw(Method.DELETE_MESSAGES, {
37769
38079
  oneofKind: "deleteMessages",
37770
38080
  deleteMessages: {
37771
- peerId: buildChatPeer2(chatId),
38081
+ peerId: buildChatPeer3(chatId),
37772
38082
  messageIds: deduped
37773
38083
  }
37774
38084
  });
@@ -37794,7 +38104,7 @@ var inlineMessageActions = {
37794
38104
  const result = await client.invokeRaw(Method.PIN_MESSAGE, {
37795
38105
  oneofKind: "pinMessage",
37796
38106
  pinMessage: {
37797
- peerId: buildChatPeer2(chatId),
38107
+ peerId: buildChatPeer3(chatId),
37798
38108
  messageId,
37799
38109
  unpin
37800
38110
  }
@@ -37819,7 +38129,7 @@ var inlineMessageActions = {
37819
38129
  const chatId = resolveChatIdFromParams(params);
37820
38130
  const result = await client.invokeRaw(Method.GET_CHAT, {
37821
38131
  oneofKind: "getChat",
37822
- getChat: { peerId: buildChatPeer2(chatId) }
38132
+ getChat: { peerId: buildChatPeer3(chatId) }
37823
38133
  });
37824
38134
  if (result.oneofKind !== "getChat") {
37825
38135
  throw new Error(`inline action: expected getChat result, got ${String(result.oneofKind)}`);
@@ -38168,8 +38478,14 @@ async function sendMessageInline(params) {
38168
38478
  context: "sendText",
38169
38479
  target
38170
38480
  });
38481
+ const effectiveChatId = resolvedTarget.kind === "chat" ? resolveInlineReplyThreadChatId({
38482
+ cfg: params.cfg,
38483
+ accountId: account.accountId,
38484
+ parentChatId: resolvedTarget.targetId,
38485
+ threadId: params.threadId ?? null
38486
+ }) : null;
38171
38487
  const result = await client.sendMessage({
38172
- ...buildInlineSendTarget(resolvedTarget),
38488
+ ...effectiveChatId != null ? { chatId: effectiveChatId } : buildInlineSendTarget(resolvedTarget),
38173
38489
  text: params.text,
38174
38490
  ...replyToMsgId != null ? { replyToMsgId } : {},
38175
38491
  parseMarkdown: account.config.parseMarkdown ?? true
@@ -38184,7 +38500,7 @@ async function sendMessageInline(params) {
38184
38500
  const bestEffort = result.messageId != null ? String(result.messageId) : BigInt(Date.now()).toString();
38185
38501
  return {
38186
38502
  messageId: bestEffort,
38187
- chatId: formatInlineResultChatId(resolvedTarget)
38503
+ chatId: effectiveChatId != null ? String(effectiveChatId) : formatInlineResultChatId(resolvedTarget)
38188
38504
  };
38189
38505
  } finally {
38190
38506
  await client.close().catch(() => {});
@@ -38213,6 +38529,12 @@ async function sendMediaInline(params) {
38213
38529
  context: "sendMedia",
38214
38530
  target
38215
38531
  });
38532
+ const effectiveChatId = resolvedTarget.kind === "chat" ? resolveInlineReplyThreadChatId({
38533
+ cfg: params.cfg,
38534
+ accountId: account.accountId,
38535
+ parentChatId: resolvedTarget.targetId,
38536
+ threadId: params.threadId ?? null
38537
+ }) : null;
38216
38538
  const media = await uploadInlineMediaFromUrl({
38217
38539
  client,
38218
38540
  cfg: params.cfg,
@@ -38220,7 +38542,7 @@ async function sendMediaInline(params) {
38220
38542
  mediaUrl: params.mediaUrl
38221
38543
  });
38222
38544
  const result = await client.sendMessage({
38223
- ...buildInlineSendTarget(resolvedTarget),
38545
+ ...effectiveChatId != null ? { chatId: effectiveChatId } : buildInlineSendTarget(resolvedTarget),
38224
38546
  ...caption ? { text: caption } : {},
38225
38547
  media,
38226
38548
  ...replyToMsgId != null ? { replyToMsgId } : {},
@@ -38236,7 +38558,7 @@ async function sendMediaInline(params) {
38236
38558
  const bestEffort = result.messageId != null ? String(result.messageId) : BigInt(Date.now()).toString();
38237
38559
  return {
38238
38560
  messageId: bestEffort,
38239
- chatId: formatInlineResultChatId(resolvedTarget)
38561
+ chatId: effectiveChatId != null ? String(effectiveChatId) : formatInlineResultChatId(resolvedTarget)
38240
38562
  };
38241
38563
  } finally {
38242
38564
  await client.close().catch(() => {});
@@ -38319,7 +38641,7 @@ var inlineChannelPlugin = {
38319
38641
  edit: true,
38320
38642
  reply: true,
38321
38643
  groupManagement: true,
38322
- threads: false,
38644
+ threads: true,
38323
38645
  nativeCommands: true,
38324
38646
  blockStreaming: true
38325
38647
  },
@@ -38402,11 +38724,43 @@ var inlineChannelPlugin = {
38402
38724
  senderE164
38403
38725
  })
38404
38726
  },
38727
+ threading: {
38728
+ resolveReplyToMode: () => "off",
38729
+ buildToolContext: ({ cfg, accountId, context, hasRepliedRef }) => {
38730
+ if (!isInlineReplyThreadsEnabled({ cfg, accountId: accountId ?? null })) {
38731
+ return;
38732
+ }
38733
+ const currentChannelId = context.To?.trim() || undefined;
38734
+ if (!currentChannelId) {
38735
+ return;
38736
+ }
38737
+ return {
38738
+ currentChannelId,
38739
+ ...context.MessageThreadId != null ? { currentThreadTs: String(context.MessageThreadId) } : {},
38740
+ ...context.CurrentMessageId != null ? { currentMessageId: context.CurrentMessageId } : {},
38741
+ replyToMode: "off",
38742
+ ...hasRepliedRef ? { hasRepliedRef } : {}
38743
+ };
38744
+ },
38745
+ resolveReplyTransport: ({ cfg, accountId, threadId, replyToId }) => {
38746
+ if (!isInlineReplyThreadsEnabled({ cfg, accountId: accountId ?? null })) {
38747
+ return null;
38748
+ }
38749
+ return {
38750
+ threadId: threadId != null ? String(threadId) : null,
38751
+ replyToId: replyToId ?? null
38752
+ };
38753
+ }
38754
+ },
38405
38755
  agentPrompt: {
38406
- messageToolHints: () => [
38756
+ messageToolHints: ({ cfg, accountId }) => [
38407
38757
  "- Inline targeting: omit `target` to reply in the current chat.",
38408
38758
  "- Inline explicit targets: `chat:<chatId>` for chats and `user:<userId>` for direct users. Prefer `user:` for DM user targets.",
38409
- "- Inline special tools: use `inline_nudge` to send a nudge, and `inline_forward` to forward message ids between chats or users."
38759
+ "- Inline history tools: `read` and `search` return media-aware message payloads (`media`, `attachments`, `attachmentUrls`) so image-only history remains discoverable.",
38760
+ "- Inline special tools: use `inline_nudge` to send a nudge, and `inline_forward` to forward message ids between chats or users.",
38761
+ ...isInlineReplyThreadsEnabled({ cfg, accountId: accountId ?? null }) ? [
38762
+ "- Inline reply threads are enabled: use `thread-reply` to send into a real reply thread, with `threadId` set to the reply-thread chat id."
38763
+ ] : []
38410
38764
  ]
38411
38765
  },
38412
38766
  messaging: {
@@ -38553,7 +38907,8 @@ var inlineChannelPlugin = {
38553
38907
  to,
38554
38908
  text,
38555
38909
  accountId: accountId ?? null,
38556
- replyToId: effectiveReplyToId
38910
+ replyToId: effectiveReplyToId,
38911
+ threadId: null
38557
38912
  });
38558
38913
  return { channel: "inline", to, messageId: result.messageId, chatId: result.chatId };
38559
38914
  }
@@ -38569,7 +38924,8 @@ var inlineChannelPlugin = {
38569
38924
  text: isFirst ? text : "",
38570
38925
  mediaUrl,
38571
38926
  accountId: accountId ?? null,
38572
- replyToId: isFirst ? effectiveReplyToId : null
38927
+ replyToId: isFirst ? effectiveReplyToId : null,
38928
+ threadId: null
38573
38929
  });
38574
38930
  }
38575
38931
  if (!finalResult) {
@@ -38578,7 +38934,8 @@ var inlineChannelPlugin = {
38578
38934
  to,
38579
38935
  text,
38580
38936
  accountId: accountId ?? null,
38581
- replyToId: effectiveReplyToId
38937
+ replyToId: effectiveReplyToId,
38938
+ threadId: null
38582
38939
  });
38583
38940
  return { channel: "inline", to, messageId: result.messageId, chatId: result.chatId };
38584
38941
  }
@@ -38590,7 +38947,8 @@ var inlineChannelPlugin = {
38590
38947
  to,
38591
38948
  text,
38592
38949
  accountId: accountId ?? null,
38593
- replyToId: replyToId ?? null
38950
+ replyToId: replyToId ?? null,
38951
+ threadId: threadId ?? null
38594
38952
  });
38595
38953
  return { channel: "inline", to, messageId: result.messageId, chatId: result.chatId };
38596
38954
  },
@@ -38601,7 +38959,8 @@ var inlineChannelPlugin = {
38601
38959
  to,
38602
38960
  text,
38603
38961
  accountId: accountId ?? null,
38604
- replyToId: replyToId ?? null
38962
+ replyToId: replyToId ?? null,
38963
+ threadId: threadId ?? null
38605
38964
  });
38606
38965
  return { channel: "inline", to, messageId: result2.messageId, chatId: result2.chatId };
38607
38966
  }
@@ -38611,7 +38970,8 @@ var inlineChannelPlugin = {
38611
38970
  text,
38612
38971
  mediaUrl,
38613
38972
  accountId: accountId ?? null,
38614
- replyToId: replyToId ?? null
38973
+ replyToId: replyToId ?? null,
38974
+ threadId: threadId ?? null
38615
38975
  });
38616
38976
  return { channel: "inline", to, messageId: result.messageId, chatId: result.chatId };
38617
38977
  }
@@ -39767,5 +40127,5 @@ export {
39767
40127
  src_default as default
39768
40128
  };
39769
40129
 
39770
- //# debugId=7535F56BE481336764756E2164756E21
40130
+ //# debugId=608084D1D5C29A8D64756E2164756E21
39771
40131
  //# sourceMappingURL=index.js.map