@inline-openclaw/inline 0.0.39 → 0.0.41

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.
@@ -5613,6 +5613,8 @@ var MessageEntity_Type;
5613
5613
  MessageEntity_Type2[MessageEntity_Type2["CODE"] = 8] = "CODE";
5614
5614
  MessageEntity_Type2[MessageEntity_Type2["PRE"] = 9] = "PRE";
5615
5615
  MessageEntity_Type2[MessageEntity_Type2["PHONE_NUMBER"] = 10] = "PHONE_NUMBER";
5616
+ MessageEntity_Type2[MessageEntity_Type2["THREAD"] = 11] = "THREAD";
5617
+ MessageEntity_Type2[MessageEntity_Type2["THREAD_TITLE"] = 12] = "THREAD_TITLE";
5616
5618
  })(MessageEntity_Type || (MessageEntity_Type = {}));
5617
5619
  var Member_Role;
5618
5620
  (function(Member_Role2) {
@@ -7743,7 +7745,9 @@ class MessageEntity$Type extends import_runtime4.MessageType {
7743
7745
  { no: 3, name: "length", kind: "scalar", T: 3, L: 0 },
7744
7746
  { no: 4, name: "mention", kind: "message", oneof: "entity", T: () => MessageEntity_MessageEntityMention },
7745
7747
  { no: 5, name: "text_url", kind: "message", oneof: "entity", T: () => MessageEntity_MessageEntityTextUrl },
7746
- { no: 6, name: "pre", kind: "message", oneof: "entity", T: () => MessageEntity_MessageEntityPre }
7748
+ { no: 6, name: "pre", kind: "message", oneof: "entity", T: () => MessageEntity_MessageEntityPre },
7749
+ { no: 7, name: "thread", kind: "message", oneof: "entity", T: () => MessageEntity_MessageEntityThread },
7750
+ { no: 8, name: "thread_title", kind: "message", oneof: "entity", T: () => MessageEntity_MessageEntityThreadTitle }
7747
7751
  ]);
7748
7752
  }
