typeclaw 0.38.0 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/auth.schema.json +109 -0
  2. package/package.json +2 -2
  3. package/secrets.schema.json +109 -0
  4. package/src/agent/session-origin.ts +15 -2
  5. package/src/bundled-plugins/memory/README.md +12 -1
  6. package/src/bundled-plugins/memory/index.ts +39 -2
  7. package/src/channels/adapters/kakaotalk.ts +1 -1
  8. package/src/channels/adapters/webex-bot-classify.ts +20 -14
  9. package/src/channels/adapters/webex-bot-reference.ts +8 -6
  10. package/src/channels/adapters/webex-bot.ts +106 -39
  11. package/src/channels/adapters/webex-channel-resolver.ts +29 -0
  12. package/src/channels/adapters/webex-classify.ts +104 -0
  13. package/src/channels/adapters/webex-format.ts +53 -0
  14. package/src/channels/adapters/webex-id-ref.ts +32 -0
  15. package/src/channels/adapters/webex-reference.ts +49 -0
  16. package/src/channels/adapters/webex.ts +493 -0
  17. package/src/channels/manager.ts +63 -7
  18. package/src/channels/persistence.ts +67 -5
  19. package/src/channels/router.ts +8 -0
  20. package/src/channels/schema.ts +2 -0
  21. package/src/cli/channel.ts +118 -7
  22. package/src/cli/init.ts +70 -1
  23. package/src/config/channels-mutation.ts +2 -1
  24. package/src/doctor/channel-checks.ts +43 -0
  25. package/src/hostd/daemon.ts +7 -5
  26. package/src/hostd/protocol.ts +2 -2
  27. package/src/init/checkpoint.ts +1 -1
  28. package/src/init/index.ts +60 -3
  29. package/src/init/run-owner-claim.ts +1 -0
  30. package/src/init/webex-auth.ts +68 -0
  31. package/src/inspect/label.ts +13 -2
  32. package/src/inspect/render.ts +5 -3
  33. package/src/permissions/resolve.ts +38 -1
  34. package/src/role-claim/match-rule.ts +5 -1
  35. package/src/secrets/codex-auth-json.ts +52 -17
  36. package/src/secrets/encryption.ts +5 -1
  37. package/src/secrets/export-codex-auth-file.ts +26 -3
  38. package/src/secrets/schema.ts +35 -0
  39. package/src/secrets/webex-store.ts +113 -0
  40. package/typeclaw.schema.json +160 -0
package/auth.schema.json CHANGED
@@ -498,6 +498,115 @@
498
498
  "currentAccount",
499
499
  "accounts"
500
500
  ]
501
+ },
502
+ "webex": {
503
+ "type": "object",
504
+ "properties": {
505
+ "currentAccount": {
506
+ "anyOf": [
507
+ {
508
+ "type": "string"
509
+ },
510
+ {
511
+ "type": "null"
512
+ }
513
+ ]
514
+ },
515
+ "accounts": {
516
+ "type": "object",
517
+ "propertyNames": {
518
+ "type": "string"
519
+ },
520
+ "additionalProperties": {
521
+ "type": "object",
522
+ "properties": {
523
+ "account_id": {
524
+ "type": "string"
525
+ },
526
+ "access_token": {
527
+ "type": "string"
528
+ },
529
+ "refresh_token": {
530
+ "type": "string"
531
+ },
532
+ "expires_at": {
533
+ "type": "number"
534
+ },
535
+ "device_url": {
536
+ "type": "string"
537
+ },
538
+ "user_id": {
539
+ "type": "string"
540
+ },
541
+ "client_id": {
542
+ "type": "string"
543
+ },
544
+ "client_secret": {
545
+ "type": "string"
546
+ },
547
+ "created_at": {
548
+ "type": "string"
549
+ },
550
+ "updated_at": {
551
+ "type": "string"
552
+ },
553
+ "email": {
554
+ "type": "string"
555
+ },
556
+ "encryptedPassword": {
557
+ "type": "object",
558
+ "properties": {
559
+ "v": {
560
+ "type": "number",
561
+ "const": 1
562
+ },
563
+ "alg": {
564
+ "type": "string",
565
+ "const": "AES-256-GCM"
566
+ },
567
+ "kid": {
568
+ "type": "string"
569
+ },
570
+ "iv": {
571
+ "type": "string"
572
+ },
573
+ "ciphertext": {
574
+ "type": "string"
575
+ },
576
+ "authTag": {
577
+ "type": "string"
578
+ },
579
+ "createdAt": {
580
+ "type": "string"
581
+ }
582
+ },
583
+ "required": [
584
+ "v",
585
+ "alg",
586
+ "kid",
587
+ "iv",
588
+ "ciphertext",
589
+ "authTag",
590
+ "createdAt"
591
+ ],
592
+ "additionalProperties": false
593
+ }
594
+ },
595
+ "required": [
596
+ "account_id",
597
+ "access_token",
598
+ "refresh_token",
599
+ "expires_at",
600
+ "created_at",
601
+ "updated_at"
602
+ ]
603
+ }
604
+ }
605
+ },
606
+ "required": [
607
+ "currentAccount",
608
+ "accounts"
609
+ ]
501
610
  }
