typeclaw 0.48.12 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/package.json +6 -3
  2. package/scripts/dump-system-prompt.ts +52 -110
  3. package/src/agent/attention-escalation.ts +8 -5
  4. package/src/agent/auth-reloadable.ts +2 -3
  5. package/src/agent/auth.ts +59 -79
  6. package/src/agent/compaction.ts +2 -2
  7. package/src/agent/index.ts +173 -85
  8. package/src/agent/live-sessions.ts +2 -2
  9. package/src/agent/live-subagents.ts +1 -0
  10. package/src/agent/llm-replay-sanitizer.ts +1 -1
  11. package/src/agent/model-overrides.ts +1 -1
  12. package/src/agent/multimodal/look-at.ts +3 -3
  13. package/src/agent/multimodal/read-redirect.ts +1 -1
  14. package/src/agent/plugin-tools.ts +76 -39
  15. package/src/agent/prompt-cache-key.ts +42 -0
  16. package/src/agent/provider-error.ts +179 -10
  17. package/src/agent/reload-tool.ts +1 -1
  18. package/src/agent/restart-handoff/index.ts +7 -14
  19. package/src/agent/reviewer-activity.ts +68 -0
  20. package/src/agent/session-origin.ts +33 -0
  21. package/src/agent/subagents.ts +14 -2
  22. package/src/agent/system-prompt.ts +68 -202
  23. package/src/agent/todo/continuation-policy.ts +12 -4
  24. package/src/agent/tool-error-remediation.ts +1 -1
  25. package/src/agent/tool-file-safety.ts +113 -14
  26. package/src/agent/tool-not-found-nudge.ts +1 -1
  27. package/src/agent/tool-result-budget.ts +2 -2
  28. package/src/agent/tools/channel-disengage.ts +2 -2
  29. package/src/agent/tools/channel-edit.ts +2 -2
  30. package/src/agent/tools/channel-fetch-attachment.ts +2 -2
  31. package/src/agent/tools/channel-history-render.ts +2 -1
  32. package/src/agent/tools/channel-history.ts +2 -2
  33. package/src/agent/tools/channel-react.ts +2 -2
  34. package/src/agent/tools/channel-read.ts +2 -2
  35. package/src/agent/tools/channel-reply.ts +25 -7
  36. package/src/agent/tools/channel-send.ts +51 -9
  37. package/src/agent/tools/curl-impersonate.ts +11 -2
  38. package/src/agent/tools/grant-role.ts +2 -2
  39. package/src/agent/tools/post-github-review.ts +79 -17
  40. package/src/agent/tools/restart.ts +2 -2
  41. package/src/agent/tools/skip-response.ts +4 -4
  42. package/src/agent/tools/spawn-subagent.ts +165 -14
  43. package/src/agent/tools/stream-snapshot.ts +2 -2
  44. package/src/agent/tools/subagent-cancel.ts +2 -2
  45. package/src/agent/tools/subagent-output.ts +10 -2
  46. package/src/agent/tools/todo/index.ts +2 -2
  47. package/src/agent/tools/webfetch/tool.ts +2 -2
  48. package/src/agent/tools/websearch.ts +2 -2
  49. package/src/bundled-plugins/backup/README.md +10 -9
  50. package/src/bundled-plugins/backup/runner.ts +140 -58
  51. package/src/bundled-plugins/backup/subagents.ts +58 -26
  52. package/src/bundled-plugins/github-cli-auth/gh-command.ts +34 -2
  53. package/src/bundled-plugins/github-cli-auth/granted-push.ts +135 -0
  54. package/src/bundled-plugins/github-cli-auth/index.ts +83 -11
  55. package/src/bundled-plugins/github-cli-auth/review-account.ts +23 -0
  56. package/src/bundled-plugins/github-cli-auth/review-checkout.ts +9 -2
  57. package/src/bundled-plugins/github-cli-auth/review-recorder.ts +45 -7
  58. package/src/bundled-plugins/operator/operator.ts +15 -4
  59. package/src/bundled-plugins/reviewer/skills/code-review.ts +1 -1
  60. package/src/bundled-plugins/security/index.ts +50 -2
  61. package/src/bundled-plugins/security/policies/git-exfil.ts +24 -12
  62. package/src/channels/adapters/discord-bot-reactions.ts +18 -0
  63. package/src/channels/adapters/discord-bot.ts +122 -67
  64. package/src/channels/adapters/discord-reactions.ts +18 -0
  65. package/src/channels/adapters/discord.ts +114 -8
  66. package/src/channels/adapters/github/inbound.ts +103 -8
  67. package/src/channels/adapters/github/index.ts +251 -19
  68. package/src/channels/adapters/github/last-alive.ts +27 -0
  69. package/src/channels/adapters/github/outbound.ts +54 -18
  70. package/src/channels/adapters/github/pending-review-store.ts +141 -0
  71. package/src/channels/adapters/github/permission-guidance.ts +1 -0
  72. package/src/channels/adapters/github/reactions.ts +100 -0
  73. package/src/channels/adapters/github/reconcile-cooldown-store.ts +197 -67
  74. package/src/channels/adapters/github/reconcile-open-prs.ts +418 -33
  75. package/src/channels/adapters/github/recovery.ts +106 -0
  76. package/src/channels/adapters/github/review-check.ts +510 -0
  77. package/src/channels/adapters/github/review-submitter.ts +34 -2
  78. package/src/channels/adapters/instagram.ts +32 -14
  79. package/src/channels/adapters/kakaotalk.ts +22 -7
  80. package/src/channels/adapters/line.ts +18 -3
  81. package/src/channels/adapters/outbound-account.ts +20 -0
  82. package/src/channels/adapters/own-reactions.ts +66 -0
  83. package/src/channels/adapters/recovery-correlation.ts +214 -0
  84. package/src/channels/adapters/slack-bot-classify.ts +18 -11
  85. package/src/channels/adapters/slack-bot-dedupe.ts +111 -28
  86. package/src/channels/adapters/slack-bot-reactions.ts +18 -0
  87. package/src/channels/adapters/slack-bot.ts +125 -57
  88. package/src/channels/adapters/slack-classify.ts +25 -4
  89. package/src/channels/adapters/slack-inbound-revision.ts +96 -0
  90. package/src/channels/adapters/slack-reactions.ts +18 -0
  91. package/src/channels/adapters/slack-thread-ts.ts +6 -0
  92. package/src/channels/adapters/slack.ts +48 -3
  93. package/src/channels/adapters/teams.ts +14 -4
  94. package/src/channels/adapters/telegram-bot.ts +56 -10
  95. package/src/channels/adapters/webex-bot.ts +12 -2
  96. package/src/channels/adapters/webex.ts +12 -2
  97. package/src/channels/background-handoff.ts +434 -0
  98. package/src/channels/background-obligations.ts +893 -0
  99. package/src/channels/continuity-types.ts +271 -0
  100. package/src/channels/github-review-check.ts +598 -0
  101. package/src/channels/github-review-turn-ledger.ts +102 -28
  102. package/src/channels/github-review-verdict-coordinator.ts +96 -13
  103. package/src/channels/github-token-bridge.ts +11 -5
  104. package/src/channels/inbound-journal.ts +1738 -0
  105. package/src/channels/index.ts +6 -1
  106. package/src/channels/manager.ts +17 -7
  107. package/src/channels/recovery-dispatcher.ts +264 -0
  108. package/src/channels/recovery-notice.ts +94 -0
  109. package/src/channels/recovery-outbox.ts +459 -0
  110. package/src/channels/router.ts +2582 -633
  111. package/src/channels/schema.ts +8 -1
  112. package/src/channels/subagent-completion-bridge.ts +17 -14
  113. package/src/channels/types.ts +121 -16
  114. package/src/channels/waiting-reactions.ts +664 -0
  115. package/src/cli/compose.ts +7 -4
  116. package/src/cli/hostd.ts +49 -3
  117. package/src/cli/inspect.ts +11 -14
  118. package/src/cli/model.ts +7 -5
  119. package/src/cli/oauth-callbacks.ts +38 -23
  120. package/src/coding-agent/broker-body.ts +38 -0
  121. package/src/coding-agent/broker.ts +290 -0
  122. package/src/coding-agent/claude.ts +95 -0
  123. package/src/coding-agent/codex.ts +104 -0
  124. package/src/coding-agent/index.ts +506 -0
  125. package/src/coding-agent/omo-state.ts +69 -0
  126. package/src/coding-agent/omo-stream.ts +98 -0
  127. package/src/coding-agent/omo.ts +192 -0
  128. package/src/coding-agent/runner.ts +263 -0
  129. package/src/coding-agent/tool.ts +62 -0
  130. package/src/coding-agent/worktree.ts +355 -0
  131. package/src/compose/restart.ts +10 -3
  132. package/src/compose/start.ts +20 -3
  133. package/src/config/config.ts +70 -26
  134. package/src/config/providers.ts +278 -50
  135. package/src/container/exit-reason.ts +44 -0
  136. package/src/container/index.ts +5 -0
  137. package/src/container/log-archive.ts +51 -13
  138. package/src/container/memory-limit.ts +1 -1
  139. package/src/container/memory-oversubscription.ts +36 -6
  140. package/src/container/oom-events.ts +86 -0
  141. package/src/container/restart.ts +2 -0
  142. package/src/container/shared.ts +8 -1
  143. package/src/container/start.ts +25 -13
  144. package/src/container/stop.ts +6 -2
  145. package/src/container/tool-oom-priority.ts +32 -0
  146. package/src/cron/consumer.ts +10 -4
  147. package/src/cron/reloadable.ts +23 -2
  148. package/src/doctor/checks.ts +14 -2
  149. package/src/hostd/daemon.ts +20 -10
  150. package/src/hostd/spawn.ts +106 -5
  151. package/src/hostd/version.ts +20 -0
  152. package/src/hostd/watchdog.ts +241 -0
  153. package/src/init/dockerfile.ts +57 -592
  154. package/src/init/index.ts +6 -7
  155. package/src/init/oauth-login.ts +57 -17
  156. package/src/inspect/transcript-view.ts +6 -3
  157. package/src/mcp/client.ts +3 -1
  158. package/src/operations/classify-tool-outcome.ts +45 -1
  159. package/src/operations/incidents.ts +10 -5
  160. package/src/plugin/core-tool-names.ts +1 -1
  161. package/src/plugin/define.ts +1 -0
  162. package/src/plugin/index.ts +1 -0
  163. package/src/plugin/types.ts +6 -1
  164. package/src/run/background-handoff-boot.ts +86 -0
  165. package/src/run/channel-session-factory.ts +5 -4
  166. package/src/run/index.ts +93 -93
  167. package/src/run/resource-sample.ts +19 -0
  168. package/src/sandbox/build.ts +4 -0
  169. package/src/sandbox/coding-agent.ts +214 -0
  170. package/src/sandbox/policy.ts +1 -0
  171. package/src/sandbox/runtime-private.ts +4 -1
  172. package/src/secrets/coding-agent-auth.ts +97 -0
  173. package/src/secrets/index.ts +0 -16
  174. package/src/secrets/refresh-provider-oauth.ts +30 -76
  175. package/src/secrets/schema.ts +3 -4
  176. package/src/secrets/storage.ts +133 -234
  177. package/src/server/command-runner.ts +6 -2
  178. package/src/server/index.ts +102 -41
  179. package/src/sessions/index.ts +1 -1
  180. package/src/skills/typeclaw-channel-github/SKILL.md +7 -5
  181. package/src/skills/typeclaw-claude-code/SKILL.md +25 -260
  182. package/src/skills/typeclaw-claude-code/references/auth-flow.md +7 -23
  183. package/src/skills/typeclaw-claude-code/references/headless-sessions.md +11 -0
  184. package/src/skills/typeclaw-claude-code/references/results-and-worktrees.md +13 -0
  185. package/src/skills/typeclaw-codex-cli/SKILL.md +35 -270
  186. package/src/skills/typeclaw-codex-cli/references/auth-flow.md +13 -20
  187. package/src/skills/typeclaw-codex-cli/references/headless-sessions.md +26 -0
  188. package/src/skills/typeclaw-codex-cli/references/results-and-worktrees.md +28 -0
  189. package/src/skills/typeclaw-config/SKILL.md +24 -24
  190. package/src/skills/typeclaw-config/references/dockerfile.md +14 -13
  191. package/src/skills/typeclaw-cron/SKILL.md +1 -1
  192. package/src/skills/typeclaw-github-contributing/SKILL.md +2 -2
  193. package/src/skills/typeclaw-memory/SKILL.md +3 -3
  194. package/src/skills/typeclaw-omo-cli/SKILL.md +52 -0
  195. package/src/skills/typeclaw-omo-cli/references/auth-flow.md +11 -0
  196. package/src/skills/typeclaw-omo-cli/references/headless-sessions.md +11 -0
  197. package/src/skills/typeclaw-omo-cli/references/results-and-worktrees.md +23 -0
  198. package/src/skills/typeclaw-plugins/SKILL.md +20 -20
  199. package/src/skills/typeclaw-skills/SKILL.md +19 -2
  200. package/src/skills/typeclaw-troubleshooting/SKILL.md +15 -2
  201. package/src/tui/index.ts +5 -3
  202. package/src/tui/theme.ts +1 -1
  203. package/typeclaw.schema.json +44 -2
  204. package/src/agent/adaptive-thinking-compat.ts +0 -79
  205. package/src/secrets/claude-credentials-json.ts +0 -129
  206. package/src/secrets/codex-auth-json.ts +0 -102
  207. package/src/secrets/export-claude-credentials-file.ts +0 -270
  208. package/src/secrets/export-codex-auth-file.ts +0 -250
  209. package/src/secrets/oauth-xai.ts +0 -348
  210. package/src/skills/typeclaw-claude-code/references/stop-hook.md +0 -101
  211. package/src/skills/typeclaw-claude-code/references/tmux-driving.md +0 -243
  212. package/src/skills/typeclaw-codex-cli/references/stop-hook.md +0 -92
  213. package/src/skills/typeclaw-codex-cli/references/tmux-driving.md +0 -239
