typeclaw 0.37.7 → 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.
- package/README.md +2 -2
- package/auth.schema.json +109 -0
- package/package.json +2 -2
- package/secrets.schema.json +109 -0
- package/src/agent/session-origin.ts +16 -2
- package/src/bundled-plugins/memory/README.md +12 -1
- package/src/bundled-plugins/memory/index.ts +39 -2
- package/src/channels/adapters/kakaotalk.ts +1 -1
- package/src/channels/adapters/webex-bot-channel-resolver.ts +29 -0
- package/src/channels/adapters/webex-bot-classify.ts +98 -0
- package/src/channels/adapters/webex-bot-reference.ts +49 -0
- package/src/channels/adapters/webex-bot.ts +462 -0
- package/src/channels/adapters/webex-channel-resolver.ts +29 -0
- package/src/channels/adapters/webex-classify.ts +104 -0
- package/src/channels/adapters/webex-format.ts +53 -0
- package/src/channels/adapters/webex-id-ref.ts +32 -0
- package/src/channels/adapters/webex-reference.ts +49 -0
- package/src/channels/adapters/webex.ts +493 -0
- package/src/channels/manager.ts +75 -4
- package/src/channels/persistence.ts +67 -5
- package/src/channels/router.ts +9 -0
- package/src/channels/schema.ts +17 -1
- package/src/cli/channel.ts +155 -8
- package/src/cli/init.ts +129 -6
- package/src/config/channels-mutation.ts +11 -2
- package/src/doctor/channel-checks.ts +56 -1
- package/src/hostd/daemon.ts +7 -5
- package/src/hostd/protocol.ts +2 -2
- package/src/init/checkpoint.ts +1 -1
- package/src/init/index.ts +97 -17
- package/src/init/run-owner-claim.ts +2 -0
- package/src/init/webex-auth.ts +68 -0
- package/src/inspect/label.ts +13 -2
- package/src/inspect/render.ts +5 -3
- package/src/permissions/match-rule.ts +7 -3
- package/src/permissions/resolve.ts +44 -5
- package/src/role-claim/match-rule.ts +7 -2
- package/src/secrets/codex-auth-json.ts +52 -17
- package/src/secrets/defaults.ts +1 -0
- package/src/secrets/encryption.ts +5 -1
- package/src/secrets/export-codex-auth-file.ts +26 -3
- package/src/secrets/schema.ts +35 -0
- package/src/secrets/webex-store.ts +113 -0
- package/typeclaw.schema.json +321 -1
package/src/channels/manager.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { GithubSecretsBlock } from '@/secrets'
|
|
|
6
6
|
import { SecretsKakaoCredentialStore } from '@/secrets/kakao-store'
|
|
7
7
|
import { SecretsLineCredentialStore } from '@/secrets/line-store'
|
|
8
8
|
import { SecretsBackend } from '@/secrets/storage'
|
|
9
|
+
import { SecretsWebexCredentialStore } from '@/secrets/webex-store'
|
|
9
10
|
import type { Stream } from '@/stream'
|
|
10
11
|
|
|
11
12
|
import { createDiscordBotAdapter, type DiscordBotAdapter } from './adapters/discord-bot'
|
|
@@ -14,6 +15,8 @@ import { createKakaotalkAdapter, type KakaotalkAdapter } from './adapters/kakaot
|
|
|
14
15
|
import { createLineAdapter, type LineAdapter } from './adapters/line'
|
|
15
16
|
import { createSlackBotAdapter, type SlackBotAdapter } from './adapters/slack-bot'
|
|
16
17
|
import { createTelegramBotAdapter, type TelegramBotAdapter } from './adapters/telegram-bot'
|
|
18
|
+
import { createWebexAdapter, type WebexAdapter } from './adapters/webex'
|
|
19
|
+
import { createWebexBotAdapter, type WebexBotAdapter } from './adapters/webex-bot'
|
|
17
20
|
import type { GithubTokenBridge } from './github-token-bridge'
|
|
18
21
|
import {
|
|
19
22
|
createChannelRouter,
|
|
@@ -71,6 +74,8 @@ export type ChannelManagerOptions = {
|
|
|
71
74
|
createLineAdapter?: typeof createLineAdapter
|
|
72
75
|
createSlackAdapter?: typeof createSlackBotAdapter
|
|
73
76
|
createTelegramAdapter?: typeof createTelegramBotAdapter
|
|
77
|
+
createWebexAdapter?: typeof createWebexAdapter
|
|
78
|
+
createWebexBotAdapter?: typeof createWebexBotAdapter
|
|
74
79
|
// Wake-up gate: forwarded to the router, which calls
|
|
75
80
|
// `permissions.has(origin, 'channel.respond')` BEFORE creating a
|
|
76
81
|
// session for any inbound. Optional here to keep direct manager-level
|
|
@@ -132,6 +137,8 @@ type AnyAdapter =
|
|
|
132
137
|
| KakaotalkAdapter
|
|
133
138
|
| SlackBotAdapter
|
|
134
139
|
| TelegramBotAdapter
|
|
140
|
+
| WebexAdapter
|
|
141
|
+
| WebexBotAdapter
|
|
135
142
|
|
|
136
143
|
// Credential signature is the comparison key for credential-rotation
|
|
137
144
|
// detection on reload. Discord and Telegram each use a single bot token;
|
|
@@ -168,6 +175,8 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
168
175
|
const createLine = options.createLineAdapter ?? createLineAdapter
|
|
169
176
|
const createSlackAdapter = options.createSlackAdapter ?? createSlackBotAdapter
|
|
170
177
|
const createTelegramAdapter = options.createTelegramAdapter ?? createTelegramBotAdapter
|
|
178
|
+
const createWebex = options.createWebexAdapter ?? createWebexAdapter
|
|
179
|
+
const createWebexBot = options.createWebexBotAdapter ?? createWebexBotAdapter
|
|
171
180
|
|
|
172
181
|
const live = new Map<AdapterId, AdapterEntry>()
|
|
173
182
|
const perAdapterSerial = new Map<AdapterId, Promise<unknown>>()
|
|
@@ -193,6 +202,7 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
193
202
|
const buildCredentialSignature = (name: AdapterId): { signature: string; missing: string[] } => {
|
|
194
203
|
if (name === 'line') return buildLineSignature(options.agentDir)
|
|
195
204
|
if (name === 'kakaotalk') return buildKakaotalkSignature(options.agentDir)
|
|
205
|
+
if (name === 'webex') return buildWebexSignature(options.agentDir)
|
|
196
206
|
if (name === 'github') return buildGithubSignature(options.agentDir)
|
|
197
207
|
const requiredEnvs = TOKEN_ENV[name]
|
|
198
208
|
const parts: string[] = []
|
|
@@ -248,6 +258,15 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
248
258
|
credentialsStore: createContainerKakaoCredentialStore(options.agentDir, env),
|
|
249
259
|
})
|
|
250
260
|
}
|
|
261
|
+
if (name === 'webex') {
|
|
262
|
+
return createWebex({
|
|
263
|
+
router,
|
|
264
|
+
configRef: () => options.channelsConfigRef()[name] ?? cfg,
|
|
265
|
+
logger,
|
|
266
|
+
selfAliasesRef: () => router.getSelfAliases(),
|
|
267
|
+
credentialsStore: createContainerWebexCredentialStore(options.agentDir, env),
|
|
268
|
+
})
|
|
269
|
+
}
|
|
251
270
|
if (name === 'github') {
|
|
252
271
|
const secrets = readGithubSecrets(options.agentDir)
|
|
253
272
|
if (secrets === null) return null
|
|
@@ -272,6 +291,17 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
272
291
|
logger,
|
|
273
292
|
})
|
|
274
293
|
}
|
|
294
|
+
if (name === 'webex-bot') {
|
|
295
|
+
const token = env.WEBEX_BOT_TOKEN
|
|
296
|
+
if (token === undefined || token.trim() === '') return null
|
|
297
|
+
return createWebexBot({
|
|
298
|
+
router,
|
|
299
|
+
configRef: () => options.channelsConfigRef()[name] ?? cfg,
|
|
300
|
+
token,
|
|
301
|
+
logger,
|
|
302
|
+
selfAliasesRef: () => router.getSelfAliases(),
|
|
303
|
+
})
|
|
304
|
+
}
|
|
275
305
|
return null
|
|
276
306
|
}
|
|
277
307
|
|
|
@@ -443,7 +473,8 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
443
473
|
await runSerially(name, () => stopAdapter(name))
|
|
444
474
|
stopped.push(name)
|
|
445
475
|
} else if (signature !== current.credentialSignature) {
|
|
446
|
-
const reason =
|
|
476
|
+
const reason =
|
|
477
|
+
name === 'kakaotalk' || name === 'line' || name === 'webex' ? 'credential rotation' : 'token rotation'
|
|
447
478
|
restartRequired.push(`${name} (${reason})`)
|
|
448
479
|
}
|
|
449
480
|
}
|
|
@@ -454,13 +485,44 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
454
485
|
}
|
|
455
486
|
}
|
|
456
487
|
|
|
457
|
-
// Token-based adapters only.
|
|
488
|
+
// Token-based adapters only. Personal-account credentials live in
|
|
458
489
|
// secrets.json#channels.<adapter>, not in env, so they go through
|
|
459
|
-
//
|
|
460
|
-
const TOKEN_ENV: Record<Exclude<AdapterId, 'kakaotalk' | 'line' | 'github'>, readonly string[]> = {
|
|
490
|
+
// structured-block signatures instead.
|
|
491
|
+
const TOKEN_ENV: Record<Exclude<AdapterId, 'kakaotalk' | 'line' | 'github' | 'webex'>, readonly string[]> = {
|
|
461
492
|
'discord-bot': ['DISCORD_BOT_TOKEN'],
|
|
462
493
|
'slack-bot': ['SLACK_BOT_TOKEN', 'SLACK_APP_TOKEN'],
|
|
463
494
|
'telegram-bot': ['TELEGRAM_BOT_TOKEN'],
|
|
495
|
+
'webex-bot': ['WEBEX_BOT_TOKEN'],
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function createContainerWebexCredentialStore(agentDir: string, env: NodeJS.ProcessEnv): SecretsWebexCredentialStore {
|
|
499
|
+
const hostdUrl = env.TYPECLAW_HOSTD_URL
|
|
500
|
+
const restartToken = env.TYPECLAW_HOSTD_TOKEN
|
|
501
|
+
const containerName = env.TYPECLAW_CONTAINER_NAME
|
|
502
|
+
if (!hostdUrl || !restartToken || !containerName) {
|
|
503
|
+
throw new Error('Webex credentials require TYPECLAW_HOSTD_URL, TYPECLAW_HOSTD_TOKEN, and TYPECLAW_CONTAINER_NAME')
|
|
504
|
+
}
|
|
505
|
+
return new SecretsWebexCredentialStore({
|
|
506
|
+
mode: 'container',
|
|
507
|
+
secretsPath: join(agentDir, 'secrets.json'),
|
|
508
|
+
hostdUrl,
|
|
509
|
+
restartToken,
|
|
510
|
+
containerName,
|
|
511
|
+
})
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function buildWebexSignature(agentDir: string): { signature: string; missing: string[] } {
|
|
515
|
+
const path = join(agentDir, 'secrets.json')
|
|
516
|
+
try {
|
|
517
|
+
const block = new SecretsBackend(path).tryReadChannelsSync()?.webex
|
|
518
|
+
if (!isWebexCredentialBlock(block)) {
|
|
519
|
+
return { signature: '', missing: ['secrets.json#channels.webex'] }
|
|
520
|
+
}
|
|
521
|
+
const digest = createHash('sha256').update(JSON.stringify(block)).digest('hex')
|
|
522
|
+
return { signature: `secrets.json#channels.webex@sha256:${digest}`, missing: [] }
|
|
523
|
+
} catch (err) {
|
|
524
|
+
return { signature: '', missing: [`secrets.json#channels.webex (${describe(err)})`] }
|
|
525
|
+
}
|
|
464
526
|
}
|
|
465
527
|
|
|
466
528
|
function createContainerKakaoCredentialStore(agentDir: string, env: NodeJS.ProcessEnv): SecretsKakaoCredentialStore {
|
|
@@ -569,6 +631,15 @@ function isLineCredentialBlock(value: unknown): value is { accounts: Record<stri
|
|
|
569
631
|
)
|
|
570
632
|
}
|
|
571
633
|
|
|
634
|
+
function isWebexCredentialBlock(value: unknown): value is { accounts: Record<string, unknown> } {
|
|
635
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
|
|
636
|
+
if (!('accounts' in value)) return false
|
|
637
|
+
const accounts = value.accounts
|
|
638
|
+
return (
|
|
639
|
+
typeof accounts === 'object' && accounts !== null && !Array.isArray(accounts) && Object.keys(accounts).length > 0
|
|
640
|
+
)
|
|
641
|
+
}
|
|
642
|
+
|
|
572
643
|
function describe(err: unknown): string {
|
|
573
644
|
return err instanceof Error ? err.message : String(err)
|
|
574
645
|
}
|
|
@@ -3,10 +3,11 @@ import { dirname, join } from 'node:path'
|
|
|
3
3
|
|
|
4
4
|
import type { ChannelParticipant } from '@/agent/session-origin'
|
|
5
5
|
|
|
6
|
+
import { toRef } from './adapters/webex-id-ref'
|
|
6
7
|
import type { AdapterId } from './schema'
|
|
7
8
|
import type { ChannelKey } from './types'
|
|
8
9
|
|
|
9
|
-
const FILE_VERSION =
|
|
10
|
+
const FILE_VERSION = 5
|
|
10
11
|
|
|
11
12
|
// `sessionFile` is the basename (not the full path) of the JSONL transcript
|
|
12
13
|
// for this (adapter, workspace, chat, thread) tuple. pi-coding-agent writes
|
|
@@ -34,6 +35,11 @@ type FileV4 = {
|
|
|
34
35
|
sessions: ChannelSessionRecord[]
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
type FileV5 = {
|
|
39
|
+
version: 5
|
|
40
|
+
sessions: ChannelSessionRecord[]
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
export type ChannelSessionsLogger = {
|
|
38
44
|
info: (msg: string) => void
|
|
39
45
|
warn: (msg: string) => void
|
|
@@ -74,9 +80,14 @@ export async function loadChannelSessions(
|
|
|
74
80
|
}
|
|
75
81
|
const version = (parsed as { version?: unknown }).version
|
|
76
82
|
if (version === FILE_VERSION) {
|
|
83
|
+
const file = parsed as FileV5
|
|
84
|
+
if (!Array.isArray(file.sessions)) return []
|
|
85
|
+
return dedupe(file.sessions.filter(isValidRecord))
|
|
86
|
+
}
|
|
87
|
+
if (version === 4) {
|
|
77
88
|
const file = parsed as FileV4
|
|
78
89
|
if (!Array.isArray(file.sessions)) return []
|
|
79
|
-
return file.sessions.filter(isValidRecord)
|
|
90
|
+
return dedupeNewest(file.sessions.filter(isValidRecord).map(migrateV4Record))
|
|
80
91
|
}
|
|
81
92
|
logger.warn(`[channels] ${path} version ${String(version)} not supported (expected ${FILE_VERSION}); ignored`)
|
|
82
93
|
return []
|
|
@@ -88,7 +99,7 @@ export async function saveChannelSessions(
|
|
|
88
99
|
logger: ChannelSessionsLogger = consoleLogger,
|
|
89
100
|
): Promise<void> {
|
|
90
101
|
const path = channelsSessionsPath(agentDir)
|
|
91
|
-
const payload:
|
|
102
|
+
const payload: FileV5 = { version: FILE_VERSION, sessions: dedupe(sessions) }
|
|
92
103
|
try {
|
|
93
104
|
await mkdir(dirname(path), { recursive: true })
|
|
94
105
|
const tmp = `${path}.tmp`
|
|
@@ -103,7 +114,17 @@ export async function saveChannelSessions(
|
|
|
103
114
|
function dedupe(sessions: readonly ChannelSessionRecord[]): ChannelSessionRecord[] {
|
|
104
115
|
const seen = new Map<string, ChannelSessionRecord>()
|
|
105
116
|
for (const s of sessions) {
|
|
106
|
-
seen.set(
|
|
117
|
+
seen.set(recordKey(s), s)
|
|
118
|
+
}
|
|
119
|
+
return Array.from(seen.values())
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function dedupeNewest(sessions: readonly ChannelSessionRecord[]): ChannelSessionRecord[] {
|
|
123
|
+
const seen = new Map<string, ChannelSessionRecord>()
|
|
124
|
+
for (const s of sessions) {
|
|
125
|
+
const key = recordKey(s)
|
|
126
|
+
const existing = seen.get(key)
|
|
127
|
+
if (existing === undefined || shouldReplaceRecord(existing, s)) seen.set(key, s)
|
|
107
128
|
}
|
|
108
129
|
return Array.from(seen.values())
|
|
109
130
|
}
|
|
@@ -112,13 +133,54 @@ export function findRecord(
|
|
|
112
133
|
sessions: readonly ChannelSessionRecord[],
|
|
113
134
|
key: ChannelKey,
|
|
114
135
|
): ChannelSessionRecord | undefined {
|
|
115
|
-
|
|
136
|
+
const exact = sessions.find(
|
|
116
137
|
(s) =>
|
|
117
138
|
s.adapter === key.adapter &&
|
|
118
139
|
s.workspace === key.workspace &&
|
|
119
140
|
s.chat === key.chat &&
|
|
120
141
|
(s.thread ?? null) === (key.thread ?? null),
|
|
121
142
|
)
|
|
143
|
+
if (exact !== undefined) return exact
|
|
144
|
+
|
|
145
|
+
// Compat insurance for legacy Webex records that may still be held in memory
|
|
146
|
+
// or loaded from hand-written/session-origin data with blob-form room ids.
|
|
147
|
+
if (!isWebexAdapter(key.adapter)) return undefined
|
|
148
|
+
return sessions.find(
|
|
149
|
+
(s) =>
|
|
150
|
+
s.adapter === key.adapter &&
|
|
151
|
+
toRef(s.workspace) === toRef(key.workspace) &&
|
|
152
|
+
toRef(s.chat) === toRef(key.chat) &&
|
|
153
|
+
(s.thread ?? null) === (key.thread ?? null),
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function migrateV4Record(record: ChannelSessionRecord): ChannelSessionRecord {
|
|
158
|
+
if (!isWebexAdapter(record.adapter)) return record
|
|
159
|
+
return {
|
|
160
|
+
...record,
|
|
161
|
+
workspace: toRef(record.workspace),
|
|
162
|
+
chat: toRef(record.chat),
|
|
163
|
+
thread: record.thread === null ? null : toRef(record.thread),
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function recordKey(record: ChannelSessionRecord): string {
|
|
168
|
+
return `${record.adapter}:${record.workspace}:${record.chat}:${record.thread ?? ''}`
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function shouldReplaceRecord(existing: ChannelSessionRecord, next: ChannelSessionRecord): boolean {
|
|
172
|
+
const existingAt = existing.lastInboundAt ?? Number.NEGATIVE_INFINITY
|
|
173
|
+
const nextAt = next.lastInboundAt ?? Number.NEGATIVE_INFINITY
|
|
174
|
+
if (nextAt !== existingAt) return nextAt > existingAt
|
|
175
|
+
return !hasSessionPointer(existing) && hasSessionPointer(next)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function hasSessionPointer(record: ChannelSessionRecord): boolean {
|
|
179
|
+
return record.sessionId !== undefined || record.sessionFile !== undefined
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function isWebexAdapter(adapter: AdapterId): boolean {
|
|
183
|
+
return adapter === 'webex' || adapter === 'webex-bot'
|
|
122
184
|
}
|
|
123
185
|
|
|
124
186
|
function isObject(v: unknown): v is Record<string, unknown> {
|
package/src/channels/router.ts
CHANGED
|
@@ -4772,6 +4772,8 @@ function formatAuthorReference(adapter: AdapterId, authorId: string, authorName:
|
|
|
4772
4772
|
case 'github':
|
|
4773
4773
|
return displayName.startsWith('@') ? displayName : `@${displayName}`
|
|
4774
4774
|
case 'telegram-bot':
|
|
4775
|
+
case 'webex':
|
|
4776
|
+
case 'webex-bot':
|
|
4775
4777
|
case 'line':
|
|
4776
4778
|
case 'kakaotalk':
|
|
4777
4779
|
return displayName
|
|
@@ -4945,7 +4947,14 @@ export type ReplyRenderMode = 'native' | 'quote'
|
|
|
4945
4947
|
// `replyTo.source`, so the router still routes it down the native branch.
|
|
4946
4948
|
const NATIVE_REPLY_TEXT_ADAPTERS = new Set<AdapterId>(['telegram-bot', 'discord-bot', 'kakaotalk'])
|
|
4947
4949
|
|
|
4950
|
+
// Webex's `parentId` rides on both `sendMessage` and `uploadFile`, so a reply is
|
|
4951
|
+
// native for every shape — including attachment-only, which the text-gated set
|
|
4952
|
+
// above cannot express. Special-cased before the text gate so the router sets
|
|
4953
|
+
// `replyTo` (not a blockquote) even when the reply carries no text.
|
|
4954
|
+
const NATIVE_REPLY_EVERY_SHAPE_ADAPTERS = new Set<AdapterId>(['webex', 'webex-bot'])
|
|
4955
|
+
|
|
4948
4956
|
export function resolveReplyRenderMode(msg: OutboundMessage): ReplyRenderMode {
|
|
4957
|
+
if (NATIVE_REPLY_EVERY_SHAPE_ADAPTERS.has(msg.adapter)) return 'native'
|
|
4949
4958
|
const hasText = normalizeSendText(msg.text) !== undefined
|
|
4950
4959
|
if (hasText && NATIVE_REPLY_TEXT_ADAPTERS.has(msg.adapter)) return 'native'
|
|
4951
4960
|
return 'quote'
|
package/src/channels/schema.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
export const ADAPTER_IDS = [
|
|
3
|
+
export const ADAPTER_IDS = [
|
|
4
|
+
'discord-bot',
|
|
5
|
+
'github',
|
|
6
|
+
'line',
|
|
7
|
+
'kakaotalk',
|
|
8
|
+
'slack-bot',
|
|
9
|
+
'telegram-bot',
|
|
10
|
+
'webex',
|
|
11
|
+
'webex-bot',
|
|
12
|
+
] as const
|
|
4
13
|
|
|
5
14
|
export type AdapterId = (typeof ADAPTER_IDS)[number]
|
|
6
15
|
|
|
@@ -262,6 +271,13 @@ export const channelsSchema = z
|
|
|
262
271
|
kakaotalk: adapterSchema.optional(),
|
|
263
272
|
'slack-bot': adapterSchema.optional(),
|
|
264
273
|
'telegram-bot': adapterSchema.optional(),
|
|
274
|
+
webex: adapterSchema.optional(),
|
|
275
|
+
// Webex bots receive messages in real time over a Mercury WebSocket
|
|
276
|
+
// (agent-messenger's WebexBotListener), the same persistent-socket model
|
|
277
|
+
// as slack-bot (Socket Mode) and discord-bot (Gateway) — no public
|
|
278
|
+
// webhook URL required. Single bot-token auth; config shape is the
|
|
279
|
+
// standard adapterSchema (engagement + history + enabled).
|
|
280
|
+
'webex-bot': adapterSchema.optional(),
|
|
265
281
|
})
|
|
266
282
|
.default({})
|
|
267
283
|
|
package/src/cli/channel.ts
CHANGED
|
@@ -29,10 +29,13 @@ import {
|
|
|
29
29
|
type GithubTunnelProvider,
|
|
30
30
|
type KakaotalkAuthResult,
|
|
31
31
|
type LineAuthResult,
|
|
32
|
+
type WebexAuthResult,
|
|
32
33
|
} from '@/init'
|
|
33
34
|
import { runKakaotalkBootstrap } from '@/init/kakaotalk-auth'
|
|
34
35
|
import { runLineBootstrap } from '@/init/line-auth'
|
|
36
|
+
import { runWebexBootstrap } from '@/init/webex-auth'
|
|
35
37
|
import { SecretsKakaoCredentialStore } from '@/secrets/kakao-store'
|
|
38
|
+
import { SecretsWebexCredentialStore } from '@/secrets/webex-store'
|
|
36
39
|
|
|
37
40
|
import { CANCEL_SYMBOL, promptPrivateKeyPem } from './prompt-pem'
|
|
38
41
|
import { displayQR } from './qr'
|
|
@@ -42,6 +45,8 @@ const CHANNEL_LABELS: Record<ChannelKind, string> = {
|
|
|
42
45
|
'slack-bot': 'Slack',
|
|
43
46
|
'discord-bot': 'Discord',
|
|
44
47
|
'telegram-bot': 'Telegram',
|
|
48
|
+
webex: 'Webex (User)',
|
|
49
|
+
'webex-bot': 'Webex',
|
|
45
50
|
line: 'LINE',
|
|
46
51
|
kakaotalk: 'KakaoTalk',
|
|
47
52
|
github: 'GitHub',
|
|
@@ -104,7 +109,7 @@ const addSub = defineCommand({
|
|
|
104
109
|
// is included here but routed through its own prompt path because it has
|
|
105
110
|
// three independent secrets (PAT or App private key + webhook secret) and a
|
|
106
111
|
// structural auth-type flip is forbidden during rotation.
|
|
107
|
-
const SETTABLE_ADAPTERS = ['slack-bot', 'discord-bot', 'telegram-bot', 'github'] as const
|
|
112
|
+
const SETTABLE_ADAPTERS = ['slack-bot', 'discord-bot', 'telegram-bot', 'webex-bot', 'github'] as const
|
|
108
113
|
type SettableAdapter = (typeof SETTABLE_ADAPTERS)[number]
|
|
109
114
|
|
|
110
115
|
const setSub = defineCommand({
|
|
@@ -158,14 +163,13 @@ const setSub = defineCommand({
|
|
|
158
163
|
},
|
|
159
164
|
})
|
|
160
165
|
|
|
161
|
-
const REAUTHABLE_ADAPTERS = ['line', 'kakaotalk'] as const
|
|
166
|
+
const REAUTHABLE_ADAPTERS = ['line', 'kakaotalk', 'webex'] as const
|
|
162
167
|
type ReauthableAdapter = (typeof REAUTHABLE_ADAPTERS)[number]
|
|
163
168
|
|
|
164
169
|
const reauthSub = defineCommand({
|
|
165
170
|
meta: {
|
|
166
171
|
name: 'reauth',
|
|
167
|
-
description:
|
|
168
|
-
're-authenticate a channel adapter (currently only `kakaotalk`). Use after a stale-token 401 or to rotate the saved password.',
|
|
172
|
+
description: `re-authenticate a channel adapter (${REAUTHABLE_ADAPTERS.join(', ')}). Use after a stale-token 401 or to rotate the saved password.`,
|
|
169
173
|
},
|
|
170
174
|
args: {
|
|
171
175
|
adapter: {
|
|
@@ -432,6 +436,9 @@ async function runReauth(cwd: string, adapter: ReauthableAdapter): Promise<void>
|
|
|
432
436
|
case 'kakaotalk':
|
|
433
437
|
await runKakaotalkReauth(cwd)
|
|
434
438
|
return
|
|
439
|
+
case 'webex':
|
|
440
|
+
await runWebexReauth(cwd)
|
|
441
|
+
return
|
|
435
442
|
}
|
|
436
443
|
}
|
|
437
444
|
|
|
@@ -475,6 +482,22 @@ async function runKakaotalkReauth(cwd: string): Promise<void> {
|
|
|
475
482
|
await maybePromptReauthRefresh(cwd, 'kakaotalk')
|
|
476
483
|
}
|
|
477
484
|
|
|
485
|
+
async function runWebexReauth(cwd: string): Promise<void> {
|
|
486
|
+
const existingEmail = await readExistingWebexEmail(cwd)
|
|
487
|
+
const creds = await promptWebexCredentials({ defaultEmail: existingEmail })
|
|
488
|
+
|
|
489
|
+
const s = spinner()
|
|
490
|
+
s.start('Logging in to Webex...')
|
|
491
|
+
const result = await runWebexBootstrap({ email: creds.email, password: creds.password, agentDir: cwd })
|
|
492
|
+
if (!result.ok) {
|
|
493
|
+
s.stop(`Webex login failed: ${result.reason}`)
|
|
494
|
+
process.exit(1)
|
|
495
|
+
}
|
|
496
|
+
s.stop('Webex credentials refreshed in secrets.json.')
|
|
497
|
+
|
|
498
|
+
await maybePromptReauthRefresh(cwd, 'webex')
|
|
499
|
+
}
|
|
500
|
+
|
|
478
501
|
async function readExistingKakaotalkEmail(cwd: string): Promise<string | undefined> {
|
|
479
502
|
try {
|
|
480
503
|
const store = new SecretsKakaoCredentialStore({ mode: 'host', secretsPath: `${cwd}/secrets.json` })
|
|
@@ -486,6 +509,16 @@ async function readExistingKakaotalkEmail(cwd: string): Promise<string | undefin
|
|
|
486
509
|
}
|
|
487
510
|
}
|
|
488
511
|
|
|
512
|
+
async function readExistingWebexEmail(cwd: string): Promise<string | undefined> {
|
|
513
|
+
try {
|
|
514
|
+
const store = new SecretsWebexCredentialStore({ mode: 'host', secretsPath: `${cwd}/secrets.json` })
|
|
515
|
+
const account = await store.getAccountWithRenewalFields()
|
|
516
|
+
return account?.email ?? undefined
|
|
517
|
+
} catch {
|
|
518
|
+
return undefined
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
489
522
|
// The renewed tokens are already on disk via secrets.json. What still needs
|
|
490
523
|
// to happen depends on the running adapter's state:
|
|
491
524
|
// - Container NOT running → nothing to do; next `typeclaw start` picks them up.
|
|
@@ -579,16 +612,47 @@ async function pickChannel(configured: Set<ChannelKind>): Promise<ChannelKind> {
|
|
|
579
612
|
process.exit(0)
|
|
580
613
|
}
|
|
581
614
|
|
|
582
|
-
|
|
615
|
+
type PickerValue = Exclude<ChannelKind, 'webex' | 'webex-bot'> | 'webex-family'
|
|
616
|
+
const webexModes = available.filter((kind): kind is 'webex' | 'webex-bot' => kind === 'webex' || kind === 'webex-bot')
|
|
617
|
+
const options: Array<{ value: PickerValue; label: string }> = []
|
|
618
|
+
for (const kind of available) {
|
|
619
|
+
if (kind === 'webex' || kind === 'webex-bot') {
|
|
620
|
+
if (!options.some((option) => option.value === 'webex-family'))
|
|
621
|
+
options.push({ value: 'webex-family', label: 'Webex' })
|
|
622
|
+
continue
|
|
623
|
+
}
|
|
624
|
+
options.push({ value: kind, label: CHANNEL_LABELS[kind] })
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const selected = await select<PickerValue>({
|
|
583
628
|
message: 'Pick a channel to add',
|
|
584
|
-
options
|
|
585
|
-
initialValue:
|
|
629
|
+
options,
|
|
630
|
+
initialValue: options[0]?.value,
|
|
586
631
|
})
|
|
587
632
|
if (isCancel(selected)) {
|
|
588
633
|
cancel('Aborted.')
|
|
589
634
|
process.exit(0)
|
|
590
635
|
}
|
|
591
|
-
return selected
|
|
636
|
+
if (selected !== 'webex-family') return selected
|
|
637
|
+
if (webexModes.length === 1) return webexModes[0]!
|
|
638
|
+
const allWebexOptions: Array<{ value: 'webex' | 'webex-bot'; label: string }> = [
|
|
639
|
+
{
|
|
640
|
+
value: 'webex',
|
|
641
|
+
label: 'User (ID/PW) — receives all messages, no @mention needed (recommended)',
|
|
642
|
+
},
|
|
643
|
+
{ value: 'webex-bot', label: 'Bot (Token) — only sees @mentions in group spaces' },
|
|
644
|
+
]
|
|
645
|
+
const webexOptions = allWebexOptions.filter((option) => webexModes.includes(option.value))
|
|
646
|
+
const mode = await select<'webex' | 'webex-bot'>({
|
|
647
|
+
message: 'Which Webex mode?',
|
|
648
|
+
options: webexOptions,
|
|
649
|
+
initialValue: webexModes[0],
|
|
650
|
+
})
|
|
651
|
+
if (isCancel(mode)) {
|
|
652
|
+
cancel('Aborted.')
|
|
653
|
+
process.exit(0)
|
|
654
|
+
}
|
|
655
|
+
return mode
|
|
592
656
|
}
|
|
593
657
|
|
|
594
658
|
function isSettableAdapter(value: string): value is SettableAdapter {
|
|
@@ -651,6 +715,9 @@ async function runSet(cwd: string, adapter: SettableAdapter): Promise<void> {
|
|
|
651
715
|
case 'telegram-bot':
|
|
652
716
|
await runSetTelegram(cwd)
|
|
653
717
|
break
|
|
718
|
+
case 'webex-bot':
|
|
719
|
+
await runSetWebex(cwd)
|
|
720
|
+
break
|
|
654
721
|
case 'slack-bot':
|
|
655
722
|
await runSetSlack(cwd)
|
|
656
723
|
break
|
|
@@ -680,6 +747,16 @@ async function runSetTelegram(cwd: string): Promise<void> {
|
|
|
680
747
|
await maybePromptCredentialRefresh(cwd, CHANNEL_LABELS['telegram-bot'], 'credentials updated')
|
|
681
748
|
}
|
|
682
749
|
|
|
750
|
+
async function runSetWebex(cwd: string): Promise<void> {
|
|
751
|
+
const token = await promptWebexToken()
|
|
752
|
+
const result = await setChannelSecrets(cwd, 'webex-bot', { token })
|
|
753
|
+
if (!result.ok) {
|
|
754
|
+
console.error(errorLine(result.reason))
|
|
755
|
+
process.exit(1)
|
|
756
|
+
}
|
|
757
|
+
await maybePromptCredentialRefresh(cwd, CHANNEL_LABELS['webex-bot'], 'credentials updated')
|
|
758
|
+
}
|
|
759
|
+
|
|
683
760
|
type SlackSetChoice = 'bot' | 'app' | 'both'
|
|
684
761
|
|
|
685
762
|
async function runSetSlack(cwd: string): Promise<void> {
|
|
@@ -778,6 +855,8 @@ type CollectedCredentials =
|
|
|
778
855
|
| { channel: 'discord-bot'; discordBotToken: string }
|
|
779
856
|
| { channel: 'slack-bot'; slackBotToken: string; slackAppToken: string }
|
|
780
857
|
| { channel: 'telegram-bot'; telegramBotToken: string }
|
|
858
|
+
| { channel: 'webex'; runWebexAuth: (options: { cwd: string }) => Promise<WebexAuthResult> }
|
|
859
|
+
| { channel: 'webex-bot'; webexBotToken: string }
|
|
781
860
|
| { channel: 'line'; runLineAuth: (options: { cwd: string }) => Promise<LineAuthResult> }
|
|
782
861
|
| { channel: 'kakaotalk'; runKakaotalkAuth: (options: { cwd: string }) => Promise<KakaotalkAuthResult> }
|
|
783
862
|
| {
|
|
@@ -804,6 +883,16 @@ async function collectCredentials(
|
|
|
804
883
|
}
|
|
805
884
|
case 'telegram-bot':
|
|
806
885
|
return { channel, telegramBotToken: await promptTelegramToken() }
|
|
886
|
+
case 'webex': {
|
|
887
|
+
const creds = await promptWebexCredentials()
|
|
888
|
+
return {
|
|
889
|
+
channel,
|
|
890
|
+
runWebexAuth: ({ cwd: agentDir }) =>
|
|
891
|
+
runWebexBootstrap({ email: creds.email, password: creds.password, agentDir }),
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
case 'webex-bot':
|
|
895
|
+
return { channel, webexBotToken: await promptWebexToken() }
|
|
807
896
|
case 'line': {
|
|
808
897
|
const login = await promptLineLogin(lineSpinnerHolder ? holderSpinnerControl(lineSpinnerHolder) : undefined)
|
|
809
898
|
return {
|
|
@@ -1212,6 +1301,25 @@ async function promptTelegramToken(): Promise<string> {
|
|
|
1212
1301
|
return token
|
|
1213
1302
|
}
|
|
1214
1303
|
|
|
1304
|
+
async function promptWebexToken(): Promise<string> {
|
|
1305
|
+
note(
|
|
1306
|
+
[
|
|
1307
|
+
'Create a bot at https://developer.webex.com/my-apps/new/bot.',
|
|
1308
|
+
'Copy the Bot Access Token from the bot settings page.',
|
|
1309
|
+
].join('\n'),
|
|
1310
|
+
'Get a Webex bot token',
|
|
1311
|
+
)
|
|
1312
|
+
const token = await password({
|
|
1313
|
+
message: 'Webex bot access token',
|
|
1314
|
+
validate: (value) => (value && value.length > 0 ? undefined : 'Token is required'),
|
|
1315
|
+
})
|
|
1316
|
+
if (isCancel(token)) {
|
|
1317
|
+
cancel('Aborted.')
|
|
1318
|
+
process.exit(0)
|
|
1319
|
+
}
|
|
1320
|
+
return token
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1215
1323
|
async function promptKakaotalkCredentials(
|
|
1216
1324
|
opts: { defaultEmail?: string } = {},
|
|
1217
1325
|
): Promise<{ email: string; password: string }> {
|
|
@@ -1247,6 +1355,36 @@ async function promptKakaotalkCredentials(
|
|
|
1247
1355
|
return { email, password: pwd }
|
|
1248
1356
|
}
|
|
1249
1357
|
|
|
1358
|
+
async function promptWebexCredentials(
|
|
1359
|
+
opts: { defaultEmail?: string } = {},
|
|
1360
|
+
): Promise<{ email: string; password: string }> {
|
|
1361
|
+
note(
|
|
1362
|
+
[
|
|
1363
|
+
'Logs in headlessly with your Webex email/password.',
|
|
1364
|
+
'SSO/MFA accounts are not supported. Messages will be sent and received under this account.',
|
|
1365
|
+
].join('\n'),
|
|
1366
|
+
'About to log in to Webex',
|
|
1367
|
+
)
|
|
1368
|
+
const email = await text({
|
|
1369
|
+
message: 'Webex email',
|
|
1370
|
+
...(opts.defaultEmail !== undefined ? { initialValue: opts.defaultEmail, placeholder: opts.defaultEmail } : {}),
|
|
1371
|
+
validate: (value) => (value && value.length > 0 ? undefined : 'Email is required'),
|
|
1372
|
+
})
|
|
1373
|
+
if (isCancel(email)) {
|
|
1374
|
+
cancel('Aborted.')
|
|
1375
|
+
process.exit(0)
|
|
1376
|
+
}
|
|
1377
|
+
const pwd = await password({
|
|
1378
|
+
message: 'Webex password',
|
|
1379
|
+
validate: (value) => (value && value.length > 0 ? undefined : 'Password is required'),
|
|
1380
|
+
})
|
|
1381
|
+
if (isCancel(pwd)) {
|
|
1382
|
+
cancel('Aborted.')
|
|
1383
|
+
process.exit(0)
|
|
1384
|
+
}
|
|
1385
|
+
return { email, password: pwd }
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1250
1388
|
type LinePromptResult =
|
|
1251
1389
|
| { method: 'qr'; callbacks: { onQRUrl: (url: string) => Promise<void>; onPincode: (pin: string) => void } }
|
|
1252
1390
|
| {
|
|
@@ -1416,6 +1554,9 @@ function reportProgress(
|
|
|
1416
1554
|
case 'kakaotalk-auth':
|
|
1417
1555
|
s.stop(reportKakaotalkAuth(event.result))
|
|
1418
1556
|
break
|
|
1557
|
+
case 'webex-auth':
|
|
1558
|
+
s.stop(reportWebexAuth(event.result))
|
|
1559
|
+
break
|
|
1419
1560
|
case 'config':
|
|
1420
1561
|
s.stop('Updated typeclaw.json.')
|
|
1421
1562
|
break
|
|
@@ -1432,6 +1573,7 @@ function reportProgress(
|
|
|
1432
1573
|
const START_MESSAGES: Record<AddChannelStepEvent['step'], string> = {
|
|
1433
1574
|
'line-auth': 'Logging in to LINE...',
|
|
1434
1575
|
'kakaotalk-auth': 'Logging in to KakaoTalk...',
|
|
1576
|
+
'webex-auth': 'Logging in to Webex...',
|
|
1435
1577
|
config: 'Updating typeclaw.json...',
|
|
1436
1578
|
secrets: 'Saving credentials to secrets.json...',
|
|
1437
1579
|
'github-webhooks': 'Installing GitHub repository webhooks...',
|
|
@@ -1442,6 +1584,11 @@ function reportKakaotalkAuth(result: KakaotalkAuthResult): string {
|
|
|
1442
1584
|
return `KakaoTalk login failed: ${result.reason}`
|
|
1443
1585
|
}
|
|
1444
1586
|
|
|
1587
|
+
function reportWebexAuth(result: WebexAuthResult): string {
|
|
1588
|
+
if (result.ok) return 'Webex credentials saved to secrets.json.'
|
|
1589
|
+
return `Webex login failed: ${result.reason}`
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1445
1592
|
function reportLineAuth(result: LineAuthResult): string {
|
|
1446
1593
|
if (result.ok) return 'LINE credentials saved to secrets.json.'
|
|
1447
1594
|
return `LINE login failed: ${result.reason}`
|