7749
7753
  create(value) {
@@ -7788,6 +7792,18 @@ class MessageEntity$Type extends import_runtime4.MessageType {
7788
7792
  pre: MessageEntity_MessageEntityPre.internalBinaryRead(reader, reader.uint32(), options, message.entity.pre)
7789
7793
  };
7790
7794
  break;
7795
+ case 7:
7796
+ message.entity = {
7797
+ oneofKind: "thread",
7798
+ thread: MessageEntity_MessageEntityThread.internalBinaryRead(reader, reader.uint32(), options, message.entity.thread)
7799
+ };
7800
+ break;
7801
+ case 8:
7802
+ message.entity = {
7803
+ oneofKind: "threadTitle",
7804
+ threadTitle: MessageEntity_MessageEntityThreadTitle.internalBinaryRead(reader, reader.uint32(), options, message.entity.threadTitle)
7805
+ };
7806
+ break;
7791
7807
  default:
7792
7808
  let u = options.readUnknownField;
7793
7809
  if (u === "throw")
@@ -7812,6 +7828,10 @@ class MessageEntity$Type extends import_runtime4.MessageType {
7812
7828
  MessageEntity_MessageEntityTextUrl.internalBinaryWrite(message.entity.textUrl, writer.tag(5, import_runtime.WireType.LengthDelimited).fork(), options).join();
7813
7829
  if (message.entity.oneofKind === "pre")
7814
7830
  MessageEntity_MessageEntityPre.internalBinaryWrite(message.entity.pre, writer.tag(6, import_runtime.WireType.LengthDelimited).fork(), options).join();
7831
+ if (message.entity.oneofKind === "thread")
7832
+ MessageEntity_MessageEntityThread.internalBinaryWrite(message.entity.thread, writer.tag(7, import_runtime.WireType.LengthDelimited).fork(), options).join();
7833
+ if (message.entity.oneofKind === "threadTitle")
7834
+ MessageEntity_MessageEntityThreadTitle.internalBinaryWrite(message.entity.threadTitle, writer.tag(8, import_runtime.WireType.LengthDelimited).fork(), options).join();
7815
7835
  let u = options.writeUnknownFields;
7816
7836
  if (u !== false)
7817
7837
  (u == true ? import_runtime2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
@@ -7949,6 +7969,99 @@ class MessageEntity_MessageEntityPre$Type extends import_runtime4.MessageType {
7949
7969
  }
7950
7970
  var MessageEntity_MessageEntityPre = new MessageEntity_MessageEntityPre$Type;
7951
7971
 
7972
+ class MessageEntity_MessageEntityThread$Type extends import_runtime4.MessageType {
7973
+ constructor() {
7974
+ super("MessageEntity.MessageEntityThread", [
7975
+ { no: 1, name: "chat_id", kind: "scalar", T: 3, L: 0 }
7976
+ ]);
7977
+ }
7978
+ create(value) {
7979
+ const message = globalThis.Object.create(this.messagePrototype);
7980
+ message.chatId = 0n;
7981
+ if (value !== undefined)
7982
+ import_runtime3.reflectionMergePartial(this, message, value);
7983
+ return message;
7984
+ }
7985
+ internalBinaryRead(reader, length, options, target) {
7986
+ let message = target ?? this.create(), end = reader.pos + length;
7987
+ while (reader.pos < end) {
7988
+ let [fieldNo, wireType] = reader.tag();
7989
+ switch (fieldNo) {
7990
+ case 1:
7991
+ message.chatId = reader.int64().toBigInt();
7992
+ break;
7993
+ default:
7994
+ let u = options.readUnknownField;
7995
+ if (u === "throw")
7996
+ throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
7997
+ let d = reader.skip(wireType);
7998
+ if (u !== false)
7999
+ (u === true ? import_runtime2.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
8000
+ }
8001
+ }
8002
+ return message;
8003
+ }
8004
+ internalBinaryWrite(message, writer, options) {
8005
+ if (message.chatId !== 0n)
8006
+ writer.tag(1, import_runtime.WireType.Varint).int64(message.chatId);
8007
+ let u = options.writeUnknownFields;
8008
+ if (u !== false)
8009
+ (u == true ? import_runtime2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
8010
+ return writer;
8011
+ }
8012
+ }
8013
+ var MessageEntity_MessageEntityThread = new MessageEntity_MessageEntityThread$Type;
8014
+
8015
+ class MessageEntity_MessageEntityThreadTitle$Type extends import_runtime4.MessageType {
8016
+ constructor() {
8017
+ super("MessageEntity.MessageEntityThreadTitle", [
8018
+ { no: 1, name: "space_id", kind: "scalar", T: 3, L: 0 },
8019
+ { no: 2, name: "title", kind: "scalar", T: 9 }
8020
+ ]);
8021
+ }
8022
+ create(value) {
8023
+ const message = globalThis.Object.create(this.messagePrototype);
8024
+ message.spaceId = 0n;
8025
+ message.title = "";
8026
+ if (value !== undefined)
8027
+ import_runtime3.reflectionMergePartial(this, message, value);
8028
+ return message;
8029
+ }
8030
+ internalBinaryRead(reader, length, options, target) {
8031
+ let message = target ?? this.create(), end = reader.pos + length;
8032
+ while (reader.pos < end) {
8033
+ let [fieldNo, wireType] = reader.tag();
8034
+ switch (fieldNo) {
8035
+ case 1:
8036
+ message.spaceId = reader.int64().toBigInt();
8037
+ break;
8038
+ case 2:
8039
+ message.title = reader.string();
8040
+ break;
8041
+ default:
8042
+ let u = options.readUnknownField;
8043
+ if (u === "throw")
8044
+ throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
8045
+ let d = reader.skip(wireType);
8046
+ if (u !== false)
8047
+ (u === true ? import_runtime2.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
8048
+ }
8049
+ }
8050
+ return message;
8051
+ }
8052
+ internalBinaryWrite(message, writer, options) {
8053
+ if (message.spaceId !== 0n)
8054
+ writer.tag(1, import_runtime.WireType.Varint).int64(message.spaceId);
8055
+ if (message.title !== "")
8056
+ writer.tag(2, import_runtime.WireType.LengthDelimited).string(message.title);
8057
+ let u = options.writeUnknownFields;
8058
+ if (u !== false)
8059
+ (u == true ? import_runtime2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
8060
+ return writer;
8061
+ }
8062
+ }
8063
+ var MessageEntity_MessageEntityThreadTitle = new MessageEntity_MessageEntityThreadTitle$Type;
8064
+
7952
8065
  class MessageReactions$Type extends import_runtime4.MessageType {
7953
8066
  constructor() {
7954
8067
  super("MessageReactions", [
@@ -36552,143 +36665,6 @@ function readInlineTokenFile(tokenFile) {
36552
36665
  }
36553
36666
  }
36554
36667
 
36555
- // src/inline/reply-threads.ts
36556
- var GET_CHAT_METHOD = typeof Method.GET_CHAT === "number" && Number.isInteger(Method.GET_CHAT) && Method.GET_CHAT > 0 ? Method.GET_CHAT : 25;
36557
- 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;
36558
- var GET_MESSAGES_METHOD = typeof Method.GET_MESSAGES === "number" && Number.isInteger(Method.GET_MESSAGES) && Method.GET_MESSAGES > 0 ? Method.GET_MESSAGES : 38;
36559
- var CREATE_SUBTHREAD_METHOD = typeof Method.CREATE_SUBTHREAD === "number" && Number.isInteger(Method.CREATE_SUBTHREAD) && Method.CREATE_SUBTHREAD > 0 ? Method.CREATE_SUBTHREAD : 42;
36560
- function isPlacementMode(raw) {
36561
- return raw === "thread" || raw === "main";
36562
- }
36563
- function hasReplyThreadConfig(config2) {
36564
- if (isPlacementMode(config2.replyThreadMode))
36565
- return true;
36566
- if (typeof config2.replyThreadAutoCreateMinMessages === "number")
36567
- return true;
36568
- if (typeof config2.replyThreadRequireExplicitMention === "boolean")
36569
- return true;
36570
- if (typeof config2.replyThreadParentHistoryLimit === "number")
36571
- return true;
36572
- if (!config2.groups || typeof config2.groups !== "object" || Array.isArray(config2.groups))
36573
- return false;
36574
- return Object.values(config2.groups).some((group) => {
36575
- if (!group || typeof group !== "object" || Array.isArray(group))
36576
- return false;
36577
- const groupConfig = group;
36578
- return isPlacementMode(groupConfig.replyThreadMode) || typeof groupConfig.replyThreadAutoCreateMinMessages === "number" || typeof groupConfig.replyThreadRequireExplicitMention === "boolean" || typeof groupConfig.replyThreadParentHistoryLimit === "number";
36579
- });
36580
- }
36581
- function buildChatPeer(chatId) {
36582
- return {
36583
- type: {
36584
- oneofKind: "chat",
36585
- chat: { chatId }
36586
- }
36587
- };
36588
- }
36589
- function getInlineReplyThreadsCapabilityConfig(params) {
36590
- const account = resolveInlineAccount({
36591
- cfg: params.cfg,
36592
- accountId: params.accountId ?? null
36593
- });
36594
- return {
36595
- replyThreads: account.config.capabilities?.replyThreads === true || hasReplyThreadConfig(account.config)
36596
- };
36597
- }
36598
- function isInlineReplyThreadsEnabled(params) {
36599
- return getInlineReplyThreadsCapabilityConfig(params).replyThreads;
36600
- }
36601
- function resolveInlineReplyThreadChatId(params) {
36602
- if (!isInlineReplyThreadsEnabled({ cfg: params.cfg, accountId: params.accountId ?? null })) {
36603
- return params.parentChatId;
36604
- }
36605
- if (params.parentChatId == null) {
36606
- return null;
36607
- }
36608
- if (params.threadId == null) {
36609
- return params.parentChatId;
36610
- }
36611
- 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() ? (() => {
36612
- try {
36613
- return BigInt(params.threadId.trim());
36614
- } catch {
36615
- return null;
36616
- }
36617
- })() : null : null;
36618
- return normalized ?? params.parentChatId;
36619
- }
36620
- async function loadInlineReplyThreadMetadata(params) {
36621
- const result = await params.client.invokeRaw(GET_CHAT_METHOD, {
36622
- oneofKind: "getChat",
36623
- getChat: { peerId: buildChatPeer(params.chatId) }
36624
- }).catch(() => null);
36625
- if (result?.oneofKind !== "getChat") {
36626
- return null;
36627
- }
36628
- const chat = result.getChat.chat;
36629
- const parentChatId = chat?.parentChatId;
36630
- if (parentChatId == null) {
36631
- return null;
36632
- }
36633
- return {
36634
- childChatId: chat?.id ?? params.chatId,
36635
- parentChatId,
36636
- parentMessageId: chat?.parentMessageId ?? null,
36637
- title: chat?.title?.trim() || null
36638
- };
36639
- }
36640
- async function loadInlineReplyThreadAnchorMessage(params) {
36641
- const directResult = await params.client.invokeRaw(GET_MESSAGES_METHOD, {
36642
- oneofKind: "getMessages",
36643
- getMessages: {
36644
- peerId: buildChatPeer(params.parentChatId),
36645
- messageIds: [params.parentMessageId]
36646
- }
36647
- }).catch(() => null);
36648
- if (directResult?.oneofKind === "getMessages") {
36649
- const directTarget = (directResult.getMessages.messages ?? []).find((item) => item.id === params.parentMessageId) ?? null;
36650
- if (directTarget) {
36651
- return directTarget;
36652
- }
36653
- }
36654
- const historyResult = await params.client.invokeRaw(GET_CHAT_HISTORY_METHOD, {
36655
- oneofKind: "getChatHistory",
36656
- getChatHistory: {
36657
- peerId: buildChatPeer(params.parentChatId),
36658
- offsetId: params.parentMessageId + 1n,
36659
- limit: 8
36660
- }
36661
- }).catch(() => null);
36662
- if (historyResult?.oneofKind !== "getChatHistory") {
36663
- return null;
36664
- }
36665
- return (historyResult.getChatHistory.messages ?? []).find((item) => item.id === params.parentMessageId) ?? null;
36666
- }
36667
- async function createInlineReplyThreadForMessage(params) {
36668
- const result = await params.client.invokeRaw(CREATE_SUBTHREAD_METHOD, {
36669
- oneofKind: "createSubthread",
36670
- createSubthread: {
36671
- parentChatId: params.parentChatId,
36672
- parentMessageId: params.parentMessageId,
36673
- participants: []
36674
- }
36675
- });
36676
- if (result.oneofKind !== "createSubthread") {
36677
- return null;
36678
- }
36679
- const chat = result.createSubthread.chat;
36680
- if (!chat?.id) {
36681
- return null;
36682
- }
36683
- return {
36684
- childChatId: chat.id,
36685
- parentChatId: chat.parentChatId ?? params.parentChatId,
36686
- parentMessageId: chat.parentMessageId ?? params.parentMessageId,
36687
- title: chat.title?.trim() || null,
36688
- anchorMessage: result.createSubthread.anchorMessage ?? null
36689
- };
36690
- }
36691
-
36692
36668
  // src/inline/media.ts
36693
36669
  import path from "node:path";
36694
36670
 
@@ -37449,6 +37425,315 @@ function looksLikeInlineTargetId(raw, normalizedInput) {
37449
37425
  return /^[0-9]+$/.test(normalized);
37450
37426
  }
37451
37427
 
37428
+ // src/inline/thread-routes.ts
37429
+ import path2 from "node:path";
37430
+ import { pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
37431
+ import { readJsonFileWithFallback, writeJsonFileAtomically } from "openclaw/plugin-sdk/json-store";
37432
+ var TTL_MS = 7 * 24 * 60 * 60 * 1000;
37433
+ var MAX_ENTRIES = 5000;
37434
+ var PERSISTENT_MAX_ENTRIES = 2000;
37435
+ var STORE_VERSION = 1;
37436
+ var PERSISTENT_NAMESPACE = "inline.reply-thread-routes";
37437
+ var INLINE_REPLY_THREAD_ROUTE_KEY = Symbol.for("openclaw.inlineReplyThreadRoutes");
37438
+ var DEFAULT_AGENT_KEY = "__any__";
37439
+ var DEFAULT_STORE_KEY = "__default__";
37440
+ var routeState;
37441
+ var persistentStore;
37442
+ var persistentStoreDisabled = false;
37443
+ function getRouteState() {
37444
+ if (routeState)
37445
+ return routeState;
37446
+ const globalStore = globalThis;
37447
+ const existing = globalStore[INLINE_REPLY_THREAD_ROUTE_KEY];
37448
+ routeState = existing ?? {
37449
+ memory: new Map,
37450
+ fileWrites: new Map
37451
+ };
37452
+ globalStore[INLINE_REPLY_THREAD_ROUTE_KEY] = routeState;
37453
+ return routeState;
37454
+ }
37455
+ function normalizePositiveId(raw) {
37456
+ if (raw == null)
37457
+ return;
37458
+ if (typeof raw === "bigint")
37459
+ return raw >= 0n ? String(raw) : undefined;
37460
+ if (typeof raw === "number") {
37461
+ return Number.isInteger(raw) && raw >= 0 ? String(raw) : undefined;
37462
+ }
37463
+ const trimmed = raw.trim();
37464
+ if (!/^\d+$/.test(trimmed))
37465
+ return;
37466
+ return trimmed;
37467
+ }
37468
+ function normalizeOptionalText(raw) {
37469
+ const trimmed = raw?.trim();
37470
+ return trimmed || undefined;
37471
+ }
37472
+ function safePathSegment(value) {
37473
+ return value.trim().replace(/[^a-z0-9._-]+/gi, "_").slice(0, 80) || "global";
37474
+ }
37475
+ function isRecord3(value) {
37476
+ return typeof value === "object" && value !== null && !Array.isArray(value);
37477
+ }
37478
+ function readString(record2, key) {
37479
+ const value = record2[key];
37480
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
37481
+ }
37482
+ function readTimestamp(record2, key, fallback) {
37483
+ const value = record2[key];
37484
+ return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.floor(value)) : fallback;
37485
+ }
37486
+ function normalizeRecord(value) {
37487
+ if (!isRecord3(value))
37488
+ return null;
37489
+ const accountId = readString(value, "accountId");
37490
+ const parentChatId = normalizePositiveId(readString(value, "parentChatId"));
37491
+ const threadId = normalizePositiveId(readString(value, "threadId"));
37492
+ if (!accountId || !parentChatId || !threadId)
37493
+ return null;
37494
+ const now = Date.now();
37495
+ const parentMessageId = normalizePositiveId(readString(value, "parentMessageId"));
37496
+ const title = normalizeOptionalText(readString(value, "title"));
37497
+ const threadLabel = normalizeOptionalText(readString(value, "threadLabel"));
37498
+ const agentId = normalizeOptionalText(readString(value, "agentId"));
37499
+ return {
37500
+ accountId,
37501
+ parentChatId,
37502
+ threadId,
37503
+ createdAt: readTimestamp(value, "createdAt", now),
37504
+ updatedAt: readTimestamp(value, "updatedAt", now),
37505
+ ...parentMessageId ? { parentMessageId } : {},
37506
+ ...title ? { title } : {},
37507
+ ...threadLabel ? { threadLabel } : {},
37508
+ ...agentId ? { agentId } : {}
37509
+ };
37510
+ }
37511
+ function isExpired(record2, now) {
37512
+ return now - record2.updatedAt > TTL_MS;
37513
+ }
37514
+ function reportRouteStateError(error51) {
37515
+ try {
37516
+ getOptionalInlineRuntime()?.logging.getChildLogger({ plugin: "inline", feature: "reply-thread-route-state" }).warn("Inline reply-thread route state failed", { error: String(error51) });
37517
+ } catch {}
37518
+ }
37519
+ function disablePersistentStore(error51) {
37520
+ persistentStoreDisabled = true;
37521
+ persistentStore = undefined;
37522
+ if (!String(error51).includes("openKeyedStore is only available")) {
37523
+ reportRouteStateError(error51);
37524
+ }
37525
+ }
37526
+ function getPersistentStore() {
37527
+ if (persistentStoreDisabled)
37528
+ return;
37529
+ if (persistentStore)
37530
+ return persistentStore;
37531
+ const openKeyedStore = getOptionalInlineRuntime()?.state?.openKeyedStore;
37532
+ if (typeof openKeyedStore !== "function")
37533
+ return;
37534
+ try {
37535
+ persistentStore = openKeyedStore({
37536
+ namespace: PERSISTENT_NAMESPACE,
37537
+ maxEntries: PERSISTENT_MAX_ENTRIES,
37538
+ defaultTtlMs: TTL_MS
37539
+ });
37540
+ return persistentStore;
37541
+ } catch (error51) {
37542
+ disablePersistentStore(error51);
37543
+ return;
37544
+ }
37545
+ }
37546
+ function resolveRoutesPath(accountId) {
37547
+ const resolveStateDir = getOptionalInlineRuntime()?.state?.resolveStateDir;
37548
+ if (typeof resolveStateDir !== "function")
37549
+ return;
37550
+ return path2.join(resolveStateDir(), "inline", "reply-thread-routes", `${safePathSegment(accountId)}.json`);
37551
+ }
37552
+ function activeKey(accountId, parentChatId, agentId) {
37553
+ return `${accountId}:parent:${parentChatId}:agent:${agentId || DEFAULT_AGENT_KEY}`;
37554
+ }
37555
+ function messageKey(accountId, parentChatId, parentMessageId) {
37556
+ return `${accountId}:parent:${parentChatId}:message:${parentMessageId}`;
37557
+ }
37558
+ function keysForRecord(record2) {
37559
+ const keys = new Set;
37560
+ if (record2.parentMessageId) {
37561
+ keys.add(messageKey(record2.accountId, record2.parentChatId, record2.parentMessageId));
37562
+ }
37563
+ if (record2.agentId) {
37564
+ keys.add(activeKey(record2.accountId, record2.parentChatId, record2.agentId));
37565
+ }
37566
+ keys.add(activeKey(record2.accountId, record2.parentChatId));
37567
+ return [...keys];
37568
+ }
37569
+ function keysForLookup(params) {
37570
+ const keys = new Set;
37571
+ if (params.parentMessageId) {
37572
+ keys.add(messageKey(params.accountId, params.parentChatId, params.parentMessageId));
37573
+ }
37574
+ if (params.agentId) {
37575
+ keys.add(activeKey(params.accountId, params.parentChatId, params.agentId));
37576
+ }
37577
+ keys.add(activeKey(params.accountId, params.parentChatId));
37578
+ return [...keys];
37579
+ }
37580
+ function setMemory(key, value, now) {
37581
+ const memory = getRouteState().memory;
37582
+ memory.delete(key);
37583
+ memory.set(key, { value, updatedAt: now });
37584
+ pruneMapToMaxSize(memory, MAX_ENTRIES);
37585
+ }
37586
+ function getMemory(key, now) {
37587
+ const memory = getRouteState().memory;
37588
+ const entry = memory.get(key);
37589
+ if (!entry)
37590
+ return;
37591
+ if (now - entry.updatedAt > TTL_MS) {
37592
+ memory.delete(key);
37593
+ return;
37594
+ }
37595
+ memory.delete(key);
37596
+ memory.set(key, { ...entry, updatedAt: now });
37597
+ return entry.value;
37598
+ }
37599
+ async function readFileRoutes(accountId) {
37600
+ const filePath = resolveRoutesPath(accountId);
37601
+ if (!filePath)
37602
+ return new Map;
37603
+ const fallback = { version: STORE_VERSION, routes: {} };
37604
+ const now = Date.now();
37605
+ try {
37606
+ const { value } = await readJsonFileWithFallback(filePath, fallback);
37607
+ if (value.version !== STORE_VERSION || !isRecord3(value.routes)) {
37608
+ return new Map;
37609
+ }
37610
+ const routes = new Map;
37611
+ for (const [key, raw] of Object.entries(value.routes)) {
37612
+ const route = normalizeRecord(raw);
37613
+ if (route && !isExpired(route, now))
37614
+ routes.set(key, route);
37615
+ }
37616
+ return routes;
37617
+ } catch (error51) {
37618
+ reportRouteStateError(error51);
37619
+ return new Map;
37620
+ }
37621
+ }
37622
+ async function writeFileRoutes(accountId, routes) {
37623
+ const filePath = resolveRoutesPath(accountId);
37624
+ if (!filePath)
37625
+ return;
37626
+ const pruned = [...routes.entries()].sort((left, right) => right[1].updatedAt - left[1].updatedAt).slice(0, PERSISTENT_MAX_ENTRIES);
37627
+ await writeJsonFileAtomically(filePath, {
37628
+ version: STORE_VERSION,
37629
+ routes: Object.fromEntries(pruned)
37630
+ });
37631
+ }
37632
+ function rememberFileRoutes(params) {
37633
+ const state = getRouteState();
37634
+ const queueKey = params.accountId || DEFAULT_STORE_KEY;
37635
+ const previous = state.fileWrites.get(queueKey) ?? Promise.resolve();
37636
+ const next = previous.catch(() => {
37637
+ return;
37638
+ }).then(async () => {
37639
+ const routes = await readFileRoutes(params.accountId);
37640
+ for (const key of params.keys) {
37641
+ routes.set(key, params.record);
37642
+ }
37643
+ await writeFileRoutes(params.accountId, routes);
37644
+ });
37645
+ state.fileWrites.set(queueKey, next);
37646
+ const cleanup = () => {
37647
+ if (state.fileWrites.get(queueKey) === next) {
37648
+ state.fileWrites.delete(queueKey);
37649
+ }
37650
+ };
37651
+ next.then(cleanup, cleanup);
37652
+ next.catch(reportRouteStateError);
37653
+ }
37654
+ function rememberInlineReplyThreadRoute(params) {
37655
+ const accountId = params.accountId.trim();
37656
+ const parentChatId = normalizePositiveId(params.parentChatId);
37657
+ const threadId = normalizePositiveId(params.threadId);
37658
+ if (!accountId || !parentChatId || !threadId)
37659
+ return null;
37660
+ const now = Date.now();
37661
+ const parentMessageId = normalizePositiveId(params.parentMessageId);
37662
+ const title = normalizeOptionalText(params.title);
37663
+ const threadLabel = normalizeOptionalText(params.threadLabel);
37664
+ const agentId = normalizeOptionalText(params.agentId);
37665
+ const record2 = {
37666
+ accountId,
37667
+ parentChatId,
37668
+ threadId,
37669
+ createdAt: now,
37670
+ updatedAt: now,
37671
+ ...parentMessageId ? { parentMessageId } : {},
37672
+ ...title ? { title } : {},
37673
+ ...threadLabel ? { threadLabel } : {},
37674
+ ...agentId ? { agentId } : {}
37675
+ };
37676
+ const keys = keysForRecord(record2);
37677
+ for (const key of keys) {
37678
+ setMemory(key, record2, now);
37679
+ }
37680
+ const store = getPersistentStore();
37681
+ if (store) {
37682
+ for (const key of keys) {
37683
+ store.register(key, record2, { ttlMs: TTL_MS }).catch(disablePersistentStore);
37684
+ }
37685
+ return record2;
37686
+ }
37687
+ rememberFileRoutes({ accountId, keys, record: record2 });
37688
+ return record2;
37689
+ }
37690
+ async function lookupInlineReplyThreadRoute(params) {
37691
+ const accountId = params.accountId.trim();
37692
+ const parentChatId = normalizePositiveId(params.parentChatId);
37693
+ if (!accountId || !parentChatId)
37694
+ return null;
37695
+ const parentMessageId = normalizePositiveId(params.parentMessageId);
37696
+ const agentId = normalizeOptionalText(params.agentId);
37697
+ const keys = keysForLookup({
37698
+ accountId,
37699
+ parentChatId,
37700
+ ...parentMessageId ? { parentMessageId } : {},
37701
+ ...agentId ? { agentId } : {}
37702
+ });
37703
+ const now = Date.now();
37704
+ for (const key of keys) {
37705
+ const cached3 = getMemory(key, now);
37706
+ if (cached3)
37707
+ return cached3;
37708
+ }
37709
+ const store = getPersistentStore();
37710
+ if (store) {
37711
+ for (const key of keys) {
37712
+ try {
37713
+ const found = await store.lookup(key);
37714
+ const normalized = normalizeRecord(found);
37715
+ if (normalized && !isExpired(normalized, now)) {
37716
+ setMemory(key, normalized, now);
37717
+ return normalized;
37718
+ }
37719
+ } catch (error51) {
37720
+ disablePersistentStore(error51);
37721
+ break;
37722
+ }
37723
+ }
37724
+ }
37725
+ const fileRoutes = await readFileRoutes(accountId);
37726
+ for (const key of keys) {
37727
+ const found = fileRoutes.get(key);
37728
+ const normalized = normalizeRecord(found);
37729
+ if (normalized) {
37730
+ setMemory(key, normalized, now);
37731
+ return normalized;
37732
+ }
37733
+ }
37734
+ return null;
37735
+ }
37736
+
37452
37737
  // src/inline/outbound-sanitize.ts
37453
37738
  var HEARTBEAT_TOKEN = "HEARTBEAT_OK";
37454
37739
  var OPENCLAW_RUNTIME_CONTEXT_NOTICE = "This context is runtime-generated, not user-authored. Keep internal details private.";
@@ -37821,8 +38106,8 @@ for (const group of ACTION_GROUPS) {
37821
38106
  }
37822
38107
  }
37823
38108
  var SUPPORTED_ACTIONS = Array.from(ACTION_TO_GATE_KEY.keys());
37824
- var GET_MESSAGES_METHOD2 = typeof Method.GET_MESSAGES === "number" && Number.isInteger(Method.GET_MESSAGES) && Method.GET_MESSAGES > 0 ? Method.GET_MESSAGES : null;
37825
- var CREATE_SUBTHREAD_METHOD2 = typeof Method.CREATE_SUBTHREAD === "number" && Number.isInteger(Method.CREATE_SUBTHREAD) && Method.CREATE_SUBTHREAD > 0 ? Method.CREATE_SUBTHREAD : 42;
38109
+ var GET_MESSAGES_METHOD = typeof Method.GET_MESSAGES === "number" && Number.isInteger(Method.GET_MESSAGES) && Method.GET_MESSAGES > 0 ? Method.GET_MESSAGES : null;
38110
+ var CREATE_SUBTHREAD_METHOD = typeof Method.CREATE_SUBTHREAD === "number" && Number.isInteger(Method.CREATE_SUBTHREAD) && Method.CREATE_SUBTHREAD > 0 ? Method.CREATE_SUBTHREAD : 42;
37826
38111
  var INLINE_ACTION_MAX_ROWS = 8;
37827
38112
  var INLINE_ACTION_MAX_PER_ROW = 8;
37828
38113
  function suppressedInternalTextResult() {
@@ -37862,7 +38147,7 @@ function optionalVisibleActionText(raw, label) {
37862
38147
  }
37863
38148
  return visible.text.trim() || undefined;
37864
38149
  }
37865
- function isRecord3(value) {
38150
+ function isRecord4(value) {
37866
38151
  return typeof value === "object" && value !== null;
37867
38152
  }
37868
38153
  function normalizeReplyMarkupButtons(raw) {
@@ -37874,7 +38159,7 @@ function normalizeReplyMarkupButtons(raw) {
37874
38159
  continue;
37875
38160
  const row = [];
37876
38161
  for (const candidateButton of candidateRow) {
37877
- if (!isRecord3(candidateButton))
38162
+ if (!isRecord4(candidateButton))
37878
38163
  continue;
37879
38164
  const text = sanitizeInlineActionLabel(typeof candidateButton.text === "string" ? candidateButton.text : "");
37880
38165
  const callbackData = sanitizeInlineActionCallbackData(typeof candidateButton.callback_data === "string" ? candidateButton.callback_data : "");
@@ -38291,7 +38576,7 @@ function resolveMessageSendTargetFromParams(params) {
38291
38576
  chatId: BigInt(normalized)
38292
38577
  };
38293
38578
  }
38294
- function buildChatPeer2(chatId) {
38579
+ function buildChatPeer(chatId) {
38295
38580
  return {
38296
38581
  type: {
38297
38582
  oneofKind: "chat",
@@ -38421,10 +38706,10 @@ async function reactionAlreadyExists(params) {
38421
38706
  return reactions.some((reaction) => reaction.emoji === params.emoji && reaction.userIds.includes(myId));
38422
38707
  }
38423
38708
  async function findMessageById(params) {
38424
- const directResult = GET_MESSAGES_METHOD2 == null ? null : await params.client.invokeRaw(GET_MESSAGES_METHOD2, {
38709
+ const directResult = GET_MESSAGES_METHOD == null ? null : await params.client.invokeRaw(GET_MESSAGES_METHOD, {
38425
38710
  oneofKind: "getMessages",
38426
38711
  getMessages: {
38427
- peerId: buildChatPeer2(params.chatId),
38712
+ peerId: buildChatPeer(params.chatId),
38428
38713
  messageIds: [params.messageId]
38429
38714
  }
38430
38715
  }).catch(() => null);
@@ -38434,7 +38719,7 @@ async function findMessageById(params) {
38434
38719
  const result = await params.client.invokeRaw(Method.GET_CHAT_HISTORY, {
38435
38720
  oneofKind: "getChatHistory",
38436
38721
  getChatHistory: {
38437
- peerId: buildChatPeer2(params.chatId),
38722
+ peerId: buildChatPeer(params.chatId),
38438
38723
  offsetId: params.messageId + 1n,
38439
38724
  limit: 8
38440
38725
  }
@@ -38456,7 +38741,7 @@ async function withInlineClient(params) {
38456
38741
  });
38457
38742
  await client.connect();
38458
38743
  try {
38459
- return await params.fn(client);
38744
+ return await params.fn(client, account);
38460
38745
  } finally {
38461
38746
  await client.close().catch(() => {});
38462
38747
  }
@@ -38508,7 +38793,7 @@ async function resolveSpaceIdFromParams(params) {
38508
38793
  const chatId = BigInt(normalizeChatId(chatTarget));
38509
38794
  const chatResult = await params.client.invokeRaw(Method.GET_CHAT, {
38510
38795
  oneofKind: "getChat",
38511
- getChat: { peerId: buildChatPeer2(chatId) }
38796
+ getChat: { peerId: buildChatPeer(chatId) }
38512
38797
  });
38513
38798
  if (chatResult.oneofKind !== "getChat") {
38514
38799
  throw new Error(`inline action: expected getChat result, got ${String(chatResult.oneofKind)}`);
@@ -38725,16 +39010,16 @@ var inlineMessageActions = {
38725
39010
  }
38726
39011
  if (normalizedAction === "reply" || normalizedAction === "thread-reply") {
38727
39012
  const parseMarkdown = resolveInlineAccount({ cfg, accountId: accountId ?? null }).config.parseMarkdown ?? true;
38728
- const replyThreadsEnabled = normalizedAction === "thread-reply" && isInlineReplyThreadsEnabled({ cfg, accountId: accountId ?? null });
39013
+ const isThreadReply = normalizedAction === "thread-reply";
38729
39014
  return await withInlineClient({
38730
39015
  cfg,
38731
39016
  accountId,
38732
39017
  fn: async (client) => {
38733
39018
  const actions = resolveInlineMessageActionsParam(params);
38734
- if (replyThreadsEnabled) {
39019
+ if (isThreadReply) {
38735
39020
  const rawThreadId = readFlexibleId(params, "threadId") ?? readStringParam(params, "threadId");
38736
39021
  if (!rawThreadId) {
38737
- throw new Error("inline thread-reply: threadId is required when reply threads are enabled");
39022
+ throw new Error("inline thread-reply: threadId is required. Call thread-create first or use reply for the parent chat.");
38738
39023
  }
38739
39024
  const chatId2 = parseInlineId(rawThreadId, "threadId");
38740
39025
  const replyToMsgId2 = parseOptionalInlineId(readFlexibleId(params, "messageId") ?? readFlexibleId(params, "replyTo") ?? readFlexibleId(params, "replyToId") ?? readStringParam(params, "messageId") ?? readStringParam(params, "replyTo") ?? readStringParam(params, "replyToId"), "messageId");
@@ -38758,7 +39043,7 @@ var inlineMessageActions = {
38758
39043
  replyToId: replyToMsgId2 != null ? String(replyToMsgId2) : null
38759
39044
  });
38760
39045
  }
38761
- const replyParams = normalizedAction === "thread-reply" && params.threadId != null && params.to == null && params.chatId == null && params.channelId == null ? { ...params, to: params.threadId } : params;
39046
+ const replyParams = params;
38762
39047
  const chatId = resolveChatIdFromParams(replyParams);
38763
39048
  const replyToMsgId = parseInlineId(readFlexibleId(replyParams, "messageId") ?? readFlexibleId(replyParams, "replyTo") ?? readFlexibleId(replyParams, "replyToId") ?? readStringParam(replyParams, "messageId") ?? readStringParam(replyParams, "replyTo") ?? readStringParam(replyParams, "replyToId", { required: true }), "messageId");
38764
39049
  const text = resolveInlineActionText(replyParams, { required: true });
@@ -38818,7 +39103,7 @@ var inlineMessageActions = {
38818
39103
  oneofKind: "deleteReaction",
38819
39104
  deleteReaction: {
38820
39105
  emoji: emoji3,
38821
- peerId: buildChatPeer2(chatId),
39106
+ peerId: buildChatPeer(chatId),
38822
39107
  messageId
38823
39108
  }
38824
39109
  });
@@ -38856,7 +39141,7 @@ var inlineMessageActions = {
38856
39141
  addReaction: {
38857
39142
  emoji: emoji3,
38858
39143
  messageId,
38859
- peerId: buildChatPeer2(chatId)
39144
+ peerId: buildChatPeer(chatId)
38860
39145
  }
38861
39146
  });
38862
39147
  if (result.oneofKind !== "addReaction") {
@@ -38923,7 +39208,7 @@ var inlineMessageActions = {
38923
39208
  const result = await client.invokeRaw(Method.GET_CHAT_HISTORY, {
38924
39209
  oneofKind: "getChatHistory",
38925
39210
  getChatHistory: {
38926
- peerId: buildChatPeer2(chatId),
39211
+ peerId: buildChatPeer(chatId),
38927
39212
  ...offsetId != null ? { offsetId } : {},
38928
39213
  limit
38929
39214
  }
@@ -38951,7 +39236,7 @@ var inlineMessageActions = {
38951
39236
  const result = await client.invokeRaw(Method.SEARCH_MESSAGES, {
38952
39237
  oneofKind: "searchMessages",
38953
39238
  searchMessages: {
38954
- peerId: buildChatPeer2(chatId),
39239
+ peerId: buildChatPeer(chatId),
38955
39240
  queries: [query],
38956
39241
  limit,
38957
39242
  ...offsetId != null ? { offsetId } : {}
@@ -38987,7 +39272,7 @@ var inlineMessageActions = {
38987
39272
  oneofKind: "editMessage",
38988
39273
  editMessage: {
38989
39274
  messageId,
38990
- peerId: buildChatPeer2(chatId),
39275
+ peerId: buildChatPeer(chatId),
38991
39276
  text: visibleText.text,
38992
39277
  ...actions !== undefined ? { actions } : {},
38993
39278
  parseMarkdown
@@ -39014,7 +39299,7 @@ var inlineMessageActions = {
39014
39299
  const chatId = resolveChatIdFromParams(params);
39015
39300
  const result = await client.invokeRaw(Method.GET_CHAT, {
39016
39301
  oneofKind: "getChat",
39017
- getChat: { peerId: buildChatPeer2(chatId) }
39302
+ getChat: { peerId: buildChatPeer(chatId) }
39018
39303
  });
39019
39304
  if (result.oneofKind !== "getChat") {
39020
39305
  throw new Error(`inline action: expected getChat result, got ${String(result.oneofKind)}`);
@@ -39097,11 +39382,11 @@ var inlineMessageActions = {
39097
39382
  });
39098
39383
  }
39099
39384
  if (normalizedAction === "channel-create" || normalizedAction === "thread-create") {
39100
- const replyThreadsEnabled = normalizedAction === "thread-create" && isInlineReplyThreadsEnabled({ cfg, accountId: accountId ?? null });
39385
+ const isThreadCreate = normalizedAction === "thread-create";
39101
39386
  return await withInlineClient({
39102
39387
  cfg,
39103
39388
  accountId,
39104
- fn: async (client) => {
39389
+ fn: async (client, account) => {
39105
39390
  const title = requireVisibleActionText(readStringParam(params, "title") ?? readStringParam(params, "name") ?? readStringParam(params, "threadName") ?? readStringParam(params, "message", { required: true }), "title");
39106
39391
  const description = optionalVisibleActionText(readStringParam(params, "description"), "description");
39107
39392
  const emoji3 = readStringParam(params, "emoji");
@@ -39120,13 +39405,13 @@ var inlineMessageActions = {
39120
39405
  values: participantRefs,
39121
39406
  label: "participant"
39122
39407
  });
39123
- if (replyThreadsEnabled) {
39408
+ if (isThreadCreate) {
39124
39409
  const parentChatId = resolveChatIdFromParams(params);
39125
39410
  const parentMessageId = parseOptionalInlineId(resolveThreadParentMessageId({
39126
39411
  args: params,
39127
39412
  ...toolContext != null ? { toolContext: { currentMessageId: toolContext.currentMessageId } } : {}
39128
39413
  }), "parentMessageId");
39129
- const result2 = await client.invokeRaw(CREATE_SUBTHREAD_METHOD2, {
39414
+ const result2 = await client.invokeRaw(CREATE_SUBTHREAD_METHOD, {
39130
39415
  oneofKind: "createSubthread",
39131
39416
  createSubthread: {
39132
39417
  parentChatId,
@@ -39140,12 +39425,23 @@ var inlineMessageActions = {
39140
39425
  if (result2.oneofKind !== "createSubthread") {
39141
39426
  throw new Error(`inline action: expected createSubthread result, got ${String(result2.oneofKind)}`);
39142
39427
  }
39428
+ const createdChat = result2.createSubthread.chat ?? null;
39429
+ if (createdChat?.id != null) {
39430
+ const routeParentMessageId = createdChat.parentMessageId ?? parentMessageId;
39431
+ rememberInlineReplyThreadRoute({
39432
+ accountId: account.accountId,
39433
+ parentChatId: createdChat.parentChatId ?? parentChatId,
39434
+ threadId: createdChat.id,
39435
+ title: createdChat.title ?? title,
39436
+ ...routeParentMessageId != null ? { parentMessageId: routeParentMessageId } : {}
39437
+ });
39438
+ }
39143
39439
  return jsonResult(toJsonSafe({
39144
39440
  ok: true,
39145
39441
  title,
39146
39442
  parentChatId: String(parentChatId),
39147
39443
  parentMessageId: parentMessageId != null ? String(parentMessageId) : null,
39148
- chat: result2.createSubthread.chat ?? null,
39444
+ chat: createdChat,
39149
39445
  dialog: result2.createSubthread.dialog ?? null,
39150
39446
  anchorMessage: result2.createSubthread.anchorMessage ?? null
39151
39447
  }));
@@ -39185,7 +39481,7 @@ var inlineMessageActions = {
39185
39481
  const result = await client.invokeRaw(Method.DELETE_CHAT, {
39186
39482
  oneofKind: "deleteChat",
39187
39483
  deleteChat: {
39188
- peerId: buildChatPeer2(chatId)
39484
+ peerId: buildChatPeer(chatId)
39189
39485
  }
39190
39486
  });
39191
39487
  if (result.oneofKind !== "deleteChat") {
@@ -39395,7 +39691,7 @@ var inlineMessageActions = {
39395
39691
  const result = await client.invokeRaw(Method.DELETE_MESSAGES, {
39396
39692
  oneofKind: "deleteMessages",
39397
39693
  deleteMessages: {
39398
- peerId: buildChatPeer2(chatId),
39694
+ peerId: buildChatPeer(chatId),
39399
39695
  messageIds: deduped
39400
39696
  }
39401
39697
  });
@@ -39421,7 +39717,7 @@ var inlineMessageActions = {
39421
39717
  const result = await client.invokeRaw(Method.PIN_MESSAGE, {
39422
39718
  oneofKind: "pinMessage",
39423
39719
  pinMessage: {
39424
- peerId: buildChatPeer2(chatId),
39720
+ peerId: buildChatPeer(chatId),
39425
39721
  messageId,
39426
39722
  unpin
39427
39723
  }
@@ -39446,7 +39742,7 @@ var inlineMessageActions = {
39446
39742
  const chatId = resolveChatIdFromParams(params);
39447
39743
  const result = await client.invokeRaw(Method.GET_CHAT, {
39448
39744
  oneofKind: "getChat",
39449
- getChat: { peerId: buildChatPeer2(chatId) }
39745
+ getChat: { peerId: buildChatPeer(chatId) }
39450
39746
  });
39451
39747
  if (result.oneofKind !== "getChat") {
39452
39748
  throw new Error(`inline action: expected getChat result, got ${String(result.oneofKind)}`);
@@ -39659,6 +39955,115 @@ function isInlineExecApprovalHandlerConfigured(params) {
39659
39955
  });
39660
39956
  }
39661
39957
 
39958
+ // src/inline/reply-threads.ts
39959
+ var GET_CHAT_METHOD = typeof Method.GET_CHAT === "number" && Number.isInteger(Method.GET_CHAT) && Method.GET_CHAT > 0 ? Method.GET_CHAT : 25;
39960
+ 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;
39961
+ var GET_MESSAGES_METHOD2 = typeof Method.GET_MESSAGES === "number" && Number.isInteger(Method.GET_MESSAGES) && Method.GET_MESSAGES > 0 ? Method.GET_MESSAGES : 38;
39962
+ var CREATE_SUBTHREAD_METHOD2 = typeof Method.CREATE_SUBTHREAD === "number" && Number.isInteger(Method.CREATE_SUBTHREAD) && Method.CREATE_SUBTHREAD > 0 ? Method.CREATE_SUBTHREAD : 42;
39963
+ function buildChatPeer2(chatId) {
39964
+ return {
39965
+ type: {
39966
+ oneofKind: "chat",
39967
+ chat: { chatId }
39968
+ }
39969
+ };
39970
+ }
39971
+ function getInlineReplyThreadsCapabilityConfig(params) {
39972
+ return { replyThreads: true };
39973
+ }
39974
+ function isInlineReplyThreadsEnabled(params) {
39975
+ return getInlineReplyThreadsCapabilityConfig(params).replyThreads;
39976
+ }
39977
+ function resolveInlineReplyThreadChatId(params) {
39978
+ params.cfg;
39979
+ params.accountId;
39980
+ if (params.parentChatId == null) {
39981
+ return null;
39982
+ }
39983
+ if (params.threadId == null) {
39984
+ return params.parentChatId;
39985
+ }
39986
+ 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() ? (() => {
39987
+ try {
39988
+ return BigInt(params.threadId.trim());
39989
+ } catch {
39990
+ return null;
39991
+ }
39992
+ })() : null : null;
39993
+ return normalized ?? params.parentChatId;
39994
+ }
39995
+ async function loadInlineReplyThreadMetadata(params) {
39996
+ const result = await params.client.invokeRaw(GET_CHAT_METHOD, {
39997
+ oneofKind: "getChat",
39998
+ getChat: { peerId: buildChatPeer2(params.chatId) }
39999
+ }).catch(() => null);
40000
+ if (result?.oneofKind !== "getChat") {
40001
+ return null;
40002
+ }
40003
+ const chat = result.getChat.chat;
40004
+ const parentChatId = chat?.parentChatId;
40005
+ if (parentChatId == null) {
40006
+ return null;
40007
+ }
40008
+ return {
40009
+ childChatId: chat?.id ?? params.chatId,
40010
+ parentChatId,
40011
+ parentMessageId: chat?.parentMessageId ?? null,
40012
+ title: chat?.title?.trim() || null
40013
+ };
40014
+ }
40015
+ async function loadInlineReplyThreadAnchorMessage(params) {
40016
+ const directResult = await params.client.invokeRaw(GET_MESSAGES_METHOD2, {
40017
+ oneofKind: "getMessages",
40018
+ getMessages: {
40019
+ peerId: buildChatPeer2(params.parentChatId),
40020
+ messageIds: [params.parentMessageId]
40021
+ }
40022
+ }).catch(() => null);
40023
+ if (directResult?.oneofKind === "getMessages") {
40024
+ const directTarget = (directResult.getMessages.messages ?? []).find((item) => item.id === params.parentMessageId) ?? null;
40025
+ if (directTarget) {
40026
+ return directTarget;
40027
+ }
40028
+ }
40029
+ const historyResult = await params.client.invokeRaw(GET_CHAT_HISTORY_METHOD, {
40030
+ oneofKind: "getChatHistory",
40031
+ getChatHistory: {
40032
+ peerId: buildChatPeer2(params.parentChatId),
40033
+ offsetId: params.parentMessageId + 1n,
40034
+ limit: 8
40035
+ }
40036
+ }).catch(() => null);
40037
+ if (historyResult?.oneofKind !== "getChatHistory") {
40038
+ return null;
40039
+ }
40040
+ return (historyResult.getChatHistory.messages ?? []).find((item) => item.id === params.parentMessageId) ?? null;
40041
+ }
40042
+ async function createInlineReplyThreadForMessage(params) {
40043
+ const result = await params.client.invokeRaw(CREATE_SUBTHREAD_METHOD2, {
40044
+ oneofKind: "createSubthread",
40045
+ createSubthread: {
40046
+ parentChatId: params.parentChatId,
40047
+ parentMessageId: params.parentMessageId,
40048
+ participants: []
40049
+ }
40050
+ });
40051
+ if (result.oneofKind !== "createSubthread") {
40052
+ return null;
40053
+ }
40054
+ const chat = result.createSubthread.chat;
40055
+ if (!chat?.id) {
40056
+ return null;
40057
+ }
40058
+ return {
40059
+ childChatId: chat.id,
40060
+ parentChatId: chat.parentChatId ?? params.parentChatId,
40061
+ parentMessageId: chat.parentMessageId ?? params.parentMessageId,
40062
+ title: chat.title?.trim() || null,
40063
+ anchorMessage: result.createSubthread.anchorMessage ?? null
40064
+ };
40065
+ }
40066
+
39662
40067
  // src/inline/approval-handler.runtime.ts
39663
40068
  var log = createSubsystemLogger("inline/approvals");
39664
40069
  function resolveHandlerContext(params) {
@@ -39878,5 +40283,5 @@ export {
39878
40283
  inlineApprovalNativeRuntime
39879
40284
  };
39880
40285
 
39881
- //# debugId=57EFBB1CEE3A32B664756E2164756E21
40286
+ //# debugId=9CC8894E01E42C4C64756E2164756E21
39882
40287
  //# sourceMappingURL=approval-handler.runtime.js.map