agent-messenger 2.20.2 → 2.20.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/bun.lock +41 -0
- package/dist/package.json +2 -1
- package/dist/src/platforms/webex/client.d.ts +2 -0
- package/dist/src/platforms/webex/client.d.ts.map +1 -1
- package/dist/src/platforms/webex/client.js +29 -5
- package/dist/src/platforms/webex/client.js.map +1 -1
- package/dist/src/platforms/webex/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/webex/commands/message.js +32 -52
- package/dist/src/platforms/webex/commands/message.js.map +1 -1
- package/dist/src/platforms/webex/encryption.d.ts +7 -0
- package/dist/src/platforms/webex/encryption.d.ts.map +1 -1
- package/dist/src/platforms/webex/encryption.js +12 -1
- package/dist/src/platforms/webex/encryption.js.map +1 -1
- package/dist/src/platforms/webex/kms-key-provider.d.ts +20 -0
- package/dist/src/platforms/webex/kms-key-provider.d.ts.map +1 -0
- package/dist/src/platforms/webex/kms-key-provider.js +78 -0
- package/dist/src/platforms/webex/kms-key-provider.js.map +1 -0
- package/docs/content/docs/cli/webex.mdx +1 -1
- package/package.json +2 -1
- package/skills/agent-channeltalk/SKILL.md +1 -1
- package/skills/agent-channeltalkbot/SKILL.md +1 -1
- package/skills/agent-discord/SKILL.md +1 -1
- package/skills/agent-discordbot/SKILL.md +1 -1
- package/skills/agent-instagram/SKILL.md +1 -1
- package/skills/agent-kakaotalk/SKILL.md +1 -1
- package/skills/agent-line/SKILL.md +1 -1
- package/skills/agent-slack/SKILL.md +1 -1
- package/skills/agent-slackbot/SKILL.md +1 -1
- package/skills/agent-teams/SKILL.md +1 -1
- package/skills/agent-telegram/SKILL.md +1 -1
- package/skills/agent-telegrambot/SKILL.md +1 -1
- package/skills/agent-webex/SKILL.md +1 -1
- package/skills/agent-webex/references/authentication.md +1 -1
- package/skills/agent-wechatbot/SKILL.md +1 -1
- package/skills/agent-whatsapp/SKILL.md +1 -1
- package/skills/agent-whatsappbot/SKILL.md +1 -1
- package/src/platforms/webex/client.ts +35 -6
- package/src/platforms/webex/commands/message.test.ts +16 -0
- package/src/platforms/webex/commands/message.ts +38 -57
- package/src/platforms/webex/encryption.test.ts +58 -3
- package/src/platforms/webex/encryption.ts +19 -1
- package/src/platforms/webex/kms-key-provider.ts +99 -0
- package/src/platforms/webex/typings/webex-message-handler.d.ts +45 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { DeviceManager, KmsClient, MercurySocket, noopLogger } from 'webex-message-handler'
|
|
2
|
+
import WebSocket from 'ws'
|
|
3
|
+
|
|
4
|
+
interface KmsKeyProviderOptions {
|
|
5
|
+
token: string
|
|
6
|
+
logger?: { debug(message: string): void }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface Registration {
|
|
10
|
+
webSocketUrl: string
|
|
11
|
+
deviceUrl: string
|
|
12
|
+
userId: string
|
|
13
|
+
encryptionServiceUrl: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type HttpRequest = {
|
|
17
|
+
url: string
|
|
18
|
+
method: string
|
|
19
|
+
headers: Record<string, string>
|
|
20
|
+
body?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class KmsKeyProvider {
|
|
24
|
+
private token: string
|
|
25
|
+
private logger?: { debug(message: string): void }
|
|
26
|
+
private mercury: MercurySocket | null = null
|
|
27
|
+
private kms: KmsClient | null = null
|
|
28
|
+
private readyPromise: Promise<void> | null = null
|
|
29
|
+
|
|
30
|
+
constructor(options: KmsKeyProviderOptions) {
|
|
31
|
+
this.token = options.token
|
|
32
|
+
this.logger = options.logger
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async fetchKey(keyUri: string): Promise<string | null> {
|
|
36
|
+
try {
|
|
37
|
+
await this.ensureReady()
|
|
38
|
+
const key = await this.kms?.getKey(keyUri)
|
|
39
|
+
if (!key) return null
|
|
40
|
+
return JSON.stringify({ uri: keyUri, jwk: key.toJSON(true) })
|
|
41
|
+
} catch (error) {
|
|
42
|
+
this.logger?.debug(`Webex KMS key fetch failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
43
|
+
await this.close()
|
|
44
|
+
this.readyPromise = null
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async close(): Promise<void> {
|
|
50
|
+
await this.mercury?.disconnect().catch(() => undefined)
|
|
51
|
+
this.mercury = null
|
|
52
|
+
this.kms = null
|
|
53
|
+
this.readyPromise = null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private async ensureReady(): Promise<void> {
|
|
57
|
+
this.readyPromise ??= this.initialize()
|
|
58
|
+
await this.readyPromise
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private async initialize(): Promise<void> {
|
|
62
|
+
const httpDo = async (req: HttpRequest) => {
|
|
63
|
+
const res = await fetch(req.url, {
|
|
64
|
+
method: req.method,
|
|
65
|
+
headers: req.headers,
|
|
66
|
+
body: req.body,
|
|
67
|
+
})
|
|
68
|
+
return {
|
|
69
|
+
status: res.status,
|
|
70
|
+
ok: res.ok,
|
|
71
|
+
json: () => res.json(),
|
|
72
|
+
text: () => res.text(),
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const wsFactory = (url: string) => new WebSocket(url) as never
|
|
76
|
+
const dm = new DeviceManager({ logger: noopLogger, httpDo })
|
|
77
|
+
const reg = (await dm.register(this.token)) as Registration
|
|
78
|
+
const mercury = new MercurySocket({ logger: noopLogger, wsFactory })
|
|
79
|
+
const kms = new KmsClient({
|
|
80
|
+
token: this.token,
|
|
81
|
+
deviceUrl: reg.deviceUrl,
|
|
82
|
+
userId: reg.userId,
|
|
83
|
+
encryptionServiceUrl: reg.encryptionServiceUrl,
|
|
84
|
+
logger: noopLogger,
|
|
85
|
+
httpDo,
|
|
86
|
+
})
|
|
87
|
+
mercury.on('kms:response', (data: unknown) => kms.handleKmsMessage(data))
|
|
88
|
+
await mercury.connect(reg.webSocketUrl, this.token)
|
|
89
|
+
this.mercury = mercury
|
|
90
|
+
try {
|
|
91
|
+
await kms.initialize()
|
|
92
|
+
} catch (error) {
|
|
93
|
+
await mercury.disconnect().catch(() => undefined)
|
|
94
|
+
this.mercury = null
|
|
95
|
+
throw error
|
|
96
|
+
}
|
|
97
|
+
this.kms = kms
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export {}
|
|
2
|
+
|
|
3
|
+
declare module 'webex-message-handler' {
|
|
4
|
+
import type * as jose from 'node-jose'
|
|
5
|
+
|
|
6
|
+
type Logger = Record<string, (...args: unknown[]) => void>
|
|
7
|
+
type HttpRequest = { url: string; method: string; headers: Record<string, string>; body?: string }
|
|
8
|
+
type HttpResponse = { status: number; ok: boolean; json(): Promise<unknown>; text(): Promise<string> }
|
|
9
|
+
type HttpDo = (req: HttpRequest) => Promise<HttpResponse>
|
|
10
|
+
|
|
11
|
+
export const noopLogger: Logger
|
|
12
|
+
export const consoleLogger: Logger
|
|
13
|
+
|
|
14
|
+
export class DeviceManager {
|
|
15
|
+
constructor(options: { logger: Logger; httpDo: HttpDo })
|
|
16
|
+
register(token: string): Promise<{
|
|
17
|
+
webSocketUrl: string
|
|
18
|
+
deviceUrl: string
|
|
19
|
+
userId: string
|
|
20
|
+
services: unknown
|
|
21
|
+
encryptionServiceUrl: string
|
|
22
|
+
}>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class MercurySocket {
|
|
26
|
+
constructor(options: { logger: Logger; wsFactory: (url: string) => unknown })
|
|
27
|
+
on(event: 'kms:response', handler: (data: unknown) => void): void
|
|
28
|
+
connect(webSocketUrl: string, token: string): Promise<void>
|
|
29
|
+
disconnect(): Promise<void>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class KmsClient {
|
|
33
|
+
constructor(options: {
|
|
34
|
+
token: string
|
|
35
|
+
deviceUrl: string
|
|
36
|
+
userId: string
|
|
37
|
+
encryptionServiceUrl: string
|
|
38
|
+
logger: Logger
|
|
39
|
+
httpDo: HttpDo
|
|
40
|
+
})
|
|
41
|
+
initialize(): Promise<void>
|
|
42
|
+
getKey(keyUri: string): Promise<jose.JWK.Key | null>
|
|
43
|
+
handleKmsMessage(data: unknown): void
|
|
44
|
+
}
|
|
45
|
+
}
|