502
611
  },
503
612
  "additionalProperties": {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typeclaw",
3
- "version": "0.38.0",
3
+ "version": "0.38.1",
4
4
  "homepage": "https://github.com/typeclaw/typeclaw#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/typeclaw/typeclaw/issues"
@@ -50,7 +50,7 @@
50
50
  "@mariozechner/pi-tui": "^0.67.3",
51
51
  "@modelcontextprotocol/sdk": "^1.29.0",
52
52
  "@mozilla/readability": "^0.6.0",
53
- "agent-messenger": "2.21.0",
53
+ "agent-messenger": "2.23.4",
54
54
  "cheerio": "^1.2.0",
55
55
  "citty": "^0.2.2",
56
56
  "cron-parser": "^5.5.0",
@@ -498,6 +498,115 @@
498
498
  "currentAccount",
499
499
  "accounts"
500
500
  ]
501
+ },
502
+ "webex": {
503
+ "type": "object",
504
+ "properties": {
505
+ "currentAccount": {
506
+ "anyOf": [
507
+ {
508
+ "type": "string"
509
+ },
510
+ {
511
+ "type": "null"
512
+ }
513
+ ]
514
+ },
515
+ "accounts": {
516
+ "type": "object",
517
+ "propertyNames": {
518
+ "type": "string"
519
+ },
520
+ "additionalProperties": {
521
+ "type": "object",
522
+ "properties": {
523
+ "account_id": {
524
+ "type": "string"
525
+ },
526
+ "access_token": {
527
+ "type": "string"
528
+ },
529
+ "refresh_token": {
530
+ "type": "string"
531
+ },
532
+ "expires_at": {
533
+ "type": "number"
534
+ },
535
+ "device_url": {
536
+ "type": "string"
537
+ },
538
+ "user_id": {
539
+ "type": "string"
540
+ },
541
+ "client_id": {
542
+ "type": "string"
543
+ },
544
+ "client_secret": {
545
+ "type": "string"
546
+ },
547
+ "created_at": {
548
+ "type": "string"
549
+ },
550
+ "updated_at": {
551
+ "type": "string"
552
+ },
553
+ "email": {
554
+ "type": "string"
555
+ },
556
+ "encryptedPassword": {
557
+ "type": "object",
558
+ "properties": {
559
+ "v": {
560
+ "type": "number",
561
+ "const": 1
562
+ },
563
+ "alg": {
564
+ "type": "string",
565
+ "const": "AES-256-GCM"
566
+ },
567
+ "kid": {
568
+ "type": "string"
569
+ },
570
+ "iv": {
571
+ "type": "string"
572
+ },
573
+ "ciphertext": {
574
+ "type": "string"
575
+ },
576
+ "authTag": {
577
+ "type": "string"
578
+ },
579
+ "createdAt": {
580
+ "type": "string"
581
+ }
582
+ },
583
+ "required": [
584
+ "v",
585
+ "alg",
586
+ "kid",
587
+ "iv",
588
+ "ciphertext",
589
+ "authTag",
590
+ "createdAt"
591
+ ],
592
+ "additionalProperties": false
593
+ }
594
+ },
595
+ "required": [
596
+ "account_id",
597
+ "access_token",
598
+ "refresh_token",
599
+ "expires_at",
600
+ "created_at",
601
+ "updated_at"
602
+ ]
603
+ }
604
+ }
605
+ },
606
+ "required": [
607
+ "currentAccount",
608
+ "accounts"
609
+ ]
501
610
  }
