@nathapp/nax 0.50.3 → 0.51.2
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/CHANGELOG.md +30 -0
- package/README.md +177 -104
- package/dist/nax.js +417 -213
- package/package.json +1 -3
- package/bin/nax.ts +0 -1195
- package/src/acceptance/fix-generator.ts +0 -322
- package/src/acceptance/generator.ts +0 -415
- package/src/acceptance/index.ts +0 -42
- package/src/acceptance/refinement.ts +0 -224
- package/src/acceptance/templates/cli.ts +0 -47
- package/src/acceptance/templates/component.ts +0 -78
- package/src/acceptance/templates/e2e.ts +0 -43
- package/src/acceptance/templates/index.ts +0 -21
- package/src/acceptance/templates/snapshot.ts +0 -50
- package/src/acceptance/templates/unit.ts +0 -48
- package/src/acceptance/types.ts +0 -138
- package/src/agents/acp/adapter.ts +0 -888
- package/src/agents/acp/cost.ts +0 -9
- package/src/agents/acp/index.ts +0 -7
- package/src/agents/acp/interaction-bridge.ts +0 -126
- package/src/agents/acp/parser.ts +0 -119
- package/src/agents/acp/spawn-client.ts +0 -373
- package/src/agents/acp/types.ts +0 -22
- package/src/agents/aider/adapter.ts +0 -135
- package/src/agents/claude/adapter.ts +0 -258
- package/src/agents/claude/complete.ts +0 -80
- package/src/agents/claude/cost.ts +0 -16
- package/src/agents/claude/execution.ts +0 -215
- package/src/agents/claude/index.ts +0 -3
- package/src/agents/claude/interactive.ts +0 -77
- package/src/agents/claude/plan.ts +0 -179
- package/src/agents/codex/adapter.ts +0 -153
- package/src/agents/cost/calculate.ts +0 -154
- package/src/agents/cost/index.ts +0 -10
- package/src/agents/cost/parse.ts +0 -97
- package/src/agents/cost/pricing.ts +0 -59
- package/src/agents/cost/types.ts +0 -45
- package/src/agents/gemini/adapter.ts +0 -177
- package/src/agents/index.ts +0 -18
- package/src/agents/opencode/adapter.ts +0 -106
- package/src/agents/registry.ts +0 -136
- package/src/agents/shared/decompose.ts +0 -154
- package/src/agents/shared/model-resolution.ts +0 -43
- package/src/agents/shared/types-extended.ts +0 -164
- package/src/agents/shared/validation.ts +0 -69
- package/src/agents/shared/version-detection.ts +0 -109
- package/src/agents/types.ts +0 -205
- package/src/analyze/classifier.ts +0 -282
- package/src/analyze/index.ts +0 -16
- package/src/analyze/scanner.ts +0 -171
- package/src/analyze/types.ts +0 -51
- package/src/cli/accept.ts +0 -108
- package/src/cli/agents.ts +0 -87
- package/src/cli/analyze-parser.ts +0 -291
- package/src/cli/analyze.ts +0 -352
- package/src/cli/config-descriptions.ts +0 -219
- package/src/cli/config-diff.ts +0 -103
- package/src/cli/config-display.ts +0 -285
- package/src/cli/config-get.ts +0 -55
- package/src/cli/config.ts +0 -14
- package/src/cli/constitution.ts +0 -17
- package/src/cli/diagnose-analysis.ts +0 -159
- package/src/cli/diagnose-formatter.ts +0 -87
- package/src/cli/diagnose.ts +0 -203
- package/src/cli/generate.ts +0 -250
- package/src/cli/index.ts +0 -42
- package/src/cli/init-context.ts +0 -405
- package/src/cli/init-detect.ts +0 -303
- package/src/cli/init.ts +0 -296
- package/src/cli/interact.ts +0 -295
- package/src/cli/plan.ts +0 -509
- package/src/cli/plugins.ts +0 -122
- package/src/cli/prompts-export.ts +0 -58
- package/src/cli/prompts-init.ts +0 -200
- package/src/cli/prompts-main.ts +0 -183
- package/src/cli/prompts-shared.ts +0 -70
- package/src/cli/prompts-tdd.ts +0 -88
- package/src/cli/prompts.ts +0 -17
- package/src/cli/runs.ts +0 -174
- package/src/cli/status-cost.ts +0 -151
- package/src/cli/status-features.ts +0 -405
- package/src/cli/status.ts +0 -13
- package/src/commands/common.ts +0 -171
- package/src/commands/diagnose.ts +0 -17
- package/src/commands/index.ts +0 -9
- package/src/commands/logs-formatter.ts +0 -201
- package/src/commands/logs-reader.ts +0 -171
- package/src/commands/logs.ts +0 -103
- package/src/commands/precheck.ts +0 -86
- package/src/commands/runs.ts +0 -220
- package/src/commands/unlock.ts +0 -96
- package/src/config/defaults.ts +0 -218
- package/src/config/index.ts +0 -22
- package/src/config/loader.ts +0 -143
- package/src/config/merge.ts +0 -106
- package/src/config/merger.ts +0 -147
- package/src/config/path-security.ts +0 -121
- package/src/config/paths.ts +0 -27
- package/src/config/permissions.ts +0 -63
- package/src/config/runtime-types.ts +0 -522
- package/src/config/schema-types.ts +0 -53
- package/src/config/schema.ts +0 -60
- package/src/config/schemas.ts +0 -426
- package/src/config/test-strategy.ts +0 -71
- package/src/config/types.ts +0 -57
- package/src/config/validate.ts +0 -103
- package/src/constitution/generator.ts +0 -158
- package/src/constitution/generators/aider.ts +0 -41
- package/src/constitution/generators/claude.ts +0 -35
- package/src/constitution/generators/cursor.ts +0 -36
- package/src/constitution/generators/opencode.ts +0 -38
- package/src/constitution/generators/types.ts +0 -33
- package/src/constitution/generators/windsurf.ts +0 -36
- package/src/constitution/index.ts +0 -11
- package/src/constitution/loader.ts +0 -121
- package/src/constitution/types.ts +0 -31
- package/src/context/auto-detect.ts +0 -228
- package/src/context/builder.ts +0 -299
- package/src/context/elements.ts +0 -122
- package/src/context/formatter.ts +0 -107
- package/src/context/generator.ts +0 -343
- package/src/context/generators/aider.ts +0 -34
- package/src/context/generators/claude.ts +0 -28
- package/src/context/generators/codex.ts +0 -28
- package/src/context/generators/cursor.ts +0 -28
- package/src/context/generators/gemini.ts +0 -28
- package/src/context/generators/opencode.ts +0 -30
- package/src/context/generators/windsurf.ts +0 -28
- package/src/context/greenfield.ts +0 -114
- package/src/context/index.ts +0 -34
- package/src/context/injector.ts +0 -279
- package/src/context/parent-context.ts +0 -39
- package/src/context/test-scanner.ts +0 -370
- package/src/context/types.ts +0 -98
- package/src/decompose/apply.ts +0 -50
- package/src/decompose/builder.ts +0 -181
- package/src/decompose/index.ts +0 -8
- package/src/decompose/sections/codebase.ts +0 -26
- package/src/decompose/sections/constraints.ts +0 -32
- package/src/decompose/sections/index.ts +0 -4
- package/src/decompose/sections/sibling-stories.ts +0 -25
- package/src/decompose/sections/target-story.ts +0 -31
- package/src/decompose/types.ts +0 -55
- package/src/decompose/validators/complexity.ts +0 -45
- package/src/decompose/validators/coverage.ts +0 -134
- package/src/decompose/validators/dependency.ts +0 -91
- package/src/decompose/validators/index.ts +0 -35
- package/src/decompose/validators/overlap.ts +0 -128
- package/src/errors.ts +0 -67
- package/src/execution/batching.ts +0 -157
- package/src/execution/crash-heartbeat.ts +0 -77
- package/src/execution/crash-recovery.ts +0 -79
- package/src/execution/crash-signals.ts +0 -165
- package/src/execution/crash-writer.ts +0 -154
- package/src/execution/deferred-review.ts +0 -105
- package/src/execution/dry-run.ts +0 -81
- package/src/execution/escalation/escalation.ts +0 -46
- package/src/execution/escalation/index.ts +0 -13
- package/src/execution/escalation/tier-escalation.ts +0 -346
- package/src/execution/escalation/tier-outcome.ts +0 -143
- package/src/execution/executor-types.ts +0 -73
- package/src/execution/helpers.ts +0 -38
- package/src/execution/index.ts +0 -27
- package/src/execution/iteration-runner.ts +0 -160
- package/src/execution/lifecycle/acceptance-loop.ts +0 -309
- package/src/execution/lifecycle/headless-formatter.ts +0 -83
- package/src/execution/lifecycle/index.ts +0 -11
- package/src/execution/lifecycle/parallel-lifecycle.ts +0 -101
- package/src/execution/lifecycle/precheck-runner.ts +0 -140
- package/src/execution/lifecycle/run-cleanup.ts +0 -81
- package/src/execution/lifecycle/run-completion.ts +0 -247
- package/src/execution/lifecycle/run-initialization.ts +0 -187
- package/src/execution/lifecycle/run-regression.ts +0 -305
- package/src/execution/lifecycle/run-setup.ts +0 -240
- package/src/execution/lifecycle/story-size-prompts.ts +0 -123
- package/src/execution/lock.ts +0 -129
- package/src/execution/parallel-coordinator.ts +0 -281
- package/src/execution/parallel-executor-rectification-pass.ts +0 -117
- package/src/execution/parallel-executor-rectify.ts +0 -136
- package/src/execution/parallel-executor.ts +0 -330
- package/src/execution/parallel-worker.ts +0 -149
- package/src/execution/parallel.ts +0 -13
- package/src/execution/pid-registry.ts +0 -275
- package/src/execution/pipeline-result-handler.ts +0 -221
- package/src/execution/progress.ts +0 -27
- package/src/execution/queue-handler.ts +0 -109
- package/src/execution/runner-completion.ts +0 -171
- package/src/execution/runner-execution.ts +0 -243
- package/src/execution/runner-setup.ts +0 -86
- package/src/execution/runner.ts +0 -265
- package/src/execution/sequential-executor.ts +0 -219
- package/src/execution/status-file.ts +0 -264
- package/src/execution/status-writer.ts +0 -181
- package/src/execution/story-context.ts +0 -266
- package/src/execution/story-selector.ts +0 -76
- package/src/execution/test-output-parser.ts +0 -14
- package/src/execution/timeout-handler.ts +0 -100
- package/src/hooks/index.ts +0 -2
- package/src/hooks/runner.ts +0 -280
- package/src/hooks/types.ts +0 -79
- package/src/interaction/chain.ts +0 -170
- package/src/interaction/index.ts +0 -61
- package/src/interaction/init.ts +0 -84
- package/src/interaction/plugins/auto.ts +0 -243
- package/src/interaction/plugins/cli.ts +0 -300
- package/src/interaction/plugins/telegram.ts +0 -384
- package/src/interaction/plugins/webhook.ts +0 -286
- package/src/interaction/state.ts +0 -171
- package/src/interaction/triggers.ts +0 -250
- package/src/interaction/types.ts +0 -170
- package/src/logger/formatters.ts +0 -84
- package/src/logger/index.ts +0 -16
- package/src/logger/logger.ts +0 -296
- package/src/logger/types.ts +0 -48
- package/src/logging/formatter.ts +0 -355
- package/src/logging/index.ts +0 -22
- package/src/logging/types.ts +0 -93
- package/src/metrics/aggregator.ts +0 -191
- package/src/metrics/index.ts +0 -14
- package/src/metrics/tracker.ts +0 -200
- package/src/metrics/types.ts +0 -115
- package/src/optimizer/index.ts +0 -63
- package/src/optimizer/noop.optimizer.ts +0 -24
- package/src/optimizer/rule-based.optimizer.ts +0 -248
- package/src/optimizer/types.ts +0 -53
- package/src/pipeline/event-bus.ts +0 -297
- package/src/pipeline/events.ts +0 -130
- package/src/pipeline/index.ts +0 -19
- package/src/pipeline/runner.ts +0 -149
- package/src/pipeline/stages/acceptance-setup.ts +0 -144
- package/src/pipeline/stages/acceptance.ts +0 -215
- package/src/pipeline/stages/autofix.ts +0 -262
- package/src/pipeline/stages/completion.ts +0 -110
- package/src/pipeline/stages/constitution.ts +0 -63
- package/src/pipeline/stages/context.ts +0 -122
- package/src/pipeline/stages/execution.ts +0 -359
- package/src/pipeline/stages/index.ts +0 -86
- package/src/pipeline/stages/optimizer.ts +0 -74
- package/src/pipeline/stages/prompt.ts +0 -79
- package/src/pipeline/stages/queue-check.ts +0 -103
- package/src/pipeline/stages/rectify.ts +0 -101
- package/src/pipeline/stages/regression.ts +0 -99
- package/src/pipeline/stages/review.ts +0 -94
- package/src/pipeline/stages/routing.ts +0 -276
- package/src/pipeline/stages/verify.ts +0 -286
- package/src/pipeline/subscribers/events-writer.ts +0 -135
- package/src/pipeline/subscribers/hooks.ts +0 -179
- package/src/pipeline/subscribers/interaction.ts +0 -103
- package/src/pipeline/subscribers/registry.ts +0 -73
- package/src/pipeline/subscribers/reporters.ts +0 -174
- package/src/pipeline/types.ts +0 -220
- package/src/plugins/extensions.ts +0 -225
- package/src/plugins/index.ts +0 -33
- package/src/plugins/loader.ts +0 -352
- package/src/plugins/plugin-logger.ts +0 -41
- package/src/plugins/registry.ts +0 -168
- package/src/plugins/types.ts +0 -206
- package/src/plugins/validator.ts +0 -352
- package/src/prd/index.ts +0 -220
- package/src/prd/schema.ts +0 -268
- package/src/prd/types.ts +0 -273
- package/src/prd/validate.ts +0 -41
- package/src/precheck/checks-agents.ts +0 -63
- package/src/precheck/checks-blockers.ts +0 -23
- package/src/precheck/checks-cli.ts +0 -68
- package/src/precheck/checks-config.ts +0 -102
- package/src/precheck/checks-git.ts +0 -117
- package/src/precheck/checks-system.ts +0 -101
- package/src/precheck/checks-warnings.ts +0 -221
- package/src/precheck/checks.ts +0 -36
- package/src/precheck/index.ts +0 -374
- package/src/precheck/story-size-gate.ts +0 -144
- package/src/precheck/types.ts +0 -31
- package/src/prompts/builder.ts +0 -166
- package/src/prompts/index.ts +0 -2
- package/src/prompts/loader.ts +0 -43
- package/src/prompts/sections/conventions.ts +0 -19
- package/src/prompts/sections/hermetic.ts +0 -41
- package/src/prompts/sections/index.ts +0 -12
- package/src/prompts/sections/isolation.ts +0 -70
- package/src/prompts/sections/role-task.ts +0 -182
- package/src/prompts/sections/story.ts +0 -55
- package/src/prompts/sections/verdict.ts +0 -70
- package/src/prompts/types.ts +0 -21
- package/src/queue/index.ts +0 -2
- package/src/queue/manager.ts +0 -254
- package/src/queue/types.ts +0 -54
- package/src/review/index.ts +0 -8
- package/src/review/orchestrator.ts +0 -154
- package/src/review/runner.ts +0 -303
- package/src/review/types.ts +0 -70
- package/src/routing/batch-route.ts +0 -35
- package/src/routing/builder.ts +0 -81
- package/src/routing/chain.ts +0 -75
- package/src/routing/content-hash.ts +0 -25
- package/src/routing/index.ts +0 -20
- package/src/routing/loader.ts +0 -62
- package/src/routing/router.ts +0 -305
- package/src/routing/strategies/adaptive.ts +0 -215
- package/src/routing/strategies/index.ts +0 -8
- package/src/routing/strategies/keyword.ts +0 -180
- package/src/routing/strategies/llm-prompts.ts +0 -224
- package/src/routing/strategies/llm.ts +0 -320
- package/src/routing/strategies/manual.ts +0 -50
- package/src/routing/strategy.ts +0 -102
- package/src/tdd/cleanup.ts +0 -120
- package/src/tdd/index.ts +0 -22
- package/src/tdd/isolation.ts +0 -117
- package/src/tdd/orchestrator.ts +0 -406
- package/src/tdd/prompts.ts +0 -40
- package/src/tdd/rectification-gate.ts +0 -274
- package/src/tdd/session-runner.ts +0 -263
- package/src/tdd/types.ts +0 -84
- package/src/tdd/verdict-reader.ts +0 -266
- package/src/tdd/verdict.ts +0 -152
- package/src/tui/App.tsx +0 -265
- package/src/tui/components/AgentPanel.tsx +0 -75
- package/src/tui/components/CostOverlay.tsx +0 -118
- package/src/tui/components/HelpOverlay.tsx +0 -107
- package/src/tui/components/StatusBar.tsx +0 -63
- package/src/tui/components/StoriesPanel.tsx +0 -177
- package/src/tui/hooks/useKeyboard.ts +0 -142
- package/src/tui/hooks/useLayout.ts +0 -137
- package/src/tui/hooks/usePipelineEvents.ts +0 -183
- package/src/tui/hooks/usePty.ts +0 -189
- package/src/tui/index.tsx +0 -38
- package/src/tui/types.ts +0 -76
- package/src/utils/errors.ts +0 -12
- package/src/utils/git.ts +0 -245
- package/src/utils/json-file.ts +0 -72
- package/src/utils/log-test-output.ts +0 -25
- package/src/utils/path-security.ts +0 -73
- package/src/utils/queue-writer.ts +0 -54
- package/src/verification/crash-detector.ts +0 -34
- package/src/verification/executor.ts +0 -250
- package/src/verification/index.ts +0 -12
- package/src/verification/orchestrator-types.ts +0 -154
- package/src/verification/orchestrator.ts +0 -76
- package/src/verification/parser.ts +0 -220
- package/src/verification/rectification-loop.ts +0 -172
- package/src/verification/rectification.ts +0 -108
- package/src/verification/runners.ts +0 -129
- package/src/verification/smart-runner.ts +0 -307
- package/src/verification/strategies/acceptance.ts +0 -136
- package/src/verification/strategies/regression.ts +0 -90
- package/src/verification/strategies/scoped.ts +0 -154
- package/src/verification/types.ts +0 -117
- package/src/version.ts +0 -40
- package/src/worktree/dispatcher.ts +0 -6
- package/src/worktree/index.ts +0 -2
- package/src/worktree/manager.ts +0 -193
- package/src/worktree/merge.ts +0 -302
- package/src/worktree/types.ts +0 -4
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Interaction Plugin (v0.15.0 US-002)
|
|
3
|
-
*
|
|
4
|
-
* Default plugin for stdin/stdout interaction in non-headless mode.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as readline from "node:readline";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
import type { InteractionPlugin, InteractionRequest, InteractionResponse } from "../types";
|
|
10
|
-
|
|
11
|
-
/** Zod schema for validating CLI plugin config */
|
|
12
|
-
const CLIConfigSchema = z.object({}).passthrough();
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* CLI plugin for interactive prompts via stdin/stdout
|
|
16
|
-
*/
|
|
17
|
-
export class CLIInteractionPlugin implements InteractionPlugin {
|
|
18
|
-
name = "cli";
|
|
19
|
-
private pendingRequests = new Map<string, InteractionRequest>();
|
|
20
|
-
private rl: readline.Interface | null = null;
|
|
21
|
-
|
|
22
|
-
async init(config: Record<string, unknown> = {}): Promise<void> {
|
|
23
|
-
CLIConfigSchema.parse(config);
|
|
24
|
-
// Initialize readline interface
|
|
25
|
-
this.rl = readline.createInterface({
|
|
26
|
-
input: process.stdin,
|
|
27
|
-
output: process.stdout,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async destroy(): Promise<void> {
|
|
32
|
-
if (this.rl) {
|
|
33
|
-
this.rl.close();
|
|
34
|
-
this.rl = null;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async send(request: InteractionRequest): Promise<void> {
|
|
39
|
-
this.pendingRequests.set(request.id, request);
|
|
40
|
-
|
|
41
|
-
// Format and print the request
|
|
42
|
-
console.log(`\n${"=".repeat(80)}`);
|
|
43
|
-
console.log(`[INTERACTION] ${request.stage.toUpperCase()} — ${request.type.toUpperCase()}`);
|
|
44
|
-
console.log("=".repeat(80));
|
|
45
|
-
console.log(`\n${request.summary}\n`);
|
|
46
|
-
|
|
47
|
-
if (request.detail) {
|
|
48
|
-
console.log(request.detail);
|
|
49
|
-
console.log("");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (request.options && request.options.length > 0) {
|
|
53
|
-
console.log("Options:");
|
|
54
|
-
for (const opt of request.options) {
|
|
55
|
-
const desc = opt.description ? ` — ${opt.description}` : "";
|
|
56
|
-
console.log(` [${opt.key}] ${opt.label}${desc}`);
|
|
57
|
-
}
|
|
58
|
-
console.log("");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (request.timeout) {
|
|
62
|
-
const timeoutSec = Math.floor(request.timeout / 1000);
|
|
63
|
-
console.log(`[Timeout: ${timeoutSec}s | Fallback: ${request.fallback}]`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log(`${"=".repeat(80)}\n`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async receive(requestId: string, timeout = 60000): Promise<InteractionResponse> {
|
|
70
|
-
const request = this.pendingRequests.get(requestId);
|
|
71
|
-
if (!request) {
|
|
72
|
-
throw new Error(`No pending request with ID: ${requestId}`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (!this.rl) {
|
|
76
|
-
throw new Error("CLI plugin not initialized");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const response = await this.promptUser(request, timeout);
|
|
80
|
-
this.pendingRequests.delete(requestId);
|
|
81
|
-
return response;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async cancel(requestId: string): Promise<void> {
|
|
85
|
-
this.pendingRequests.delete(requestId);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Prompt user for response with timeout
|
|
90
|
-
*/
|
|
91
|
-
private async promptUser(request: InteractionRequest, timeout: number): Promise<InteractionResponse> {
|
|
92
|
-
if (!this.rl) {
|
|
93
|
-
throw new Error("CLI plugin not initialized");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const timeoutPromise = new Promise<InteractionResponse>((resolve) => {
|
|
97
|
-
setTimeout(() => {
|
|
98
|
-
resolve({
|
|
99
|
-
requestId: request.id,
|
|
100
|
-
action: "skip",
|
|
101
|
-
respondedBy: "timeout",
|
|
102
|
-
respondedAt: Date.now(),
|
|
103
|
-
});
|
|
104
|
-
}, timeout);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const userPromise = this.getUserInput(request);
|
|
108
|
-
|
|
109
|
-
const response = await Promise.race([userPromise, timeoutPromise]);
|
|
110
|
-
return response;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Get user input based on interaction type
|
|
115
|
-
*/
|
|
116
|
-
private async getUserInput(request: InteractionRequest): Promise<InteractionResponse> {
|
|
117
|
-
if (!this.rl) {
|
|
118
|
-
throw new Error("CLI plugin not initialized");
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
switch (request.type) {
|
|
122
|
-
case "confirm":
|
|
123
|
-
return this.promptConfirm(request);
|
|
124
|
-
case "choose":
|
|
125
|
-
return this.promptChoose(request);
|
|
126
|
-
case "input":
|
|
127
|
-
return this.promptInput(request);
|
|
128
|
-
case "review":
|
|
129
|
-
return this.promptReview(request);
|
|
130
|
-
case "notify":
|
|
131
|
-
// Notify doesn't require input
|
|
132
|
-
return {
|
|
133
|
-
requestId: request.id,
|
|
134
|
-
action: "approve",
|
|
135
|
-
respondedBy: "system",
|
|
136
|
-
respondedAt: Date.now(),
|
|
137
|
-
};
|
|
138
|
-
case "webhook":
|
|
139
|
-
// Webhook is handled externally
|
|
140
|
-
return {
|
|
141
|
-
requestId: request.id,
|
|
142
|
-
action: "approve",
|
|
143
|
-
respondedBy: "system",
|
|
144
|
-
respondedAt: Date.now(),
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Prompt for confirmation (yes/no)
|
|
151
|
-
*/
|
|
152
|
-
private async promptConfirm(request: InteractionRequest): Promise<InteractionResponse> {
|
|
153
|
-
const answer = await this.question("Approve? [y/n/skip/abort]: ");
|
|
154
|
-
const normalized = answer.toLowerCase().trim();
|
|
155
|
-
|
|
156
|
-
let action: InteractionResponse["action"];
|
|
157
|
-
if (normalized === "y" || normalized === "yes") {
|
|
158
|
-
action = "approve";
|
|
159
|
-
} else if (normalized === "n" || normalized === "no") {
|
|
160
|
-
action = "reject";
|
|
161
|
-
} else if (normalized === "skip") {
|
|
162
|
-
action = "skip";
|
|
163
|
-
} else if (normalized === "abort") {
|
|
164
|
-
action = "abort";
|
|
165
|
-
} else {
|
|
166
|
-
// Invalid input, default to skip
|
|
167
|
-
action = "skip";
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
requestId: request.id,
|
|
172
|
-
action,
|
|
173
|
-
respondedBy: "user",
|
|
174
|
-
respondedAt: Date.now(),
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Prompt for choice from options
|
|
180
|
-
*/
|
|
181
|
-
private async promptChoose(request: InteractionRequest): Promise<InteractionResponse> {
|
|
182
|
-
const answer = await this.question("Choose [key or skip/abort]: ");
|
|
183
|
-
const normalized = answer.toLowerCase().trim();
|
|
184
|
-
|
|
185
|
-
if (normalized === "skip") {
|
|
186
|
-
return {
|
|
187
|
-
requestId: request.id,
|
|
188
|
-
action: "skip",
|
|
189
|
-
respondedBy: "user",
|
|
190
|
-
respondedAt: Date.now(),
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (normalized === "abort") {
|
|
195
|
-
return {
|
|
196
|
-
requestId: request.id,
|
|
197
|
-
action: "abort",
|
|
198
|
-
respondedBy: "user",
|
|
199
|
-
respondedAt: Date.now(),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Check if answer matches an option key
|
|
204
|
-
const option = request.options?.find((opt) => opt.key === normalized);
|
|
205
|
-
if (option) {
|
|
206
|
-
return {
|
|
207
|
-
requestId: request.id,
|
|
208
|
-
action: "choose",
|
|
209
|
-
value: option.key,
|
|
210
|
-
respondedBy: "user",
|
|
211
|
-
respondedAt: Date.now(),
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Invalid choice, default to skip
|
|
216
|
-
return {
|
|
217
|
-
requestId: request.id,
|
|
218
|
-
action: "skip",
|
|
219
|
-
respondedBy: "user",
|
|
220
|
-
respondedAt: Date.now(),
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Prompt for text input
|
|
226
|
-
*/
|
|
227
|
-
private async promptInput(request: InteractionRequest): Promise<InteractionResponse> {
|
|
228
|
-
const answer = await this.question("Input [or skip/abort]: ");
|
|
229
|
-
const normalized = answer.trim();
|
|
230
|
-
|
|
231
|
-
if (normalized.toLowerCase() === "skip") {
|
|
232
|
-
return {
|
|
233
|
-
requestId: request.id,
|
|
234
|
-
action: "skip",
|
|
235
|
-
respondedBy: "user",
|
|
236
|
-
respondedAt: Date.now(),
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (normalized.toLowerCase() === "abort") {
|
|
241
|
-
return {
|
|
242
|
-
requestId: request.id,
|
|
243
|
-
action: "abort",
|
|
244
|
-
respondedBy: "user",
|
|
245
|
-
respondedAt: Date.now(),
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return {
|
|
250
|
-
requestId: request.id,
|
|
251
|
-
action: "input",
|
|
252
|
-
value: normalized,
|
|
253
|
-
respondedBy: "user",
|
|
254
|
-
respondedAt: Date.now(),
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Prompt for review (detailed approval)
|
|
260
|
-
*/
|
|
261
|
-
private async promptReview(request: InteractionRequest): Promise<InteractionResponse> {
|
|
262
|
-
const answer = await this.question("Review complete? [approve/reject/skip/abort]: ");
|
|
263
|
-
const normalized = answer.toLowerCase().trim();
|
|
264
|
-
|
|
265
|
-
let action: InteractionResponse["action"];
|
|
266
|
-
if (normalized === "approve") {
|
|
267
|
-
action = "approve";
|
|
268
|
-
} else if (normalized === "reject") {
|
|
269
|
-
action = "reject";
|
|
270
|
-
} else if (normalized === "skip") {
|
|
271
|
-
action = "skip";
|
|
272
|
-
} else if (normalized === "abort") {
|
|
273
|
-
action = "abort";
|
|
274
|
-
} else {
|
|
275
|
-
action = "skip";
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return {
|
|
279
|
-
requestId: request.id,
|
|
280
|
-
action,
|
|
281
|
-
respondedBy: "user",
|
|
282
|
-
respondedAt: Date.now(),
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Async wrapper for readline.question
|
|
288
|
-
*/
|
|
289
|
-
private async question(prompt: string): Promise<string> {
|
|
290
|
-
if (!this.rl) {
|
|
291
|
-
throw new Error("CLI plugin not initialized");
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return new Promise((resolve) => {
|
|
295
|
-
this.rl?.question(prompt, (answer) => {
|
|
296
|
-
resolve(answer);
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
}
|
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Telegram Interaction Plugin (v0.15.0 US-005)
|
|
3
|
-
*
|
|
4
|
-
* Send interaction requests via Telegram Bot API with inline keyboard.
|
|
5
|
-
* Poll for callback query or reply message responses.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
import type { InteractionPlugin, InteractionRequest, InteractionResponse } from "../types";
|
|
10
|
-
|
|
11
|
-
/** Telegram plugin configuration */
|
|
12
|
-
interface TelegramConfig {
|
|
13
|
-
/** Bot token (or env var NAX_TELEGRAM_TOKEN) */
|
|
14
|
-
botToken?: string;
|
|
15
|
-
/** Chat ID (or env var NAX_TELEGRAM_CHAT_ID) */
|
|
16
|
-
chatId?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Zod schema for validating telegram plugin config */
|
|
20
|
-
const TelegramConfigSchema = z.object({
|
|
21
|
-
botToken: z.string().optional(),
|
|
22
|
-
chatId: z.string().optional(),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
/** Telegram API response types */
|
|
26
|
-
interface TelegramMessage {
|
|
27
|
-
message_id: number;
|
|
28
|
-
chat: { id: number };
|
|
29
|
-
text?: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface TelegramUpdate {
|
|
33
|
-
update_id: number;
|
|
34
|
-
callback_query?: {
|
|
35
|
-
id: string;
|
|
36
|
-
data: string;
|
|
37
|
-
message: TelegramMessage;
|
|
38
|
-
};
|
|
39
|
-
message?: TelegramMessage;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Telegram plugin for remote interaction via Telegram Bot API
|
|
44
|
-
*/
|
|
45
|
-
export class TelegramInteractionPlugin implements InteractionPlugin {
|
|
46
|
-
name = "telegram";
|
|
47
|
-
private botToken: string | null = null;
|
|
48
|
-
private chatId: string | null = null;
|
|
49
|
-
private pendingMessages = new Map<string, number>(); // requestId -> messageId
|
|
50
|
-
private lastUpdateId = 0;
|
|
51
|
-
private backoffMs = 1000; // Exponential backoff for getUpdates (starts at 1s)
|
|
52
|
-
private readonly maxBackoffMs = 30000; // Max 30 seconds between retries
|
|
53
|
-
|
|
54
|
-
async init(config: Record<string, unknown>): Promise<void> {
|
|
55
|
-
const cfg = TelegramConfigSchema.parse(config);
|
|
56
|
-
this.botToken = cfg.botToken ?? process.env.NAX_TELEGRAM_TOKEN ?? process.env.TELEGRAM_BOT_TOKEN ?? null;
|
|
57
|
-
this.chatId = cfg.chatId ?? process.env.NAX_TELEGRAM_CHAT_ID ?? null;
|
|
58
|
-
|
|
59
|
-
if (!this.botToken || !this.chatId) {
|
|
60
|
-
throw new Error(
|
|
61
|
-
"Telegram plugin requires botToken and chatId (env: NAX_TELEGRAM_TOKEN or TELEGRAM_BOT_TOKEN, NAX_TELEGRAM_CHAT_ID)",
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async destroy(): Promise<void> {
|
|
67
|
-
// Cleanup pending messages
|
|
68
|
-
this.pendingMessages.clear();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async send(request: InteractionRequest): Promise<void> {
|
|
72
|
-
if (!this.botToken || !this.chatId) {
|
|
73
|
-
throw new Error("Telegram plugin not initialized");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const text = this.formatMessage(request);
|
|
77
|
-
const keyboard = this.buildKeyboard(request);
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const response = await fetch(`https://api.telegram.org/bot${this.botToken}/sendMessage`, {
|
|
81
|
-
method: "POST",
|
|
82
|
-
headers: { "Content-Type": "application/json" },
|
|
83
|
-
body: JSON.stringify({
|
|
84
|
-
chat_id: this.chatId,
|
|
85
|
-
text,
|
|
86
|
-
reply_markup: keyboard ? { inline_keyboard: keyboard } : undefined,
|
|
87
|
-
parse_mode: "Markdown",
|
|
88
|
-
}),
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
if (!response.ok) {
|
|
92
|
-
const errorBody = await response.text().catch(() => "");
|
|
93
|
-
throw new Error(`Telegram API error (${response.status}): ${errorBody || response.statusText}`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const data = (await response.json()) as { ok: boolean; result: TelegramMessage };
|
|
97
|
-
if (!data.ok) {
|
|
98
|
-
throw new Error(`Telegram API returned ok=false: ${JSON.stringify(data)}`);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Store message ID for later updates
|
|
102
|
-
this.pendingMessages.set(request.id, data.result.message_id);
|
|
103
|
-
} catch (err) {
|
|
104
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
105
|
-
throw new Error(`Failed to send Telegram message: ${msg}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async receive(requestId: string, timeout = 60000): Promise<InteractionResponse> {
|
|
110
|
-
if (!this.botToken || !this.chatId) {
|
|
111
|
-
throw new Error("Telegram plugin not initialized");
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const startTime = Date.now();
|
|
115
|
-
|
|
116
|
-
while (Date.now() - startTime < timeout) {
|
|
117
|
-
const updates = await this.getUpdates();
|
|
118
|
-
|
|
119
|
-
for (const update of updates) {
|
|
120
|
-
const response = this.parseUpdate(requestId, update);
|
|
121
|
-
if (response) {
|
|
122
|
-
// Answer callback query if present
|
|
123
|
-
if (update.callback_query) {
|
|
124
|
-
await this.answerCallbackQuery(update.callback_query.id);
|
|
125
|
-
}
|
|
126
|
-
// Reset backoff on successful response
|
|
127
|
-
this.backoffMs = 1000;
|
|
128
|
-
return response;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Use dynamic backoff (set by getUpdates on error)
|
|
133
|
-
await Bun.sleep(this.backoffMs);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Timeout reached — send expiration message
|
|
137
|
-
await this.sendTimeoutMessage(requestId);
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
requestId,
|
|
141
|
-
action: "skip",
|
|
142
|
-
respondedBy: "timeout",
|
|
143
|
-
respondedAt: Date.now(),
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async cancel(requestId: string): Promise<void> {
|
|
148
|
-
await this.sendTimeoutMessage(requestId);
|
|
149
|
-
this.pendingMessages.delete(requestId);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Format interaction request as Telegram message
|
|
154
|
-
*/
|
|
155
|
-
private formatMessage(request: InteractionRequest): string {
|
|
156
|
-
const emoji = this.getStageEmoji(request.stage);
|
|
157
|
-
let text = `${emoji} *${request.stage.toUpperCase()}*\n\n`;
|
|
158
|
-
text += `*Feature:* ${request.featureName}\n`;
|
|
159
|
-
if (request.storyId) {
|
|
160
|
-
text += `*Story:* ${request.storyId}\n`;
|
|
161
|
-
}
|
|
162
|
-
text += `\n${request.summary}\n`;
|
|
163
|
-
|
|
164
|
-
if (request.detail) {
|
|
165
|
-
text += `\n${request.detail}\n`;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (request.options && request.options.length > 0) {
|
|
169
|
-
text += "\n*Options:*\n";
|
|
170
|
-
for (const opt of request.options) {
|
|
171
|
-
const desc = opt.description ? ` — ${opt.description}` : "";
|
|
172
|
-
text += ` • ${opt.label}${desc}\n`;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (request.timeout) {
|
|
177
|
-
const timeoutSec = Math.floor(request.timeout / 1000);
|
|
178
|
-
text += `\n⏱ Timeout: ${timeoutSec}s | Fallback: ${request.fallback}`;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return text;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Build inline keyboard for interaction type
|
|
186
|
-
*/
|
|
187
|
-
private buildKeyboard(request: InteractionRequest): Array<Array<{ text: string; callback_data: string }>> | null {
|
|
188
|
-
switch (request.type) {
|
|
189
|
-
case "confirm":
|
|
190
|
-
return [
|
|
191
|
-
[
|
|
192
|
-
{ text: "✅ Approve", callback_data: `${request.id}:approve` },
|
|
193
|
-
{ text: "❌ Reject", callback_data: `${request.id}:reject` },
|
|
194
|
-
],
|
|
195
|
-
[
|
|
196
|
-
{ text: "⏭ Skip", callback_data: `${request.id}:skip` },
|
|
197
|
-
{ text: "🛑 Abort", callback_data: `${request.id}:abort` },
|
|
198
|
-
],
|
|
199
|
-
];
|
|
200
|
-
|
|
201
|
-
case "choose": {
|
|
202
|
-
if (!request.options || request.options.length === 0) return null;
|
|
203
|
-
const rows: Array<Array<{ text: string; callback_data: string }>> = [];
|
|
204
|
-
for (const opt of request.options) {
|
|
205
|
-
rows.push([{ text: opt.label, callback_data: `${request.id}:choose:${opt.key}` }]);
|
|
206
|
-
}
|
|
207
|
-
rows.push([
|
|
208
|
-
{ text: "⏭ Skip", callback_data: `${request.id}:skip` },
|
|
209
|
-
{ text: "🛑 Abort", callback_data: `${request.id}:abort` },
|
|
210
|
-
]);
|
|
211
|
-
return rows;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
case "review":
|
|
215
|
-
return [
|
|
216
|
-
[
|
|
217
|
-
{ text: "✅ Approve", callback_data: `${request.id}:approve` },
|
|
218
|
-
{ text: "❌ Reject", callback_data: `${request.id}:reject` },
|
|
219
|
-
],
|
|
220
|
-
[
|
|
221
|
-
{ text: "⏭ Skip", callback_data: `${request.id}:skip` },
|
|
222
|
-
{ text: "🛑 Abort", callback_data: `${request.id}:abort` },
|
|
223
|
-
],
|
|
224
|
-
];
|
|
225
|
-
|
|
226
|
-
default:
|
|
227
|
-
// input, notify, webhook don't use buttons
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Get emoji for stage
|
|
234
|
-
*/
|
|
235
|
-
private getStageEmoji(stage: string): string {
|
|
236
|
-
switch (stage) {
|
|
237
|
-
case "pre-flight":
|
|
238
|
-
return "🚀";
|
|
239
|
-
case "execution":
|
|
240
|
-
return "⚙️";
|
|
241
|
-
case "review":
|
|
242
|
-
return "🔍";
|
|
243
|
-
case "merge":
|
|
244
|
-
return "🔀";
|
|
245
|
-
case "cost":
|
|
246
|
-
return "💰";
|
|
247
|
-
default:
|
|
248
|
-
return "📌";
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Get updates from Telegram Bot API with exponential backoff on failure
|
|
254
|
-
*/
|
|
255
|
-
private async getUpdates(): Promise<TelegramUpdate[]> {
|
|
256
|
-
if (!this.botToken) return [];
|
|
257
|
-
|
|
258
|
-
try {
|
|
259
|
-
const response = await fetch(`https://api.telegram.org/bot${this.botToken}/getUpdates`, {
|
|
260
|
-
method: "POST",
|
|
261
|
-
headers: { "Content-Type": "application/json" },
|
|
262
|
-
body: JSON.stringify({
|
|
263
|
-
offset: this.lastUpdateId + 1,
|
|
264
|
-
timeout: 1, // Short polling
|
|
265
|
-
}),
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
if (!response.ok) {
|
|
269
|
-
const errorBody = await response.text().catch(() => "");
|
|
270
|
-
throw new Error(`Telegram getUpdates error (${response.status}): ${errorBody || response.statusText}`);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const data = (await response.json()) as { ok: boolean; result: TelegramUpdate[] };
|
|
274
|
-
if (!data.ok || !data.result) {
|
|
275
|
-
throw new Error("Telegram API returned ok=false or missing result");
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const updates = data.result;
|
|
279
|
-
if (updates.length > 0) {
|
|
280
|
-
this.lastUpdateId = Math.max(...updates.map((u: TelegramUpdate) => u.update_id));
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Reset backoff on success
|
|
284
|
-
this.backoffMs = 1000;
|
|
285
|
-
return updates;
|
|
286
|
-
} catch (err) {
|
|
287
|
-
// Apply exponential backoff on network error
|
|
288
|
-
this.backoffMs = Math.min(this.backoffMs * 2, this.maxBackoffMs);
|
|
289
|
-
// Return empty updates and retry with backoff (logged for debugging, not exposed to user)
|
|
290
|
-
return [];
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Parse Telegram update into interaction response
|
|
296
|
-
*/
|
|
297
|
-
private parseUpdate(requestId: string, update: TelegramUpdate): InteractionResponse | null {
|
|
298
|
-
// Check callback query (button click)
|
|
299
|
-
if (update.callback_query) {
|
|
300
|
-
const data = update.callback_query.data;
|
|
301
|
-
if (!data.startsWith(requestId)) return null;
|
|
302
|
-
|
|
303
|
-
const parts = data.split(":");
|
|
304
|
-
if (parts.length < 2) return null;
|
|
305
|
-
|
|
306
|
-
const action = parts[1] as InteractionResponse["action"];
|
|
307
|
-
const value = parts.length > 2 ? parts[2] : undefined;
|
|
308
|
-
|
|
309
|
-
return {
|
|
310
|
-
requestId,
|
|
311
|
-
action,
|
|
312
|
-
value,
|
|
313
|
-
respondedBy: "telegram",
|
|
314
|
-
respondedAt: Date.now(),
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// Check text message (for input type)
|
|
319
|
-
if (update.message?.text) {
|
|
320
|
-
const messageId = this.pendingMessages.get(requestId);
|
|
321
|
-
if (!messageId) return null;
|
|
322
|
-
|
|
323
|
-
// Simple heuristic: if message is reply to our message
|
|
324
|
-
// For now, accept any message as input
|
|
325
|
-
return {
|
|
326
|
-
requestId,
|
|
327
|
-
action: "input",
|
|
328
|
-
value: update.message.text,
|
|
329
|
-
respondedBy: "telegram",
|
|
330
|
-
respondedAt: Date.now(),
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
return null;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Answer callback query to remove loading state
|
|
339
|
-
*/
|
|
340
|
-
private async answerCallbackQuery(callbackQueryId: string): Promise<void> {
|
|
341
|
-
if (!this.botToken) return;
|
|
342
|
-
|
|
343
|
-
try {
|
|
344
|
-
await fetch(`https://api.telegram.org/bot${this.botToken}/answerCallbackQuery`, {
|
|
345
|
-
method: "POST",
|
|
346
|
-
headers: { "Content-Type": "application/json" },
|
|
347
|
-
body: JSON.stringify({
|
|
348
|
-
callback_query_id: callbackQueryId,
|
|
349
|
-
}),
|
|
350
|
-
});
|
|
351
|
-
} catch {
|
|
352
|
-
// Non-critical - fire-and-forget, no logging needed
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Edit message to show timeout/expired
|
|
358
|
-
*/
|
|
359
|
-
private async sendTimeoutMessage(requestId: string): Promise<void> {
|
|
360
|
-
const messageId = this.pendingMessages.get(requestId);
|
|
361
|
-
if (!messageId || !this.botToken || !this.chatId) {
|
|
362
|
-
// Still cleanup even if we can't send timeout message
|
|
363
|
-
this.pendingMessages.delete(requestId);
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
try {
|
|
368
|
-
await fetch(`https://api.telegram.org/bot${this.botToken}/editMessageText`, {
|
|
369
|
-
method: "POST",
|
|
370
|
-
headers: { "Content-Type": "application/json" },
|
|
371
|
-
body: JSON.stringify({
|
|
372
|
-
chat_id: this.chatId,
|
|
373
|
-
message_id: messageId,
|
|
374
|
-
text: "⏱ *EXPIRED* — Interaction timed out",
|
|
375
|
-
parse_mode: "Markdown",
|
|
376
|
-
}),
|
|
377
|
-
});
|
|
378
|
-
} catch {
|
|
379
|
-
// Non-critical - fire-and-forget, no logging needed
|
|
380
|
-
} finally {
|
|
381
|
-
this.pendingMessages.delete(requestId);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|