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
@@ -93,6 +93,18 @@ const kakaoEncryptedPasswordSchema = z
93
93
  })
94
94
  .strict()
95
95
 
96
+ export const webexEncryptedPasswordSchema = z
97
+ .object({
98
+ v: z.literal(1),
99
+ alg: z.literal('AES-256-GCM'),
100
+ kid: z.string(),
101
+ iv: z.string(),
102
+ ciphertext: z.string(),
103
+ authTag: z.string(),
104
+ createdAt: z.string(),
105
+ })
106
+ .strict()
107
+
96
108
  export const kakaoAccountRecordSchema = z.object({
97
109
  account_id: z.string(),
98
110
  oauth_token: z.string(),
@@ -112,6 +124,26 @@ export const kakaoAccountRecordSchema = z.object({
112
124
 
113
125
  export type KakaoEncryptedPassword = z.infer<typeof kakaoEncryptedPasswordSchema>
114
126
 
127
+ export const webexAccountRecordSchema = z.object({
128
+ account_id: z.string(),
129
+ access_token: z.string(),
130
+ refresh_token: z.string(),
131
+ expires_at: z.number(),
132
+ device_url: z.string().optional(),
133
+ user_id: z.string().optional(),
134
+ client_id: z.string().optional(),
135
+ client_secret: z.string().optional(),
136
+ created_at: z.string(),
137
+ updated_at: z.string(),
138
+ email: z.string().optional(),
139
+ encryptedPassword: webexEncryptedPasswordSchema.optional(),
140
+ })
141
+
142
+ export const webexChannelBlockSchema = z.object({
143
+ currentAccount: z.string().nullable(),
144
+ accounts: z.record(z.string(), webexAccountRecordSchema),
145
+ })
146
+
115
147
  export const kakaoPendingLoginRecordSchema = z.object({
116
148
  device_uuid: z.string(),
117
149
  device_type: z.union([z.literal('pc'), z.literal('tablet')]),
@@ -133,6 +165,7 @@ export const channelsSchema = z
133
165
  'telegram-bot': telegramBotChannelSchema.optional(),
134
166
  line: lineChannelBlockSchema.optional(),
135
167
  kakaotalk: kakaoChannelBlockSchema.optional(),
168
+ webex: webexChannelBlockSchema.optional(),
136
169
  })
137
170
  .catchall(z.unknown())
138
171
 
@@ -158,6 +191,8 @@ export type LineChannelBlock = z.infer<typeof lineChannelBlockSchema>
158
191
  export type KakaoAccountRecord = z.infer<typeof kakaoAccountRecordSchema>
159
192
  export type PendingLoginRecord = z.infer<typeof kakaoPendingLoginRecordSchema>
160
193
  export type KakaoChannelBlock = z.infer<typeof kakaoChannelBlockSchema>
194
+ export type WebexAccountRecord = z.infer<typeof webexAccountRecordSchema>
195
+ export type WebexChannelBlock = z.infer<typeof webexChannelBlockSchema>
161
196
  export type SecretsFile = z.infer<typeof secretsFileSchema>
162
197
 
163
198
  export type ParseSecretsResult = { ok: true; file: SecretsFile } | { ok: false; reason: string }
@@ -0,0 +1,113 @@
1
+ import { sendHttp } from '@/hostd/client'
2
+
3
+ import { type WebexAccountRecord, type WebexChannelBlock, webexChannelBlockSchema } from './schema'
4
+ import { SecretsBackend } from './storage'
5
+
6
+ export type SetWebexAccountInput = WebexAccountRecord
7
+
8
+ export type SecretsWebexCredentialStoreOptions =
9
+ | { mode: 'host'; secretsPath: string }
10
+ | { mode: 'container'; secretsPath: string; hostdUrl: string; restartToken: string; containerName: string }
11
+
12
+ const EMPTY_BLOCK: WebexChannelBlock = { currentAccount: null, accounts: {} }
13
+
14
+ export class SecretsWebexCredentialStore {
15
+ private readonly backend: SecretsBackend
16
+ private writeChain: Promise<void> = Promise.resolve()
17
+
18
+ constructor(private readonly options: SecretsWebexCredentialStoreOptions) {
19
+ this.backend = new SecretsBackend(options.secretsPath)
20
+ }
21
+
22
+ async getAccount(id?: string): Promise<WebexAccountRecord | null> {
23
+ const block = this.readBlock()
24
+ const accountId = id ?? block.currentAccount
25
+ if (!accountId) return null
26
+ return block.accounts[accountId] ?? null
27
+ }
28
+
29
+ async getAccountWithRenewalFields(id?: string): Promise<WebexAccountRecord | null> {
30
+ return await this.getAccount(id)
31
+ }
32
+
33
+ async setAccount(account: SetWebexAccountInput): Promise<void> {
34
+ await this.writeBlock((block) => {
35
+ const merged = mergeAccountPreservingRenewalFields(account, block.accounts[account.account_id])
36
+ const accounts = { ...block.accounts, [account.account_id]: merged }
37
+ return { ...block, currentAccount: block.currentAccount ?? account.account_id, accounts }
38
+ })
39
+ }
40
+
41
+ async removeAccount(id: string): Promise<void> {
42
+ await this.writeBlock((block) => {
43
+ const accounts = { ...block.accounts }
44
+ delete accounts[id]
45
+ const currentAccount = block.currentAccount === id ? (Object.keys(accounts)[0] ?? null) : block.currentAccount
46
+ return { ...block, currentAccount, accounts }
47
+ })
48
+ }
49
+
50
+ async listAccounts(): Promise<Array<WebexAccountRecord & { is_current: boolean }>> {
51
+ const block = this.readBlock()
52
+ return Object.values(block.accounts).map((account) => ({
53
+ ...account,
54
+ is_current: account.account_id === block.currentAccount,
55
+ }))
56
+ }
57
+
58
+ async setCurrentAccount(id: string): Promise<void> {
59
+ await this.writeBlock((block) => ({ ...block, currentAccount: id }))
60
+ }
61
+
62
+ private readBlock(): WebexChannelBlock {
63
+ const channels =
64
+ this.options.mode === 'container' ? this.backend.tryReadChannelsSync() : this.backend.readChannelsSync()
65
+ return parseBlock(channels?.webex)
66
+ }
67
+
68
+ private async writeBlock(update: (current: WebexChannelBlock) => WebexChannelBlock): Promise<void> {
69
+ return this.enqueueWrite(async () => {
70
+ if (this.options.mode === 'container') {
71
+ const next = update(this.readBlock())
72
+ const response = await sendHttp(
73
+ {
74
+ kind: 'secrets-patch',
75
+ containerName: this.options.containerName,
76
+ patch: { channels: { webex: next } },
77
+ },
78
+ { url: this.options.hostdUrl, token: this.options.restartToken },
79
+ )
80
+ if (!response.ok) throw new Error(`secrets-patch failed: ${response.reason}`)
81
+ return
82
+ }
83
+
84
+ await this.backend.updateChannelsAsync(async (channels) => {
85
+ const next = { ...channels, webex: update(parseBlock(channels.webex)) }
86
+ return { result: undefined, next }
87
+ })
88
+ })
89
+ }
90
+
91
+ private enqueueWrite(op: () => Promise<void>): Promise<void> {
92
+ const next = this.writeChain.then(op, op)
93
+ this.writeChain = next.catch(() => {})
94
+ return next
95
+ }
96
+ }
97
+
98
+ function parseBlock(value: unknown): WebexChannelBlock {
99
+ if (value === undefined) return EMPTY_BLOCK
100
+ return webexChannelBlockSchema.parse(value)
101
+ }
102
+
103
+ function mergeAccountPreservingRenewalFields(
104
+ incoming: SetWebexAccountInput,
105
+ priorOnDisk: WebexChannelBlock['accounts'][string] | undefined,
106
+ ): WebexAccountRecord {
107
+ const merged: WebexAccountRecord = { ...incoming }
108
+ if (incoming.email !== undefined) merged.email = incoming.email
109
+ else if (priorOnDisk?.email !== undefined) merged.email = priorOnDisk.email
110
+ if (incoming.encryptedPassword !== undefined) merged.encryptedPassword = incoming.encryptedPassword
111
+ else if (priorOnDisk?.encryptedPassword !== undefined) merged.encryptedPassword = priorOnDisk.encryptedPassword
112
+ return merged
113
+ }
@@ -1320,6 +1320,166 @@
1320
1320
  }
1321
1321
  }
1322
1322
  },
1323
+ "webex": {
1324
+ "type": "object",
1325
+ "properties": {
1326
+ "engagement": {
1327
+ "default": {
1328
+ "trigger": [
1329
+ "mention",
1330
+ "reply",
1331
+ "dm"
1332
+ ],
1333
+ "stickiness": {
1334
+ "perReply": {
1335
+ "window": 900000
1336
+ }
1337
+ }
1338
+ },
1339
+ "type": "object",
1340
+ "properties": {
1341
+ "trigger": {
1342
+ "default": [
1343
+ "mention",
1344
+ "reply",
1345
+ "dm"
1346
+ ],
1347
+ "type": "array",
1348
+ "items": {
1349
+ "type": "string",
1350
+ "enum": [
1351
+ "mention",
1352
+ "reply",
1353
+ "dm"
1354
+ ]
1355
+ }
1356
+ },
1357
+ "stickiness": {
1358
+ "default": {
1359
+ "perReply": {
1360
+ "window": 900000
1361
+ }
1362
+ },
1363
+ "anyOf": [
1364
+ {
1365
+ "type": "string",
1366
+ "const": "off"
1367
+ },
1368
+ {
1369
+ "type": "object",
1370
+ "properties": {
1371
+ "perReply": {
1372
+ "type": "object",
1373
+ "properties": {
1374
+ "window": {
1375
+ "type": "integer",
1376
+ "minimum": 1,
1377
+ "maximum": 86400000
1378
+ }
1379
+ },
1380
+ "required": [
1381
+ "window"
1382
+ ]
1383
+ }
1384
+ },
1385
+ "required": [
1386
+ "perReply"
1387
+ ]
1388
+ }
1389
+ ]
1390
+ }
1391
+ }
1392
+ },
1393
+ "history": {
1394
+ "default": {
1395
+ "prefetch": {
1396
+ "thread": {
1397
+ "head": 3,
1398
+ "tail": 10
1399
+ },
1400
+ "channel": {
1401
+ "tail": 10
1402
+ }
1403
+ }
1404
+ },
1405
+ "type": "object",
1406
+ "properties": {
1407
+ "prefetch": {
1408
+ "default": {
1409
+ "thread": {
1410
+ "head": 3,
1411
+ "tail": 10
1412
+ },
1413
+ "channel": {
1414
+ "tail": 10
1415
+ }
1416
+ },
1417
+ "type": "object",
1418
+ "properties": {
1419
+ "thread": {
1420
+ "default": {
1421
+ "head": 3,
1422
+ "tail": 10
1423
+ },
1424
+ "type": "object",
1425
+ "properties": {
1426
+ "head": {
1427
+ "default": 3,
1428
+ "type": "integer",
1429
+ "minimum": 0,
1430
+ "maximum": 200
1431
+ },
1432
+ "tail": {
1433
+ "default": 10,
1434
+ "type": "integer",
1435
+ "minimum": 0,
1436
+ "maximum": 200
1437
+ }
1438
+ }
1439
+ },
1440
+ "channel": {
1441
+ "default": {
1442
+ "tail": 10
1443
+ },
1444
+ "type": "object",
1445
+ "properties": {
1446
+ "tail": {
1447
+ "default": 10,
1448
+ "type": "integer",
1449
+ "minimum": 0,
1450
+ "maximum": 200
1451
+ }
1452
+ }
1453
+ }
1454
+ }
1455
+ }
1456
+ }
1457
+ },
1458
+ "enabled": {
1459
+ "default": true,
1460
+ "type": "boolean"
1461
+ },
1462
+ "quotedReply": {
1463
+ "default": {
1464
+ "enabled": true,
1465
+ "queueDelayMs": 10000
1466
+ },
1467
+ "type": "object",
1468
+ "properties": {
1469
+ "enabled": {
1470
+ "default": true,
1471
+ "type": "boolean"
1472
+ },
1473
+ "queueDelayMs": {
1474
+ "default": 10000,
1475
+ "type": "integer",
1476
+ "minimum": 0,
1477
+ "maximum": 9007199254740991
1478
+ }
1479
+ }
1480
+ }
1481
+ }
1482
+ },
1323
1483
  "webex-bot": {
1324
1484
  "type": "object",
1325
1485
  "properties": {