Personal Telegram developer console for GitHub
fix: recover durable workspace after approved write failure
davoodmehraban89 committed
Oct 4, 2026 at 07:41 UTC
13c1dce244cc257ed2c64cca8cd1033ba1952d31
1 file changed
+7
-53
src/bot.js
+7
-53
@@ -8,7 +8,7 @@ import { DurableApprovalReplayStore } from './core/durable-replay-store.js';
8
import { DurableWorkspaceStoreClient } from './core/workspace-store.js';
9
import { AuditLogger } from './core/audit.js';
10
import { PluginRouter } from './core/router.js';
11
-import { buildCallbackFailureView } from './core/callback-failure-view.js';
11
+import { buildApprovedActionFailedView, buildCallbackFailureView } from './core/callback-failure-view.js';
12
import { createGitHubPlugin } from './plugins/github/plugin.js';
13
14
const INTENT_ID_PATTERN = /^[A-Za-z0-9_-]{8}$/;
@@ -106,57 +106,6 @@ ${detail}
106
};
107
}
108
109
-function approvedActionFailedView(payload, error) {
110
- const reason = String(error?.message || 'GitHub operation failed');
111
- const permissionDenied = /403|resource not accessible by personal access token/i.test(reason);
112
- const repoId = payload?.input?.repoId;
113
- const runId = payload?.input?.runId;
114
- const workspaceAction = payload?.actionId === 'github.workspace.commit_branch';
115
- const fallback = workspaceAction && Number.isSafeInteger(Number(repoId))
116
- ? `repo:${repoId}`
117
- : Number.isSafeInteger(Number(repoId)) && Number.isSafeInteger(Number(runId))
118
- ? `run:${repoId}:${runId}`
119
- : 'menu:main';
120
- const detail = workspaceAction
121
- ? permissionDenied
122
- ? 'تأیید شما معتبر بود، اما GitHub درخواست Commit شاخه را با خطای 403 رد کرد. دسترسی Contents WRITE توکن فعلی را بررسی کنید.'
123
- : `تأیید شما معتبر بود، اما Commit شاخه انجام نشد: ${escapeHtml(reason)}`
124
- : permissionDenied
125
- ? 'تأیید شما معتبر بود، اما GitHub درخواست را با خطای 403 رد کرد. دسترسی توکن فعلی برای GitHub Actions WRITE کافی نیست.'
126
- : 'تأیید شما معتبر بود، اما GitHub عملیات را موفق اعلام نکرد. وضعیت Run را بررسی کنید.';
127
- return {
128
- text:
129
-`⚠️ <b>اجرای عملیات در GitHub ناموفق بود</b>
130
-➖➖➖➖➖➖➖➖➖➖
131
-${detail}
132
-
133
-این تأیید یکبار مصرف شده و با همان دکمه دوباره اجرا نمیشود.`,
134
- reply_markup: { inline_keyboard: [[{ text: workspaceAction ? '↩️ بازگشت به پروژه' : '↩️ بازگشت به Run', callback_data: fallback }]] }
135
- };
136
-}
137
-
138
-function callbackReadFailedView(data, error) {
139
- const reason = String(error?.message || 'Provider read failed');
140
- const permissionDenied = /403|resource not accessible by personal access token/i.test(reason);
141
- const repoMatch = String(data || '').match(/^[^:]+:(\d+)/);
142
- const fallback = repoMatch ? `repo:${repoMatch[1]}` : 'menu:main';
143
- const isIssues = String(data || '').startsWith('issues:');
144
- const detail = permissionDenied
145
- ? isIssues
146
- ? 'GitHub درخواست Issues را با خطای 403 رد کرد. در Fine-grained token، مجوز Repository permissions → Issues را روی Read قرار دهید.'
147
- : 'GitHub این درخواست خواندنی را با خطای 403 رد کرد. مجوز Read مربوط به این بخش در توکن فعلی کافی نیست.'
148
- : 'دریافت اطلاعات از سرویس با خطا مواجه شد. هیچ تغییری انجام نشد.';
149
- return {
150
- text:
151
-`⚠️ <b>دریافت اطلاعات با خطا مواجه شد</b>
152
-➖➖➖➖➖➖➖➖➖➖
153
-${detail}
154
-
155
-این خطا هیچ عملیات تغییردهندهای اجرا نکرد.`,
156
- reply_markup: { inline_keyboard: [[{ text: repoMatch ? '↩️ بازگشت به پروژه' : '↩️ منوی اصلی', callback_data: fallback }]] }
157
- };
158
-}
159
-
109
export class NexaDevBot {
110
constructor(env = {}) {
111
this.env = env;
@@ -226,7 +175,12 @@ export class NexaDevBot {
175
});
176
if (!routed || routed.requiresApproval || routed.denied) throw new Error('Approved action could not be dispatched');
177
} catch (error) {
229
- const view = approvedActionFailedView(payload, error);
178
+ const view = await buildApprovedActionFailedView({
179
+ payload,
180
+ error,
181
+ ownerId,
182
+ workspaces: this.workspaceStore
183
+ });
184
const res = await this.telegram.editMessageText(chatId, messageId, view.text, view.reply_markup);
185
return { ok: false, approved: true, providerError: true, actionId: payload.actionId, error: error?.message || 'GitHub operation failed', callbackAnswered, edited: true, res };
186
}