@@ -12,11 +12,23 @@ export type SlackInboundMessageEvent = SlackRTMMessageEvent & {
12
12
  // Modern RTM file messages are subtype-less but retain the `files` array.
13
13
  files?: SlackFile[]
14
14
  is_mpim?: boolean
15
+ // `message_changed` envelopes carry the edited message and its previous body;
16
+ // admitSlackInbound validates both before anything reads them.
17
+ message?: unknown
18
+ previous_message?: unknown
15
19
  }
16
20
 
17
21
  export type SlackConversationType = 'im' | 'mpim' | 'channel'
18
22
 
19
- export type InboundDropReason = 'self_author' | 'no_user' | 'slack_system_message' | 'empty_text' | 'pre_connect'
23
+ export type InboundDropReason =
24
+ | 'self_author'
25
+ | 'no_user'
26
+ | 'slack_system_message'
27
+ | 'empty_text'
28
+ | 'pre_connect'
29
+ | 'unverified_edit'
30
+ | 'edit_without_new_mention'
31
+ | 'edited_control'
20
32
 
21
33
  export type InboundClassification =
22
34
  | { kind: 'drop'; reason: InboundDropReason }
@@ -29,11 +41,18 @@ export type SlackInboundContext = {
29
41
  conversationType?: SlackConversationType
30
42
  }
