agent-messenger 2.20.4 → 2.21.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 (115) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +8 -5
  3. package/bun.lock +2 -2
  4. package/dist/package.json +10 -2
  5. package/dist/src/cli.d.ts.map +1 -1
  6. package/dist/src/cli.js +3 -0
  7. package/dist/src/cli.js.map +1 -1
  8. package/dist/src/platforms/webexbot/cli.d.ts +5 -0
  9. package/dist/src/platforms/webexbot/cli.d.ts.map +1 -0
  10. package/dist/src/platforms/webexbot/cli.js +30 -0
  11. package/dist/src/platforms/webexbot/cli.js.map +1 -0
  12. package/dist/src/platforms/webexbot/client.d.ts +41 -0
  13. package/dist/src/platforms/webexbot/client.d.ts.map +1 -0
  14. package/dist/src/platforms/webexbot/client.js +66 -0
  15. package/dist/src/platforms/webexbot/client.js.map +1 -0
  16. package/dist/src/platforms/webexbot/commands/auth.d.ts +28 -0
  17. package/dist/src/platforms/webexbot/commands/auth.d.ts.map +1 -0
  18. package/dist/src/platforms/webexbot/commands/auth.js +166 -0
  19. package/dist/src/platforms/webexbot/commands/auth.js.map +1 -0
  20. package/dist/src/platforms/webexbot/commands/index.d.ts +7 -0
  21. package/dist/src/platforms/webexbot/commands/index.d.ts.map +1 -0
  22. package/dist/src/platforms/webexbot/commands/index.js +7 -0
  23. package/dist/src/platforms/webexbot/commands/index.js.map +1 -0
  24. package/dist/src/platforms/webexbot/commands/listen.d.ts +12 -0
  25. package/dist/src/platforms/webexbot/commands/listen.d.ts.map +1 -0
  26. package/dist/src/platforms/webexbot/commands/listen.js +85 -0
  27. package/dist/src/platforms/webexbot/commands/listen.js.map +1 -0
  28. package/dist/src/platforms/webexbot/commands/member.d.ts +19 -0
  29. package/dist/src/platforms/webexbot/commands/member.d.ts.map +1 -0
  30. package/dist/src/platforms/webexbot/commands/member.js +33 -0
  31. package/dist/src/platforms/webexbot/commands/member.js.map +1 -0
  32. package/dist/src/platforms/webexbot/commands/message.d.ts +37 -0
  33. package/dist/src/platforms/webexbot/commands/message.d.ts.map +1 -0
  34. package/dist/src/platforms/webexbot/commands/message.js +142 -0
  35. package/dist/src/platforms/webexbot/commands/message.js.map +1 -0
  36. package/dist/src/platforms/webexbot/commands/shared.d.ts +9 -0
  37. package/dist/src/platforms/webexbot/commands/shared.d.ts.map +1 -0
  38. package/dist/src/platforms/webexbot/commands/shared.js +13 -0
  39. package/dist/src/platforms/webexbot/commands/shared.js.map +1 -0
  40. package/dist/src/platforms/webexbot/commands/space.d.ts +28 -0
  41. package/dist/src/platforms/webexbot/commands/space.d.ts.map +1 -0
  42. package/dist/src/platforms/webexbot/commands/space.js +61 -0
  43. package/dist/src/platforms/webexbot/commands/space.js.map +1 -0
  44. package/dist/src/platforms/webexbot/commands/whoami.d.ts +16 -0
  45. package/dist/src/platforms/webexbot/commands/whoami.d.ts.map +1 -0
  46. package/dist/src/platforms/webexbot/commands/whoami.js +29 -0
  47. package/dist/src/platforms/webexbot/commands/whoami.js.map +1 -0
  48. package/dist/src/platforms/webexbot/credential-manager.d.ts +17 -0
  49. package/dist/src/platforms/webexbot/credential-manager.d.ts.map +1 -0
  50. package/dist/src/platforms/webexbot/credential-manager.js +120 -0
  51. package/dist/src/platforms/webexbot/credential-manager.js.map +1 -0
  52. package/dist/src/platforms/webexbot/index.d.ts +9 -0
  53. package/dist/src/platforms/webexbot/index.d.ts.map +1 -0
  54. package/dist/src/platforms/webexbot/index.js +6 -0
  55. package/dist/src/platforms/webexbot/index.js.map +1 -0
  56. package/dist/src/platforms/webexbot/listener.d.ts +44 -0
  57. package/dist/src/platforms/webexbot/listener.d.ts.map +1 -0
  58. package/dist/src/platforms/webexbot/listener.js +214 -0
  59. package/dist/src/platforms/webexbot/listener.js.map +1 -0
  60. package/dist/src/platforms/webexbot/types.d.ts +60 -0
  61. package/dist/src/platforms/webexbot/types.d.ts.map +1 -0
  62. package/dist/src/platforms/webexbot/types.js +28 -0
  63. package/dist/src/platforms/webexbot/types.js.map +1 -0
  64. package/dist/src/platforms/webexbot/wdm-discovery.d.ts +4 -0
  65. package/dist/src/platforms/webexbot/wdm-discovery.d.ts.map +1 -0
  66. package/dist/src/platforms/webexbot/wdm-discovery.js +36 -0
  67. package/dist/src/platforms/webexbot/wdm-discovery.js.map +1 -0
  68. package/docs/content/docs/cli/meta.json +1 -0
  69. package/docs/content/docs/cli/webexbot.mdx +290 -0
  70. package/docs/content/docs/sdk/meta.json +1 -0
  71. package/docs/content/docs/sdk/webexbot.mdx +340 -0
  72. package/docs/src/app/page.tsx +115 -19
  73. package/package.json +10 -2
  74. package/skills/agent-channeltalk/SKILL.md +1 -1
  75. package/skills/agent-channeltalkbot/SKILL.md +1 -1
  76. package/skills/agent-discord/SKILL.md +1 -1
  77. package/skills/agent-discordbot/SKILL.md +1 -1
  78. package/skills/agent-instagram/SKILL.md +1 -1
  79. package/skills/agent-kakaotalk/SKILL.md +1 -1
  80. package/skills/agent-line/SKILL.md +1 -1
  81. package/skills/agent-slack/SKILL.md +1 -1
  82. package/skills/agent-slackbot/SKILL.md +1 -1
  83. package/skills/agent-teams/SKILL.md +1 -1
  84. package/skills/agent-telegram/SKILL.md +1 -1
  85. package/skills/agent-telegrambot/SKILL.md +1 -1
  86. package/skills/agent-webex/SKILL.md +1 -1
  87. package/skills/agent-webexbot/SKILL.md +361 -0
  88. package/skills/agent-webexbot/references/authentication.md +225 -0
  89. package/skills/agent-webexbot/references/common-patterns.md +590 -0
  90. package/skills/agent-wechatbot/SKILL.md +1 -1
  91. package/skills/agent-whatsapp/SKILL.md +1 -1
  92. package/skills/agent-whatsappbot/SKILL.md +1 -1
  93. package/src/cli.ts +4 -0
  94. package/src/platforms/webex/typings/webex-message-handler.d.ts +360 -29
  95. package/src/platforms/webexbot/cli.ts +42 -0
  96. package/src/platforms/webexbot/client.ts +87 -0
  97. package/src/platforms/webexbot/commands/auth.test.ts +185 -0
  98. package/src/platforms/webexbot/commands/auth.ts +210 -0
  99. package/src/platforms/webexbot/commands/index.ts +6 -0
  100. package/src/platforms/webexbot/commands/listen.test.ts +20 -0
  101. package/src/platforms/webexbot/commands/listen.ts +104 -0
  102. package/src/platforms/webexbot/commands/member.ts +51 -0
  103. package/src/platforms/webexbot/commands/message.ts +197 -0
  104. package/src/platforms/webexbot/commands/shared.ts +22 -0
  105. package/src/platforms/webexbot/commands/space.ts +88 -0
  106. package/src/platforms/webexbot/commands/whoami.ts +43 -0
  107. package/src/platforms/webexbot/credential-manager.test.ts +182 -0
  108. package/src/platforms/webexbot/credential-manager.ts +149 -0
  109. package/src/platforms/webexbot/index.ts +8 -0
  110. package/src/platforms/webexbot/listener.test.ts +234 -0
  111. package/src/platforms/webexbot/listener.ts +255 -0
  112. package/src/platforms/webexbot/types.test.ts +87 -0
  113. package/src/platforms/webexbot/types.ts +72 -0
  114. package/src/platforms/webexbot/wdm-discovery.test.ts +97 -0
  115. package/src/platforms/webexbot/wdm-discovery.ts +43 -0
