@cortex-agent/server 2026.6.18 → 2026.6.22
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/defaults/CORTEX.md +5 -0
- package/defaults/hooks/ask-user-question-hook.mjs +6 -1
- package/defaults/hooks/exit-plan-mode-hook.mjs +6 -1
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +7 -0
- package/defaults/prompts/systemPrompts/coder.md +6 -1
- package/defaults/prompts/systemPrompts/direct.md +5 -0
- package/defaults/prompts/systemPrompts/web-opus-4-6.md +6 -1
- package/defaults/prompts/systemPrompts/web-sonnet-4-6.md +6 -1
- package/defaults/prompts/systemPrompts/web.md +6 -1
- package/defaults/prompts/systemPrompts/worker.md +6 -1
- package/dist/agent-adapter/claude/adapter.d.ts +110 -1
- package/dist/agent-adapter/claude/adapter.js +117 -0
- package/dist/agent-adapter/claude/bg-task-tracker.d.ts +37 -0
- package/dist/agent-adapter/claude/bg-task-tracker.js +78 -0
- package/dist/agent-adapter/normalize/event-types.d.ts +4 -0
- package/dist/agent-adapter/pi/event-parser.d.ts +3 -1
- package/dist/agent-adapter/pi/event-parser.js +12 -2
- package/dist/agent-adapter/types.d.ts +19 -0
- package/dist/core/auth.d.ts +36 -0
- package/dist/core/auth.js +85 -0
- package/dist/core/locales/en.d.ts +6 -0
- package/dist/core/locales/slices/status.d.ts +6 -0
- package/dist/core/locales/slices/status.js +16 -0
- package/dist/core/types/agent-types.d.ts +5 -0
- package/dist/core/types/thread-types.d.ts +12 -1
- package/dist/core/version.d.ts +3 -0
- package/dist/core/version.js +4 -1
- package/dist/domain/agents/facade.js +12 -0
- package/dist/domain/costs/rate-limit-throttle.d.ts +1 -1
- package/dist/domain/costs/rate-limit-throttle.js +23 -2
- package/dist/domain/costs/resume-registry.d.ts +30 -0
- package/dist/domain/costs/resume-registry.js +68 -0
- package/dist/domain/mcp/core-server.js +5 -0
- package/dist/domain/mcp/tools/manager-qa.d.ts +2 -0
- package/dist/domain/mcp/tools/manager-qa.js +72 -0
- package/dist/domain/mcp/tools/task-ops.js +4 -2
- package/dist/domain/mcp/tools/thread-ops.js +2 -1
- package/dist/domain/mcp/tui-server.js +2 -1
- package/dist/domain/remote/client-bootstrap.js +14 -2
- package/dist/domain/remote/client-manager.d.ts +1 -1
- package/dist/domain/remote/client-manager.js +31 -5
- package/dist/domain/remote/cortex-client-config.d.ts +32 -0
- package/dist/domain/remote/cortex-client-config.js +49 -0
- package/dist/domain/remote/cortex-client.js +11 -7
- package/dist/domain/scheduling/jobs/scheduled-task.js +17 -1
- package/dist/domain/scheduling/jobs/task-dispatch.js +21 -0
- package/dist/domain/tasks/dispatcher.js +8 -0
- package/dist/domain/tasks/system/cortex-run.js +4 -2
- package/dist/domain/threads/runner.d.ts +8 -1
- package/dist/domain/threads/runner.js +81 -11
- package/dist/domain/threads/state-machine.d.ts +5 -0
- package/dist/domain/threads/state-machine.js +16 -0
- package/dist/entry/app.js +19 -4
- package/dist/entry/init.js +6 -0
- package/dist/hooks/ask-user-question-hook.mjs +6 -1
- package/dist/hooks/exit-plan-mode-hook.mjs +6 -1
- package/dist/orchestration/agent-runner.js +28 -3
- package/dist/orchestration/bg-continuation.d.ts +26 -0
- package/dist/orchestration/bg-continuation.js +34 -0
- package/dist/orchestration/conversation-runner.d.ts +3 -0
- package/dist/orchestration/conversation-runner.js +1 -1
- package/dist/orchestration/interactions/interaction-handlers.js +13 -2
- package/dist/orchestration/lifecycle.d.ts +3 -1
- package/dist/orchestration/lifecycle.js +72 -2
- package/dist/orchestration/manager-qa.d.ts +55 -0
- package/dist/orchestration/manager-qa.js +218 -0
- package/dist/orchestration/resume-dispatcher.d.ts +22 -0
- package/dist/orchestration/resume-dispatcher.js +129 -0
- package/dist/orchestration/routing/webhook.d.ts +1 -1
- package/dist/orchestration/routing/webhook.js +75 -14
- package/dist/orchestration/status-helpers.d.ts +3 -0
- package/dist/orchestration/status-helpers.js +16 -0
- package/dist/orchestration/thread-callback.d.ts +13 -1
- package/dist/orchestration/thread-callback.js +18 -1
- package/dist/orchestration/turn-notify.d.ts +26 -0
- package/dist/orchestration/turn-notify.js +66 -0
- package/dist/platform/adapters/feishu.d.ts +16 -0
- package/dist/platform/adapters/feishu.js +67 -6
- package/dist/store/schedule-repo.d.ts +6 -0
- package/dist/store/schedule-repo.js +11 -1
- package/dist/store/thread-repo.js +14 -0
- package/dist/store/version-migrations.d.ts +14 -4
- package/dist/store/version-migrations.js +67 -9
- package/package.json +1 -1
|
@@ -85,6 +85,22 @@ export interface AgentSpawnConfig {
|
|
|
85
85
|
taskProject?: string | null;
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Session-level sink for background-task continuation turns (run_in_background Bash/Agent).
|
|
90
|
+
* After a background task finishes, the Claude CLI spontaneously re-invokes the model and
|
|
91
|
+
* emits a follow-up turn with no caller awaiting it. The adapter routes that turn here so
|
|
92
|
+
* orchestration can merge it into the originating reply and seal the status once the
|
|
93
|
+
* background tasks are done. Only the Claude backend implements this (capability-gated).
|
|
94
|
+
*/
|
|
95
|
+
export interface ContinuationSink {
|
|
96
|
+
/** Assistant text from the continuation turn (append to the original reply). */
|
|
97
|
+
onAssistantText: (text: string) => void;
|
|
98
|
+
/** Optional tool_use trace from the continuation turn. */
|
|
99
|
+
onToolUse?: (name: string, input: any) => void;
|
|
100
|
+
/** Continuation turn's terminating result. `result.pendingBackgroundTasks` is the number
|
|
101
|
+
* of background tasks still running (0 ⇒ safe to seal the status as complete). */
|
|
102
|
+
onResult: (result: AgentResult) => void;
|
|
103
|
+
}
|
|
88
104
|
export interface AgentProcess {
|
|
89
105
|
sessionKey: string;
|
|
90
106
|
/** May be null at spawn time; adapter fills in asynchronously when the backend assigns a session id. */
|
|
@@ -93,6 +109,9 @@ export interface AgentProcess {
|
|
|
93
109
|
send(message: UserMessage): Promise<AgentResult>;
|
|
94
110
|
/** Async iterable of normalized events. Iterator returns done after close(). */
|
|
95
111
|
events: AsyncIterable<NormalizedEvent>;
|
|
112
|
+
/** Register a sink for spontaneous background-task continuation turns (Claude backend only).
|
|
113
|
+
* Persists across normal turns; the adapter clears it on session close/kill. */
|
|
114
|
+
setContinuationSink?(sink: ContinuationSink): void;
|
|
96
115
|
close(): Promise<void>;
|
|
97
116
|
kill(): boolean;
|
|
98
117
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Header name carrying the bearer token on both the WS upgrade and webhook requests. */
|
|
2
|
+
export declare const AUTH_HEADER = "x-cortex-token";
|
|
3
|
+
/** Env var holding the cortex-client ↔ server WebSocket token. */
|
|
4
|
+
export declare const CLIENT_TOKEN_ENV = "CORTEX_CLIENT_TOKEN";
|
|
5
|
+
/** Env var holding the webhook HTTP bearer token. */
|
|
6
|
+
export declare const WEBHOOK_TOKEN_ENV = "CORTEX_WEBHOOK_TOKEN";
|
|
7
|
+
/**
|
|
8
|
+
* Constant-time string comparison. Returns false (fail-closed) when either side is
|
|
9
|
+
* empty/undefined or the lengths differ — an unset configured token never matches.
|
|
10
|
+
*/
|
|
11
|
+
export declare function timingSafeEqualStr(a: string | undefined, b: string | undefined): boolean;
|
|
12
|
+
/** Read the configured client (WebSocket) token at call time (after dotenv loads). */
|
|
13
|
+
export declare function getClientToken(): string;
|
|
14
|
+
/** Read the configured webhook token at call time (after dotenv loads). */
|
|
15
|
+
export declare function getWebhookToken(): string;
|
|
16
|
+
export interface EnsureAuthTokensOptions {
|
|
17
|
+
/** Path to the .env file to persist generated tokens into. Defaults to CONFIG_DIR/.env. */
|
|
18
|
+
envPath?: string;
|
|
19
|
+
/** Env object to read/mutate. Defaults to process.env (injectable for tests). */
|
|
20
|
+
env?: Record<string, string | undefined>;
|
|
21
|
+
}
|
|
22
|
+
export interface EnsureAuthTokensResult {
|
|
23
|
+
clientToken: string;
|
|
24
|
+
webhookToken: string;
|
|
25
|
+
/** Names of tokens that were freshly generated this call (empty when all pre-existed). */
|
|
26
|
+
generated: string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Ensure both auth tokens exist. For each missing/blank token: generate a 32-byte hex
|
|
30
|
+
* secret, set it on `env`, and (if anything was generated) append the new keys to the
|
|
31
|
+
* .env file so they survive restarts. Idempotent — pre-existing tokens are left untouched.
|
|
32
|
+
*
|
|
33
|
+
* Called once at server startup BEFORE the WebSocket and webhook servers start, so both
|
|
34
|
+
* surfaces enforce a real token (fail-closed).
|
|
35
|
+
*/
|
|
36
|
+
export declare function ensureAuthTokens(opts?: EnsureAuthTokensOptions): EnsureAuthTokensResult;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// input: process.env / CONFIG_DIR/.env, request headers
|
|
2
|
+
// output: ensureAuthTokens + getClientToken/getWebhookToken + timingSafeEqualStr + AUTH_HEADER
|
|
3
|
+
// pos: Shared-secret auth for the cortex-client WebSocket and the webhook HTTP server.
|
|
4
|
+
// No Cloudflare dependency — two independent bearer tokens carried in the
|
|
5
|
+
// `x-cortex-token` header, generated on first start and persisted to .env (fail-closed).
|
|
6
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
7
|
+
import * as crypto from 'crypto';
|
|
8
|
+
import { readFileSync, appendFileSync, mkdirSync } from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import { CONFIG_DIR } from './utils.js';
|
|
11
|
+
import { createLogger } from './log.js';
|
|
12
|
+
const log = createLogger('auth');
|
|
13
|
+
/** Header name carrying the bearer token on both the WS upgrade and webhook requests. */
|
|
14
|
+
export const AUTH_HEADER = 'x-cortex-token';
|
|
15
|
+
/** Env var holding the cortex-client ↔ server WebSocket token. */
|
|
16
|
+
export const CLIENT_TOKEN_ENV = 'CORTEX_CLIENT_TOKEN';
|
|
17
|
+
/** Env var holding the webhook HTTP bearer token. */
|
|
18
|
+
export const WEBHOOK_TOKEN_ENV = 'CORTEX_WEBHOOK_TOKEN';
|
|
19
|
+
/**
|
|
20
|
+
* Constant-time string comparison. Returns false (fail-closed) when either side is
|
|
21
|
+
* empty/undefined or the lengths differ — an unset configured token never matches.
|
|
22
|
+
*/
|
|
23
|
+
export function timingSafeEqualStr(a, b) {
|
|
24
|
+
const aBuf = Buffer.from(a || '');
|
|
25
|
+
const bBuf = Buffer.from(b || '');
|
|
26
|
+
if (aBuf.length === 0 || bBuf.length !== aBuf.length)
|
|
27
|
+
return false;
|
|
28
|
+
return crypto.timingSafeEqual(aBuf, bBuf);
|
|
29
|
+
}
|
|
30
|
+
/** Read the configured client (WebSocket) token at call time (after dotenv loads). */
|
|
31
|
+
export function getClientToken() {
|
|
32
|
+
return (process.env[CLIENT_TOKEN_ENV] || '').trim();
|
|
33
|
+
}
|
|
34
|
+
/** Read the configured webhook token at call time (after dotenv loads). */
|
|
35
|
+
export function getWebhookToken() {
|
|
36
|
+
return (process.env[WEBHOOK_TOKEN_ENV] || '').trim();
|
|
37
|
+
}
|
|
38
|
+
function genToken() {
|
|
39
|
+
return crypto.randomBytes(32).toString('hex');
|
|
40
|
+
}
|
|
41
|
+
function appendTokensToEnvFile(envPath, names, env) {
|
|
42
|
+
let existing = '';
|
|
43
|
+
try {
|
|
44
|
+
existing = readFileSync(envPath, 'utf-8');
|
|
45
|
+
}
|
|
46
|
+
catch { /* no file yet */ }
|
|
47
|
+
const lines = ['', '# Auth tokens (auto-generated) — WS client + webhook bearer'];
|
|
48
|
+
for (const name of names)
|
|
49
|
+
lines.push(`${name}=${env[name]}`);
|
|
50
|
+
lines.push('');
|
|
51
|
+
// Guard against gluing the first key onto a file that lacks a trailing newline.
|
|
52
|
+
const needsLeadingNl = existing.length > 0 && !existing.endsWith('\n');
|
|
53
|
+
const block = (needsLeadingNl ? '\n' : '') + lines.join('\n');
|
|
54
|
+
mkdirSync(path.dirname(envPath), { recursive: true });
|
|
55
|
+
appendFileSync(envPath, block);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Ensure both auth tokens exist. For each missing/blank token: generate a 32-byte hex
|
|
59
|
+
* secret, set it on `env`, and (if anything was generated) append the new keys to the
|
|
60
|
+
* .env file so they survive restarts. Idempotent — pre-existing tokens are left untouched.
|
|
61
|
+
*
|
|
62
|
+
* Called once at server startup BEFORE the WebSocket and webhook servers start, so both
|
|
63
|
+
* surfaces enforce a real token (fail-closed).
|
|
64
|
+
*/
|
|
65
|
+
export function ensureAuthTokens(opts = {}) {
|
|
66
|
+
const env = opts.env ?? process.env;
|
|
67
|
+
const envPath = opts.envPath ?? path.join(CONFIG_DIR, '.env');
|
|
68
|
+
const generated = [];
|
|
69
|
+
const ensureOne = (name) => {
|
|
70
|
+
const existing = env[name]?.trim();
|
|
71
|
+
if (existing)
|
|
72
|
+
return existing;
|
|
73
|
+
const value = genToken();
|
|
74
|
+
env[name] = value;
|
|
75
|
+
generated.push(name);
|
|
76
|
+
return value;
|
|
77
|
+
};
|
|
78
|
+
const clientToken = ensureOne(CLIENT_TOKEN_ENV);
|
|
79
|
+
const webhookToken = ensureOne(WEBHOOK_TOKEN_ENV);
|
|
80
|
+
if (generated.length > 0) {
|
|
81
|
+
appendTokensToEnvFile(envPath, generated, env);
|
|
82
|
+
log.info(`Generated auth token(s): ${generated.join(', ')} → ${envPath}`);
|
|
83
|
+
}
|
|
84
|
+
return { clientToken, webhookToken, generated };
|
|
85
|
+
}
|
|
@@ -414,6 +414,7 @@ export declare const en: {
|
|
|
414
414
|
'status.processing': "Processing";
|
|
415
415
|
'status.done': "Done";
|
|
416
416
|
'status.waitingForUserInput': "Waiting for user input";
|
|
417
|
+
'status.backgroundRunning': "Background task running";
|
|
417
418
|
'status.cancelled': "Cancelled";
|
|
418
419
|
'status.error': "Error";
|
|
419
420
|
'status.supersededByEdit': "Superseded by edit";
|
|
@@ -423,11 +424,16 @@ export declare const en: {
|
|
|
423
424
|
'status.supersededSeeNewReply': "see new reply";
|
|
424
425
|
'status.processingAskResponse': "Processing AskUserQuestion response...";
|
|
425
426
|
'status.errorBody': "Error: ${message}";
|
|
427
|
+
'notify.turnComplete': "Turn complete";
|
|
428
|
+
'notify.turnFailed': "Turn failed";
|
|
429
|
+
'notify.contextCompacted': "Context auto-compacted (${trigger}${tokens}). Earlier conversation history has been summarized; please restate key information if needed.";
|
|
430
|
+
'notify.contextCompactedTokens': ", ~${preTokens} tokens before compaction";
|
|
426
431
|
'status.noRunningExecutions': "No running executions.";
|
|
427
432
|
'status.runningExecutions': "Running executions: ${count}";
|
|
428
433
|
'btn.cancel': "Cancel";
|
|
429
434
|
'btn.resume': "Resume";
|
|
430
435
|
'btn.new': "New";
|
|
436
|
+
'btn.newq': "New (quiet)";
|
|
431
437
|
'lang.current': "Current language: *${lang}*";
|
|
432
438
|
'lang.switched': "Language switched to *${lang}*.";
|
|
433
439
|
'lang.usage': "Usage: `!lang <en|zh>`";
|
|
@@ -2,6 +2,7 @@ export declare const statusEn: {
|
|
|
2
2
|
readonly 'status.processing': "Processing";
|
|
3
3
|
readonly 'status.done': "Done";
|
|
4
4
|
readonly 'status.waitingForUserInput': "Waiting for user input";
|
|
5
|
+
readonly 'status.backgroundRunning': "Background task running";
|
|
5
6
|
readonly 'status.cancelled': "Cancelled";
|
|
6
7
|
readonly 'status.error': "Error";
|
|
7
8
|
readonly 'status.supersededByEdit': "Superseded by edit";
|
|
@@ -11,10 +12,15 @@ export declare const statusEn: {
|
|
|
11
12
|
readonly 'status.supersededSeeNewReply': "see new reply";
|
|
12
13
|
readonly 'status.processingAskResponse': "Processing AskUserQuestion response...";
|
|
13
14
|
readonly 'status.errorBody': "Error: ${message}";
|
|
15
|
+
readonly 'notify.turnComplete': "Turn complete";
|
|
16
|
+
readonly 'notify.turnFailed': "Turn failed";
|
|
17
|
+
readonly 'notify.contextCompacted': "Context auto-compacted (${trigger}${tokens}). Earlier conversation history has been summarized; please restate key information if needed.";
|
|
18
|
+
readonly 'notify.contextCompactedTokens': ", ~${preTokens} tokens before compaction";
|
|
14
19
|
readonly 'status.noRunningExecutions': "No running executions.";
|
|
15
20
|
readonly 'status.runningExecutions': "Running executions: ${count}";
|
|
16
21
|
readonly 'btn.cancel': "Cancel";
|
|
17
22
|
readonly 'btn.resume': "Resume";
|
|
18
23
|
readonly 'btn.new': "New";
|
|
24
|
+
readonly 'btn.newq': "New (quiet)";
|
|
19
25
|
};
|
|
20
26
|
export declare const statusZh: Record<keyof typeof statusEn, string>;
|
|
@@ -7,6 +7,7 @@ export const statusEn = {
|
|
|
7
7
|
'status.processing': 'Processing',
|
|
8
8
|
'status.done': 'Done',
|
|
9
9
|
'status.waitingForUserInput': 'Waiting for user input',
|
|
10
|
+
'status.backgroundRunning': 'Background task running',
|
|
10
11
|
'status.cancelled': 'Cancelled',
|
|
11
12
|
'status.error': 'Error',
|
|
12
13
|
'status.supersededByEdit': 'Superseded by edit',
|
|
@@ -16,6 +17,12 @@ export const statusEn = {
|
|
|
16
17
|
'status.supersededSeeNewReply': 'see new reply',
|
|
17
18
|
'status.processingAskResponse': 'Processing AskUserQuestion response...',
|
|
18
19
|
'status.errorBody': 'Error: ${message}',
|
|
20
|
+
// --- Turn-completion notification ---
|
|
21
|
+
'notify.turnComplete': 'Turn complete',
|
|
22
|
+
'notify.turnFailed': 'Turn failed',
|
|
23
|
+
// --- Context compaction notification ---
|
|
24
|
+
'notify.contextCompacted': 'Context auto-compacted (${trigger}${tokens}). Earlier conversation history has been summarized; please restate key information if needed.',
|
|
25
|
+
'notify.contextCompactedTokens': ', ~${preTokens} tokens before compaction',
|
|
19
26
|
// --- Execution report ---
|
|
20
27
|
'status.noRunningExecutions': 'No running executions.',
|
|
21
28
|
'status.runningExecutions': 'Running executions: ${count}',
|
|
@@ -23,12 +30,14 @@ export const statusEn = {
|
|
|
23
30
|
'btn.cancel': 'Cancel',
|
|
24
31
|
'btn.resume': 'Resume',
|
|
25
32
|
'btn.new': 'New',
|
|
33
|
+
'btn.newq': 'New (quiet)',
|
|
26
34
|
};
|
|
27
35
|
export const statusZh = {
|
|
28
36
|
// --- Status / lifecycle phrases ---
|
|
29
37
|
'status.processing': '处理中',
|
|
30
38
|
'status.done': '完成',
|
|
31
39
|
'status.waitingForUserInput': '等待用户输入',
|
|
40
|
+
'status.backgroundRunning': '后台任务运行中',
|
|
32
41
|
'status.cancelled': '已取消',
|
|
33
42
|
'status.error': '错误',
|
|
34
43
|
'status.supersededByEdit': '已被编辑取代',
|
|
@@ -38,6 +47,12 @@ export const statusZh = {
|
|
|
38
47
|
'status.supersededSeeNewReply': '查看新回复',
|
|
39
48
|
'status.processingAskResponse': '正在处理 AskUserQuestion 回复……',
|
|
40
49
|
'status.errorBody': '错误:${message}',
|
|
50
|
+
// --- Turn-completion notification ---
|
|
51
|
+
'notify.turnComplete': '回合完成',
|
|
52
|
+
'notify.turnFailed': '回合失败',
|
|
53
|
+
// --- Context compaction notification ---
|
|
54
|
+
'notify.contextCompacted': '上下文已自动压缩(${trigger}${tokens})。早期对话历史已被摘要,如有需要请重述关键信息。',
|
|
55
|
+
'notify.contextCompactedTokens': ',压缩前 ~${preTokens} tokens',
|
|
41
56
|
// --- Execution report ---
|
|
42
57
|
'status.noRunningExecutions': '没有正在运行的执行。',
|
|
43
58
|
'status.runningExecutions': '正在运行的执行:${count}',
|
|
@@ -45,4 +60,5 @@ export const statusZh = {
|
|
|
45
60
|
'btn.cancel': '取消',
|
|
46
61
|
'btn.resume': '恢复',
|
|
47
62
|
'btn.new': '新建',
|
|
63
|
+
'btn.newq': '新建(静默)',
|
|
48
64
|
};
|
|
@@ -16,6 +16,11 @@ export interface AgentResult {
|
|
|
16
16
|
finalOutput: string | null;
|
|
17
17
|
codexRateLimits?: Record<string, unknown>;
|
|
18
18
|
codexRawLogPath?: string | null;
|
|
19
|
+
/** Number of background tasks (run_in_background) still running when this turn's
|
|
20
|
+
* result fired. >0 means the CC backend will spontaneously emit a continuation turn
|
|
21
|
+
* once they finish; orchestration holds the status in a "waiting" state instead of
|
|
22
|
+
* sealing it as complete. Absent/0 for backends without background-task support. */
|
|
23
|
+
pendingBackgroundTasks?: number;
|
|
19
24
|
}
|
|
20
25
|
export interface AgentHandle {
|
|
21
26
|
promise: Promise<AgentResult>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type ThreadId = string;
|
|
2
2
|
export type AgentSlotId = string;
|
|
3
|
-
export type ThreadStatus = 'running' | 'waiting' | 'completed' | 'failed' | 'cancelled' | 'aborted';
|
|
3
|
+
export type ThreadStatus = 'running' | 'waiting' | 'rate_limited' | 'completed' | 'failed' | 'cancelled' | 'aborted';
|
|
4
4
|
/** A named stage of an agent. When an agent declares `stages`, each transition target
|
|
5
5
|
* may select one stage (syntax `"agent:stage"`). Stages that set `continuesSession: true`
|
|
6
6
|
* send only an incremental prompt when the persistent session is being resumed — the
|
|
@@ -248,6 +248,14 @@ export interface ThreadMetadata {
|
|
|
248
248
|
/** Children whose results were already queued into pendingMessages — persistent
|
|
249
249
|
* idempotency for completion callbacks (survives restarts, unlike the in-memory fired set). */
|
|
250
250
|
deliveredChildResults?: string[];
|
|
251
|
+
/** Open questions a subtask asked this manager via ask_manager (DR-0016), for visibility /
|
|
252
|
+
* debugging. The authoritative pending-question state lives in orchestration/manager-qa's
|
|
253
|
+
* in-memory store; this is the manager-side mirror, cleared by answer_subtask. */
|
|
254
|
+
pendingQuestions?: Array<{
|
|
255
|
+
questionId: string;
|
|
256
|
+
fromTaskId: string | null;
|
|
257
|
+
question: string;
|
|
258
|
+
}>;
|
|
251
259
|
/** Delegation contract this thread was spawned with (child side). */
|
|
252
260
|
contract?: ThreadContract | null;
|
|
253
261
|
/** Ancestor goal chain, root-first — injected into the child prompt to prevent drift. */
|
|
@@ -256,6 +264,9 @@ export interface ThreadMetadata {
|
|
|
256
264
|
* onEnd task-status-check hook on re-entry (extraHooks are not persisted). */
|
|
257
265
|
taskId?: string | null;
|
|
258
266
|
taskProject?: string | null;
|
|
267
|
+
/** Set when the thread was paused (status==='rate_limited') by an API rate limit, so the
|
|
268
|
+
* resume path and startup recovery can tell a rate-limit pause apart from a real failure. */
|
|
269
|
+
interruptedByRateLimit?: boolean;
|
|
259
270
|
/** Destination kind decided at spawn time, so re-entry can rebuild RunThreadOptions. */
|
|
260
271
|
resumeDest?: 'interactive-reply' | 'project-report' | null;
|
|
261
272
|
/** Live status message persisted at suspension so the post-resume settle can refresh it
|
package/dist/core/version.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
/** Cortex version — reads from package.json at module load time.
|
|
2
2
|
* Format: CalVer `YYYY.M.D` (no zero-padding), e.g. `2026.5.19`. */
|
|
3
3
|
export declare const CORTEX_VERSION: string;
|
|
4
|
+
/** Canonical Cortex usage documentation site. Single source of truth for the
|
|
5
|
+
* docs URL injected into system prompts (see store/version-migrations.ts docs block). */
|
|
6
|
+
export declare const CORTEX_DOCS_URL = "https://fangxm233.github.io/cortex-agent/";
|
package/dist/core/version.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// input: package.json (read at module load)
|
|
2
|
-
// output: CORTEX_VERSION string (CalVer: YYYY.M.D, no zero-padding)
|
|
2
|
+
// output: CORTEX_VERSION string (CalVer: YYYY.M.D, no zero-padding); CORTEX_DOCS_URL (docs site)
|
|
3
3
|
// pos: single source of truth for Cortex version — imported by MCP servers and anywhere else
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { readFileSync } from 'node:fs';
|
|
@@ -10,3 +10,6 @@ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
|
10
10
|
/** Cortex version — reads from package.json at module load time.
|
|
11
11
|
* Format: CalVer `YYYY.M.D` (no zero-padding), e.g. `2026.5.19`. */
|
|
12
12
|
export const CORTEX_VERSION = pkg.version;
|
|
13
|
+
/** Canonical Cortex usage documentation site. Single source of truth for the
|
|
14
|
+
* docs URL injected into system prompts (see store/version-migrations.ts docs block). */
|
|
15
|
+
export const CORTEX_DOCS_URL = 'https://fangxm233.github.io/cortex-agent/';
|
|
@@ -9,6 +9,7 @@ import { isModeRateLimited, isThrottled } from '../costs/rate-limit-throttle.js'
|
|
|
9
9
|
import { GATEWAY_URL } from '../costs/gateway-manager.js';
|
|
10
10
|
import { createLogger } from '../../core/log.js';
|
|
11
11
|
import { loadCortexRules } from '../memory/rules-loader.js';
|
|
12
|
+
import { t } from '../../core/i18n.js';
|
|
12
13
|
const log = createLogger('facade');
|
|
13
14
|
// --- PI gateway routing ---
|
|
14
15
|
/**
|
|
@@ -130,6 +131,17 @@ export function runWithAdapter(adapter, message, options, config, anthropicBaseU
|
|
|
130
131
|
model: event.model || undefined,
|
|
131
132
|
}).catch(err => log.warn('recordCost failed:', err?.message ?? err));
|
|
132
133
|
break;
|
|
134
|
+
case 'context_compacted':
|
|
135
|
+
// Notify the user that the context was compacted. Off by default; opt in via
|
|
136
|
+
// CORTEX_NOTIFY_COMPACTION=1. Reuses onAssistantMessage so the notice reaches the
|
|
137
|
+
// user through the same channel as normal assistant output.
|
|
138
|
+
if (process.env.CORTEX_NOTIFY_COMPACTION === '1') {
|
|
139
|
+
const tokens = event.preTokens
|
|
140
|
+
? t('notify.contextCompactedTokens', { preTokens: event.preTokens })
|
|
141
|
+
: '';
|
|
142
|
+
options.onAssistantMessage?.(`🗜️ ${t('notify.contextCompacted', { trigger: event.trigger, tokens })}`);
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
133
145
|
case 'plan_written':
|
|
134
146
|
options.onPlanWritten?.({ path: event.path, content: event.content, toolUseId: event.toolUseId });
|
|
135
147
|
break;
|
|
@@ -11,7 +11,7 @@ export interface ThrottlePersistence {
|
|
|
11
11
|
modes?: string[];
|
|
12
12
|
} | null>;
|
|
13
13
|
}
|
|
14
|
-
declare function initRateLimitThrottle(adapter: PlatformAdapter, persistence: ThrottlePersistence): Promise<void>;
|
|
14
|
+
declare function initRateLimitThrottle(adapter: PlatformAdapter, persistence: ThrottlePersistence, onResume?: () => void): Promise<void>;
|
|
15
15
|
interface RateLimitInfo {
|
|
16
16
|
status?: string;
|
|
17
17
|
resetsAt?: number;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
// input: rate_limit_event + persistence + slack client
|
|
1
|
+
// input: rate_limit_event + persistence + slack client + optional onResume hook
|
|
2
2
|
// output: init/handleRateLimitEvent/isThrottled/isModeRateLimited/getThrottleState
|
|
3
3
|
// pos: Pure state tracker — no scheduler coupling. Mode-level rate limit tracking.
|
|
4
|
+
// onResume (injected) fires when the window clears (timer path + expired-on-restart),
|
|
5
|
+
// decoupling the resume dispatch (orchestration) from this domain module.
|
|
4
6
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
7
|
import { createLogger } from '../../core/log.js';
|
|
6
8
|
import { Icons } from '../../core/icons.js';
|
|
@@ -10,6 +12,7 @@ const RESUME_BUFFER_MS = 5_000;
|
|
|
10
12
|
// --- Module state ---
|
|
11
13
|
let _adapter = null;
|
|
12
14
|
let _persistence = null;
|
|
15
|
+
let _onResume = null;
|
|
13
16
|
let _isThrottled = false;
|
|
14
17
|
let _resetsAt = null; // Unix seconds
|
|
15
18
|
let _resumeTimer = null;
|
|
@@ -48,6 +51,19 @@ function clearThrottle() {
|
|
|
48
51
|
_persistence?.save(null).catch(e => {
|
|
49
52
|
log.error(`Failed to persist cleared throttle: ${e.message}`);
|
|
50
53
|
});
|
|
54
|
+
fireResume();
|
|
55
|
+
}
|
|
56
|
+
/** Notify the (optional) resume hook that the rate-limit window has ended. Errors are
|
|
57
|
+
* swallowed so a faulty resume path can never break the throttle state machine. */
|
|
58
|
+
function fireResume() {
|
|
59
|
+
if (!_onResume)
|
|
60
|
+
return;
|
|
61
|
+
try {
|
|
62
|
+
_onResume();
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
log.error(`onResume hook failed: ${e.message}`);
|
|
66
|
+
}
|
|
51
67
|
}
|
|
52
68
|
function scheduleResumeTimer() {
|
|
53
69
|
if (_resumeTimer)
|
|
@@ -59,9 +75,10 @@ function scheduleResumeTimer() {
|
|
|
59
75
|
}, delayMs);
|
|
60
76
|
}
|
|
61
77
|
// --- Public API ---
|
|
62
|
-
async function initRateLimitThrottle(adapter, persistence) {
|
|
78
|
+
async function initRateLimitThrottle(adapter, persistence, onResume) {
|
|
63
79
|
_adapter = adapter;
|
|
64
80
|
_persistence = persistence;
|
|
81
|
+
_onResume = onResume ?? null;
|
|
65
82
|
// Recover throttle state from disk (survives restart)
|
|
66
83
|
const persisted = await persistence.load();
|
|
67
84
|
if (persisted) {
|
|
@@ -79,6 +96,9 @@ async function initRateLimitThrottle(adapter, persistence) {
|
|
|
79
96
|
else {
|
|
80
97
|
log.info(`Throttle expired during downtime (resetsAt was ${new Date(persisted.resetsAt * 1000).toISOString()}). Clearing.`);
|
|
81
98
|
await persistence.save(null);
|
|
99
|
+
// The window already reset while the process was down — resume anything that was
|
|
100
|
+
// recorded before the restart.
|
|
101
|
+
fireResume();
|
|
82
102
|
}
|
|
83
103
|
}
|
|
84
104
|
log.info('Initialized');
|
|
@@ -134,5 +154,6 @@ function _testReset() {
|
|
|
134
154
|
_rateLimitedModes.clear();
|
|
135
155
|
_adapter = null;
|
|
136
156
|
_persistence = null;
|
|
157
|
+
_onResume = null;
|
|
137
158
|
}
|
|
138
159
|
export { initRateLimitThrottle, handleRateLimitEvent, isThrottled, isModeRateLimited, getThrottleState, _testReset };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** One unit of work that was interrupted by a rate limit and should be resumed
|
|
2
|
+
* once the limit window resets. `direct` = an interactive conversation (resumed by
|
|
3
|
+
* re-routing a message into the channel's pooled session); `thread` = a thread
|
|
4
|
+
* pipeline (resumed via continueThread). */
|
|
5
|
+
export type ResumeEntry = {
|
|
6
|
+
kind: 'direct';
|
|
7
|
+
channel: string;
|
|
8
|
+
userMessage: string;
|
|
9
|
+
recordedAt: number;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'thread';
|
|
12
|
+
threadId: string;
|
|
13
|
+
channel: string;
|
|
14
|
+
userMessage: string;
|
|
15
|
+
recordedAt: number;
|
|
16
|
+
};
|
|
17
|
+
export interface ResumePersistence {
|
|
18
|
+
save: (entries: ResumeEntry[]) => Promise<void>;
|
|
19
|
+
load: () => Promise<ResumeEntry[]>;
|
|
20
|
+
}
|
|
21
|
+
declare function initResumeRegistry(persistence: ResumePersistence): Promise<void>;
|
|
22
|
+
/** Record an interrupted session/thread for later resume. Idempotent per key
|
|
23
|
+
* (direct→channel, thread→threadId): a newer record overwrites the older one. */
|
|
24
|
+
declare function recordResume(entry: ResumeEntry): void;
|
|
25
|
+
/** Drain the registry: return all pending entries and clear (persists the empty list).
|
|
26
|
+
* "take + clear" is atomic so each entry is dispatched at most once. */
|
|
27
|
+
declare function takeAllResumes(): ResumeEntry[];
|
|
28
|
+
declare function getResumeCount(): number;
|
|
29
|
+
declare function _testReset(): void;
|
|
30
|
+
export { initResumeRegistry, recordResume, takeAllResumes, getResumeCount, _testReset };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// input: persistence (load/save) + recordResume calls from interruption points
|
|
2
|
+
// output: init/recordResume/takeAllResumes/getResumeCount — pending resume bookkeeping
|
|
3
|
+
// pos: Pure state tracker for sessions/threads interrupted by a rate limit. No
|
|
4
|
+
// orchestration/scheduler coupling — the resume *dispatch* lives in orchestration.
|
|
5
|
+
// Mirrors rate-limit-throttle.ts purity & injected-persistence shape.
|
|
6
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
7
|
+
import { createLogger } from '../../core/log.js';
|
|
8
|
+
const log = createLogger('resume-registry');
|
|
9
|
+
// --- Module state ---
|
|
10
|
+
let _persistence = null;
|
|
11
|
+
// Direct conversations dedupe by channel (pooled per channel — only the latest turn matters).
|
|
12
|
+
const _direct = new Map();
|
|
13
|
+
// Threads dedupe by threadId (each thread is an independent resumable unit).
|
|
14
|
+
const _threads = new Map();
|
|
15
|
+
function snapshot() {
|
|
16
|
+
return [..._direct.values(), ..._threads.values()];
|
|
17
|
+
}
|
|
18
|
+
function persist() {
|
|
19
|
+
_persistence?.save(snapshot()).catch(e => {
|
|
20
|
+
log.error(`Failed to persist resume queue: ${e.message}`);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// --- Public API ---
|
|
24
|
+
async function initResumeRegistry(persistence) {
|
|
25
|
+
_persistence = persistence;
|
|
26
|
+
try {
|
|
27
|
+
const persisted = await persistence.load();
|
|
28
|
+
for (const entry of persisted ?? []) {
|
|
29
|
+
if (entry.kind === 'direct')
|
|
30
|
+
_direct.set(entry.channel, entry);
|
|
31
|
+
else if (entry.kind === 'thread')
|
|
32
|
+
_threads.set(entry.threadId, entry);
|
|
33
|
+
}
|
|
34
|
+
log.info(`Initialized — ${_direct.size + _threads.size} pending resume(s) restored`);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
log.error(`Failed to load resume queue: ${e.message}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Record an interrupted session/thread for later resume. Idempotent per key
|
|
41
|
+
* (direct→channel, thread→threadId): a newer record overwrites the older one. */
|
|
42
|
+
function recordResume(entry) {
|
|
43
|
+
if (entry.kind === 'direct')
|
|
44
|
+
_direct.set(entry.channel, entry);
|
|
45
|
+
else if (entry.kind === 'thread')
|
|
46
|
+
_threads.set(entry.threadId, entry);
|
|
47
|
+
persist();
|
|
48
|
+
}
|
|
49
|
+
/** Drain the registry: return all pending entries and clear (persists the empty list).
|
|
50
|
+
* "take + clear" is atomic so each entry is dispatched at most once. */
|
|
51
|
+
function takeAllResumes() {
|
|
52
|
+
const all = snapshot();
|
|
53
|
+
_direct.clear();
|
|
54
|
+
_threads.clear();
|
|
55
|
+
if (all.length > 0)
|
|
56
|
+
persist();
|
|
57
|
+
return all;
|
|
58
|
+
}
|
|
59
|
+
function getResumeCount() {
|
|
60
|
+
return _direct.size + _threads.size;
|
|
61
|
+
}
|
|
62
|
+
// --- Test helpers ---
|
|
63
|
+
function _testReset() {
|
|
64
|
+
_direct.clear();
|
|
65
|
+
_threads.clear();
|
|
66
|
+
_persistence = null;
|
|
67
|
+
}
|
|
68
|
+
export { initResumeRegistry, recordResume, takeAllResumes, getResumeCount, _testReset };
|
|
@@ -11,6 +11,7 @@ import { registerTaskOpsTools } from './tools/task-ops.js';
|
|
|
11
11
|
import { registerTimeTools } from './tools/time.js';
|
|
12
12
|
import { registerThreadTools } from './tools/thread-ops.js';
|
|
13
13
|
import { registerTaskMonitorTools } from './tools/task-monitor.js';
|
|
14
|
+
import { registerManagerQaTools } from './tools/manager-qa.js';
|
|
14
15
|
import { isMainModule } from '../../core/utils.js';
|
|
15
16
|
import { createLogger } from '../../core/log.js';
|
|
16
17
|
import { CORTEX_VERSION } from '../../core/version.js';
|
|
@@ -21,6 +22,7 @@ registerTaskOpsTools(server);
|
|
|
21
22
|
registerTimeTools(server);
|
|
22
23
|
registerThreadTools(server);
|
|
23
24
|
registerTaskMonitorTools(server);
|
|
25
|
+
registerManagerQaTools(server);
|
|
24
26
|
// --- Exported tool name list (for verification) ---
|
|
25
27
|
export const TOOL_NAMES = [
|
|
26
28
|
'remote_bash',
|
|
@@ -38,6 +40,9 @@ export const TOOL_NAMES = [
|
|
|
38
40
|
'task_status',
|
|
39
41
|
'task_result',
|
|
40
42
|
'task_list',
|
|
43
|
+
// DR-0016 up-ask channel: a subtask asks its manager (or a human) a clarifying question.
|
|
44
|
+
'ask_manager',
|
|
45
|
+
'answer_subtask',
|
|
41
46
|
];
|
|
42
47
|
// --- Start (called by barrel when run as standalone) ---
|
|
43
48
|
export async function startServer() {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// input: McpServer, webhook proxy (/webhook/manager-qa), CORTEX_THREAD_ID env
|
|
2
|
+
// output: ask_manager / answer_subtask registrations (DR-0016 up-ask channel)
|
|
3
|
+
// pos: A subtask asks its manager (or, at the top of the tree, a human) a clarifying question and
|
|
4
|
+
// BLOCKS synchronously — ask_manager registers the question, then polls until answered and
|
|
5
|
+
// returns the answer as the tool result. The manager answers with answer_subtask. Managers
|
|
6
|
+
// nest: a manager that is itself unsure can ask_manager upward. Proxied through the daemon
|
|
7
|
+
// webhook (separate process; no shared memory with the thread store / runner).
|
|
8
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
const WEBHOOK_BASE = `http://127.0.0.1:${process.env.WEBHOOK_PORT || '3001'}`;
|
|
11
|
+
const POLL_INTERVAL_MS = 3000;
|
|
12
|
+
const TIMEOUT_MS = parseInt(process.env.CORTEX_ASK_MANAGER_TIMEOUT_MS || '1800000', 10) || 1800000; // 30 min
|
|
13
|
+
async function proxyQa(action, payload) {
|
|
14
|
+
const res = await fetch(`${WEBHOOK_BASE}/webhook/manager-qa`, {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: { 'Content-Type': 'application/json', 'x-cortex-token': process.env.CORTEX_WEBHOOK_TOKEN || '' },
|
|
17
|
+
body: JSON.stringify({ action, ...payload }),
|
|
18
|
+
});
|
|
19
|
+
const data = await res.json();
|
|
20
|
+
if (!data.success)
|
|
21
|
+
throw new Error(data.error || 'manager-qa failed');
|
|
22
|
+
return data.data;
|
|
23
|
+
}
|
|
24
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
25
|
+
export function registerManagerQaTools(server) {
|
|
26
|
+
const selfThreadId = () => {
|
|
27
|
+
const id = process.env.CORTEX_THREAD_ID;
|
|
28
|
+
if (!id)
|
|
29
|
+
throw new Error('not running inside a thread (CORTEX_THREAD_ID unset) — ask_manager only works from within a dispatched task/thread');
|
|
30
|
+
return id;
|
|
31
|
+
};
|
|
32
|
+
// --- ask_manager ---
|
|
33
|
+
server.tool('ask_manager', 'Ask the manager who planned your task a clarifying question when you hit confusion, a contradiction, or an ambiguous/under-specified intent — instead of guessing or aborting. This is LIGHTER than thread_abort: it does not give up the task; it resolves the uncertainty and lets you continue. The call BLOCKS until the manager replies, then returns their answer. Managers nest: if your manager is itself unsure it may ask its own manager upward; at the top of the tree the question goes to a human. Use for genuine planning/intent questions (e.g. "did you mean approach A or B?", "two done_when conditions conflict — which wins?"), not for things you can settle by reading the deliverable, code, or task spec yourself.', {
|
|
34
|
+
question: z.string().min(1).describe('A specific, self-contained question about the planning intent. Include the conflict/ambiguity and the options you see so the manager can answer crisply.'),
|
|
35
|
+
}, async ({ question }) => {
|
|
36
|
+
try {
|
|
37
|
+
const threadId = selfThreadId();
|
|
38
|
+
const reg = await proxyQa('ask', { threadId, question });
|
|
39
|
+
const questionId = reg.questionId;
|
|
40
|
+
const target = reg.target;
|
|
41
|
+
const deadline = Date.now() + TIMEOUT_MS;
|
|
42
|
+
while (Date.now() < deadline) {
|
|
43
|
+
await sleep(POLL_INTERVAL_MS);
|
|
44
|
+
const poll = await proxyQa('poll', { questionId });
|
|
45
|
+
if (poll.answered) {
|
|
46
|
+
const who = target === 'human' ? 'human' : 'manager';
|
|
47
|
+
return { content: [{ type: 'text', text: `Answer from your ${who}:\n\n${poll.answer}` }] };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
content: [{ type: 'text', text: `ask_manager timed out after ${Math.round(TIMEOUT_MS / 60000)} min with no reply (${target}). Proceed with your best judgment and record the assumption explicitly, or call thread_abort with a diagnosis if you cannot.` }],
|
|
52
|
+
isError: true,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
return { content: [{ type: 'text', text: `ask_manager error: ${e.message}` }], isError: true };
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
// --- answer_subtask ---
|
|
60
|
+
server.tool('answer_subtask', 'Answer a question a subtask asked you via ask_manager (the question, with its question_id, arrives in your context while you are waiting on your children). Give a concrete, actionable answer about your planning intent. After you answer, your thread automatically returns to waiting for your children — end your step. If the question is really about a HIGHER-level intent you are unsure of, call ask_manager to ask your own manager first, then answer the subtask with what you learn.', {
|
|
61
|
+
question_id: z.string().min(1).describe('The question_id from the subtask question notice.'),
|
|
62
|
+
answer: z.string().min(1).describe('Your answer / clarification for the subtask.'),
|
|
63
|
+
}, async ({ question_id, answer }) => {
|
|
64
|
+
try {
|
|
65
|
+
const result = await proxyQa('answer', { question_id, answer });
|
|
66
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
return { content: [{ type: 'text', text: `answer_subtask error: ${e.message}` }], isError: true };
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|