typeclaw 0.41.0 → 0.42.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.
- package/README.md +3 -2
- package/auth.schema.json +57 -0
- package/package.json +2 -2
- package/secrets.schema.json +57 -0
- package/src/agent/index.ts +10 -6
- package/src/agent/session-origin.ts +1 -0
- package/src/agent/tools/channel-history-render.ts +21 -0
- package/src/agent/tools/channel-history.ts +2 -17
- package/src/agent/tools/channel-read.ts +206 -0
- package/src/bundled-plugins/agent-browser/skills/agent-browser/SKILL.md +26 -2
- package/src/bundled-plugins/github-cli-auth/index.ts +25 -6
- package/src/bundled-plugins/memory/vector/hybrid.ts +73 -6
- package/src/bundled-plugins/memory/vector/passages.ts +2 -24
- package/src/bundled-plugins/memory/vector/truncation.ts +28 -0
- package/src/bundled-plugins/tool-result-cap/README.md +10 -1
- package/src/bundled-plugins/tool-result-cap/cap-result.ts +8 -0
- package/src/channels/adapters/discord-bot.ts +112 -0
- package/src/channels/adapters/instagram-channel-resolver.ts +113 -0
- package/src/channels/adapters/instagram-classify.ts +69 -0
- package/src/channels/adapters/instagram-format.ts +8 -0
- package/src/channels/adapters/instagram.ts +346 -0
- package/src/channels/adapters/slack-bot.ts +147 -0
- package/src/channels/manager.ts +60 -2
- package/src/channels/router.ts +64 -0
- package/src/channels/schema.ts +5 -0
- package/src/channels/types.ts +46 -0
- package/src/cli/channel.ts +76 -1
- package/src/cli/init.ts +1 -0
- package/src/cli/status.ts +37 -14
- package/src/config/channels-mutation.ts +2 -1
- package/src/doctor/channel-checks.ts +28 -0
- package/src/hostd/daemon.ts +11 -7
- package/src/hostd/protocol.ts +2 -0
- package/src/init/index.ts +50 -1
- package/src/init/instagram-auth.ts +134 -0
- package/src/init/run-owner-claim.ts +1 -0
- package/src/permissions/match-rule.ts +1 -1
- package/src/permissions/resolve.ts +1 -0
- package/src/role-claim/match-rule.ts +2 -1
- package/src/secrets/instagram-store.ts +112 -0
- package/src/secrets/schema.ts +18 -0
- package/src/skills/typeclaw-channel-instagram/SKILL.md +30 -0
- package/typeclaw.schema.json +161 -1
package/src/channels/router.ts
CHANGED
|
@@ -74,10 +74,16 @@ import type {
|
|
|
74
74
|
FetchAttachmentResult,
|
|
75
75
|
FetchHistoryArgs,
|
|
76
76
|
FetchHistoryResult,
|
|
77
|
+
GetMessageArgs,
|
|
78
|
+
GetMessageResult,
|
|
77
79
|
HistoryCallback,
|
|
78
80
|
InboundAttachment,
|
|
79
81
|
InboundMessage,
|
|
80
82
|
InboundReferenceContext,
|
|
83
|
+
ListCallback,
|
|
84
|
+
ListChannelsArgs,
|
|
85
|
+
ListChannelsResult,
|
|
86
|
+
MessageGetCallback,
|
|
81
87
|
RemoveReactionCallback,
|
|
82
88
|
RemoveReactionRequest,
|
|
83
89
|
OutboundCallback,
|
|
@@ -1049,6 +1055,16 @@ export type ChannelRouter = {
|
|
|
1049
1055
|
registerHistory: (adapter: ChannelKey['adapter'], cb: HistoryCallback) => void
|
|
1050
1056
|
unregisterHistory: (adapter: ChannelKey['adapter'], cb: HistoryCallback) => void
|
|
1051
1057
|
fetchHistory: (adapter: ChannelKey['adapter'], args: FetchHistoryArgs) => Promise<FetchHistoryResult>
|
|
1058
|
+
// Single-message-get and channel-list are opt-in per adapter and last-write-
|
|
1059
|
+
// wins (one bot account per adapter). When unregistered, `getMessage` /
|
|
1060
|
+
// `listChannels` answer `code: 'not-supported'`, matching `fetchHistory`'s
|
|
1061
|
+
// 'history-not-supported' fallback.
|
|
1062
|
+
registerMessageGet: (adapter: ChannelKey['adapter'], cb: MessageGetCallback) => void
|
|
1063
|
+
unregisterMessageGet: (adapter: ChannelKey['adapter'], cb: MessageGetCallback) => void
|
|
1064
|
+
getMessage: (adapter: ChannelKey['adapter'], args: GetMessageArgs) => Promise<GetMessageResult>
|
|
1065
|
+
registerList: (adapter: ChannelKey['adapter'], cb: ListCallback) => void
|
|
1066
|
+
unregisterList: (adapter: ChannelKey['adapter'], cb: ListCallback) => void
|
|
1067
|
+
listChannels: (adapter: ChannelKey['adapter'], args: ListChannelsArgs) => Promise<ListChannelsResult>
|
|
1052
1068
|
registerFetchAttachment: (adapter: ChannelKey['adapter'], cb: FetchAttachmentCallback) => void
|
|
1053
1069
|
unregisterFetchAttachment: (adapter: ChannelKey['adapter'], cb: FetchAttachmentCallback) => void
|
|
1054
1070
|
fetchAttachment: (adapter: ChannelKey['adapter'], args: FetchAttachmentArgs) => Promise<FetchAttachmentResult>
|
|
@@ -1385,6 +1401,8 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
|
|
|
1385
1401
|
const selfIdentityResolvers = new Map<ChannelKey['adapter'], ChannelSelfIdentityResolver>()
|
|
1386
1402
|
const membershipCaches = new Map<ChannelKey['adapter'], MembershipCache>()
|
|
1387
1403
|
const historyCallbacks = new Map<ChannelKey['adapter'], Set<HistoryCallback>>()
|
|
1404
|
+
const messageGetCallbacks = new Map<ChannelKey['adapter'], MessageGetCallback>()
|
|
1405
|
+
const listCallbacks = new Map<ChannelKey['adapter'], ListCallback>()
|
|
1388
1406
|
const fetchAttachmentCallbacks = new Map<ChannelKey['adapter'], Set<FetchAttachmentCallback>>()
|
|
1389
1407
|
const reviewThreadResolvers = new Map<ChannelKey['adapter'], ReviewThreadResolver>()
|
|
1390
1408
|
const reviewStateResolvers = new Map<ChannelKey['adapter'], ReviewStateResolver>()
|
|
@@ -3374,6 +3392,44 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
|
|
|
3374
3392
|
return lastError
|
|
3375
3393
|
}
|
|
3376
3394
|
|
|
3395
|
+
const registerMessageGet = (adapter: ChannelKey['adapter'], cb: MessageGetCallback): void => {
|
|
3396
|
+
messageGetCallbacks.set(adapter, cb)
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3399
|
+
const unregisterMessageGet = (adapter: ChannelKey['adapter'], cb: MessageGetCallback): void => {
|
|
3400
|
+
if (messageGetCallbacks.get(adapter) === cb) messageGetCallbacks.delete(adapter)
|
|
3401
|
+
}
|
|
3402
|
+
|
|
3403
|
+
const getMessage = async (adapter: ChannelKey['adapter'], args: GetMessageArgs): Promise<GetMessageResult> => {
|
|
3404
|
+
const cb = messageGetCallbacks.get(adapter)
|
|
3405
|
+
if (cb === undefined) return { ok: false, error: 'message-get-not-supported', code: 'not-supported' }
|
|
3406
|
+
try {
|
|
3407
|
+
return await raceWithTimeout(cb(args), fetchHistoryTimeoutMs, `[channels] ${adapter} message get`)
|
|
3408
|
+
} catch (err) {
|
|
3409
|
+
logger.warn(`[channels] message get threw for ${adapter}: ${describe(err)}`)
|
|
3410
|
+
return { ok: false, error: 'message-get-not-supported', code: 'not-supported' }
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
|
|
3414
|
+
const registerList = (adapter: ChannelKey['adapter'], cb: ListCallback): void => {
|
|
3415
|
+
listCallbacks.set(adapter, cb)
|
|
3416
|
+
}
|
|
3417
|
+
|
|
3418
|
+
const unregisterList = (adapter: ChannelKey['adapter'], cb: ListCallback): void => {
|
|
3419
|
+
if (listCallbacks.get(adapter) === cb) listCallbacks.delete(adapter)
|
|
3420
|
+
}
|
|
3421
|
+
|
|
3422
|
+
const listChannels = async (adapter: ChannelKey['adapter'], args: ListChannelsArgs): Promise<ListChannelsResult> => {
|
|
3423
|
+
const cb = listCallbacks.get(adapter)
|
|
3424
|
+
if (cb === undefined) return { ok: false, error: 'list-not-supported', code: 'not-supported' }
|
|
3425
|
+
try {
|
|
3426
|
+
return await raceWithTimeout(cb(args), fetchHistoryTimeoutMs, `[channels] ${adapter} list channels`)
|
|
3427
|
+
} catch (err) {
|
|
3428
|
+
logger.warn(`[channels] list channels threw for ${adapter}: ${describe(err)}`)
|
|
3429
|
+
return { ok: false, error: 'list-not-supported', code: 'not-supported' }
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
|
|
3377
3433
|
const registerFetchAttachment = (adapter: ChannelKey['adapter'], cb: FetchAttachmentCallback): void => {
|
|
3378
3434
|
let set = fetchAttachmentCallbacks.get(adapter)
|
|
3379
3435
|
if (!set) {
|
|
@@ -4798,6 +4854,12 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
|
|
|
4798
4854
|
registerHistory,
|
|
4799
4855
|
unregisterHistory,
|
|
4800
4856
|
fetchHistory,
|
|
4857
|
+
registerMessageGet,
|
|
4858
|
+
unregisterMessageGet,
|
|
4859
|
+
getMessage,
|
|
4860
|
+
registerList,
|
|
4861
|
+
unregisterList,
|
|
4862
|
+
listChannels,
|
|
4801
4863
|
registerFetchAttachment,
|
|
4802
4864
|
unregisterFetchAttachment,
|
|
4803
4865
|
fetchAttachment,
|
|
@@ -5158,6 +5220,7 @@ export function formatAuthorAttribution(adapter: AdapterId, authorId: string, au
|
|
|
5158
5220
|
case 'telegram-bot':
|
|
5159
5221
|
case 'webex':
|
|
5160
5222
|
case 'webex-bot':
|
|
5223
|
+
case 'instagram':
|
|
5161
5224
|
case 'line':
|
|
5162
5225
|
case 'kakaotalk':
|
|
5163
5226
|
return hasDisplayName ? `${displayName} <${id}>` : id
|
|
@@ -5190,6 +5253,7 @@ function formatAuthorReference(adapter: AdapterId, authorId: string, authorName:
|
|
|
5190
5253
|
case 'telegram-bot':
|
|
5191
5254
|
case 'webex':
|
|
5192
5255
|
case 'webex-bot':
|
|
5256
|
+
case 'instagram':
|
|
5193
5257
|
case 'line':
|
|
5194
5258
|
case 'kakaotalk':
|
|
5195
5259
|
return displayName
|
package/src/channels/schema.ts
CHANGED
|
@@ -4,6 +4,7 @@ export const ADAPTER_IDS = [
|
|
|
4
4
|
'discord',
|
|
5
5
|
'discord-bot',
|
|
6
6
|
'github',
|
|
7
|
+
'instagram',
|
|
7
8
|
'line',
|
|
8
9
|
'kakaotalk',
|
|
9
10
|
'slack',
|
|
@@ -266,6 +267,10 @@ export const channelsSchema = z
|
|
|
266
267
|
discord: adapterSchema.optional(),
|
|
267
268
|
'discord-bot': adapterSchema.optional(),
|
|
268
269
|
github: githubChannelSchema.optional(),
|
|
270
|
+
// Instagram is a personal-account channel: plain-text sends only,
|
|
271
|
+
// alias-only engagement in groups, and DM/group buckets backed by
|
|
272
|
+
// secrets.json#channels.instagram credentials rather than env vars.
|
|
273
|
+
instagram: adapterSchema.optional(),
|
|
269
274
|
// LINE is a personal-account channel like KakaoTalk: plain-text only,
|
|
270
275
|
// alias-only engagement (no native @-mention), credentials in
|
|
271
276
|
// secrets.json#channels.line (not env). Unlike KakaoTalk it has no
|
package/src/channels/types.ts
CHANGED
|
@@ -358,6 +358,52 @@ export type FetchHistoryResult =
|
|
|
358
358
|
// 'history-not-supported' for those.
|
|
359
359
|
export type HistoryCallback = (args: FetchHistoryArgs) => Promise<FetchHistoryResult>
|
|
360
360
|
|
|
361
|
+
// Fetch a single message by its platform id from an arbitrary chat. Backs the
|
|
362
|
+
// `channel_read` tool's `mode: "message"`. `thread` narrows the lookup on
|
|
363
|
+
// platforms where a message id is only addressable within a thread (Slack
|
|
364
|
+
// thread replies); pass null for channel-root lookups. Reuses
|
|
365
|
+
// `ChannelHistoryMessage` as the result shape — a single message is just a
|
|
366
|
+
// one-element history with the same author/ts/isBot fields.
|
|
367
|
+
export type GetMessageArgs = {
|
|
368
|
+
chat: string
|
|
369
|
+
thread: string | null
|
|
370
|
+
messageId: string
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export type GetMessageResult =
|
|
374
|
+
| { ok: true; message: ChannelHistoryMessage }
|
|
375
|
+
// `code: 'not-found'` is an expected miss (deleted/wrong id) the tool surfaces
|
|
376
|
+
// as a soft error; `code: 'not-supported'` means no adapter callback is
|
|
377
|
+
// registered, mirroring `fetchHistory`'s 'history-not-supported' contract.
|
|
378
|
+
| { ok: false; error: string; code?: 'not-found' | 'not-supported' }
|
|
379
|
+
|
|
380
|
+
export type MessageGetCallback = (args: GetMessageArgs) => Promise<GetMessageResult>
|
|
381
|
+
|
|
382
|
+
// One channel/chat the bot account can see, returned by `ListCallback`. `chat`
|
|
383
|
+
// is the id the agent passes back to `channel_read`/`channel_send`; `name` is a
|
|
384
|
+
// human label for the agent to recognize. `isMember` is best-effort — omitted
|
|
385
|
+
// when the adapter can't cheaply determine membership.
|
|
386
|
+
export type ChannelListEntry = {
|
|
387
|
+
chat: string
|
|
388
|
+
name: string
|
|
389
|
+
kind: 'channel' | 'dm' | 'group' | 'thread'
|
|
390
|
+
isMember?: boolean
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export type ListChannelsArgs = {
|
|
394
|
+
workspace: string
|
|
395
|
+
limit: number
|
|
396
|
+
cursor?: string
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export type ListChannelsResult =
|
|
400
|
+
| { ok: true; entries: ChannelListEntry[]; nextCursor?: string }
|
|
401
|
+
| { ok: false; error: string; code?: 'not-supported' }
|
|
402
|
+
|
|
403
|
+
// Backs the `channel_read` tool's `mode: "list"`. Opt-in per adapter like
|
|
404
|
+
// history; the router answers 'list-not-supported' when none is registered.
|
|
405
|
+
export type ListCallback = (args: ListChannelsArgs) => Promise<ListChannelsResult>
|
|
406
|
+
|
|
361
407
|
export type FetchAttachmentArgs = {
|
|
362
408
|
ref: string
|
|
363
409
|
filename?: string
|
package/src/cli/channel.ts
CHANGED
|
@@ -30,12 +30,14 @@ import {
|
|
|
30
30
|
type DiscordAuthResult,
|
|
31
31
|
type GithubCredentialPatch,
|
|
32
32
|
type GithubTunnelProvider,
|
|
33
|
+
type InstagramAuthResult,
|
|
33
34
|
type KakaotalkAuthResult,
|
|
34
35
|
type LineAuthResult,
|
|
35
36
|
type SlackAuthResult,
|
|
36
37
|
type WebexAuthResult,
|
|
37
38
|
} from '@/init'
|
|
38
39
|
import { runDiscordBootstrap } from '@/init/discord-auth'
|
|
40
|
+
import { runInstagramBootstrap } from '@/init/instagram-auth'
|
|
39
41
|
import { runKakaotalkBootstrap } from '@/init/kakaotalk-auth'
|
|
40
42
|
import { runLineBootstrap } from '@/init/line-auth'
|
|
41
43
|
import { runSlackBootstrap } from '@/init/slack-auth'
|
|
@@ -55,6 +57,7 @@ const CHANNEL_LABELS: Record<ChannelKind, string> = {
|
|
|
55
57
|
'telegram-bot': 'Telegram',
|
|
56
58
|
webex: 'Webex (User)',
|
|
57
59
|
'webex-bot': 'Webex',
|
|
60
|
+
instagram: 'Instagram',
|
|
58
61
|
line: 'LINE',
|
|
59
62
|
kakaotalk: 'KakaoTalk',
|
|
60
63
|
github: 'GitHub',
|
|
@@ -160,6 +163,15 @@ const setSub = defineCommand({
|
|
|
160
163
|
process.exit(1)
|
|
161
164
|
}
|
|
162
165
|
|
|
166
|
+
if (args.adapter === 'instagram') {
|
|
167
|
+
console.error(
|
|
168
|
+
errorLine(
|
|
169
|
+
'Instagram uses a username/password auth flow. Use `typeclaw channel reauth instagram` to rotate its credentials.',
|
|
170
|
+
),
|
|
171
|
+
)
|
|
172
|
+
process.exit(1)
|
|
173
|
+
}
|
|
174
|
+
|
|
163
175
|
const adapter =
|
|
164
176
|
args.adapter === undefined
|
|
165
177
|
? await pickSettableAdapter(configured)
|
|
@@ -171,7 +183,7 @@ const setSub = defineCommand({
|
|
|
171
183
|
},
|
|
172
184
|
})
|
|
173
185
|
|
|
174
|
-
const REAUTHABLE_ADAPTERS = ['line', 'kakaotalk', 'webex'] as const
|
|
186
|
+
const REAUTHABLE_ADAPTERS = ['line', 'instagram', 'kakaotalk', 'webex'] as const
|
|
175
187
|
type ReauthableAdapter = (typeof REAUTHABLE_ADAPTERS)[number]
|
|
176
188
|
|
|
177
189
|
const reauthSub = defineCommand({
|
|
@@ -441,6 +453,9 @@ async function runReauth(cwd: string, adapter: ReauthableAdapter): Promise<void>
|
|
|
441
453
|
case 'line':
|
|
442
454
|
await runLineReauth(cwd)
|
|
443
455
|
return
|
|
456
|
+
case 'instagram':
|
|
457
|
+
await runInstagramReauth(cwd)
|
|
458
|
+
return
|
|
444
459
|
case 'kakaotalk':
|
|
445
460
|
await runKakaotalkReauth(cwd)
|
|
446
461
|
return
|
|
@@ -450,6 +465,20 @@ async function runReauth(cwd: string, adapter: ReauthableAdapter): Promise<void>
|
|
|
450
465
|
}
|
|
451
466
|
}
|
|
452
467
|
|
|
468
|
+
async function runInstagramReauth(cwd: string): Promise<void> {
|
|
469
|
+
const creds = await promptInstagramCredentials()
|
|
470
|
+
const s = spinner()
|
|
471
|
+
s.start('Logging in to Instagram...')
|
|
472
|
+
const result = await runInstagramBootstrap({ username: creds.username, password: creds.password, agentDir: cwd })
|
|
473
|
+
if (!result.ok) {
|
|
474
|
+
s.stop(`Instagram login failed: ${result.reason}`)
|
|
475
|
+
process.exit(1)
|
|
476
|
+
}
|
|
477
|
+
s.stop('Instagram credentials refreshed in secrets.json.')
|
|
478
|
+
|
|
479
|
+
await maybePromptReauthRefresh(cwd, 'instagram')
|
|
480
|
+
}
|
|
481
|
+
|
|
453
482
|
async function runLineReauth(cwd: string): Promise<void> {
|
|
454
483
|
const holder: LineAuthSpinnerHolder = { current: null }
|
|
455
484
|
const login = await promptLineLogin(holderSpinnerControl(holder))
|
|
@@ -940,6 +969,7 @@ type CollectedCredentials =
|
|
|
940
969
|
| { channel: 'telegram-bot'; telegramBotToken: string }
|
|
941
970
|
| { channel: 'webex'; runWebexAuth: (options: { cwd: string }) => Promise<WebexAuthResult> }
|
|
942
971
|
| { channel: 'webex-bot'; webexBotToken: string }
|
|
972
|
+
| { channel: 'instagram'; runInstagramAuth: (options: { cwd: string }) => Promise<InstagramAuthResult> }
|
|
943
973
|
| { channel: 'line'; runLineAuth: (options: { cwd: string }) => Promise<LineAuthResult> }
|
|
944
974
|
| { channel: 'kakaotalk'; runKakaotalkAuth: (options: { cwd: string }) => Promise<KakaotalkAuthResult> }
|
|
945
975
|
| {
|
|
@@ -986,6 +1016,14 @@ async function collectCredentials(
|
|
|
986
1016
|
}
|
|
987
1017
|
case 'webex-bot':
|
|
988
1018
|
return { channel, webexBotToken: await promptWebexToken() }
|
|
1019
|
+
case 'instagram': {
|
|
1020
|
+
const creds = await promptInstagramCredentials()
|
|
1021
|
+
return {
|
|
1022
|
+
channel,
|
|
1023
|
+
runInstagramAuth: ({ cwd: agentDir }) =>
|
|
1024
|
+
runInstagramBootstrap({ username: creds.username, password: creds.password, agentDir }),
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
989
1027
|
case 'line': {
|
|
990
1028
|
const login = await promptLineLogin(lineSpinnerHolder ? holderSpinnerControl(lineSpinnerHolder) : undefined)
|
|
991
1029
|
return {
|
|
@@ -1515,6 +1553,34 @@ async function promptWebexCredentials(
|
|
|
1515
1553
|
return { email, password: pwd }
|
|
1516
1554
|
}
|
|
1517
1555
|
|
|
1556
|
+
async function promptInstagramCredentials(): Promise<{ username: string; password: string }> {
|
|
1557
|
+
note(
|
|
1558
|
+
[
|
|
1559
|
+
'Instagram authentication uses a personal account.',
|
|
1560
|
+
'Messages will be sent and received under this account.',
|
|
1561
|
+
'2FA/checkpointed accounts are not supported; use a dedicated account without those challenges.',
|
|
1562
|
+
].join('\n'),
|
|
1563
|
+
'About to log in to Instagram',
|
|
1564
|
+
)
|
|
1565
|
+
const username = await text({
|
|
1566
|
+
message: 'Instagram username',
|
|
1567
|
+
validate: (value) => (value && value.length > 0 ? undefined : 'Username is required'),
|
|
1568
|
+
})
|
|
1569
|
+
if (isCancel(username)) {
|
|
1570
|
+
cancel('Aborted.')
|
|
1571
|
+
process.exit(0)
|
|
1572
|
+
}
|
|
1573
|
+
const pwd = await password({
|
|
1574
|
+
message: 'Instagram password',
|
|
1575
|
+
validate: (value) => (value && value.length > 0 ? undefined : 'Password is required'),
|
|
1576
|
+
})
|
|
1577
|
+
if (isCancel(pwd)) {
|
|
1578
|
+
cancel('Aborted.')
|
|
1579
|
+
process.exit(0)
|
|
1580
|
+
}
|
|
1581
|
+
return { username, password: pwd }
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1518
1584
|
type LinePromptResult =
|
|
1519
1585
|
| { method: 'qr'; callbacks: { onQRUrl: (url: string) => Promise<void>; onPincode: (pin: string) => void } }
|
|
1520
1586
|
| {
|
|
@@ -1681,6 +1747,9 @@ function reportProgress(
|
|
|
1681
1747
|
if (lineSpinnerHolder) lineSpinnerHolder.current = null
|
|
1682
1748
|
s.stop(reportLineAuth(event.result))
|
|
1683
1749
|
break
|
|
1750
|
+
case 'instagram-auth':
|
|
1751
|
+
s.stop(reportInstagramAuth(event.result))
|
|
1752
|
+
break
|
|
1684
1753
|
case 'kakaotalk-auth':
|
|
1685
1754
|
s.stop(reportKakaotalkAuth(event.result))
|
|
1686
1755
|
break
|
|
@@ -1708,6 +1777,7 @@ function reportProgress(
|
|
|
1708
1777
|
|
|
1709
1778
|
const START_MESSAGES: Record<AddChannelStepEvent['step'], string> = {
|
|
1710
1779
|
'line-auth': 'Logging in to LINE...',
|
|
1780
|
+
'instagram-auth': 'Logging in to Instagram...',
|
|
1711
1781
|
'kakaotalk-auth': 'Logging in to KakaoTalk...',
|
|
1712
1782
|
'webex-auth': 'Logging in to Webex...',
|
|
1713
1783
|
'discord-auth': 'Logging in to Discord...',
|
|
@@ -1742,6 +1812,11 @@ function reportLineAuth(result: LineAuthResult): string {
|
|
|
1742
1812
|
return `LINE login failed: ${result.reason}`
|
|
1743
1813
|
}
|
|
1744
1814
|
|
|
1815
|
+
function reportInstagramAuth(result: InstagramAuthResult): string {
|
|
1816
|
+
if (result.ok) return 'Instagram credentials saved to secrets.json.'
|
|
1817
|
+
return `Instagram login failed: ${result.reason}`
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1745
1820
|
async function maybePromptRestart(
|
|
1746
1821
|
cwd: string,
|
|
1747
1822
|
channel: ChannelKind,
|
package/src/cli/init.ts
CHANGED
|
@@ -2047,6 +2047,7 @@ const START_MESSAGES: Record<Exclude<InitStep, 'hatching'>, string> = {
|
|
|
2047
2047
|
scaffold: 'Laying the egg...',
|
|
2048
2048
|
'slack-auth': 'Logging in to Slack...',
|
|
2049
2049
|
'discord-auth': 'Logging in to Discord...',
|
|
2050
|
+
'instagram-auth': 'Logging in to Instagram...',
|
|
2050
2051
|
'kakaotalk-auth': 'Logging in to KakaoTalk...',
|
|
2051
2052
|
'webex-auth': 'Logging in to Webex...',
|
|
2052
2053
|
'github-webhooks': 'Installing GitHub repository webhooks...',
|
package/src/cli/status.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { styleText } from 'node:util'
|
|
|
2
2
|
|
|
3
3
|
import { defineCommand } from 'citty'
|
|
4
4
|
|
|
5
|
-
import { status as containerStatus, type ContainerStatus } from '@/container'
|
|
5
|
+
import { status as containerStatus, type ContainerStatus, type DockerExec } from '@/container'
|
|
6
6
|
import { isDaemonReachable, send } from '@/hostd'
|
|
7
7
|
import type { StatusResult } from '@/hostd'
|
|
8
8
|
import { findAgentDir } from '@/init'
|
|
9
9
|
|
|
10
|
-
import { preflightDocker, printDockerGuidance } from './docker-preflight'
|
|
10
|
+
import { type DockerPreflightResult, preflightDocker, printDockerGuidance } from './docker-preflight'
|
|
11
11
|
|
|
12
12
|
export type HostdStatus =
|
|
13
13
|
| { kind: 'unreachable' }
|
|
@@ -26,21 +26,44 @@ export const statusCommand = defineCommand({
|
|
|
26
26
|
description: 'show the agent container and host daemon status (host stage)',
|
|
27
27
|
},
|
|
28
28
|
async run() {
|
|
29
|
-
|
|
29
|
+
await runStatus()
|
|
30
|
+
},
|
|
31
|
+
})
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
// Injectable seam so the render/flow can be exercised without spawning the real
|
|
34
|
+
// Docker CLI. The broken-config path otherwise pays a ~70s Docker Desktop
|
|
35
|
+
// cold-start on the first `docker info` of a Windows CI run; injecting the
|
|
36
|
+
// preflight + exec keeps the test on the pure flow it actually cares about.
|
|
37
|
+
export type RunStatusDeps = {
|
|
38
|
+
cwd?: string
|
|
39
|
+
preflight?: () => Promise<DockerPreflightResult>
|
|
40
|
+
exec?: DockerExec
|
|
41
|
+
fetchHostd?: (containerName: string) => Promise<HostdStatus>
|
|
42
|
+
write?: (text: string) => void
|
|
43
|
+
onDockerUnavailable?: (failure: Extract<DockerPreflightResult, { ok: false }>) => void
|
|
44
|
+
}
|
|
36
45
|
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
export async function runStatus(deps: RunStatusDeps = {}): Promise<void> {
|
|
47
|
+
const cwd = deps.cwd ?? findAgentDir(process.cwd()) ?? process.cwd()
|
|
39
48
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
const preflight = await (deps.preflight ?? preflightDocker)()
|
|
50
|
+
if (!preflight.ok) {
|
|
51
|
+
;(deps.onDockerUnavailable ?? defaultOnDockerUnavailable)(preflight)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const container = await containerStatus({ cwd, exec: deps.exec })
|
|
56
|
+
const hostd = await (deps.fetchHostd ?? fetchHostdStatus)(container.containerName)
|
|
57
|
+
|
|
58
|
+
const useColor = Boolean(process.stdout.isTTY) && process.env.NO_COLOR === undefined
|
|
59
|
+
const write = deps.write ?? ((text: string) => process.stdout.write(text))
|
|
60
|
+
write(`${formatStatus({ cwd, container, hostd }, { useColor })}\n`)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function defaultOnDockerUnavailable(failure: Extract<DockerPreflightResult, { ok: false }>): never {
|
|
64
|
+
printDockerGuidance(failure)
|
|
65
|
+
process.exit(1)
|
|
66
|
+
}
|
|
44
67
|
|
|
45
68
|
async function fetchHostdStatus(containerName: string): Promise<HostdStatus> {
|
|
46
69
|
if (!(await isDaemonReachable())) return { kind: 'unreachable' }
|
|
@@ -15,6 +15,7 @@ export const CHANNEL_KINDS = [
|
|
|
15
15
|
'telegram-bot',
|
|
16
16
|
'webex',
|
|
17
17
|
'webex-bot',
|
|
18
|
+
'instagram',
|
|
18
19
|
'line',
|
|
19
20
|
'kakaotalk',
|
|
20
21
|
'github',
|
|
@@ -189,7 +190,7 @@ function buildDetail(kind: ChannelKind, channelConfig: unknown, secretsBlock: un
|
|
|
189
190
|
const repos = isObjectRecord(channelConfig) && Array.isArray(channelConfig.repos) ? channelConfig.repos.length : 0
|
|
190
191
|
return { detail: `${repos} repo${repos === 1 ? '' : 's'}` }
|
|
191
192
|
}
|
|
192
|
-
if (kind === 'line' || kind === 'kakaotalk' || kind === 'webex' || kind === 'discord') {
|
|
193
|
+
if (kind === 'line' || kind === 'instagram' || kind === 'kakaotalk' || kind === 'webex' || kind === 'discord') {
|
|
193
194
|
if (!isObjectRecord(secretsBlock)) return {}
|
|
194
195
|
const accounts = isObjectRecord(secretsBlock.accounts) ? Object.keys(secretsBlock.accounts).length : 0
|
|
195
196
|
const current = typeof secretsBlock.currentAccount === 'string' ? secretsBlock.currentAccount : undefined
|
|
@@ -32,6 +32,7 @@ export function buildChannelChecks(): DoctorCheck[] {
|
|
|
32
32
|
discordUserCredentials(),
|
|
33
33
|
slackUserCredentials(),
|
|
34
34
|
webexUserCredentials(),
|
|
35
|
+
instagramCredentials(),
|
|
35
36
|
lineCredentials(),
|
|
36
37
|
kakaotalkCredentials(),
|
|
37
38
|
githubCredentials(),
|
|
@@ -157,6 +158,33 @@ function webexUserCredentials(): DoctorCheck {
|
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
|
|
161
|
+
function instagramCredentials(): DoctorCheck {
|
|
162
|
+
return {
|
|
163
|
+
name: 'channel.instagram.credentials',
|
|
164
|
+
category: 'channels',
|
|
165
|
+
description: 'instagram adapter has at least one account in secrets.json',
|
|
166
|
+
applies: (ctx) => ctx.hasAgentFolder,
|
|
167
|
+
async run(ctx) {
|
|
168
|
+
const channels = readDeclaredChannels(ctx)
|
|
169
|
+
if (channels === null) return configInvalidResult()
|
|
170
|
+
if (!isAdapterActive(channels, 'instagram')) {
|
|
171
|
+
return { status: 'skipped', message: 'instagram not configured' }
|
|
172
|
+
}
|
|
173
|
+
const block = readChannelsSecrets(ctx)?.instagram
|
|
174
|
+
const accountCount = block?.accounts ? Object.keys(block.accounts).length : 0
|
|
175
|
+
if (accountCount === 0) {
|
|
176
|
+
return {
|
|
177
|
+
status: 'warning',
|
|
178
|
+
message: 'instagram has no accounts in secrets.json',
|
|
179
|
+
details: ['Adapter will start but fail authentication and stay disconnected.'],
|
|
180
|
+
fix: { description: 'Run `typeclaw channel add instagram` to log in an account.' },
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return { status: 'ok', message: `instagram has ${accountCount} account(s)` }
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
160
188
|
function lineCredentials(): DoctorCheck {
|
|
161
189
|
return {
|
|
162
190
|
name: 'channel.line.credentials',
|
package/src/hostd/daemon.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { defaultDockerExec, type DockerExec, type HostDaemonRegisterPayload } fr
|
|
|
8
8
|
import type { PortForwardEvent } from '@/portbroker'
|
|
9
9
|
import {
|
|
10
10
|
discordChannelBlockSchema,
|
|
11
|
+
instagramChannelBlockSchema,
|
|
11
12
|
kakaoChannelBlockSchema,
|
|
12
13
|
lineChannelBlockSchema,
|
|
13
14
|
slackChannelBlockSchema,
|
|
@@ -530,6 +531,7 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
530
531
|
channels:
|
|
531
532
|
| { kakaotalk: unknown }
|
|
532
533
|
| { discord: unknown }
|
|
534
|
+
| { instagram: unknown }
|
|
533
535
|
| { line: unknown }
|
|
534
536
|
| { webex: unknown }
|
|
535
537
|
| { slack: unknown }
|
|
@@ -545,13 +547,15 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
545
547
|
const patch =
|
|
546
548
|
'line' in channelsPatch
|
|
547
549
|
? { key: 'line' as const, parsed: lineChannelBlockSchema.safeParse(channelsPatch.line) }
|
|
548
|
-
: '
|
|
549
|
-
? { key: '
|
|
550
|
-
: '
|
|
551
|
-
? { key: '
|
|
552
|
-
: '
|
|
553
|
-
? { key: '
|
|
554
|
-
:
|
|
550
|
+
: 'instagram' in channelsPatch
|
|
551
|
+
? { key: 'instagram' as const, parsed: instagramChannelBlockSchema.safeParse(channelsPatch.instagram) }
|
|
552
|
+
: 'discord' in channelsPatch
|
|
553
|
+
? { key: 'discord' as const, parsed: discordChannelBlockSchema.safeParse(channelsPatch.discord) }
|
|
554
|
+
: 'webex' in channelsPatch
|
|
555
|
+
? { key: 'webex' as const, parsed: webexChannelBlockSchema.safeParse(channelsPatch.webex) }
|
|
556
|
+
: 'slack' in channelsPatch
|
|
557
|
+
? { key: 'slack' as const, parsed: slackChannelBlockSchema.safeParse(channelsPatch.slack) }
|
|
558
|
+
: { key: 'kakaotalk' as const, parsed: kakaoChannelBlockSchema.safeParse(channelsPatch.kakaotalk) }
|
|
555
559
|
if (!patch.parsed.success) {
|
|
556
560
|
return { ok: false, reason: patch.parsed.error.issues.map((issue) => issue.message).join('; ') }
|
|
557
561
|
}
|
package/src/hostd/protocol.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PortForward } from '@/config'
|
|
2
2
|
import type {
|
|
3
3
|
DiscordChannelBlock,
|
|
4
|
+
InstagramChannelBlock,
|
|
4
5
|
KakaoChannelBlock,
|
|
5
6
|
LineChannelBlock,
|
|
6
7
|
SlackChannelBlock,
|
|
@@ -28,6 +29,7 @@ export type Request =
|
|
|
28
29
|
channels:
|
|
29
30
|
| { kakaotalk: KakaoChannelBlock }
|
|
30
31
|
| { discord: DiscordChannelBlock }
|
|
32
|
+
| { instagram: InstagramChannelBlock }
|
|
31
33
|
| { line: LineChannelBlock }
|
|
32
34
|
| { webex: WebexChannelBlock }
|
|
33
35
|
| { slack: SlackChannelBlock }
|