@@ -0,0 +1,97 @@
1
+ import { afterEach, describe, expect, it, mock } from 'bun:test'
2
+
3
+ import { createWdmRewriteFetch, discoverWdmDevicesUrl } from './wdm-discovery'
4
+
5
+ const realFetch = globalThis.fetch
6
+
7
+ afterEach(() => {
8
+ globalThis.fetch = realFetch
9
+ })
10
+
11
+ function jsonResponse(body: unknown, ok = true, status = 200): Response {
12
+ return { ok, status, json: () => Promise.resolve(body) } as unknown as Response
13
+ }
14
+
15
+ describe('discoverWdmDevicesUrl', () => {
16
+ it('returns the U2C wdm serviceLink with /devices appended', async () => {
17
+ globalThis.fetch = mock(() =>
18
+ Promise.resolve(jsonResponse({ serviceLinks: { wdm: 'https://wdm-r.wbx2.com/wdm/api/v1' } })),
19
+ )
20
+
21
+ const url = await discoverWdmDevicesUrl('token123')
22
+
23
+ expect(url).toBe('https://wdm-r.wbx2.com/wdm/api/v1/devices')
24
+ })
25
+
26
+ it('strips a trailing slash before appending /devices', async () => {
27
+ globalThis.fetch = mock(() =>
28
+ Promise.resolve(jsonResponse({ serviceLinks: { wdm: 'https://wdm-r.wbx2.com/wdm/api/v1/' } })),
29
+ )
30
+
31
+ const url = await discoverWdmDevicesUrl('token123')
32
+
33
+ expect(url).toBe('https://wdm-r.wbx2.com/wdm/api/v1/devices')
34
+ })
35
+
36
+ it('throws when the catalog request fails', async () => {
37
+ globalThis.fetch = mock(() => Promise.resolve(jsonResponse({}, false, 401)))
38
+
39
+ await expect(discoverWdmDevicesUrl('bad')).rejects.toThrow('Failed to discover Webex WDM cluster')
40
+ })
41
+
42
+ it('throws when the catalog lacks serviceLinks.wdm', async () => {
43
+ globalThis.fetch = mock(() => Promise.resolve(jsonResponse({ serviceLinks: {} })))
44
+
45
+ await expect(discoverWdmDevicesUrl('token123')).rejects.toThrow('did not include serviceLinks.wdm')
46
+ })
47
+ })
48
+
49
+ describe('createWdmRewriteFetch', () => {
50
+ it('rewrites the hardcoded WDM device-registration URL to the discovered cluster', async () => {
51
+ const seen: string[] = []
52
+ globalThis.fetch = mock((url: string) => {
53
+ seen.push(url)
54
+ return Promise.resolve(jsonResponse({ ok: true }))
55
+ })
56
+
57
+ const fetchFn = createWdmRewriteFetch('https://wdm-r.wbx2.com/wdm/api/v1/devices')
58
+ await fetchFn({
59
+ url: 'https://wdm-a.wbx2.com/wdm/api/v1/devices',
60
+ method: 'POST',
61
+ headers: { Authorization: 'Bearer x' },
62
+ body: '{}',
63
+ })
64
+
65
+ expect(seen[0]).toBe('https://wdm-r.wbx2.com/wdm/api/v1/devices')
66
+ })
67
+
68
+ it('rewrites WDM device sub-paths too', async () => {
69
+ const seen: string[] = []
70
+ globalThis.fetch = mock((url: string) => {
71
+ seen.push(url)
72
+ return Promise.resolve(jsonResponse({}))
73
+ })
74
+
75
+ const fetchFn = createWdmRewriteFetch('https://wdm-r.wbx2.com/wdm/api/v1/devices')
76
+ await fetchFn({
77
+ url: 'https://wdm-a.wbx2.com/wdm/api/v1/devices/abc-123',
78
+ method: 'DELETE',
79
+ headers: {},
80
+ })
81
+
82
+ expect(seen[0]).toBe('https://wdm-r.wbx2.com/wdm/api/v1/devices/abc-123')
83
+ })
84
+
85
+ it('leaves non-WDM URLs untouched', async () => {
86
+ const seen: string[] = []
87
+ globalThis.fetch = mock((url: string) => {
88
+ seen.push(url)
89
+ return Promise.resolve(jsonResponse({}))
90
+ })
91
+
92
+ const fetchFn = createWdmRewriteFetch('https://wdm-r.wbx2.com/wdm/api/v1/devices')
93
+ await fetchFn({ url: 'https://webexapis.com/v1/people/me', method: 'GET', headers: {} })
94
+
95
+ expect(seen[0]).toBe('https://webexapis.com/v1/people/me')
96
+ })
97
+ })
@@ -0,0 +1,43 @@
1
+ import type { FetchFunction, FetchRequest, FetchResponse } from 'webex-message-handler'
2
+
3
+ import { WebexBotError } from './types'
4
+
5
+ const U2C_CATALOG_URL = 'https://u2c.wbx2.com/u2c/api/v1/catalog?format=hostmap'
6
+ const HARDCODED_WDM_DEVICES_URL = 'https://wdm-a.wbx2.com/wdm/api/v1/devices'
7
+
8
+ // webex-message-handler hardcodes the WDM cluster to wdm-a. A bot whose org lives
9
+ // on another cluster (e.g. wdm-r) registers its device on the wrong cluster, so
10
+ // Webex never routes conversation activities to its Mercury socket — the socket
11
+ // connects but no messages arrive. The U2C catalog returns the correct WDM cluster
12
+ // for the token; rewriting the device-registration request to it makes the bot
13
+ // receive real-time events.
14
+ export async function discoverWdmDevicesUrl(token: string): Promise<string> {
15
+ const response = await fetch(U2C_CATALOG_URL, { headers: { Authorization: `Bearer ${token}` } })
16
+ if (!response.ok) {
17
+ throw new WebexBotError(`Failed to discover Webex WDM cluster: HTTP ${response.status}`, 'wdm_discovery_failed')
18
+ }
19
+
20
+ const catalog = (await response.json()) as { serviceLinks?: { wdm?: string } }
21
+ const wdm = catalog.serviceLinks?.wdm
22
+ if (!wdm) {
23
+ throw new WebexBotError('Webex U2C catalog did not include serviceLinks.wdm', 'wdm_discovery_failed')
24
+ }
25
+
26
+ return `${wdm.replace(/\/$/, '')}/devices`
27
+ }
28
+
29
+ export function createWdmRewriteFetch(wdmDevicesUrl: string): FetchFunction {
30
+ return async (req: FetchRequest): Promise<FetchResponse> => {
31
+ const url = req.url.startsWith(HARDCODED_WDM_DEVICES_URL)
32
+ ? wdmDevicesUrl + req.url.slice(HARDCODED_WDM_DEVICES_URL.length)
33
+ : req.url
34
+
35
+ const res = await fetch(url, { method: req.method, headers: req.headers, body: req.body })
36
+ return {
37
+ status: res.status,
38
+ ok: res.ok,
39
+ json: () => res.json(),
40
+ text: () => res.text(),
41
+ }
42
+ }
43
+ }