typeclaw 0.47.2 → 0.48.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/package.json +1 -1
- package/src/agent/index.ts +1 -2
- package/src/agent/loop-guard.ts +71 -41
- package/src/agent/plugin-tools.ts +167 -50
- package/src/agent/system-prompt.ts +1 -1
- package/src/agent/turn-runner.ts +12 -2
- package/src/bundled-plugins/agent-browser/index.ts +0 -38
- package/src/bundled-plugins/agent-browser/skills/agent-browser/SKILL.md +1 -1
- package/src/bundled-plugins/guard/policies/non-workspace-write.ts +16 -1
- package/src/bundled-plugins/memory/append-tool.ts +75 -2
- package/src/bundled-plugins/memory/frontmatter.ts +13 -2
- package/src/bundled-plugins/memory/load-memory.ts +1 -1
- package/src/bundled-plugins/memory/memory-logger.ts +5 -1
- package/src/bundled-plugins/memory/secret-detector.ts +7 -0
- package/src/bundled-plugins/memory/vector/hybrid.ts +3 -1
- package/src/bundled-plugins/memory/vector/passages.ts +5 -1
- package/src/bundled-plugins/security/index.ts +148 -98
- package/src/bundled-plugins/security/policies/private-surface-read.ts +43 -28
- package/src/channels/adapters/discord-bot-edit.ts +3 -5
- package/src/channels/adapters/discord-bot-reactions.ts +4 -6
- package/src/channels/adapters/discord-bot-slash-commands.ts +3 -1
- package/src/channels/adapters/discord-bot.ts +20 -23
- package/src/channels/adapters/discord-edit.ts +3 -5
- package/src/channels/adapters/discord-reactions.ts +4 -6
- package/src/channels/adapters/discord.ts +1 -1
- package/src/channels/adapters/github/decoy-reviewer.ts +2 -1
- package/src/channels/adapters/github/history.ts +2 -1
- package/src/channels/adapters/github/inbound.ts +4 -11
- package/src/channels/adapters/github/index.ts +6 -9
- package/src/channels/adapters/github/outbound.ts +3 -6
- package/src/channels/adapters/github/reactions.ts +3 -2
- package/src/channels/adapters/github/reconcile-cooldown-store.ts +4 -6
- package/src/channels/adapters/github/reconcile-open-prs.ts +5 -4
- package/src/channels/adapters/github/recover-failed-deliveries.ts +2 -5
- package/src/channels/adapters/github/review-state.ts +3 -2
- package/src/channels/adapters/github/review-thread-resolver.ts +3 -2
- package/src/channels/adapters/github/webhook-register.ts +5 -8
- package/src/channels/adapters/instagram-channel-resolver.ts +3 -5
- package/src/channels/adapters/instagram.ts +1 -1
- package/src/channels/adapters/kakaotalk-author-resolver.ts +2 -5
- package/src/channels/adapters/kakaotalk-channel-resolver.ts +3 -5
- package/src/channels/adapters/kakaotalk-fetch-attachment.ts +2 -1
- package/src/channels/adapters/kakaotalk-membership.ts +2 -5
- package/src/channels/adapters/kakaotalk-typing.ts +1 -1
- package/src/channels/adapters/kakaotalk.ts +1 -1
- package/src/channels/adapters/line-channel-resolver.ts +3 -5
- package/src/channels/adapters/line.ts +1 -1
- package/src/channels/adapters/slack-bot-edit.ts +1 -1
- package/src/channels/adapters/slack-bot-reactions.ts +4 -6
- package/src/channels/adapters/slack-bot.ts +8 -8
- package/src/channels/adapters/slack-edit.ts +3 -5
- package/src/channels/adapters/slack-reactions.ts +4 -6
- package/src/channels/adapters/slack.ts +1 -1
- package/src/channels/adapters/teams-edit.ts +2 -5
- package/src/channels/adapters/teams.ts +1 -1
- package/src/channels/adapters/telegram-bot-edit.ts +4 -7
- package/src/channels/adapters/telegram-bot.ts +1 -1
- package/src/channels/adapters/webex-bot.ts +1 -1
- package/src/channels/adapters/webex-edit.ts +3 -5
- package/src/channels/adapters/webex.ts +1 -1
- package/src/channels/github-review-claim.ts +89 -4
- package/src/channels/github-token-bridge.ts +2 -1
- package/src/channels/manager.ts +478 -64
- package/src/channels/membership-cache.ts +2 -5
- package/src/channels/persistence.ts +3 -6
- package/src/channels/reloadable.ts +23 -6
- package/src/channels/router.ts +134 -56
- package/src/channels/tunnel-bridge.ts +2 -1
- package/src/channels/types.ts +6 -3
- package/src/cli/hostd.ts +56 -28
- package/src/config/config.ts +10 -0
- package/src/config/providers.ts +179 -0
- package/src/dependencies/bin-resolver.ts +88 -0
- package/src/dependencies/bins.ts +227 -0
- package/src/dependencies/index.ts +17 -0
- package/src/doctor/checks.ts +2 -0
- package/src/doctor/operational-incidents.ts +32 -0
- package/src/hostd/credential-rotation-apply.ts +94 -0
- package/src/init/models-dev.ts +17 -3
- package/src/init/validate-api-key.ts +26 -4
- package/src/operations/classify-tool-outcome.ts +151 -0
- package/src/operations/incidents.ts +274 -0
- package/src/operations/index.ts +3 -0
- package/src/operations/remediations.ts +41 -0
- package/src/reload/client.ts +8 -2
- package/src/reload/docker-exec-client.ts +10 -2
- package/src/reload/index.ts +1 -1
- package/src/reload/recover.ts +5 -3
- package/src/reload/registry.ts +5 -5
- package/src/reload/types.ts +9 -1
- package/src/run/index.ts +5 -0
- package/src/sandbox/dependency-bins.ts +125 -0
- package/src/sandbox/errors.ts +32 -0
- package/src/sandbox/hidden-paths.ts +4 -1
- package/src/sandbox/index.ts +8 -0
- package/src/sandbox/policy.ts +1 -1
- package/src/sandbox/privileged-runtime.ts +88 -7
- package/src/sandbox/runtime-private.ts +4 -0
- package/src/sandbox/writable-zones.ts +4 -4
- package/src/server/index.ts +7 -5
- package/src/shared/protocol.ts +6 -1
- package/typeclaw.schema.json +35 -5
- package/src/bundled-plugins/agent-browser/shim-install.ts +0 -179
- package/src/bundled-plugins/agent-browser/shim.ts +0 -108
- /package/src/channels/{adapters/describe-error.ts → describe-error.ts} +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises'
|
|
2
2
|
import { dirname, join } from 'node:path'
|
|
3
3
|
|
|
4
|
+
import { describeError } from '../../describe-error'
|
|
5
|
+
|
|
4
6
|
// Durable per-PR replay cooldown for the open-PR reconcile pass.
|
|
5
7
|
//
|
|
6
8
|
// The reconcile pass (reconcile-open-prs.ts) runs on every adapter start() and
|
|
@@ -128,7 +130,7 @@ export async function loadReconcileCooldownStore(
|
|
|
128
130
|
try {
|
|
129
131
|
await flush()
|
|
130
132
|
} catch (err) {
|
|
131
|
-
logger.error(`[github] failed to persist reconcile cooldown: ${
|
|
133
|
+
logger.error(`[github] failed to persist reconcile cooldown: ${describeError(err)}`)
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
},
|
|
@@ -146,7 +148,7 @@ async function readMarkers(path: string, logger: ReconcileCooldownLogger): Promi
|
|
|
146
148
|
try {
|
|
147
149
|
parsed = JSON.parse(raw)
|
|
148
150
|
} catch (err) {
|
|
149
|
-
logger.error(`[github] ${path} corrupted: ${
|
|
151
|
+
logger.error(`[github] ${path} corrupted: ${describeError(err)}; starting fresh`)
|
|
150
152
|
return []
|
|
151
153
|
}
|
|
152
154
|
if (!isObject(parsed)) {
|
|
@@ -172,7 +174,3 @@ function isValidMarker(v: unknown): v is ReconcileMarker {
|
|
|
172
174
|
const r = v as Record<string, unknown>
|
|
173
175
|
return typeof r.repo === 'string' && typeof r.prId === 'number' && typeof r.lastReplayAt === 'number'
|
|
174
176
|
}
|
|
175
|
-
|
|
176
|
-
function describe(err: unknown): string {
|
|
177
|
-
return err instanceof Error ? err.message : String(err)
|
|
178
|
-
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GithubReviewOn } from '@/channels/schema'
|
|
2
2
|
import type { InboundMessage } from '@/channels/types'
|
|
3
3
|
|
|
4
|
+
import { describeError } from '../../describe-error'
|
|
4
5
|
import type { GithubAuthContext } from './auth'
|
|
5
6
|
import { GITHUB_API_BASE, githubJsonHeaders } from './auth-pat'
|
|
6
7
|
import { DEFAULT_RECONCILE_COOLDOWN_MS, type ReconcileCooldownStore } from './reconcile-cooldown-store'
|
|
@@ -67,7 +68,7 @@ export async function reconcileOpenPrs(options: ReconcileOpenPrsOptions): Promis
|
|
|
67
68
|
options.logger.info(`[github] reconcile ${repo}: replayed ${outcome.replayed}/${outcome.scanned} open PR(s)`)
|
|
68
69
|
}
|
|
69
70
|
} catch (err) {
|
|
70
|
-
const message =
|
|
71
|
+
const message = describeError(err)
|
|
71
72
|
options.logger.warn(`[github] reconcile ${repo} failed: ${message}`)
|
|
72
73
|
outcomes.push({ repo, error: message })
|
|
73
74
|
}
|
|
@@ -103,9 +104,9 @@ async function reconcileRepo(
|
|
|
103
104
|
await cooldownStore.markReplayed(repo, pr.id, now())
|
|
104
105
|
} catch (err) {
|
|
105
106
|
options.logger.warn(
|
|
106
|
-
`[github] reconcile ${repo}: skipping PR #${pr.number} replay, cooldown persist failed: ${
|
|
107
|
-
err
|
|
108
|
-
}`,
|
|
107
|
+
`[github] reconcile ${repo}: skipping PR #${pr.number} replay, cooldown persist failed: ${describeError(
|
|
108
|
+
err,
|
|
109
|
+
)}`,
|
|
109
110
|
)
|
|
110
111
|
continue
|
|
111
112
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describeError } from '../../describe-error'
|
|
1
2
|
import { GITHUB_API_BASE, githubJsonHeaders } from './auth-pat'
|
|
2
3
|
|
|
3
4
|
// Recovers webhook events whose delivery to our ingress FAILED and that GitHub
|
|
@@ -99,7 +100,7 @@ export async function recoverFailedGithubDeliveries(options: RecoverFailedDelive
|
|
|
99
100
|
} catch (err) {
|
|
100
101
|
// Per-hook isolation: one repo's token/list/detail failure must not abort
|
|
101
102
|
// the others. The next interval retries this hook.
|
|
102
|
-
options.logger.warn(`[github] delivery recovery failed for ${hook.repo}: ${
|
|
103
|
+
options.logger.warn(`[github] delivery recovery failed for ${hook.repo}: ${describeError(err)}`)
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
return { recovered, scanned }
|
|
@@ -264,7 +265,3 @@ function nextLink(linkHeader: string | null): string | null {
|
|
|
264
265
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
265
266
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
266
267
|
}
|
|
267
|
-
|
|
268
|
-
function describe(err: unknown): string {
|
|
269
|
-
return err instanceof Error ? err.message : String(err)
|
|
270
|
-
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReviewStateResolver, ReviewStateResult } from '@/channels/types'
|
|
2
2
|
|
|
3
|
+
import { describeError } from '../../describe-error'
|
|
3
4
|
import type { GithubAuthContext } from './auth'
|
|
4
5
|
import { GITHUB_API_BASE, githubJsonHeaders } from './auth-pat'
|
|
5
6
|
|
|
@@ -111,7 +112,7 @@ async function fetchSelfReviews(
|
|
|
111
112
|
try {
|
|
112
113
|
response = await fetchImpl(url, { headers: githubJsonHeaders(token) })
|
|
113
114
|
} catch (err) {
|
|
114
|
-
return { ok: false, error:
|
|
115
|
+
return { ok: false, error: describeError(err), code: 'transient' }
|
|
115
116
|
}
|
|
116
117
|
if (!response.ok) {
|
|
117
118
|
const text = await response.text().catch(() => '')
|
|
@@ -153,7 +154,7 @@ async function fetchReviewDecision(
|
|
|
153
154
|
}),
|
|
154
155
|
})
|
|
155
156
|
} catch (err) {
|
|
156
|
-
return { ok: false, error:
|
|
157
|
+
return { ok: false, error: describeError(err), code: 'transient' }
|
|
157
158
|
}
|
|
158
159
|
if (!response.ok) {
|
|
159
160
|
const text = await response.text().catch(() => '')
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReviewThreadResolveRequest, ReviewThreadResolveResult, ReviewThreadResolver } from '@/channels/types'
|
|
2
2
|
|
|
3
|
+
import { describeError } from '../../describe-error'
|
|
3
4
|
import type { GithubAuthContext } from './auth'
|
|
4
5
|
import { GITHUB_API_BASE, githubJsonHeaders } from './auth-pat'
|
|
5
6
|
|
|
@@ -233,7 +234,7 @@ async function walkThreadPages(
|
|
|
233
234
|
} catch (err) {
|
|
234
235
|
return {
|
|
235
236
|
kind: 'error',
|
|
236
|
-
result: { ok: false, error:
|
|
237
|
+
result: { ok: false, error: describeError(err), code: 'transient' },
|
|
237
238
|
}
|
|
238
239
|
}
|
|
239
240
|
const parsed = await parseThreadsPage(response)
|
|
@@ -308,7 +309,7 @@ async function runResolveMutation(
|
|
|
308
309
|
body: JSON.stringify({ query: RESOLVE_MUTATION, variables: { threadId } }),
|
|
309
310
|
})
|
|
310
311
|
} catch (err) {
|
|
311
|
-
return { ok: false, error:
|
|
312
|
+
return { ok: false, error: describeError(err), code: 'transient' }
|
|
312
313
|
}
|
|
313
314
|
if (!response.ok) {
|
|
314
315
|
const text = await response.text().catch(() => '')
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describeError } from '../../describe-error'
|
|
1
2
|
import { GITHUB_API_BASE, githubJsonHeaders } from './auth-pat'
|
|
2
3
|
|
|
3
4
|
export type RegisterGithubWebhooksOptions = {
|
|
@@ -68,7 +69,7 @@ export async function registerGithubWebhooks(
|
|
|
68
69
|
try {
|
|
69
70
|
token = await options.token(repo)
|
|
70
71
|
} catch (err) {
|
|
71
|
-
return { repo, action: 'failed', error:
|
|
72
|
+
return { repo, action: 'failed', error: describeError(err) }
|
|
72
73
|
}
|
|
73
74
|
return registerOne(fetchImpl, token, repo, options)
|
|
74
75
|
}),
|
|
@@ -96,7 +97,7 @@ export async function deregisterGithubWebhooks(
|
|
|
96
97
|
try {
|
|
97
98
|
token = await options.token(hook.repo)
|
|
98
99
|
} catch (err) {
|
|
99
|
-
return { ...hook, action: 'failed', error:
|
|
100
|
+
return { ...hook, action: 'failed', error: describeError(err) }
|
|
100
101
|
}
|
|
101
102
|
return deleteOne(fetchImpl, token, hook)
|
|
102
103
|
}),
|
|
@@ -137,7 +138,7 @@ async function registerOne(
|
|
|
137
138
|
const stalePruned = pruned.filter(Boolean).length
|
|
138
139
|
return { repo, action: 'updated', hookId: keep!, stalePruned }
|
|
139
140
|
} catch (err) {
|
|
140
|
-
return { repo, action: 'failed', error:
|
|
141
|
+
return { repo, action: 'failed', error: describeError(err) }
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
|
|
@@ -166,7 +167,7 @@ async function deleteOne(
|
|
|
166
167
|
}
|
|
167
168
|
return { ...hook, action: 'deleted' }
|
|
168
169
|
} catch (err) {
|
|
169
|
-
return { ...hook, action: 'failed', error:
|
|
170
|
+
return { ...hook, action: 'failed', error: describeError(err) }
|
|
170
171
|
}
|
|
171
172
|
}
|
|
172
173
|
|
|
@@ -351,7 +352,3 @@ function toCoarseEvents(events: readonly string[]): string[] {
|
|
|
351
352
|
}
|
|
352
353
|
return [...seen]
|
|
353
354
|
}
|
|
354
|
-
|
|
355
|
-
function describe(err: unknown): string {
|
|
356
|
-
return err instanceof Error ? err.message : String(err)
|
|
357
|
-
}
|
|
@@ -2,6 +2,8 @@ import type { InstagramChatSummary } from 'agent-messenger/instagram'
|
|
|
2
2
|
|
|
3
3
|
import type { ChannelKey, ChannelNameResolver, ResolvedChannelNames } from '@/channels/types'
|
|
4
4
|
|
|
5
|
+
import { describeError } from '../describe-error'
|
|
6
|
+
|
|
5
7
|
const DEFAULT_TTL_MS = 5 * 60 * 1000
|
|
6
8
|
const CHAT_FETCH_LIMIT = 500
|
|
7
9
|
|
|
@@ -64,7 +66,7 @@ export function createInstagramChannelResolver(options: InstagramChannelResolver
|
|
|
64
66
|
const expiresAt = now() + ttlMs
|
|
65
67
|
for (const chat of chats) ingest(chat, expiresAt)
|
|
66
68
|
} catch (err) {
|
|
67
|
-
options.logger?.warn(`[instagram] channel resolver refresh failed: ${
|
|
69
|
+
options.logger?.warn(`[instagram] channel resolver refresh failed: ${describeError(err)}`)
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
|
|
@@ -107,7 +109,3 @@ export function createInstagramChannelResolver(options: InstagramChannelResolver
|
|
|
107
109
|
|
|
108
110
|
return { resolve, lookupChat, refresh, ingestProvisional }
|
|
109
111
|
}
|
|
110
|
-
|
|
111
|
-
function describe(err: unknown): string {
|
|
112
|
-
return err instanceof Error ? err.message : String(err)
|
|
113
|
-
}
|
|
@@ -19,7 +19,7 @@ import type {
|
|
|
19
19
|
SendResult,
|
|
20
20
|
} from '@/channels/types'
|
|
21
21
|
|
|
22
|
-
import { describeError } from '
|
|
22
|
+
import { describeError } from '../describe-error'
|
|
23
23
|
import { createInstagramChannelResolver } from './instagram-channel-resolver'
|
|
24
24
|
import { classifyInbound } from './instagram-classify'
|
|
25
25
|
import { toInstagramPlainText } from './instagram-format'
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describeError } from '../describe-error'
|
|
1
2
|
import type { KakaoTalkClient } from './kakaotalk'
|
|
2
3
|
|
|
3
4
|
const DEFAULT_TTL_MS = 5 * 60 * 1000
|
|
@@ -50,7 +51,7 @@ export function createKakaoAuthorResolver(options: KakaoAuthorResolverOptions):
|
|
|
50
51
|
.catch((err: unknown): null => {
|
|
51
52
|
// Author resolution is best-effort. Failing here makes the message
|
|
52
53
|
// render with the raw user_id, which is uglier but still routes.
|
|
53
|
-
logger?.warn(`[kakaotalk] getMembers(${chatId}) failed: ${
|
|
54
|
+
logger?.warn(`[kakaotalk] getMembers(${chatId}) failed: ${describeError(err)}`)
|
|
54
55
|
return null
|
|
55
56
|
})
|
|
56
57
|
.finally(() => {
|
|
@@ -72,7 +73,3 @@ export function createKakaoAuthorResolver(options: KakaoAuthorResolverOptions):
|
|
|
72
73
|
|
|
73
74
|
return { resolve }
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
-
function describe(err: unknown): string {
|
|
77
|
-
return err instanceof Error ? err.message : String(err)
|
|
78
|
-
}
|
|
@@ -2,6 +2,8 @@ import { classifyKakaoChat, type KakaoChat, type KakaoChatKind, type KakaoTalkCl
|
|
|
2
2
|
|
|
3
3
|
import type { ChannelKey, ChannelNameResolver, ResolvedChannelNames } from '@/channels/types'
|
|
4
4
|
|
|
5
|
+
import { describeError } from '../describe-error'
|
|
6
|
+
|
|
5
7
|
const DEFAULT_TTL_MS = 5 * 60 * 1000
|
|
6
8
|
|
|
7
9
|
export type KakaoWorkspace = '@kakao-dm' | '@kakao-group' | '@kakao-open'
|
|
@@ -78,7 +80,7 @@ export function createKakaoChannelResolver(options: KakaoChannelResolverOptions)
|
|
|
78
80
|
const expiresAt = now() + ttlMs
|
|
79
81
|
for (const chat of chats) ingest(chat, expiresAt)
|
|
80
82
|
} catch (err) {
|
|
81
|
-
options.logger?.warn(`[kakaotalk] channel resolver refresh failed: ${
|
|
83
|
+
options.logger?.warn(`[kakaotalk] channel resolver refresh failed: ${describeError(err)}`)
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
|
|
@@ -129,7 +131,3 @@ export function createKakaoChannelResolver(options: KakaoChannelResolverOptions)
|
|
|
129
131
|
|
|
130
132
|
return { resolve, lookupChat, refresh, ingestProvisional }
|
|
131
133
|
}
|
|
132
|
-
|
|
133
|
-
function describe(err: unknown): string {
|
|
134
|
-
return err instanceof Error ? err.message : String(err)
|
|
135
|
-
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
} from '@/channels/fetch-attachment'
|
|
6
6
|
import type { FetchAttachmentCallback } from '@/channels/types'
|
|
7
7
|
|
|
8
|
+
import { describeError } from '../describe-error'
|
|
8
9
|
import type { KakaotalkAdapterLogger } from './kakaotalk'
|
|
9
10
|
|
|
10
11
|
// KakaoCDN hosts that the LOCO push payload mints pre-signed URLs against.
|
|
@@ -68,7 +69,7 @@ export function createFetchAttachmentCallback(deps: {
|
|
|
68
69
|
size: buffer.length,
|
|
69
70
|
}
|
|
70
71
|
} catch (err) {
|
|
71
|
-
const message =
|
|
72
|
+
const message = describeError(err)
|
|
72
73
|
logger.error(`[kakaotalk] fetchAttachment failed for ${url.toString()}: ${message}`)
|
|
73
74
|
return { ok: false, error: message }
|
|
74
75
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describeError } from '../describe-error'
|
|
1
2
|
import type {
|
|
2
3
|
MembershipCount,
|
|
3
4
|
MembershipResolver,
|
|
@@ -56,12 +57,8 @@ export function createKakaoMembershipResolver(options: KakaoMembershipResolverOp
|
|
|
56
57
|
humanMemberIds,
|
|
57
58
|
} satisfies MembershipCount
|
|
58
59
|
} catch (err) {
|
|
59
|
-
options.logger.warn(`[kakaotalk] membership chat=${key.chat} failed: ${
|
|
60
|
+
options.logger.warn(`[kakaotalk] membership chat=${key.chat} failed: ${describeError(err)}`)
|
|
60
61
|
return { kind: 'transient' } satisfies MembershipResolverFailure
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
function describe(err: unknown): string {
|
|
66
|
-
return err instanceof Error ? err.message : String(err)
|
|
67
|
-
}
|
|
@@ -2,7 +2,7 @@ import type { KakaoTypingResult } from 'agent-messenger/kakaotalk'
|
|
|
2
2
|
|
|
3
3
|
import type { TypingCallback } from '@/channels/types'
|
|
4
4
|
|
|
5
|
-
import { describeError } from '
|
|
5
|
+
import { describeError } from '../describe-error'
|
|
6
6
|
|
|
7
7
|
export type KakaoTypingLogger = {
|
|
8
8
|
info: (msg: string) => void
|
|
@@ -2,6 +2,8 @@ import type { LineChat, LineClient } from 'agent-messenger/line'
|
|
|
2
2
|
|
|
3
3
|
import type { ChannelKey, ChannelNameResolver, ResolvedChannelNames } from '@/channels/types'
|
|
4
4
|
|
|
5
|
+
import { describeError } from '../describe-error'
|
|
6
|
+
|
|
5
7
|
const DEFAULT_TTL_MS = 5 * 60 * 1000
|
|
6
8
|
|
|
7
9
|
// LINE's chat list is fetched in a bounded page; there is no `{ all: true }`
|
|
@@ -77,7 +79,7 @@ export function createLineChannelResolver(options: LineChannelResolverOptions):
|
|
|
77
79
|
const expiresAt = now() + ttlMs
|
|
78
80
|
for (const chat of chats) ingest(chat, expiresAt)
|
|
79
81
|
} catch (err) {
|
|
80
|
-
options.logger?.warn(`[line] channel resolver refresh failed: ${
|
|
82
|
+
options.logger?.warn(`[line] channel resolver refresh failed: ${describeError(err)}`)
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
|
|
@@ -123,7 +125,3 @@ export function createLineChannelResolver(options: LineChannelResolverOptions):
|
|
|
123
125
|
|
|
124
126
|
return { resolve, lookupChat, refresh, ingestProvisional }
|
|
125
127
|
}
|
|
126
|
-
|
|
127
|
-
function describe(err: unknown): string {
|
|
128
|
-
return err instanceof Error ? err.message : String(err)
|
|
129
|
-
}
|
|
@@ -25,7 +25,7 @@ import type {
|
|
|
25
25
|
SendResult,
|
|
26
26
|
} from '@/channels/types'
|
|
27
27
|
|
|
28
|
-
import { describeError } from '
|
|
28
|
+
import { describeError } from '../describe-error'
|
|
29
29
|
import { splitInboundLine } from './line-attachment'
|
|
30
30
|
import { createLineChannelResolver } from './line-channel-resolver'
|
|
31
31
|
import { classifyInbound } from './line-classify'
|
|
@@ -8,6 +8,8 @@ import type {
|
|
|
8
8
|
RemoveReactionCallback,
|
|
9
9
|
} from '@/channels/types'
|
|
10
10
|
|
|
11
|
+
import { describeError } from '../describe-error'
|
|
12
|
+
|
|
11
13
|
// The reactable target on Slack: a message is addressed by its channel id plus
|
|
12
14
|
// the message `ts`. The classifier stamps this because `ts` is the inbound's
|
|
13
15
|
// own message timestamp — the same value that becomes `externalMessageId`
|
|
@@ -78,7 +80,7 @@ export function createSlackReactionCallback(deps: { client: Pick<SlackBotClient,
|
|
|
78
80
|
if (code === 'already_reacted') {
|
|
79
81
|
return { ok: true, reactionRef: encodeSlackRemovalRef({ ...target, emoji }) }
|
|
80
82
|
}
|
|
81
|
-
return { ok: false, error: withScopeHint(code,
|
|
83
|
+
return { ok: false, error: withScopeHint(code, describeError(err)), code: classifySlackError(code) }
|
|
82
84
|
}
|
|
83
85
|
return { ok: true, reactionRef: encodeSlackRemovalRef({ ...target, emoji }) }
|
|
84
86
|
}
|
|
@@ -101,7 +103,7 @@ export function createSlackRemoveReactionCallback(deps: {
|
|
|
101
103
|
// `already_reacted` handling on the add path.
|
|
102
104
|
const code = slackErrorCode(err)
|
|
103
105
|
if (code === 'no_reaction') return { ok: true }
|
|
104
|
-
return { ok: false, error:
|
|
106
|
+
return { ok: false, error: describeError(err), code: classifySlackError(code) }
|
|
105
107
|
}
|
|
106
108
|
return { ok: true }
|
|
107
109
|
}
|
|
@@ -161,7 +163,3 @@ function parseRecord(value: string): Record<string, unknown> | null {
|
|
|
161
163
|
? (parsed as Record<string, unknown>)
|
|
162
164
|
: null
|
|
163
165
|
}
|
|
164
|
-
|
|
165
|
-
function describe(err: unknown): string {
|
|
166
|
-
return err instanceof Error ? err.message : String(err)
|
|
167
|
-
}
|
|
@@ -40,7 +40,7 @@ import type {
|
|
|
40
40
|
} from '@/channels/types'
|
|
41
41
|
import { chunkMarkdown } from '@/markdown'
|
|
42
42
|
|
|
43
|
-
import { describeError } from '
|
|
43
|
+
import { describeError } from '../describe-error'
|
|
44
44
|
import { addSlackMentionHints } from './mention-hints'
|
|
45
45
|
import { downloadSlackAttachment, type SlackAttachmentFetch } from './slack-attachment-download'
|
|
46
46
|
import { createSlackAuthorResolver, type SlackAuthorResolver } from './slack-bot-author-resolver'
|
|
@@ -720,7 +720,7 @@ export function createSlackHistoryCallback(deps: {
|
|
|
720
720
|
})
|
|
721
721
|
raw = (await response.json()) as SlackHistoryResponse
|
|
722
722
|
} catch (err) {
|
|
723
|
-
const message =
|
|
723
|
+
const message = describeError(err)
|
|
724
724
|
logger.warn(`[slack-bot] history fetch failed: ${message}`)
|
|
725
725
|
return { ok: false, error: message }
|
|
726
726
|
}
|
|
@@ -800,7 +800,7 @@ export function createSlackMessageGetCallback(deps: {
|
|
|
800
800
|
})
|
|
801
801
|
raw = (await response.json()) as SlackHistoryResponse
|
|
802
802
|
} catch (err) {
|
|
803
|
-
const message =
|
|
803
|
+
const message = describeError(err)
|
|
804
804
|
logger.warn(`[slack-bot] message get failed: ${message}`)
|
|
805
805
|
return { ok: false, error: message }
|
|
806
806
|
}
|
|
@@ -847,7 +847,7 @@ export function createSlackListCallback(deps: {
|
|
|
847
847
|
})
|
|
848
848
|
raw = (await response.json()) as SlackConversationsListResponse
|
|
849
849
|
} catch (err) {
|
|
850
|
-
const message =
|
|
850
|
+
const message = describeError(err)
|
|
851
851
|
logger.warn(`[slack-bot] channel list failed: ${message}`)
|
|
852
852
|
return { ok: false, error: message }
|
|
853
853
|
}
|
|
@@ -1008,7 +1008,7 @@ export function createOutboundCallback(deps: {
|
|
|
1008
1008
|
if (typingTracker) await typingTracker.clearAfterSend(msg.chat, msg.typingThread ?? msg.thread)
|
|
1009
1009
|
return { ok: true, messageId: sentTs[0], messageIds: sentTs }
|
|
1010
1010
|
} catch (err) {
|
|
1011
|
-
const message =
|
|
1011
|
+
const message = describeError(err)
|
|
1012
1012
|
logger.error(`[slack-bot] postMessage failed: ${message}`)
|
|
1013
1013
|
return { ok: false, error: message }
|
|
1014
1014
|
}
|
|
@@ -1021,7 +1021,7 @@ export function createOutboundCallback(deps: {
|
|
|
1021
1021
|
try {
|
|
1022
1022
|
buffer = await readFile(attachment.path)
|
|
1023
1023
|
} catch (err) {
|
|
1024
|
-
const message =
|
|
1024
|
+
const message = describeError(err)
|
|
1025
1025
|
logger.error(`[slack-bot] readFile failed for ${attachment.path}: ${message}`)
|
|
1026
1026
|
return { ok: false, error: `readFile failed: ${message}` }
|
|
1027
1027
|
}
|
|
@@ -1037,7 +1037,7 @@ export function createOutboundCallback(deps: {
|
|
|
1037
1037
|
const file = await client.uploadFile(msg.chat, buffer, filename, uploadOptions)
|
|
1038
1038
|
logger.info(`[slack-bot] uploaded id=${file.id} filename=${file.name} size=${file.size} ${tag}`)
|
|
1039
1039
|
} catch (err) {
|
|
1040
|
-
const message =
|
|
1040
|
+
const message = describeError(err)
|
|
1041
1041
|
logger.error(`[slack-bot] uploadFile failed for ${attachment.path}: ${message}`)
|
|
1042
1042
|
return { ok: false, error: `uploadFile failed: ${message}` }
|
|
1043
1043
|
}
|
|
@@ -1085,7 +1085,7 @@ export function createFetchAttachmentCallback(deps: {
|
|
|
1085
1085
|
size: buffer.length,
|
|
1086
1086
|
}
|
|
1087
1087
|
} catch (err) {
|
|
1088
|
-
const message =
|
|
1088
|
+
const message = describeError(err)
|
|
1089
1089
|
logger.error(`[slack-bot] downloadFile failed for ${fileId}: ${message}`)
|
|
1090
1090
|
return { ok: false, error: message }
|
|
1091
1091
|
}
|
|
@@ -2,6 +2,8 @@ import type { SlackClient } from 'agent-messenger/slack'
|
|
|
2
2
|
|
|
3
3
|
import type { EditMessageCallback, EditMessageResult } from '@/channels/types'
|
|
4
4
|
|
|
5
|
+
import { describeError } from '../describe-error'
|
|
6
|
+
|
|
5
7
|
export function createSlackUserEditMessageCallback(deps: {
|
|
6
8
|
client: Pick<SlackClient, 'updateMessage'>
|
|
7
9
|
}): EditMessageCallback {
|
|
@@ -13,7 +15,7 @@ export function createSlackUserEditMessageCallback(deps: {
|
|
|
13
15
|
await deps.client.updateMessage(req.chat, req.messageId, req.text)
|
|
14
16
|
} catch (err) {
|
|
15
17
|
const code = slackErrorCode(err)
|
|
16
|
-
return { ok: false, error:
|
|
18
|
+
return { ok: false, error: describeError(err), code: classifyEditError(code) }
|
|
17
19
|
}
|
|
18
20
|
return { ok: true }
|
|
19
21
|
}
|
|
@@ -41,7 +43,3 @@ function classifyEditError(code: string | null): NonNullable<(EditMessageResult
|
|
|
41
43
|
return 'not-found'
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
|
-
|
|
45
|
-
function describe(err: unknown): string {
|
|
46
|
-
return err instanceof Error ? err.message : String(err)
|
|
47
|
-
}
|
|
@@ -8,6 +8,8 @@ import type {
|
|
|
8
8
|
RemoveReactionCallback,
|
|
9
9
|
} from '@/channels/types'
|
|
10
10
|
|
|
11
|
+
import { describeError } from '../describe-error'
|
|
12
|
+
|
|
11
13
|
export type SlackReactionTarget = { channel: string; ts: string }
|
|
12
14
|
export type SlackReactionRemovalTarget = { channel: string; ts: string; emoji: string }
|
|
13
15
|
|
|
@@ -51,7 +53,7 @@ export function createSlackReactionCallback(deps: { client: Pick<SlackClient, 'a
|
|
|
51
53
|
} catch (err) {
|
|
52
54
|
const code = slackErrorCode(err)
|
|
53
55
|
if (code === 'already_reacted') return { ok: true, reactionRef: encodeSlackRemovalRef({ ...target, emoji }) }
|
|
54
|
-
return { ok: false, error:
|
|
56
|
+
return { ok: false, error: describeError(err), code: classifySlackError(code) }
|
|
55
57
|
}
|
|
56
58
|
return { ok: true, reactionRef: encodeSlackRemovalRef({ ...target, emoji }) }
|
|
57
59
|
}
|
|
@@ -69,7 +71,7 @@ export function createSlackRemoveReactionCallback(deps: {
|
|
|
69
71
|
} catch (err) {
|
|
70
72
|
const code = slackErrorCode(err)
|
|
71
73
|
if (code === 'no_reaction') return { ok: true }
|
|
72
|
-
return { ok: false, error:
|
|
74
|
+
return { ok: false, error: describeError(err), code: classifySlackError(code) }
|
|
73
75
|
}
|
|
74
76
|
return { ok: true }
|
|
75
77
|
}
|
|
@@ -120,7 +122,3 @@ function parseRecord(value: string): Record<string, unknown> | null {
|
|
|
120
122
|
? (parsed as Record<string, unknown>)
|
|
121
123
|
: null
|
|
122
124
|
}
|
|
123
|
-
|
|
124
|
-
function describe(err: unknown): string {
|
|
125
|
-
return err instanceof Error ? err.message : String(err)
|
|
126
|
-
}
|
|
@@ -33,7 +33,7 @@ import type {
|
|
|
33
33
|
import { chunkMarkdown } from '@/markdown'
|
|
34
34
|
import type { SlackAccountRecord } from '@/secrets/schema'
|
|
35
35
|
|
|
36
|
-
import { describeError } from '
|
|
36
|
+
import { describeError } from '../describe-error'
|
|
37
37
|
import { downloadSlackAttachment, type SlackAttachmentFetch } from './slack-attachment-download'
|
|
38
38
|
import { createSlackAuthorResolver } from './slack-author-resolver'
|
|
39
39
|
import { slackTsToMillis } from './slack-bot-time'
|
|
@@ -2,6 +2,7 @@ import type { TeamsClient } from 'agent-messenger/teams'
|
|
|
2
2
|
|
|
3
3
|
import type { EditMessageCallback, EditMessageResult } from '@/channels/types'
|
|
4
4
|
|
|
5
|
+
import { describeError } from '../describe-error'
|
|
5
6
|
import { decodeTeamsConversationKey } from './teams-key'
|
|
6
7
|
|
|
7
8
|
// The Teams user-account SDK only exposes an edit primitive for 1:1/group
|
|
@@ -25,7 +26,7 @@ export function createTeamsEditMessageCallback(deps: {
|
|
|
25
26
|
try {
|
|
26
27
|
await deps.client.editChatMessage(decoded.chatId, req.messageId, req.text)
|
|
27
28
|
} catch (err) {
|
|
28
|
-
return { ok: false, error:
|
|
29
|
+
return { ok: false, error: describeError(err), code: classifyEditError(err) }
|
|
29
30
|
}
|
|
30
31
|
return { ok: true }
|
|
31
32
|
}
|
|
@@ -55,7 +56,3 @@ function errorCode(err: unknown): string | null {
|
|
|
55
56
|
}
|
|
56
57
|
return null
|
|
57
58
|
}
|
|
58
|
-
|
|
59
|
-
function describe(err: unknown): string {
|
|
60
|
-
return err instanceof Error ? err.message : String(err)
|
|
61
|
-
}
|
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
} from '@/channels/types'
|
|
16
16
|
import type { TeamsAccountRecord } from '@/secrets/schema'
|
|
17
17
|
|
|
18
|
-
import { describeError } from '
|
|
18
|
+
import { describeError } from '../describe-error'
|
|
19
19
|
import {
|
|
20
20
|
classifyChannelInbound,
|
|
21
21
|
classifyChatInbound,
|
|
@@ -2,6 +2,7 @@ import type { TelegramBotClient } from 'agent-messenger/telegrambot'
|
|
|
2
2
|
|
|
3
3
|
import type { EditMessageCallback, EditMessageResult } from '@/channels/types'
|
|
4
4
|
|
|
5
|
+
import { describeError } from '../describe-error'
|
|
5
6
|
import { toTelegramMarkdownV2 } from './telegram-bot-format'
|
|
6
7
|
|
|
7
8
|
export function createTelegramEditMessageCallback(deps: {
|
|
@@ -31,8 +32,8 @@ export function createTelegramEditMessageCallback(deps: {
|
|
|
31
32
|
// "message is not modified" fires when the new text equals the current
|
|
32
33
|
// body — the desired end state already holds, so treat it as success
|
|
33
34
|
// (idempotent), mirroring the reaction adapters' already-in-state handling.
|
|
34
|
-
if (
|
|
35
|
-
return { ok: false, error:
|
|
35
|
+
if (describeError(err).toLowerCase().includes('message is not modified')) return { ok: true }
|
|
36
|
+
return { ok: false, error: describeError(err), code: classifyEditError(err) }
|
|
36
37
|
}
|
|
37
38
|
return { ok: true }
|
|
38
39
|
}
|
|
@@ -41,11 +42,7 @@ export function createTelegramEditMessageCallback(deps: {
|
|
|
41
42
|
// "message to edit not found" / "message can't be edited" (too old) map to
|
|
42
43
|
// not-found; a chat-permission error to permission-denied.
|
|
43
44
|
function classifyEditError(err: unknown): NonNullable<(EditMessageResult & { ok: false })['code']> {
|
|
44
|
-
const message =
|
|
45
|
+
const message = describeError(err).toLowerCase()
|
|
45
46
|
if (message.includes('not enough rights') || message.includes('forbidden')) return 'permission-denied'
|
|
46
47
|
return 'not-found'
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
-
function describe(err: unknown): string {
|
|
50
|
-
return err instanceof Error ? err.message : String(err)
|
|
51
|
-
}
|
|
@@ -22,7 +22,7 @@ import type {
|
|
|
22
22
|
TypingTarget,
|
|
23
23
|
} from '@/channels/types'
|
|
24
24
|
|
|
25
|
-
import { describeError } from '
|
|
25
|
+
import { describeError } from '../describe-error'
|
|
26
26
|
import { classifyInbound, type InboundDropReason, TELEGRAM_WORKSPACE } from './telegram-bot-classify'
|
|
27
27
|
import { createTelegramEditMessageCallback } from './telegram-bot-edit'
|
|
28
28
|
import { toTelegramMarkdownV2 } from './telegram-bot-format'
|
|
@@ -34,7 +34,7 @@ import type {
|
|
|
34
34
|
SendResult,
|
|
35
35
|
} from '@/channels/types'
|
|
36
36
|
|
|
37
|
-
import { describeError } from '
|
|
37
|
+
import { describeError } from '../describe-error'
|
|
38
38
|
import { createWebexChannelNameResolver } from './webex-bot-channel-resolver'
|
|
39
39
|
import { classifyInbound, type InboundDropReason, type WebexInboundMessage } from './webex-bot-classify'
|
|
40
40
|
import { enrichWebexMessageReference } from './webex-bot-reference'
|