31
43
 
44
+ import { addressesSlackSelf, admitSlackInbound } from './slack-inbound-revision'
45
+
32
46
  export function classifyInbound(
33
47
  event: SlackInboundMessageEvent,
34
48
  _config: ChannelAdapterConfig,
35
49
  context: SlackInboundContext,
36
50
  ): InboundClassification {
51
+ // Edits are gated on the raw envelope before normalization drops its subtype.
52
+ // RTM has no app_mention stream, so every user-session delivery is a 'message'.
53
+ const admission = admitSlackInbound(event, context.selfUserId)
54
+ if (admission.kind === 'drop') return { kind: 'drop', reason: admission.reason }
55
+ event = admission.event
37
56
  if (context.selfUserId !== null && event.user === context.selfUserId) return { kind: 'drop', reason: 'self_author' }
38
57
  if (event.user === undefined || event.user === '') return { kind: 'drop', reason: 'no_user' }
39
58
  if (!isRouteableSlackMessageSubtype(event.subtype)) return { kind: 'drop', reason: 'slack_system_message' }
@@ -45,8 +64,7 @@ export function classifyInbound(
45
64
  const conversationType = classifyConversation(event, context.conversationType)
46
65
  const isDm = conversationType === 'im'
47
66
  const workspace = isDm ? '@dm' : context.teamId
48
- const hasGroupMention = GROUP_MENTION_PATTERN.test(rawText)
49
- const isBotMention = hasGroupMention || rawText.includes(`<@${context.selfUserId}>`)
67
+ const isBotMention = addressesSlackSelf(rawText, context.selfUserId)
50
68
  const aliasMatched = !isBotMention && matchesAnyAlias(rawText, context.selfAliases ?? [])
51
69
  const thread = event.thread_ts ?? (!isDm && (isBotMention || aliasMatched) ? event.ts : null)
52
70
  const mentionedUserIds = extractMentionedUserIds(rawText)
@@ -63,6 +81,10 @@ export function classifyInbound(
63
81
  text,
64
82
  ...(attachments.length > 0 ? { attachments } : {}),
65
83
  externalMessageId: event.ts,
84
+ accountIdentity: `slack:${context.teamId}:${context.selfUserId}`,
85
+ eventKind: 'message',
86
+ // One engagement per Slack message: edits never mint a new revision.
87
+ revision: 'original',
66
88
  reactionRef: encodeSlackReactionRef({ channel: event.channel, ts: event.ts }),
67
89
  authorId: event.user,
68
90
  authorName: event.user,
@@ -127,7 +149,6 @@ function renderPlaceholder(attachment: InboundAttachment): string {
127
149
  }
128
150
 
129
151
  const MENTION_PATTERN = /<@([UW][A-Z0-9]+)(?:\|[^>]*)?>/g
130
- const GROUP_MENTION_PATTERN = /<!(?:here|channel|everyone)(?:\|[^>]*)?>/
131
152
 
132
153
  function extractMentionedUserIds(text: string): string[] {
133
154
  const seen = new Set<string>()
@@ -0,0 +1,96 @@
1
+ import { parseCommand } from '@/commands'
2
+ import { extractClaimCode } from '@/role-claim/code'
3
+
4
+ // Slack engages at most once per message. Every admitted delivery keeps the
5
+ // original message ts as its identity and revision 'original'; the inbound
6
+ // journal's per-message latch rejects any later delivery of a message it has
7
+ // already admitted, whatever its revision or routing thread. This gate decides
8
+ // only whether an edit may be treated as a first engagement at all:
9
+ //
10
+ // - A raw `message_changed` envelope must prove a fresh explicit address: the
11
+ // previous body has no self/group mention and the new body has one. Typo
12
+ // fixes, unchanged or removed mentions and unfurl/metadata updates drop.
13
+ // - An `app_mention` carrying a valid `edited` marker may engage without the
14
+ // previous body when it explicitly addresses this account. That is a
15
+ // first-engagement fallback, not proof the edit added the mention.
16
+ // - A flattened `message` carrying `edited` cannot prove anything and drops.
17
+ // - An edit is never control traffic: known slash commands and claim codes in
18
+ // an edit-derived delivery drop before any handler sees them. An app_mention
19
+ // without `edited` is indistinguishable from an original and stays on the
20
+ // original path, so this guarantee covers known edits only.
21
+ //
22
+ // The decision is stateless so a cold dedupe cache or a restart cannot widen it.
23
+
24
+ export type SlackInboundSource = 'message' | 'app_mention'
25
+
26
+ export type SlackEditDropReason = 'pre_connect' | 'unverified_edit' | 'edit_without_new_mention' | 'edited_control'
27
+
28
+ export type SlackInboundAdmission<T> =
29
+ | { kind: 'admit'; event: T; isEdit: boolean }
30
+ | { kind: 'drop'; reason: SlackEditDropReason }
31
+
32
+ const SLACK_TS_PATTERN = /^\d+\.\d+$/
33
+
34
+ // Slack's group mention markup uses `!` (not `@`) and may carry an optional
35
+ // `|label` suffix. `<!subteam^ID>` is deliberately excluded: engaging on every
36
+ // user-group ping would require knowing the account's subteam membership.
37
+ const GROUP_MENTION_PATTERN = /<!(?:here|channel|everyone)(?:\|[^>]*)?>/
38
+
39
+ // Group broadcasts address everyone present, including this account, so they
40
+ // count as an explicit mention alongside `<@self>`.
41
+ export function addressesSlackSelf(text: string, selfUserId: string): boolean {
42
+ return GROUP_MENTION_PATTERN.test(text) || text.includes(`<@${selfUserId}>`)
43
+ }
44
+
45
+ export function admitSlackInbound<T extends { subtype?: string; channel: string; ts: string }>(
46
+ event: T,
47
+ selfUserId: string | null,
48
+ source: SlackInboundSource = 'message',
49
+ ): SlackInboundAdmission<T> {
50
+ if (event.subtype === 'message_changed') return admitRawEdit(event, selfUserId)
51
+ if (!('edited' in event) || event.edited === undefined) return { kind: 'admit', event, isEdit: false }
52
+ if (source !== 'app_mention' || !validEditRevision(recordOf(event.edited)?.ts, event.ts))
53
+ return { kind: 'drop', reason: 'unverified_edit' }
54
+ if (selfUserId === null) return { kind: 'drop', reason: 'pre_connect' }
55
+ const text = 'text' in event && typeof event.text === 'string' ? event.text : ''
56
+ if (!addressesSlackSelf(text, selfUserId)) return { kind: 'drop', reason: 'edit_without_new_mention' }
57
+ return admitEdit(event, text)
58
+ }
59
+
60
+ function admitRawEdit<T extends { channel: string; ts: string }>(
61
+ event: T,
62
+ selfUserId: string | null,
63
+ ): SlackInboundAdmission<T> {
64
+ const message = 'message' in event ? recordOf(event.message) : null
65
+ const previous = 'previous_message' in event ? recordOf(event.previous_message) : null
66
+ if (message === null || previous === null) return { kind: 'drop', reason: 'unverified_edit' }
67
+ const { ts, text } = message
68
+ if (
69
+ typeof ts !== 'string' ||
70
+ typeof text !== 'string' ||
71
+ typeof previous.text !== 'string' ||
72
+ previous.ts !== ts ||
73
+ !validEditRevision(recordOf(message.edited)?.ts, ts)
74
+ )
75
+ return { kind: 'drop', reason: 'unverified_edit' }
76
+ if (selfUserId === null) return { kind: 'drop', reason: 'pre_connect' }
77
+ if (addressesSlackSelf(previous.text, selfUserId) || !addressesSlackSelf(text, selfUserId))
78
+ return { kind: 'drop', reason: 'edit_without_new_mention' }
79
+ const subtype = typeof message.subtype === 'string' ? message.subtype : undefined
80
+ // Keep the original message ts as the replyable identity, not the envelope ts.
81
+ return admitEdit({ ...event, ...message, channel: event.channel, ts, subtype }, text)
82
+ }
83
+
84
+ function admitEdit<T>(event: T, text: string): SlackInboundAdmission<T> {
85
+ if (parseCommand(text) !== null || extractClaimCode(text) !== null) return { kind: 'drop', reason: 'edited_control' }
86
+ return { kind: 'admit', event, isEdit: true }
87
+ }
88
+
89
+ // A real edit marker is a Slack ts distinct from the message's own ts.
90
+ function validEditRevision(revision: unknown, messageTs: string): boolean {
91
+ return typeof revision === 'string' && SLACK_TS_PATTERN.test(revision) && revision !== messageTs
92
+ }
93
+
94
+ function recordOf(value: unknown): Record<string, unknown> | null {
95
+ return typeof value === 'object' && value !== null ? (value as Record<string, unknown>) : null
96
+ }
@@ -9,6 +9,7 @@ import type {
9
9
  } from '@/channels/types'
10
10
 
11
11
  import { describeError } from '../describe-error'
12
+ import { createOwnReactionCallbacks } from './own-reactions'
12
13
 
13
14
  export type SlackReactionTarget = { channel: string; ts: string }
14
15
  export type SlackReactionRemovalTarget = { channel: string; ts: string; emoji: string }
@@ -105,6 +106,7 @@ function classifySlackError(code: string | null): ReactionErrorCode {
105
106
  return 'not-found'
106
107
  case 'ratelimited':
107
108
  case 'rate_limited':
109
+ case 'slack_webapi_rate_limited_error':
108
110
  return 'rate-limited'
109
111
  default:
110
112
  return 'transient'
@@ -122,3 +124,19 @@ function parseRecord(value: string): Record<string, unknown> | null {
122
124
  ? (parsed as Record<string, unknown>)
123
125
  : null
124
126
  }
127
+
128
+ export function createSlackOwnReactionCallbacks(deps: {
129
+ client: Pick<SlackClient, 'removeReaction'>
130
+ identity: () => string | null | Promise<string | null>
131
+ }) {
132
+ return createOwnReactionCallbacks({
133
+ adapter: 'slack',
134
+ identity: deps.identity,
135
+ decode: decodeSlackReactionRef,
136
+ encode: encodeSlackReactionRef,
137
+ emoji: normalizeEmoji,
138
+ remove: (target, emoji) => deps.client.removeReaction(target.channel, target.ts, emoji),
139
+ classify: (error) => classifySlackError(slackErrorCode(error)),
140
+ absent: (error) => slackErrorCode(error) === 'no_reaction',
141
+ })
142
+ }
@@ -0,0 +1,6 @@
1
+ // Slack timestamps are opaque message IDs, not decimal numbers. Preserve all six fractional digits.
2
+ export function invalidSlackThreadTs(thread: unknown): string | null {
3
+ if (thread === null || thread === undefined) return null
4
+ if (typeof thread === 'string' && /^\d+\.\d{6}$/.test(thread)) return null
5
+ return 'Invalid Slack thread timestamp: use the parent message ts as a string with exactly six digits after the decimal (e.g. 1700000000.000100). No message was sent.'
6
+ }
@@ -26,6 +26,7 @@ import type {
26
26
  FetchHistoryResult,
27
27
  HistoryCallback,
28
28
  OutboundCallback,
29
+ RecoveryAdapterCallbacks,
29
30
  OutboundMessage,
30
31
  ResolvedChannelNames,
31
32
  SendResult,
@@ -34,6 +35,7 @@ import { chunkMarkdown } from '@/markdown'
34
35
  import type { SlackAccountRecord } from '@/secrets/schema'
35
36
 
36
37
  import { describeError } from '../describe-error'
38
+ import { withOutboundAccount } from './outbound-account'
37
39
  import { downloadSlackAttachment, type SlackAttachmentFetch } from './slack-attachment-download'
38
40
  import { createSlackAuthorResolver } from './slack-author-resolver'
39
41
  import { slackTsToMillis } from './slack-bot-time'
@@ -41,6 +43,8 @@ import { createSlackChannelResolver } from './slack-channel-resolver'
41
43
  import { classifyInbound, type InboundDropReason, type SlackConversationType, splitSlackFiles } from './slack-classify'
42
44
  import { createSlackUserEditMessageCallback } from './slack-edit'
43
45
  import { createSlackReactionCallback, createSlackRemoveReactionCallback } from './slack-reactions'
46
+ import { createSlackOwnReactionCallbacks } from './slack-reactions'
47
+ import { invalidSlackThreadTs } from './slack-thread-ts'
44
48
 
45
49
  export type SlackAdapterLogger = {
46
50
  info: (msg: string) => void
@@ -93,6 +97,8 @@ export function createSlackOutboundCallback(deps: {
93
97
  if (text === '' && attachments.length === 0) return { ok: false, error: 'message has neither text nor attachments' }
94
98
  const tag = await deps.formatChannelTag(msg.chat)
95
99
  const threadTs = msg.replyTo?.externalMessageId ?? msg.thread ?? undefined
100
+ const invalidThread = invalidSlackThreadTs(threadTs)
101
+ if (invalidThread !== null) return { ok: false, error: invalidThread }
96
102
  deps.logger.info(
97
103
  `[slack] outbound ${tag} text_len=${text.length} attachments=${attachments.length}${threadTs !== undefined ? ` thread=${threadTs}` : ''}`,
98
104
  )
@@ -226,6 +232,21 @@ export function createSlackAdapter(options: SlackAdapterOptions): SlackAdapter {
226
232
  const authorResolver = createSlackAuthorResolver({ client })
227
233
  const selfIdentityResolver: ChannelSelfIdentityResolver = () =>
228
234
  selfUserId !== null ? { id: selfUserId, username: selfName ?? selfUserId } : null
235
+ const recoveryCallbacks: RecoveryAdapterCallbacks = {
236
+ cachedAccountIdentity: (workspace) =>
237
+ selfUserId !== null && teamId !== '' && (workspace === undefined || workspace === '@dm' || workspace === teamId)
238
+ ? `slack:${teamId}:${selfUserId}`
239
+ : undefined,
240
+ accountIdentity: async (workspace) => {
241
+ const auth = await client.testAuth()
242
+ return auth.team_id &&
243
+ auth.user_id &&
244
+ (workspace === undefined || workspace === '@dm' || workspace === auth.team_id)
245
+ ? `slack:${auth.team_id}:${auth.user_id}`
246
+ : undefined
247
+ },
248
+ reconcile: async () => ({ status: 'unreconcilable' }),
249
+ }
229
250
  const formatChannelTag = async (chat: string): Promise<string> => {
230
251
  const names = await channelResolver({ adapter: 'slack', workspace: teamId, chat, thread: null }).catch(
231
252
  (): ResolvedChannelNames => ({}),
@@ -240,7 +261,10 @@ export function createSlackAdapter(options: SlackAdapterOptions): SlackAdapter {
240
261
  historyCallback,
241
262
  selfUserIdRef: () => selfUserId,
242
263
  })
243
- const outboundCallback = createSlackOutboundCallback({ client, logger, formatChannelTag })
264
+ const outboundCallback = withOutboundAccount(
265
+ createSlackOutboundCallback({ client, logger, formatChannelTag }),
266
+ (workspace) => recoveryCallbacks.cachedAccountIdentity?.(workspace),
267
+ )
244
268
  const fetchAttachmentCallback = createSlackFetchAttachmentCallback({
245
269
  client,
246
270
  logger,
@@ -249,6 +273,13 @@ export function createSlackAdapter(options: SlackAdapterOptions): SlackAdapter {
249
273
  })
250
274
  const reactionCallback = createSlackReactionCallback({ client })
251
275
  const removeReactionCallback = createSlackRemoveReactionCallback({ client })
276
+ const ownReaction = createSlackOwnReactionCallbacks({
277
+ client,
278
+ identity: async () => {
279
+ const self = await client.testAuth()
280
+ return self.team_id && self.user_id ? `${self.team_id}:${self.user_id}` : null
281
+ },
282
+ })
252
283
  const editMessageCallback = createSlackUserEditMessageCallback({ client })
253
284
 
254
285
  const resolveConversationType = async (event: SlackRTMMessageEvent): Promise<SlackConversationType | undefined> => {
@@ -273,6 +304,8 @@ export function createSlackAdapter(options: SlackAdapterOptions): SlackAdapter {
273
304
  }
274
305
 
275
306
  const handleMessage = async (event: SlackRTMMessageEvent): Promise<void> => {
307
+ const inboundTeamId = teamId
308
+ const inboundSelfId = selfUserId
276
309
  inflightInbounds++
277
310
  try {
278
311
  const tag = await formatChannelTag(event.channel)
@@ -280,8 +313,8 @@ export function createSlackAdapter(options: SlackAdapterOptions): SlackAdapter {
280
313
  `[slack] inbound id=${event.ts} author=${event.user ?? '(none)'} ${tag} text_len=${(event.text ?? '').length}`,
281
314
  )
282
315
  const verdict = classifyInbound(event, options.configRef(), {
283
- teamId,
284
- selfUserId,
316
+ teamId: inboundTeamId,
317
+ selfUserId: inboundSelfId,
285
318
  selfAliases: options.selfAliasesRef?.() ?? [],
286
319
  conversationType: await resolveConversationType(event),
287
320
  })
@@ -384,6 +417,7 @@ export function createSlackAdapter(options: SlackAdapterOptions): SlackAdapter {
384
417
  listener.on('reaction_removed', (event) => handleReaction('removed', event))
385
418
 
386
419
  options.router.registerOutbound('slack', outboundCallback)
420
+ options.router.registerRecoveryAdapter('slack', recoveryCallbacks)
387
421
  options.router.setTypingCapability('slack', false)
388
422
  options.router.registerChannelNameResolver('slack', channelResolver)
389
423
  options.router.registerSelfIdentity('slack', selfIdentityResolver)
@@ -392,10 +426,13 @@ export function createSlackAdapter(options: SlackAdapterOptions): SlackAdapter {
392
426
  options.router.registerMembership('slack', membershipResolver)
393
427
  options.router.registerReaction('slack', reactionCallback)
394
428
  options.router.registerRemoveReaction('slack', removeReactionCallback)
429
+ options.router.registerPrepareOwnReaction('slack', ownReaction.prepare)
430
+ options.router.registerRemoveOwnReaction('slack', ownReaction.remove)
395
431
  options.router.registerEditMessage('slack', editMessageCallback)
396
432
 
397
433
  const rollbackStart = (reason: string, cause: Error): never => {
398
434
  options.router.unregisterOutbound('slack', outboundCallback)
435
+ options.router.unregisterRecoveryAdapter('slack', recoveryCallbacks)
399
436
  options.router.setTypingCapability('slack', false)
400
437
  options.router.unregisterChannelNameResolver('slack', channelResolver)
401
438
  options.router.unregisterSelfIdentity('slack', selfIdentityResolver)
@@ -404,6 +441,8 @@ export function createSlackAdapter(options: SlackAdapterOptions): SlackAdapter {
404
441
  options.router.unregisterMembership('slack', membershipResolver)
405
442
  options.router.unregisterReaction('slack', reactionCallback)
406
443
  options.router.unregisterRemoveReaction('slack', removeReactionCallback)
444
+ options.router.unregisterPrepareOwnReaction('slack', ownReaction.prepare)
445
+ options.router.unregisterRemoveOwnReaction('slack', ownReaction.remove)
407
446
  options.router.unregisterEditMessage('slack', editMessageCallback)
408
447
  clearTimeout(startupTimer)
409
448
  listener?.stop()
@@ -430,6 +469,7 @@ export function createSlackAdapter(options: SlackAdapterOptions): SlackAdapter {
430
469
  started = false
431
470
  accountToken = null
432
471
  options.router.unregisterOutbound('slack', outboundCallback)
472
+ options.router.unregisterRecoveryAdapter('slack', recoveryCallbacks)
433
473
  options.router.setTypingCapability('slack', false)
434
474
  options.router.unregisterChannelNameResolver('slack', channelResolver)
435
475
  options.router.unregisterSelfIdentity('slack', selfIdentityResolver)
@@ -438,6 +478,8 @@ export function createSlackAdapter(options: SlackAdapterOptions): SlackAdapter {
438
478
  options.router.unregisterMembership('slack', membershipResolver)
439
479
  options.router.unregisterReaction('slack', reactionCallback)
440
480
  options.router.unregisterRemoveReaction('slack', removeReactionCallback)
481
+ options.router.unregisterPrepareOwnReaction('slack', ownReaction.prepare)
482
+ options.router.unregisterRemoveOwnReaction('slack', ownReaction.remove)
441
483
  options.router.unregisterEditMessage('slack', editMessageCallback)
442
484
  listener?.stop()
443
485
  listener = null
@@ -487,6 +529,9 @@ function dropHint(reason: InboundDropReason): string {
487
529
  case 'self_author':
488
530
  case 'no_user':
489
531
  case 'slack_system_message':
532
+ case 'unverified_edit':
533
+ case 'edit_without_new_mention':
534
+ case 'edited_control':
490
535
  return ''
491
536
  }
492
537
  }
@@ -3,6 +3,7 @@ import type { TeamsListenerEventMap, TeamsMessage, TeamsUser } from 'agent-messe
3
3
 
4
4
  import type { ChannelRouter } from '@/channels/router'
5
5
  import type { ChannelAdapterConfig } from '@/channels/schema'
6
+ import { fallbackChannelAccountIdentity } from '@/channels/types'
6
7
  import type {
7
8
  ChannelHistoryMessage,
8
9
  ChannelSelfIdentityResolver,
@@ -16,6 +17,7 @@ import type {
16
17
  import type { TeamsAccountRecord } from '@/secrets/schema'
17
18
 
18
19
  import { describeError } from '../describe-error'
20
+ import { withOutboundAccount } from './outbound-account'
19
21
  import {
20
22
  classifyChannelInbound,
21
23
  classifyChatInbound,
@@ -204,7 +206,9 @@ export function createTeamsAdapter(options: TeamsAdapterOptions): TeamsAdapter {
204
206
  return false
205
207
  }
206
208
 
207
- const outboundCallback = createOutboundCallback({ client, logger, reserveEcho })
209
+ const outboundCallback = withOutboundAccount(createOutboundCallback({ client, logger, reserveEcho }), (workspace) =>
210
+ fallbackChannelAccountIdentity('teams', workspace, self?.id),
211
+ )
208
212
  const historyCallback = createTeamsHistoryCallback({ client, logger, selfIdRef: () => self?.id ?? null })
209
213
  const editMessageCallback = createTeamsEditMessageCallback({ client })
210
214
 
@@ -236,6 +240,7 @@ export function createTeamsAdapter(options: TeamsAdapterOptions): TeamsAdapter {
236
240
  }
237
241
 
238
242
  const handleMessage = async (event: TeamsInboundEvent): Promise<void> => {
243
+ const selfSnapshot = self
239
244
  inflightInbounds++
240
245
  try {
241
246
  if (isSelfEcho(event)) {
@@ -249,10 +254,10 @@ export function createTeamsAdapter(options: TeamsAdapterOptions): TeamsAdapter {
249
254
  verdict =
250
255
  channel === null
251
256
  ? ({ kind: 'drop', reason: 'unknown_channel' } as const)
252
- : classifyChannelInbound(event, options.configRef(), self, channel, aliases)
257
+ : classifyChannelInbound(event, options.configRef(), selfSnapshot, channel, aliases)
253
258
  } else {
254
259
  const chat = await resolveChat(event.chatId)
255
- verdict = classifyChatInbound(event, options.configRef(), self, chat, aliases)
260
+ verdict = classifyChatInbound(event, options.configRef(), selfSnapshot, chat, aliases)
256
261
  }
257
262
  if (verdict.kind === 'drop') {
258
263
  logger.info(`[teams] dropped id=${event.id} reason=${verdict.reason}${dropHint(verdict.reason)}`)
@@ -261,7 +266,12 @@ export function createTeamsAdapter(options: TeamsAdapterOptions): TeamsAdapter {
261
266
  logger.info(
262
267
  `[teams] routed id=${event.id} ${event.conversationType}=${event.chatId} mention=${verdict.payload.isBotMention} dm=${verdict.payload.isDm}`,
263
268
  )
264
- await options.router.route(verdict.payload)
269
+ await options.router.route({
270
+ ...verdict.payload,
271
+ accountIdentity: fallbackChannelAccountIdentity('teams', verdict.payload.workspace, selfSnapshot?.id),
272
+ eventKind: 'message',
273
+ revision: 'original',
274
+ })
265
275
  } catch (err) {
266
276
  logger.error(`[teams] handleInbound failed: ${describeError(err)}`)
267
277
  } finally {
@@ -1,3 +1,7 @@
1
+ import { copyFile, mkdtemp, rm } from 'node:fs/promises'
2
+ import { tmpdir } from 'node:os'
3
+ import { basename, join } from 'node:path'
4
+
1
5
  import { TelegramBotClient, TelegramBotListener } from 'agent-messenger/telegrambot'
2
6
  import type { TelegramBotUser, TelegramMessage } from 'agent-messenger/telegrambot'
3
7
 
@@ -10,6 +14,7 @@ import {
10
14
  import type { MembershipResolver, MembershipResolverFailure, MembershipResolverResult } from '@/channels/membership'
11
15
  import type { ChannelRouter } from '@/channels/router'
12
16
  import type { ChannelAdapterConfig } from '@/channels/schema'
17
+ import { fallbackChannelAccountIdentity } from '@/channels/types'
13
18
  import type {
14
19
  ChannelNameResolver,
15
20
  ChannelSelfIdentityResolver,
@@ -23,6 +28,7 @@ import type {
23
28
  } from '@/channels/types'
24
29
 
25
30
  import { describeError } from '../describe-error'
31
+ import { withOutboundAccount } from './outbound-account'
26
32
  import { classifyInbound, type InboundDropReason, TELEGRAM_WORKSPACE } from './telegram-bot-classify'
27
33
  import { createTelegramEditMessageCallback } from './telegram-bot-edit'
28
34
  import { toTelegramMarkdownV2 } from './telegram-bot-format'
@@ -239,7 +245,9 @@ export function createOutboundCallback(deps: {
239
245
  for (const attachment of attachments) {
240
246
  const path = resolvePath ? resolvePath(attachment.path) : attachment.path
241
247
  try {
242
- const sent = await client.sendDocument(msg.chat, path)
248
+ const sent = await withUploadFilename(path, attachment.filename, (uploadPath) =>
249
+ client.sendDocument(msg.chat, uploadPath),
250
+ )
243
251
  logger.info(`[telegram-bot] uploaded message_id=${sent.message_id} ${tag}`)
244
252
  if (threadId !== undefined) {
245
253
  logger.warn(
@@ -260,10 +268,14 @@ export function createOutboundCallback(deps: {
260
268
 
261
269
  try {
262
270
  const rendered = toTelegramMarkdownV2(text)
263
- const sendOptions: { message_thread_id?: number; reply_to_message_id?: number; parse_mode: 'MarkdownV2' } = {
264
- parse_mode: 'MarkdownV2',
265
- }
271
+ const sendOptions: {
272
+ message_thread_id?: number
273
+ reply_to_message_id?: number
274
+ parse_mode: 'MarkdownV2'
275
+ link_preview_options?: { is_disabled: boolean }
276
+ } = { parse_mode: 'MarkdownV2' }
266
277
  if (threadId !== undefined) sendOptions.message_thread_id = threadId
278
+ if (msg.link_previews === false) sendOptions.link_preview_options = { is_disabled: true }
267
279
  const replyToId = parseTelegramMessageId(msg.replyTo?.externalMessageId)
268
280
  if (replyToId !== undefined) sendOptions.reply_to_message_id = replyToId
269
281
  const sent = await client.sendMessage(msg.chat, rendered, sendOptions)
@@ -278,6 +290,27 @@ export function createOutboundCallback(deps: {
278
290
  }
279
291
  }
280
292
 
293
+ // agent-messenger's `sendDocument` names the upload after the path's basename
294
+ // and takes no filename argument, so honoring the OutboundAttachment
295
+ // `filename` override means uploading from a copy that carries that name.
296
+ // The copy lives in a private temp dir removed right after the send.
297
+ async function withUploadFilename<T>(
298
+ path: string,
299
+ filename: string | undefined,
300
+ upload: (uploadPath: string) => Promise<T>,
301
+ ): Promise<T> {
302
+ const name = filename !== undefined ? basename(filename) : ''
303
+ if (name === '' || name === basename(path)) return upload(path)
304
+ const dir = await mkdtemp(join(tmpdir(), 'typeclaw-telegram-upload-'))
305
+ try {
306
+ const staged = join(dir, name)
307
+ await copyFile(path, staged)
308
+ return await upload(staged)
309
+ } finally {
310
+ await rm(dir, { recursive: true, force: true })
311
+ }
312
+ }
313
+
281
314
  function parseThreadId(thread: string | null | undefined): number | undefined {
282
315
  if (thread === null || thread === undefined || thread === '') return undefined
283
316
  const n = Number(thread)
@@ -427,11 +460,15 @@ export function createTelegramBotAdapter(options: TelegramBotAdapterOptions): Te
427
460
 
428
461
  const membershipResolver = createTelegramMembershipResolver({ client, logger })
429
462
 
430
- const outboundCallback = createOutboundCallback({
431
- client,
432
- logger,
433
- formatChannelTag,
434
- })
463
+ const outboundCallback = withOutboundAccount(
464
+ createOutboundCallback({
465
+ client,
466
+ logger,
467
+ formatChannelTag,
468
+ }),
469
+ (workspace) =>
470
+ fallbackChannelAccountIdentity('telegram-bot', workspace, botUser === null ? undefined : String(botUser.id)),
471
+ )
435
472
 
436
473
  const fetchAttachmentCallback = createFetchAttachmentCallback({ token: options.token, logger })
437
474
  const editMessageCallback = createTelegramEditMessageCallback({ client })
@@ -463,7 +500,16 @@ export function createTelegramBotAdapter(options: TelegramBotAdapterOptions): Te
463
500
  logger.info(
464
501
  `[telegram-bot] routed message_id=${event.message_id} ${tag} mention=${verdict.payload.isBotMention} reply=${verdict.payload.replyToBotMessageId !== null}`,
465
502
  )
466
- await options.router.route(verdict.payload)
503
+ await options.router.route({
504
+ ...verdict.payload,
505
+ accountIdentity: fallbackChannelAccountIdentity(
506
+ 'telegram-bot',
507
+ verdict.payload.workspace,
508
+ botSnapshot === null ? undefined : String(botSnapshot.id),
509
+ ),
510
+ eventKind: 'message',
511
+ revision: 'original',
512
+ })
467
513
  } catch (err) {
468
514
  logger.error(`[telegram-bot] handleInbound failed: ${describeError(err)}`)
469
515
  } finally {
@@ -21,6 +21,7 @@ import {
21
21
  import { deriveMembershipFromHistory } from '@/channels/membership-from-history'
22
22
  import type { ChannelRouter } from '@/channels/router'
23
23
  import type { ChannelAdapterConfig } from '@/channels/schema'
24
+ import { fallbackChannelAccountIdentity } from '@/channels/types'
24
25
  import type {
25
26
  ChannelHistoryMessage,
26
27
  ChannelSelfIdentityResolver,
@@ -35,6 +36,7 @@ import type {
35
36
  } from '@/channels/types'
36
37
 
37
38
  import { describeError } from '../describe-error'
39
+ import { withOutboundAccount } from './outbound-account'
38
40
  import { createWebexChannelNameResolver } from './webex-bot-channel-resolver'
39
41
  import { classifyInbound, type InboundDropReason, type WebexInboundMessage } from './webex-bot-classify'
40
42
  import { enrichWebexMessageReference } from './webex-bot-reference'
@@ -316,7 +318,10 @@ export function createWebexBotAdapter(options: WebexBotAdapterOptions): WebexBot
316
318
  historyCallback,
317
319
  botPersonIdRef: () => botPerson?.ref ?? null,
318
320
  })
319
- const outboundCallback = createOutboundCallback({ client, logger, formatChannelTag })
321
+ const outboundCallback = withOutboundAccount(
322
+ createOutboundCallback({ client, logger, formatChannelTag }),
323
+ (workspace) => fallbackChannelAccountIdentity('webex-bot', workspace, botPerson?.ref),
324
+ )
320
325
  const fetchAttachmentCallback = createFetchAttachmentCallback({ token: options.token, logger, fetchImpl })
321
326
  const editMessageCallback = createWebexEditMessageCallback({ adapter: 'webex-bot', client })
322
327
 
@@ -348,7 +353,12 @@ export function createWebexBotAdapter(options: WebexBotAdapterOptions): WebexBot
348
353
  logger.info(
349
354
  `[webex-bot] routed id=${event.ref} ${tag} mention=${payload.isBotMention} reply=${payload.replyToBotMessageId !== null}`,
350
355
  )
351
- await options.router.route(payload)
356
+ await options.router.route({
357
+ ...payload,
358
+ accountIdentity: fallbackChannelAccountIdentity('webex-bot', payload.workspace, botSnapshot?.ref),
359
+ eventKind: 'message',
360
+ revision: 'original',
361
+ })
352
362
  } catch (err) {
353
363
  logger.error(`[webex-bot] handleInbound failed: ${describeError(err)}`)
354
364
  } finally {
@@ -23,6 +23,7 @@ import {
23
23
  import { deriveMembershipFromHistory } from '@/channels/membership-from-history'
24
24
  import type { ChannelRouter } from '@/channels/router'
25
25
  import type { ChannelAdapterConfig } from '@/channels/schema'
26
+ import { fallbackChannelAccountIdentity } from '@/channels/types'
26
27
  import type {
27
28
  ChannelHistoryMessage,
28
29
  ChannelSelfIdentityResolver,
@@ -40,6 +41,7 @@ import type {
40
41
  import type { WebexAccountRecord } from '@/secrets/schema'
41
42
 
42
43
  import { describeError } from '../describe-error'
44
+ import { withOutboundAccount } from './outbound-account'
43
45
  import { createWebexChannelNameResolver } from './webex-channel-resolver'
44
46
  import { classifyInbound, type InboundDropReason, type WebexInboundMessage } from './webex-classify'
45
47
  import { createWebexEditMessageCallback } from './webex-edit'
@@ -368,7 +370,10 @@ export function createWebexAdapter(options: WebexAdapterOptions): WebexAdapter {
368
370
  historyCallback,
369
371
  botPersonIdRef: () => botPerson?.ref ?? null,
370
372
  })
371
- const outboundCallback = createOutboundCallback({ client, logger, formatChannelTag })
373
+ const outboundCallback = withOutboundAccount(
374
+ createOutboundCallback({ client, logger, formatChannelTag }),
375
+ (workspace) => fallbackChannelAccountIdentity('webex', workspace, botPerson?.ref),
376
+ )
372
377
  const typingCallback = createTypingCallback({ client, logger, formatChannelTag })
373
378
  const fetchAttachmentCallback = createFetchAttachmentCallback({ tokenRef: () => currentToken, logger, fetchImpl })
374
379
  const editMessageCallback = createWebexEditMessageCallback({ adapter: 'webex', client })
@@ -399,7 +404,12 @@ export function createWebexAdapter(options: WebexAdapterOptions): WebexAdapter {
399
404
  logger.info(
400
405
  `[webex] routed id=${event.ref} ${tag} mention=${payload.isBotMention} reply=${payload.replyToBotMessageId !== null}`,
401
406
  )
402
- await options.router.route(payload)
407
+ await options.router.route({
408
+ ...payload,
409
+ accountIdentity: fallbackChannelAccountIdentity('webex', payload.workspace, botSnapshot?.ref),
410
+ eventKind: 'message',
411
+ revision: 'original',
412
+ })
403
413
  } catch (err) {
404
414
  logger.error(`[webex] handleInbound failed: ${describeError(err)}`)
405
415
  } finally {