502
611
  },
503
612
  "additionalProperties": {}
@@ -1,3 +1,4 @@
1
+ import { toRef } from '@/channels/adapters/webex-id-ref'
1
2
  import { MEMBERSHIP_FRESHNESS_MS, type MembershipCount } from '@/channels/membership'
2
3
  import type { AdapterId } from '@/channels/schema'
3
4
  import type { ChannelSelfIdentity, ReactionRef } from '@/channels/types'
@@ -156,6 +157,7 @@ const PLATFORM_INFO: Record<AdapterId, PlatformInfo> = {
156
157
  supportsReactions: false,
157
158
  supportsAttachments: true,
158
159
  },
160
+ webex: { displayName: 'Webex', mentionMode: 'angle-id', supportsReactions: false, supportsAttachments: true },
159
161
  'webex-bot': { displayName: 'Webex', mentionMode: 'angle-id', supportsReactions: false, supportsAttachments: false },
160
162
  line: { displayName: 'LINE', mentionMode: 'alias', supportsReactions: false, supportsAttachments: false },
161
163
  kakaotalk: { displayName: 'KakaoTalk', mentionMode: 'alias', supportsReactions: false, supportsAttachments: true },
@@ -630,6 +632,12 @@ function renderSelfMention(platformInfo: PlatformInfo, self: ChannelSelfIdentity
630
632
  }
631
633
  }
632
634
 
