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.
- package/auth.schema.json +109 -0
- package/package.json +2 -2
- package/secrets.schema.json +109 -0
- package/src/agent/session-origin.ts +15 -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-classify.ts +20 -14
- package/src/channels/adapters/webex-bot-reference.ts +8 -6
- package/src/channels/adapters/webex-bot.ts +106 -39
- 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 +63 -7
- package/src/channels/persistence.ts +67 -5
- package/src/channels/router.ts +8 -0
- package/src/channels/schema.ts +2 -0
- package/src/cli/channel.ts +118 -7
- package/src/cli/init.ts +70 -1
- package/src/config/channels-mutation.ts +2 -1
- package/src/doctor/channel-checks.ts +43 -0
- 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 +60 -3
- package/src/init/run-owner-claim.ts +1 -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/resolve.ts +38 -1
- package/src/role-claim/match-rule.ts +5 -1
- package/src/secrets/codex-auth-json.ts +52 -17
- 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 +160 -0
|
@@ -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,7 @@ 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':
|
|
4775
4776
|
case 'webex-bot':
|
|
4776
4777
|
case 'line':
|
|
4777
4778
|
case 'kakaotalk':
|
|
@@ -4946,7 +4947,14 @@ export type ReplyRenderMode = 'native' | 'quote'
|
|
|
4946
4947
|
// `replyTo.source`, so the router still routes it down the native branch.
|
|
4947
4948
|
const NATIVE_REPLY_TEXT_ADAPTERS = new Set<AdapterId>(['telegram-bot', 'discord-bot', 'kakaotalk'])
|
|
4948
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
|
+
|
|
4949
4956
|
export function resolveReplyRenderMode(msg: OutboundMessage): ReplyRenderMode {
|
|
4957
|
+
if (NATIVE_REPLY_EVERY_SHAPE_ADAPTERS.has(msg.adapter)) return 'native'
|
|
4950
4958
|
const hasText = normalizeSendText(msg.text) !== undefined
|
|
4951
4959
|
if (hasText && NATIVE_REPLY_TEXT_ADAPTERS.has(msg.adapter)) return 'native'
|
|
4952
4960
|
return 'quote'
|
package/src/channels/schema.ts
CHANGED
|
@@ -7,6 +7,7 @@ export const ADAPTER_IDS = [
|
|
|
7
7
|
'kakaotalk',
|
|
8
8
|
'slack-bot',
|
|
9
9
|
'telegram-bot',
|
|
10
|
+
'webex',
|
|
10
11
|
'webex-bot',
|
|
11
12
|
] as const
|
|
12
13
|
|
|
@@ -270,6 +271,7 @@ export const channelsSchema = z
|
|
|
270
271
|
kakaotalk: adapterSchema.optional(),
|
|
271
272
|
'slack-bot': adapterSchema.optional(),
|
|
272
273
|
'telegram-bot': adapterSchema.optional(),
|
|
274
|
+
webex: adapterSchema.optional(),
|
|
273
275
|
// Webex bots receive messages in real time over a Mercury WebSocket
|
|
274
276
|
// (agent-messenger's WebexBotListener), the same persistent-socket model
|
|
275
277
|
// as slack-bot (Socket Mode) and discord-bot (Gateway) — no public
|
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,7 @@ 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)',
|
|
45
49
|
'webex-bot': 'Webex',
|
|
46
50
|
line: 'LINE',
|
|
47
51
|
kakaotalk: 'KakaoTalk',
|
|
@@ -159,14 +163,13 @@ const setSub = defineCommand({
|
|
|
159
163
|
},
|
|
160
164
|
})
|
|
161
165
|
|
|
162
|
-
const REAUTHABLE_ADAPTERS = ['line', 'kakaotalk'] as const
|
|
166
|
+
const REAUTHABLE_ADAPTERS = ['line', 'kakaotalk', 'webex'] as const
|
|
163
167
|
type ReauthableAdapter = (typeof REAUTHABLE_ADAPTERS)[number]
|
|
164
168
|
|
|
165
169
|
const reauthSub = defineCommand({
|
|
166
170
|
meta: {
|
|
167
171
|
name: 'reauth',
|
|
168
|
-
description:
|
|
169
|
-
'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.`,
|
|
170
173
|
},
|
|
171
174
|
args: {
|
|
172
175
|
adapter: {
|
|
@@ -433,6 +436,9 @@ async function runReauth(cwd: string, adapter: ReauthableAdapter): Promise<void>
|
|
|
433
436
|
case 'kakaotalk':
|
|
434
437
|
await runKakaotalkReauth(cwd)
|
|
435
438
|
return
|
|
439
|
+
case 'webex':
|
|
440
|
+
await runWebexReauth(cwd)
|
|
441
|
+
return
|
|
436
442
|
}
|
|
437
443
|
}
|
|
438
444
|
|
|
@@ -476,6 +482,22 @@ async function runKakaotalkReauth(cwd: string): Promise<void> {
|
|
|
476
482
|
await maybePromptReauthRefresh(cwd, 'kakaotalk')
|
|
477
483
|
}
|
|
478
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
|
+
|
|
479
501
|
async function readExistingKakaotalkEmail(cwd: string): Promise<string | undefined> {
|
|
480
502
|
try {
|
|
481
503
|
const store = new SecretsKakaoCredentialStore({ mode: 'host', secretsPath: `${cwd}/secrets.json` })
|
|
@@ -487,6 +509,16 @@ async function readExistingKakaotalkEmail(cwd: string): Promise<string | undefin
|
|
|
487
509
|
}
|
|
488
510
|
}
|
|
489
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
|
+
|
|
490
522
|
// The renewed tokens are already on disk via secrets.json. What still needs
|
|
491
523
|
// to happen depends on the running adapter's state:
|
|
492
524
|
// - Container NOT running → nothing to do; next `typeclaw start` picks them up.
|
|
@@ -580,16 +612,47 @@ async function pickChannel(configured: Set<ChannelKind>): Promise<ChannelKind> {
|
|
|
580
612
|
process.exit(0)
|
|
581
613
|
}
|
|
582
614
|
|
|
583
|
-
|
|
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>({
|
|
584
628
|
message: 'Pick a channel to add',
|
|
585
|
-
options
|
|
586
|
-
initialValue:
|
|
629
|
+
options,
|
|
630
|
+
initialValue: options[0]?.value,
|
|
587
631
|
})
|
|
588
632
|
if (isCancel(selected)) {
|
|
589
633
|
cancel('Aborted.')
|
|
590
634
|
process.exit(0)
|
|
591
635
|
}
|
|
592
|
-
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
|
|
593
656
|
}
|
|
594
657
|
|
|
595
658
|
function isSettableAdapter(value: string): value is SettableAdapter {
|
|
@@ -792,6 +855,7 @@ type CollectedCredentials =
|
|
|
792
855
|
| { channel: 'discord-bot'; discordBotToken: string }
|
|
793
856
|
| { channel: 'slack-bot'; slackBotToken: string; slackAppToken: string }
|
|
794
857
|
| { channel: 'telegram-bot'; telegramBotToken: string }
|
|
858
|
+
| { channel: 'webex'; runWebexAuth: (options: { cwd: string }) => Promise<WebexAuthResult> }
|
|
795
859
|
| { channel: 'webex-bot'; webexBotToken: string }
|
|
796
860
|
| { channel: 'line'; runLineAuth: (options: { cwd: string }) => Promise<LineAuthResult> }
|
|
797
861
|
| { channel: 'kakaotalk'; runKakaotalkAuth: (options: { cwd: string }) => Promise<KakaotalkAuthResult> }
|
|
@@ -819,6 +883,14 @@ async function collectCredentials(
|
|
|
819
883
|
}
|
|
820
884
|
case 'telegram-bot':
|
|
821
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
|
+
}
|
|
822
894
|
case 'webex-bot':
|
|
823
895
|
return { channel, webexBotToken: await promptWebexToken() }
|
|
824
896
|
case 'line': {
|
|
@@ -1283,6 +1355,36 @@ async function promptKakaotalkCredentials(
|
|
|
1283
1355
|
return { email, password: pwd }
|
|
1284
1356
|
}
|
|
1285
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
|
+
|
|
1286
1388
|
type LinePromptResult =
|
|
1287
1389
|
| { method: 'qr'; callbacks: { onQRUrl: (url: string) => Promise<void>; onPincode: (pin: string) => void } }
|
|
1288
1390
|
| {
|
|
@@ -1452,6 +1554,9 @@ function reportProgress(
|
|
|
1452
1554
|
case 'kakaotalk-auth':
|
|
1453
1555
|
s.stop(reportKakaotalkAuth(event.result))
|
|
1454
1556
|
break
|
|
1557
|
+
case 'webex-auth':
|
|
1558
|
+
s.stop(reportWebexAuth(event.result))
|
|
1559
|
+
break
|
|
1455
1560
|
case 'config':
|
|
1456
1561
|
s.stop('Updated typeclaw.json.')
|
|
1457
1562
|
break
|
|
@@ -1468,6 +1573,7 @@ function reportProgress(
|
|
|
1468
1573
|
const START_MESSAGES: Record<AddChannelStepEvent['step'], string> = {
|
|
1469
1574
|
'line-auth': 'Logging in to LINE...',
|
|
1470
1575
|
'kakaotalk-auth': 'Logging in to KakaoTalk...',
|
|
1576
|
+
'webex-auth': 'Logging in to Webex...',
|
|
1471
1577
|
config: 'Updating typeclaw.json...',
|
|
1472
1578
|
secrets: 'Saving credentials to secrets.json...',
|
|
1473
1579
|
'github-webhooks': 'Installing GitHub repository webhooks...',
|
|
@@ -1478,6 +1584,11 @@ function reportKakaotalkAuth(result: KakaotalkAuthResult): string {
|
|
|
1478
1584
|
return `KakaoTalk login failed: ${result.reason}`
|
|
1479
1585
|
}
|
|
1480
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
|
+
|
|
1481
1592
|
function reportLineAuth(result: LineAuthResult): string {
|
|
1482
1593
|
if (result.ok) return 'LINE credentials saved to secrets.json.'
|
|
1483
1594
|
return `LINE login failed: ${result.reason}`
|
package/src/cli/init.ts
CHANGED
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
validateApiKey,
|
|
67
67
|
type KeyValidationResult,
|
|
68
68
|
} from '@/init/validate-api-key'
|
|
69
|
+
import { runWebexBootstrap } from '@/init/webex-auth'
|
|
69
70
|
|
|
70
71
|
import { fuzzyMatch } from './fuzzy-filter'
|
|
71
72
|
import { buildOAuthCallbacks } from './oauth-callbacks'
|
|
@@ -215,6 +216,8 @@ export const init = defineCommand({
|
|
|
215
216
|
telegramBotToken,
|
|
216
217
|
kakaotalkEmail,
|
|
217
218
|
kakaotalkPassword,
|
|
219
|
+
webexEmail,
|
|
220
|
+
webexPassword,
|
|
218
221
|
github: githubCredentials,
|
|
219
222
|
} = channelSecrets
|
|
220
223
|
const modelMeta = customModelMetaFromOption(model)
|
|
@@ -233,8 +236,10 @@ export const init = defineCommand({
|
|
|
233
236
|
const reuseSlack = reuseExistingChannel && channelChoice === 'slack'
|
|
234
237
|
const reuseTelegram = reuseExistingChannel && channelChoice === 'telegram'
|
|
235
238
|
const reuseKakaotalk = reuseExistingChannel && channelChoice === 'kakaotalk'
|
|
239
|
+
const reuseWebex = reuseExistingChannel && channelChoice === 'webex'
|
|
236
240
|
const reuseGithub = reuseExistingChannel && channelChoice === 'github'
|
|
237
241
|
const wantsKakaotalk = (kakaotalkEmail !== undefined && kakaotalkPassword !== undefined) || reuseKakaotalk
|
|
242
|
+
const wantsWebex = (webexEmail !== undefined && webexPassword !== undefined) || reuseWebex
|
|
238
243
|
const wantsGithub = githubCredentials !== undefined || reuseGithub
|
|
239
244
|
let hatchingOk = false
|
|
240
245
|
let preflightFailure: Extract<DockerAvailability, { ok: false }> | null = null
|
|
@@ -276,6 +281,17 @@ export const init = defineCommand({
|
|
|
276
281
|
}),
|
|
277
282
|
}
|
|
278
283
|
: {}),
|
|
284
|
+
...(wantsWebex
|
|
285
|
+
? {
|
|
286
|
+
withWebexUser: true,
|
|
287
|
+
...(reuseWebex
|
|
288
|
+
? {}
|
|
289
|
+
: {
|
|
290
|
+
runWebexAuth: ({ cwd: agentDir }) =>
|
|
291
|
+
runWebexBootstrap({ email: webexEmail!, password: webexPassword!, agentDir }),
|
|
292
|
+
}),
|
|
293
|
+
}
|
|
294
|
+
: {}),
|
|
279
295
|
...(wantsGithub
|
|
280
296
|
? {
|
|
281
297
|
withGithub: true,
|
|
@@ -384,7 +400,7 @@ interface WizardState {
|
|
|
384
400
|
channelReuseExisting?: boolean
|
|
385
401
|
}
|
|
386
402
|
|
|
387
|
-
type ChannelChoice = 'slack' | 'discord' | 'telegram' | 'kakaotalk' | 'github' | 'none'
|
|
403
|
+
type ChannelChoice = 'slack' | 'discord' | 'telegram' | 'webex' | 'kakaotalk' | 'github' | 'none'
|
|
388
404
|
|
|
389
405
|
interface CollectedInputs {
|
|
390
406
|
model: ModelOption
|
|
@@ -404,6 +420,8 @@ interface CollectedInputs {
|
|
|
404
420
|
slackBotToken?: string
|
|
405
421
|
slackAppToken?: string
|
|
406
422
|
telegramBotToken?: string
|
|
423
|
+
webexEmail?: string
|
|
424
|
+
webexPassword?: string
|
|
407
425
|
kakaotalkEmail?: string
|
|
408
426
|
kakaotalkPassword?: string
|
|
409
427
|
// Structured (auth union + webhook + repo allowlist) rather than flat
|
|
@@ -1114,6 +1132,8 @@ function channelDisplayName(choice: Exclude<ChannelChoice, 'none'>): string {
|
|
|
1114
1132
|
return 'Discord'
|
|
1115
1133
|
case 'telegram':
|
|
1116
1134
|
return 'Telegram'
|
|
1135
|
+
case 'webex':
|
|
1136
|
+
return 'Webex (User)'
|
|
1117
1137
|
case 'kakaotalk':
|
|
1118
1138
|
return 'KakaoTalk'
|
|
1119
1139
|
case 'github':
|
|
@@ -1455,6 +1475,7 @@ async function pickChannel(initial: ChannelChoice | undefined): Promise<StepResu
|
|
|
1455
1475
|
{ value: 'slack', label: 'Slack' },
|
|
1456
1476
|
{ value: 'discord', label: 'Discord' },
|
|
1457
1477
|
{ value: 'telegram', label: 'Telegram' },
|
|
1478
|
+
{ value: 'webex', label: 'Webex (User)' },
|
|
1458
1479
|
{ value: 'kakaotalk', label: 'KakaoTalk' },
|
|
1459
1480
|
{ value: 'github', label: 'GitHub' },
|
|
1460
1481
|
{ value: 'none', label: 'Skip — no channel right now' },
|
|
@@ -1480,6 +1501,8 @@ async function runChannelFlow(
|
|
|
1480
1501
|
return runSlackFlow()
|
|
1481
1502
|
case 'telegram':
|
|
1482
1503
|
return runTelegramFlow()
|
|
1504
|
+
case 'webex':
|
|
1505
|
+
return runWebexUserFlow()
|
|
1483
1506
|
case 'github':
|
|
1484
1507
|
return runGithubFlow(cwd)
|
|
1485
1508
|
}
|
|
@@ -1549,6 +1572,43 @@ async function runKakaotalkFlow(): Promise<StepResult<CollectedInputs['channelSe
|
|
|
1549
1572
|
}
|
|
1550
1573
|
}
|
|
1551
1574
|
|
|
1575
|
+
async function runWebexUserFlow(): Promise<StepResult<CollectedInputs['channelSecrets']>> {
|
|
1576
|
+
type SubStep = 'email' | 'password'
|
|
1577
|
+
let sub: SubStep = 'email'
|
|
1578
|
+
let email: string | undefined
|
|
1579
|
+
|
|
1580
|
+
note(
|
|
1581
|
+
[
|
|
1582
|
+
'Logs in headlessly with your Webex email/password.',
|
|
1583
|
+
'SSO/MFA accounts are not supported. Messages will be sent and received under this account.',
|
|
1584
|
+
].join('\n'),
|
|
1585
|
+
'About to log in to Webex',
|
|
1586
|
+
)
|
|
1587
|
+
|
|
1588
|
+
while (true) {
|
|
1589
|
+
if (sub === 'email') {
|
|
1590
|
+
const input = await text({
|
|
1591
|
+
message: 'Webex email',
|
|
1592
|
+
...(email !== undefined ? { initialValue: email } : {}),
|
|
1593
|
+
validate: (v) => (v && v.length > 0 ? undefined : 'Email is required'),
|
|
1594
|
+
})
|
|
1595
|
+
if (isCancel(input)) return back()
|
|
1596
|
+
email = input
|
|
1597
|
+
sub = 'password'
|
|
1598
|
+
continue
|
|
1599
|
+
}
|
|
1600
|
+
const input = await password({
|
|
1601
|
+
message: 'Webex password',
|
|
1602
|
+
validate: (v) => (v && v.length > 0 ? undefined : 'Password is required'),
|
|
1603
|
+
})
|
|
1604
|
+
if (isCancel(input)) {
|
|
1605
|
+
sub = 'email'
|
|
1606
|
+
continue
|
|
1607
|
+
}
|
|
1608
|
+
return value({ webexEmail: email, webexPassword: input })
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1552
1612
|
async function runSlackFlow(): Promise<StepResult<CollectedInputs['channelSecrets']>> {
|
|
1553
1613
|
type SubStep = 'bot' | 'app'
|
|
1554
1614
|
let sub: SubStep = 'bot'
|
|
@@ -1834,6 +1894,9 @@ function reportProgress(
|
|
|
1834
1894
|
case 'kakaotalk-auth':
|
|
1835
1895
|
s.stop(reportKakaotalkAuth(event.result))
|
|
1836
1896
|
break
|
|
1897
|
+
case 'webex-auth':
|
|
1898
|
+
s.stop(reportWebexAuth(event.result))
|
|
1899
|
+
break
|
|
1837
1900
|
case 'github-webhooks':
|
|
1838
1901
|
s.stop(formatEagerGithubWebhookInstallResult(event.result))
|
|
1839
1902
|
break
|
|
@@ -1897,6 +1960,11 @@ function reportKakaotalkAuth(result: KakaotalkAuthResult): string {
|
|
|
1897
1960
|
return `KakaoTalk login failed: ${result.reason}`
|
|
1898
1961
|
}
|
|
1899
1962
|
|
|
1963
|
+
function reportWebexAuth(result: { ok: true } | { ok: false; reason: string }): string {
|
|
1964
|
+
if (result.ok) return 'Webex credentials saved to secrets.json.'
|
|
1965
|
+
return `Webex login failed: ${result.reason}`
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1900
1968
|
// Hatching launches the container and foregrounds the TUI, so it steals stdin
|
|
1901
1969
|
// and cannot share the spinner lifecycle with the other steps. Print plain
|
|
1902
1970
|
// lines instead.
|
|
@@ -1976,6 +2044,7 @@ const START_MESSAGES: Record<Exclude<InitStep, 'hatching'>, string> = {
|
|
|
1976
2044
|
'oauth-login': 'Waiting for browser login...',
|
|
1977
2045
|
scaffold: 'Laying the egg...',
|
|
1978
2046
|
'kakaotalk-auth': 'Logging in to KakaoTalk...',
|
|
2047
|
+
'webex-auth': 'Logging in to Webex...',
|
|
1979
2048
|
'github-webhooks': 'Installing GitHub repository webhooks...',
|
|
1980
2049
|
install: 'Installing dependencies with bun...',
|
|
1981
2050
|
dockerfile: 'Writing Dockerfile...',
|
|
@@ -11,6 +11,7 @@ export const CHANNEL_KINDS = [
|
|
|
11
11
|
'slack-bot',
|
|
12
12
|
'discord-bot',
|
|
13
13
|
'telegram-bot',
|
|
14
|
+
'webex',
|
|
14
15
|
'webex-bot',
|
|
15
16
|
'line',
|
|
16
17
|
'kakaotalk',
|
|
@@ -186,7 +187,7 @@ function buildDetail(kind: ChannelKind, channelConfig: unknown, secretsBlock: un
|
|
|
186
187
|
const repos = isObjectRecord(channelConfig) && Array.isArray(channelConfig.repos) ? channelConfig.repos.length : 0
|
|
187
188
|
return { detail: `${repos} repo${repos === 1 ? '' : 's'}` }
|
|
188
189
|
}
|
|
189
|
-
if (kind === 'line' || kind === 'kakaotalk') {
|
|
190
|
+
if (kind === 'line' || kind === 'kakaotalk' || kind === 'webex') {
|
|
190
191
|
if (!isObjectRecord(secretsBlock)) return {}
|
|
191
192
|
const accounts = isObjectRecord(secretsBlock.accounts) ? Object.keys(secretsBlock.accounts).length : 0
|
|
192
193
|
const current = typeof secretsBlock.currentAccount === 'string' ? secretsBlock.currentAccount : undefined
|
|
@@ -29,6 +29,7 @@ export function buildChannelChecks(): DoctorCheck[] {
|
|
|
29
29
|
discordBotCredentials(),
|
|
30
30
|
telegramBotCredentials(),
|
|
31
31
|
webexBotCredentials(),
|
|
32
|
+
webexUserCredentials(),
|
|
32
33
|
lineCredentials(),
|
|
33
34
|
kakaotalkCredentials(),
|
|
34
35
|
githubCredentials(),
|
|
@@ -76,6 +77,32 @@ function webexBotCredentials(): DoctorCheck {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
function webexUserCredentials(): DoctorCheck {
|
|
81
|
+
return {
|
|
82
|
+
name: 'channel.webex.credentials',
|
|
83
|
+
category: 'channels',
|
|
84
|
+
description: 'webex adapter has a current account with an access token in secrets.json',
|
|
85
|
+
applies: (ctx) => ctx.hasAgentFolder,
|
|
86
|
+
async run(ctx) {
|
|
87
|
+
const channels = readDeclaredChannels(ctx)
|
|
88
|
+
if (channels === null) return configInvalidResult()
|
|
89
|
+
if (!isAdapterActive(channels, 'webex')) {
|
|
90
|
+
return { status: 'skipped', message: 'webex not configured' }
|
|
91
|
+
}
|
|
92
|
+
const block = readChannelsSecrets(ctx)?.webex
|
|
93
|
+
if (!hasCurrentAccountToken(block)) {
|
|
94
|
+
return {
|
|
95
|
+
status: 'warning',
|
|
96
|
+
message: 'webex has no current account access_token in secrets.json',
|
|
97
|
+
details: ['Adapter will start but fail authentication and stay disconnected.'],
|
|
98
|
+
fix: { description: 'Run `typeclaw channel add webex` to log in an account.' },
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { status: 'ok', message: 'webex has a current account access_token' }
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
79
106
|
function lineCredentials(): DoctorCheck {
|
|
80
107
|
return {
|
|
81
108
|
name: 'channel.line.credentials',
|
|
@@ -326,6 +353,22 @@ function isSecretShape(value: unknown): value is { value?: string; env?: string
|
|
|
326
353
|
return hasValue || hasEnv
|
|
327
354
|
}
|
|
328
355
|
|
|
356
|
+
function hasCurrentAccountToken(block: unknown): boolean {
|
|
357
|
+
if (!isObjectRecord(block)) return false
|
|
358
|
+
const current = (block as { currentAccount?: unknown }).currentAccount
|
|
359
|
+
if (typeof current !== 'string' || current.length === 0) return false
|
|
360
|
+
const accounts = (block as { accounts?: unknown }).accounts
|
|
361
|
+
if (!isObjectRecord(accounts)) return false
|
|
362
|
+
const account = accounts[current]
|
|
363
|
+
if (!isObjectRecord(account)) return false
|
|
364
|
+
const token = (account as { access_token?: unknown }).access_token
|
|
365
|
+
return typeof token === 'string' && token.length > 0
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function isObjectRecord(value: unknown): value is Record<string, unknown> {
|
|
369
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
370
|
+
}
|
|
371
|
+
|
|
329
372
|
function readDeclaredChannels(ctx: CheckContext): ChannelsConfig | null {
|
|
330
373
|
const cfg = safeLoadConfig(ctx)
|
|
331
374
|
return cfg?.channels ?? null
|
package/src/hostd/daemon.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { join } from 'node:path'
|
|
|
6
6
|
import type { PortForward } from '@/config'
|
|
7
7
|
import { defaultDockerExec, type DockerExec } from '@/container'
|
|
8
8
|
import type { PortForwardEvent } from '@/portbroker'
|
|
9
|
-
import { kakaoChannelBlockSchema, lineChannelBlockSchema } from '@/secrets/schema'
|
|
9
|
+
import { kakaoChannelBlockSchema, lineChannelBlockSchema, webexChannelBlockSchema } from '@/secrets/schema'
|
|
10
10
|
import { SecretsBackend } from '@/secrets/storage'
|
|
11
11
|
import { isWindows } from '@/shared'
|
|
12
12
|
|
|
@@ -450,19 +450,21 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
450
450
|
|
|
451
451
|
const handleSecretsPatch = async (req: {
|
|
452
452
|
containerName: string
|
|
453
|
-
patch: { channels: { kakaotalk: unknown } | { line: unknown } }
|
|
453
|
+
patch: { channels: { kakaotalk: unknown } | { line: unknown } | { webex: unknown } }
|
|
454
454
|
}): Promise<RpcResponse> =>
|
|
455
455
|
runSerially(req.containerName, async () => {
|
|
456
456
|
const cwd = cwds.get(req.containerName)
|
|
457
457
|
if (!cwd) return { ok: false, reason: `not registered: ${req.containerName}` }
|
|
458
458
|
const channelsPatch = req.patch?.channels
|
|
459
|
-
// Exactly one personal-account channel block per patch. KakaoTalk
|
|
460
|
-
//
|
|
459
|
+
// Exactly one personal-account channel block per patch. KakaoTalk, LINE,
|
|
460
|
+
// and Webex write their structured account block through this RPC; the
|
|
461
461
|
// key present in the patch selects which block to validate and merge.
|
|
462
462
|
const patch =
|
|
463
463
|
'line' in channelsPatch
|
|
464
464
|
? { key: 'line' as const, parsed: lineChannelBlockSchema.safeParse(channelsPatch.line) }
|
|
465
|
-
:
|
|
465
|
+
: 'webex' in channelsPatch
|
|
466
|
+
? { key: 'webex' as const, parsed: webexChannelBlockSchema.safeParse(channelsPatch.webex) }
|
|
467
|
+
: { key: 'kakaotalk' as const, parsed: kakaoChannelBlockSchema.safeParse(channelsPatch.kakaotalk) }
|
|
466
468
|
if (!patch.parsed.success) {
|
|
467
469
|
return { ok: false, reason: patch.parsed.error.issues.map((issue) => issue.message).join('; ') }
|
|
468
470
|
}
|
package/src/hostd/protocol.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PortForward } from '@/config'
|
|
2
|
-
import type { KakaoChannelBlock, LineChannelBlock } from '@/secrets/schema'
|
|
2
|
+
import type { KakaoChannelBlock, LineChannelBlock, WebexChannelBlock } from '@/secrets/schema'
|
|
3
3
|
|
|
4
4
|
export type Request =
|
|
5
5
|
| {
|
|
@@ -18,7 +18,7 @@ export type Request =
|
|
|
18
18
|
| {
|
|
19
19
|
kind: 'secrets-patch'
|
|
20
20
|
containerName: string
|
|
21
|
-
patch: { channels: { kakaotalk: KakaoChannelBlock } | { line: LineChannelBlock } }
|
|
21
|
+
patch: { channels: { kakaotalk: KakaoChannelBlock } | { line: LineChannelBlock } | { webex: WebexChannelBlock } }
|
|
22
22
|
}
|
|
23
23
|
| { kind: 'http-info' }
|
|
24
24
|
| { kind: 'version' }
|