635
+ const WEBEX_ADAPTERS = new Set<AdapterId>(['webex', 'webex-bot'])
636
+
637
+ function readableChannelId(adapter: AdapterId, id: string): string {
638
+ return WEBEX_ADAPTERS.has(adapter) ? toRef(id) : id
639
+ }
640
+
633
641
  function renderConversationLine(origin: {
634
642
  adapter: AdapterId
635
643
  workspace: string
@@ -642,8 +650,13 @@ function renderConversationLine(origin: {
642
650
  if (!hasChat && !hasWorkspace) return null
643
651
 
644
652
  const chatPrefix = origin.adapter === 'slack-bot' ? '#' : ''
645
- const chatLabel = hasChat ? `**${chatPrefix}${origin.chatName!}** (${origin.chat})` : `\`${origin.chat}\``
646
- const workspaceLabel = hasWorkspace ? `**${origin.workspaceName!}** (${origin.workspace})` : `\`${origin.workspace}\``
653
+ // The parenthetical/backtick id is a human-and-model disambiguator, NOT the
654
+ // send target — tools source the canonical room id from the JSON origin block,
655
+ // which stays raw. So decode webex base64 blobs to their readable ref here.
656
+ const chatId = readableChannelId(origin.adapter, origin.chat)
657
+ const workspaceId = readableChannelId(origin.adapter, origin.workspace)
658
+ const chatLabel = hasChat ? `**${chatPrefix}${origin.chatName!}** (${chatId})` : `\`${chatId}\``
659
+ const workspaceLabel = hasWorkspace ? `**${origin.workspaceName!}** (${workspaceId})` : `\`${workspaceId}\``
647
660
 
648
661
  return `Conversation: ${chatLabel} in ${workspaceLabel}.`
649
662
  }
@@ -42,7 +42,7 @@ All fields are **restart-required** — the plugin reads them once at boot. The
42
42
  | Cron | `__plugin_memory_dreaming` | `kind: 'prompt'`, `subagent: 'dreaming'`, scheduled per `memory.dreaming.schedule`. |
43
43
  | Hook | `session.idle` | Per-session debouncer with size-based ceiling. Spawns `memory-logger` on idle or buffer-trip. |
44
44
  | Hook | `session.end` | Spawns `memory-logger` immediately; also unlinks the retrieval-cache file for this session. |
45
- | Hook | `session.turn.start` | **Vector on:** renders the per-turn user-prompt memory block into `event.retrievalContext.results` (direct-mode shards under budget, de-duplicated across turns per session; top-K `hybridSearch` over budget; channel origins always index/headings-only); runs for every origin that supplies a `retrievalContext`, including subagents. **Vector off:** when `buildInjectionPlan` returns `mode: 'index'` and origin is not a subagent, spawns `memory-retrieval` (detached) with the turn's `userPrompt` so the cache reflects the user's current question. Fire-and-forget; failures route through the plugin logger. |
45
+ | Hook | `session.turn.start` | **Vector on:** renders the per-turn user-prompt memory block into `event.retrievalContext.results` (direct-mode shards under budget, de-duplicated across turns per session; top-K `hybridSearch` over budget; channel origins always index/headings-only); runs for every origin that supplies a `retrievalContext`, including user-delegated subagents (researcher, reviewer) — but NOT TypeClaw-owned infrastructure turns (`system` origins and `system`-spawned subagents memory-logger/backup, plus the dreaming cron job matched by its `__plugin_memory_dreaming` job id), whose `userPrompt` is a fixed instruction block, not a user message (see [Internal-infrastructure turns skip retrieval](#internal-infrastructure-turns-skip-retrieval)). **Vector off:** when `buildInjectionPlan` returns `mode: 'index'` and origin is not a subagent, spawns `memory-retrieval` (detached) with the turn's `userPrompt` so the cache reflects the user's current question. Fire-and-forget; failures route through the plugin logger. |
46
46
 
47
47
  ## Memory injection (two-tier, topic shards only)
48
48
 
@@ -61,6 +61,17 @@ Default budget is 16 KB. Direct mode when shard bytes sum ≤ budget: all shard
61
61
 
62
62
  The invariant `suppressSystemMemory === memory.vector.enabled` is load-bearing: a session must never carry memory in both the system prompt and the user turn.
63
63
 
64
+ ### Internal-infrastructure turns skip retrieval
65
+
66
+ The `session.turn.start` per-turn injection runs for user-delegated subagents (researcher, reviewer) but is skipped entirely for **TypeClaw-owned infrastructure turns**. Their `userPrompt` is a fixed instruction block (`buildInitialPrompt`), not a user message — feeding it into `hybridSearch` keyword-mines the subagent's own framing prose ("Read the transcript past the watermark…"), retrieves nothing useful, and embeds a ~560-token query that trips the 512-token bound warning on every spawn. None of these subagents consume injected long-term memory the way a conversational turn does, so retrieval there is pure waste.
67
+
68
+ The discriminator (`isInternalInfraTurn` in `index.ts`) matches two provenance shapes, because the infra subagents are spawned two different ways:
69
+
70
+ - **`system` provenance** — `memory-logger` and `backup` are spawned directly with a `system` parent origin, so either a `system` origin itself or a subagent whose `spawnedByOrigin.kind === 'system'` is skipped.
71
+ - **The dreaming cron job** — `dreaming` is spawned by the memory plugin's own cron job (`__plugin_memory_dreaming`), so its parent origin is `cron`, NOT `system` (the cron consumer stamps a `cron` parentOrigin so the subagent resolves to the right role). It is matched by that specific job id — `spawnedByOrigin.kind === 'cron' && jobId === __plugin_memory_dreaming` — derived via `buildPluginCronGlobalId` so it can't drift from the registration. A **user-scheduled** cron subagent has a different job id and is real delegated work, so it keeps memory.
72
+
73
+ This is the same "don't mine framing prose" class of bug PR #340 fixed for `memory-retrieval`, applied to the subagent turn-start path.
74
+
64
75
  ### Vector retrieval is parent-child, not a flat pool
65
76
 
66
77
  When `memory.vector.enabled` is true, `hybridSearch` does **not** rank topic vectors and stream-fragment vectors together in one flat cosine pool. It uses a parent-child collapse so the result set is always topic-level current truth:
@@ -6,7 +6,7 @@ import { CronExpressionParser } from 'cron-parser'
6
6
  import { z } from 'zod'
7
7
 
8
8
  import type { SessionOrigin } from '@/agent/session-origin'
9
- import { definePlugin, type SpawnSubagentOptions } from '@/plugin'
9
+ import { buildPluginCronGlobalId, definePlugin, type SpawnSubagentOptions } from '@/plugin'
10
10
  import { formatLocalDate } from '@/shared'
11
11
 
12
12
  import { createDreamingSubagent, type DreamingPayload } from './dreaming'
@@ -58,6 +58,13 @@ const DEFAULT_MIN_IDLE_DELTA_LINES = 3
58
58
  // sporadic agents entirely. Operators can override via `memory.dreaming.schedule`.
59
59
  const DEFAULT_DREAMING_SCHEDULE = '*/30 * * * *'
60
60
 
61
+ // Local key of the dreaming cron job (registered under `cronJobs.dreaming`) and
62
+ // the global id the scheduler stamps on its `parentOrigin.jobId`. Derived
63
+ // through the same builder the registry uses so the registration site and the
64
+ // infra-turn discriminator below cannot drift to different ids.
65
+ const DREAMING_CRON_KEY = 'dreaming'
66
+ const DREAMING_CRON_JOB_ID = buildPluginCronGlobalId('memory', DREAMING_CRON_KEY)
67
+
61
68
  // memory-retrieval's ceiling, enforced by the orchestration layer (see
62
69
  // `awaitWithSubagentTimeout` in @/agent/subagents). 30s is sized for the
63
70
  // declared workload — up to 3 `memory_search` calls + 1 `write` against a
@@ -167,6 +174,35 @@ const defaultDeps: MemoryPluginDeps = {
167
174
  openAppendVectorStore: (agentDir) => VectorStore.open(join(agentDir, 'memory', '.vectors', 'index.db')),
168
175
  }
169
176
 
177
+ // TypeClaw-owned infrastructure subagents (memory-logger, dreaming, backup) run
178
+ // the agent over their OWN fixed instruction prompt, not a user message. Their
179
+ // `userPrompt` is the static framing block buildInitialPrompt produces — feeding
180
+ // it into hybridSearch keyword-mines the subagent's own prose ("Read the
181
+ // transcript past the watermark…"), retrieves nothing useful, and embeds a
182
+ // ~560-token query that trips the 512-token bound warning on every spawn. None
183
+ // of these subagents consume injected long-term memory the way a conversational
184
+ // turn does, so per-turn retrieval is pure waste here. This is the same class of
185
+ // "don't mine framing prose" bug PR #340 fixed for memory-retrieval, applied to
186
+ // the subagent turn-start path.
187
+ //
188
+ // Two provenance shapes carry infra work, because the two infra subagents are
189
+ // spawned differently:
190
+ // - memory-logger / backup: spawned directly with a `system` parent origin.
191
+ // - dreaming: spawned by the memory plugin's own CRON job, so its parent
192
+ // origin is `cron` (jobId `__plugin_memory_dreaming`), NOT `system` — the
193
+ // cron consumer stamps a `cron` parentOrigin so the subagent resolves to the
194
+ // right role (src/cron/consumer.ts). It must be matched by its specific job
195
+ // id, not by "any cron subagent": a user-SCHEDULED cron subagent is real
196
+ // delegated work and keeps memory.
197
+ function isInternalInfraTurn(origin: SessionOrigin | undefined): boolean {
198
+ if (origin === undefined) return false
199
+ if (origin.kind === 'system') return true
200
+ if (origin.kind !== 'subagent') return false
201
+ const spawnedBy = origin.spawnedByOrigin
202
+ if (spawnedBy?.kind === 'system') return true
203
+ return spawnedBy?.kind === 'cron' && spawnedBy.jobId === DREAMING_CRON_JOB_ID
204
+ }
205
+
170
206
  // Builds the per-turn user-prompt memory block for a vector agent. Non-channel
171
207
  // turns always use top-K hybrid search, regardless of total shard size. Repeated
172
208
  // retrieved excerpts de-duplicate across turns, and an empty retrieval falls back
@@ -184,6 +220,7 @@ async function renderVectorTurnMemory(
184
220
  deps: MemoryPluginDeps,
185
221
  logger?: { info: (msg: string) => void },
186
222
  ): Promise<string> {
223
+ if (isInternalInfraTurn(event.origin)) return ''
187
224
  const plan = await loadMemoryInjectionPlan(event.agentDir, { injectionBudgetBytes })
188
225
  const isChannel = event.origin?.kind === 'channel'
189
226
  if (plan.mode === 'direct' && isChannel) {
@@ -431,7 +468,7 @@ export function createMemoryPlugin(deps: MemoryPluginDeps = defaultDeps) {
431
468
  memory_search: createMemorySearchTool(),
432
469
  },
433
470
  cronJobs: {
434
- dreaming: {
471
+ [DREAMING_CRON_KEY]: {
435
472
  schedule: dreamingSchedule,
436
473
  kind: 'prompt' as const,
437
474
  prompt: '(internal: dreaming consolidation; user prompt is built by the dreaming subagent handler)',
@@ -436,7 +436,7 @@ export function createKakaotalkAdapter(options: KakaotalkAdapterOptions): Kakaot
436
436
  event.chat_id,
437
437
  )
438
438
  logger.info(
439
- `[kakaotalk] inbound log_id=${event.log_id} author=${event.author_id} ${inboundTag} type=${event.message_type} text_len=${event.message.length}`,
439
+ `[kakaotalk] inbound log_id=${event.log_id} author=${event.author_name ?? event.author_id} ${inboundTag} type=${event.message_type} text_len=${event.message.length}`,
440
440
  )
441
441
 
442
442
  // Ack the message BEFORE classify/route so the sender's unread "1"
@@ -1,5 +1,6 @@
1
1
  import type { WebexBotListenerEventMap } from 'agent-messenger/webexbot'
2
2
 
3
+ import { matchesAnyAlias } from '@/channels/engagement'
3
4
  import type { ChannelAdapterConfig } from '@/channels/schema'
4
5
  import type { InboundAttachment, InboundMessage } from '@/channels/types'
5
6
 
@@ -14,44 +15,49 @@ export type InboundClassification =
14
15
  export function classifyInbound(
15
16
  event: WebexInboundMessage,
16
17
  _config: ChannelAdapterConfig,
17
- botPersonId: string | null,
18
+ botPersonRef: string | null,
19
+ selfAliases: readonly string[] = [],
18
20
  ): InboundClassification {
19
- if (botPersonId !== null && event.personId === botPersonId) {
21
+ if (botPersonRef !== null && event.personRef === botPersonRef) {
20
22
  return { kind: 'drop', reason: 'self_author' }
21
23
  }
22
24
 
23
25
  const { text, attachments } = splitInbound(event)
24
26
  if (text === '') return { kind: 'drop', reason: 'empty_content' }
25
27
 
26
- if (botPersonId === null) {
28
+ if (botPersonRef === null) {
27
29
  return { kind: 'drop', reason: 'pre_connect' }
28
30
  }
29
31
 
30
32
  const isDm = event.roomType === 'direct'
31
- const isBotMention = event.mentionedPeople.includes(botPersonId) || event.mentionedGroups.includes('all')
32
- const mentionsOthers = event.mentionedPeople.length > 0 && !event.mentionedPeople.includes(botPersonId)
33
+ const structuredBotMention = event.mentionedPeopleRefs.includes(botPersonRef) || event.mentionedGroups.includes('all')
34
+ const aliasMatched = !structuredBotMention && matchesAnyAlias(text, selfAliases)
35
+ const isBotMention = structuredBotMention || aliasMatched
36
+ const mentionsOthers = event.mentionedPeopleRefs.length > 0 && !event.mentionedPeopleRefs.includes(botPersonRef)
33
37
  const ts = Date.parse(event.created)
34
38
 
35
39
  return {
36
40
  kind: 'route',
37
41
  payload: {
38
42
  adapter: 'webex-bot',
39
- // Webex message events do not include an org/team id; the room id is the
43
+ // Webex message events do not include an org/team id; the room ref is the
40
44
  // stable permission bucket for group spaces while DMs use the shared key.
41
- workspace: isDm ? '@dm' : event.roomId,
42
- chat: event.roomId,
45
+ workspace: isDm ? '@dm' : event.roomRef,
46
+ chat: event.roomRef,
43
47
  thread: null,
44
48
  text,
45
49
  ...(attachments.length > 0 ? { attachments } : {}),
46
- externalMessageId: event.id,
47
- authorId: event.personId,
50
+ externalMessageId: event.ref,
51
+ authorId: event.personRef,
48
52
  authorName: event.personEmail,
49
53
  authorIsBot: false,
50
54
  isBotMention,
51
- // Webex Mercury only exposes parentId inline, not the parent author. When
52
- // the reply auto-mentions the bot we can identify it as bot-directed;
53
- // otherwise leave the parent unattributed instead of guessing.
54
- replyToBotMessageId: event.parentId !== undefined && isBotMention ? event.parentId : null,
55
+ // Webex Mercury only exposes parentRef inline, not the parent author. When
56
+ // the reply has a structured bot mention we can identify it as bot-directed;
57
+ // otherwise leave the parent unattributed instead of guessing. Alias matches
58
+ // are mention-equivalent for engagement, but they do not prove the parent
59
+ // is bot-authored; enrichment fetches the parent and attributes it.
60
+ replyToBotMessageId: event.parentRef !== undefined && structuredBotMention ? event.parentRef : null,
55
61
  mentionsOthers,
56
62
  replyToOtherMessageId: null,
57
63
  isDm,
@@ -2,6 +2,8 @@ import type { WebexBotClient } from 'agent-messenger/webexbot'
2
2
 
3
3
  import type { InboundMessage, QuoteAnchorSource } from '@/channels/types'
4
4
 
5
+ import { resolveWebexBodyText } from './webex-format'
6
+
5
7
  // Webex Mercury delivers only the parent message id inline, not its author,
6
8
  // so the classifier cannot tell whether a reply targets the bot. We fetch the
7
9
  // parent here (already needed for the quote anchor) and use its author to set
@@ -13,18 +15,18 @@ import type { InboundMessage, QuoteAnchorSource } from '@/channels/types'
13
15
  export async function enrichWebexMessageReference(args: {
14
16
  client: Pick<WebexBotClient, 'getMessage'>
15
17
  inbound: InboundMessage
16
- parentId?: string
18
+ parentRef?: string
17
19
  botPersonId: string | null
18
20
  }): Promise<InboundMessage> {
19
- if (args.parentId === undefined || args.parentId === '') return args.inbound
21
+ if (args.parentRef === undefined || args.parentRef === '') return args.inbound
20
22
  try {
21
- const parent = await args.client.getMessage(args.parentId)
22
- const attributed = attributeReply(args.inbound, parent.id, parent.personId, args.botPersonId)
23
+ const parent = await args.client.getMessage(args.parentRef)
24
+ const attributed = attributeReply(args.inbound, parent.ref, parent.personRef, args.botPersonId)
23
25
  const source: QuoteAnchorSource = {
24
26
  adapter: 'webex-bot',
25
- authorId: parent.personId,
27
+ authorId: parent.personRef,
26
28
  authorName: parent.personEmail,
27
- text: parent.text ?? parent.markdown ?? parent.html ?? '',
29
+ text: resolveWebexBodyText(parent),
28
30
  }
29
31
  if (source.text.trim() === '') return attributed
30
32
  return { ...attributed, referenceContext: { kind: 'reply', sources: [source] } }