@keyou007/agent-bot 0.1.19-alpha.1 → 0.1.20-alpha.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/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/dist/cli/controlProtocol.js.map +1 -1
- package/dist/cli/help.js +2 -2
- package/dist/cli.js +5 -4
- package/dist/cli.js.map +1 -1
- package/dist/codex/CodexRuntime.js +59 -1
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/feishu/CardRenderer.js +10 -6
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +34 -73
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/docs/technical-reference.md +1 -1
- package/docs/technical-reference.zh.md +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +2 -1
- package/src/cli/controlProtocol.ts +0 -1
- package/src/cli/help.ts +2 -2
- package/src/cli.ts +6 -7
- package/src/codex/CodexRuntime.ts +79 -1
- package/src/feishu/CardRenderer.ts +11 -7
- package/src/proxy/ProxySessionController.ts +39 -78
- package/src/runtime/types.ts +1 -0
|
@@ -46,7 +46,6 @@ const RECOVERY_HEARTBEAT_INTERVAL_MS = 60 * 1_000;
|
|
|
46
46
|
const SHELL_COMMAND_JOB_POLL_INTERVAL_MS = 1_000;
|
|
47
47
|
const SHELL_COMMAND_JOB_RELAUNCH_DELAY_MS = 5_000;
|
|
48
48
|
const APP_SERVER_RELEASE_POLL_INTERVAL_MS = 500;
|
|
49
|
-
const APP_SERVER_RELEASE_IDLE_DELAY_MS = 5_000;
|
|
50
49
|
const FORWARD_ATTACHMENT_WINDOW_MS = 800;
|
|
51
50
|
const DEFAULT_MERGED_FORWARD_INSTRUCTION = "请参考以下内容回复用户";
|
|
52
51
|
const DEFAULT_REFERENCED_MESSAGE_INSTRUCTION = "请参考引用消息回复用户";
|
|
@@ -907,7 +906,6 @@ export class ProxySessionController {
|
|
|
907
906
|
agentName: result.agentName,
|
|
908
907
|
status: result.status,
|
|
909
908
|
blockingTaskCount: result.blockingTaskCount,
|
|
910
|
-
...(result.releaseInSeconds !== undefined ? { releaseInSeconds: result.releaseInSeconds } : {}),
|
|
911
909
|
};
|
|
912
910
|
}
|
|
913
911
|
async controlArchiveTask(localSessionId) {
|
|
@@ -2324,7 +2322,7 @@ export class ProxySessionController {
|
|
|
2324
2322
|
else {
|
|
2325
2323
|
if (!taskId)
|
|
2326
2324
|
throw new Error("缺少要 fork 的 App Server 任务 ID。");
|
|
2327
|
-
const resolved = await this.resolveRemoteCodexSession(taskId);
|
|
2325
|
+
const resolved = await this.resolveRemoteCodexSession(taskId, { forFork: true });
|
|
2328
2326
|
agentName = resolved.agentName;
|
|
2329
2327
|
runtime = resolved.runtime;
|
|
2330
2328
|
remote = resolved.remote;
|
|
@@ -4982,7 +4980,7 @@ export class ProxySessionController {
|
|
|
4982
4980
|
? this.store.findSessionByRemoteSessionId(scoped.remoteSessionId, contextKey, scoped.agentName)
|
|
4983
4981
|
: this.store.findSessionByRemoteSessionId(reference, contextKey);
|
|
4984
4982
|
}
|
|
4985
|
-
async resolveRemoteCodexSession(reference) {
|
|
4983
|
+
async resolveRemoteCodexSession(reference, options = {}) {
|
|
4986
4984
|
const scoped = parseRemoteSessionReference(reference);
|
|
4987
4985
|
const candidates = scoped
|
|
4988
4986
|
? [[scoped.agentName, this.runtimes.forAgent(scoped.agentName)]]
|
|
@@ -4993,10 +4991,13 @@ export class ProxySessionController {
|
|
|
4993
4991
|
if (runtime.kind !== "codex" || !runtime.readRemoteSession) {
|
|
4994
4992
|
throw new Error(`Agent ${agentName} 不支持读取远端任务。`);
|
|
4995
4993
|
}
|
|
4994
|
+
const remoteSessionId = scoped?.remoteSessionId ?? reference;
|
|
4996
4995
|
return {
|
|
4997
4996
|
agentName,
|
|
4998
4997
|
runtime,
|
|
4999
|
-
remote:
|
|
4998
|
+
remote: options.forFork && runtime.readRemoteForkSource
|
|
4999
|
+
? await runtime.readRemoteForkSource(remoteSessionId)
|
|
5000
|
+
: await runtime.readRemoteSession(remoteSessionId),
|
|
5000
5001
|
};
|
|
5001
5002
|
}));
|
|
5002
5003
|
const matches = reads
|
|
@@ -5637,20 +5638,17 @@ export class ProxySessionController {
|
|
|
5637
5638
|
let schedule = this.appServerReleaseSchedules.get(record.agentName);
|
|
5638
5639
|
const created = !schedule;
|
|
5639
5640
|
if (!schedule) {
|
|
5640
|
-
const
|
|
5641
|
+
const blockers = this.appServerReleaseBlockers(record.agentName, runtime);
|
|
5642
|
+
const blockingTaskCount = blockers.length;
|
|
5641
5643
|
schedule = {
|
|
5642
5644
|
id: this.nextAppServerReleaseScheduleId++,
|
|
5643
5645
|
agentName: record.agentName,
|
|
5644
5646
|
runtime,
|
|
5645
5647
|
status: "waiting",
|
|
5646
5648
|
blockingTaskCount,
|
|
5649
|
+
blockingTaskTitles: this.appServerReleaseTaskTitles(blockers),
|
|
5647
5650
|
targets: new Map(),
|
|
5648
5651
|
forced: false,
|
|
5649
|
-
...(blockingTaskCount === 0
|
|
5650
|
-
? {
|
|
5651
|
-
releaseCountdownSeconds: Math.ceil(APP_SERVER_RELEASE_IDLE_DELAY_MS / 1_000),
|
|
5652
|
-
}
|
|
5653
|
-
: {}),
|
|
5654
5652
|
};
|
|
5655
5653
|
this.appServerReleaseSchedules.set(record.agentName, schedule);
|
|
5656
5654
|
}
|
|
@@ -5659,12 +5657,6 @@ export class ProxySessionController {
|
|
|
5659
5657
|
if (messageId) {
|
|
5660
5658
|
schedule.targets.set(`${contextKey}\u0000${messageId}`, { contextKey, messageId });
|
|
5661
5659
|
}
|
|
5662
|
-
if (schedule.status === "waiting"
|
|
5663
|
-
&& schedule.blockingTaskCount === 0
|
|
5664
|
-
&& schedule.releaseCountdownSeconds !== undefined
|
|
5665
|
-
&& schedule.releaseAt === undefined) {
|
|
5666
|
-
schedule.releaseAt = Date.now() + APP_SERVER_RELEASE_IDLE_DELAY_MS;
|
|
5667
|
-
}
|
|
5668
5660
|
}
|
|
5669
5661
|
catch (error) {
|
|
5670
5662
|
if (created && schedule.targets.size === 0) {
|
|
@@ -5677,9 +5669,6 @@ export class ProxySessionController {
|
|
|
5677
5669
|
agentName: schedule.agentName,
|
|
5678
5670
|
status: schedule.status === "failed" ? "failed" : schedule.status === "released" ? "released" : "waiting",
|
|
5679
5671
|
blockingTaskCount: schedule.blockingTaskCount,
|
|
5680
|
-
...(schedule.releaseCountdownSeconds !== undefined
|
|
5681
|
-
? { releaseInSeconds: schedule.releaseCountdownSeconds }
|
|
5682
|
-
: {}),
|
|
5683
5672
|
...(schedule.error ? { error: schedule.error } : {}),
|
|
5684
5673
|
};
|
|
5685
5674
|
}
|
|
@@ -5690,7 +5679,7 @@ export class ProxySessionController {
|
|
|
5690
5679
|
if (!Number.isSafeInteger(scheduleId) || !schedule || schedule.id !== scheduleId || schedule.status !== "waiting") {
|
|
5691
5680
|
throw new Error("释放卡片已失效,请重新发送 /release。");
|
|
5692
5681
|
}
|
|
5693
|
-
await this.performAppServerRelease(schedule
|
|
5682
|
+
await this.performAppServerRelease(schedule);
|
|
5694
5683
|
}
|
|
5695
5684
|
async cancelAppServerRelease(action) {
|
|
5696
5685
|
const scheduleId = Number(action.value.scheduleId);
|
|
@@ -5724,6 +5713,9 @@ export class ProxySessionController {
|
|
|
5724
5713
|
|| Boolean(runtime.getSession(session.localSessionId)?.activeTurnId);
|
|
5725
5714
|
});
|
|
5726
5715
|
}
|
|
5716
|
+
appServerReleaseTaskTitles(blockers) {
|
|
5717
|
+
return blockers.map((session) => session.title?.trim() || "未命名任务");
|
|
5718
|
+
}
|
|
5727
5719
|
armAppServerReleaseCheck(schedule) {
|
|
5728
5720
|
if (schedule.status !== "waiting" || schedule.timer || schedule.inFlight)
|
|
5729
5721
|
return;
|
|
@@ -5739,36 +5731,22 @@ export class ProxySessionController {
|
|
|
5739
5731
|
async refreshAppServerReleaseSchedule(schedule) {
|
|
5740
5732
|
if (this.appServerReleaseSchedules.get(schedule.agentName) !== schedule || schedule.status !== "waiting")
|
|
5741
5733
|
return;
|
|
5742
|
-
const
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
schedule.
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
this.armAppServerReleaseCheck(schedule);
|
|
5752
|
-
return;
|
|
5753
|
-
}
|
|
5754
|
-
schedule.blockingTaskCount = 0;
|
|
5755
|
-
if (schedule.releaseAt !== undefined) {
|
|
5756
|
-
const releaseCountdownSeconds = Math.max(0, Math.ceil((schedule.releaseAt - Date.now()) / 1_000));
|
|
5757
|
-
if (releaseCountdownSeconds > 0) {
|
|
5758
|
-
if (schedule.releaseCountdownSeconds !== releaseCountdownSeconds) {
|
|
5759
|
-
schedule.releaseCountdownSeconds = releaseCountdownSeconds;
|
|
5760
|
-
await this.publishAppServerReleaseSchedule(schedule);
|
|
5761
|
-
}
|
|
5762
|
-
this.armAppServerReleaseCheck(schedule);
|
|
5763
|
-
return;
|
|
5764
|
-
}
|
|
5734
|
+
const blockers = this.appServerReleaseBlockers(schedule.agentName, schedule.runtime);
|
|
5735
|
+
const blockingTaskCount = blockers.length;
|
|
5736
|
+
const blockingTaskTitles = this.appServerReleaseTaskTitles(blockers);
|
|
5737
|
+
const titlesChanged = schedule.blockingTaskTitles.length !== blockingTaskTitles.length
|
|
5738
|
+
|| schedule.blockingTaskTitles.some((title, index) => title !== blockingTaskTitles[index]);
|
|
5739
|
+
if (schedule.blockingTaskCount !== blockingTaskCount || titlesChanged) {
|
|
5740
|
+
schedule.blockingTaskCount = blockingTaskCount;
|
|
5741
|
+
schedule.blockingTaskTitles = blockingTaskTitles;
|
|
5742
|
+
await this.publishAppServerReleaseSchedule(schedule);
|
|
5765
5743
|
}
|
|
5766
|
-
|
|
5744
|
+
this.armAppServerReleaseCheck(schedule);
|
|
5767
5745
|
}
|
|
5768
|
-
async performAppServerRelease(schedule
|
|
5746
|
+
async performAppServerRelease(schedule) {
|
|
5769
5747
|
if (schedule.inFlight)
|
|
5770
5748
|
return schedule.inFlight;
|
|
5771
|
-
const operation = this.performAppServerReleaseNow(schedule
|
|
5749
|
+
const operation = this.performAppServerReleaseNow(schedule);
|
|
5772
5750
|
schedule.inFlight = operation;
|
|
5773
5751
|
try {
|
|
5774
5752
|
await operation;
|
|
@@ -5780,31 +5758,16 @@ export class ProxySessionController {
|
|
|
5780
5758
|
this.armAppServerReleaseCheck(schedule);
|
|
5781
5759
|
}
|
|
5782
5760
|
}
|
|
5783
|
-
async performAppServerReleaseNow(schedule
|
|
5761
|
+
async performAppServerReleaseNow(schedule) {
|
|
5784
5762
|
if (schedule.timer) {
|
|
5785
5763
|
clearTimeout(schedule.timer);
|
|
5786
5764
|
schedule.timer = undefined;
|
|
5787
5765
|
}
|
|
5788
|
-
const interruptedWork =
|
|
5789
|
-
|
|
5790
|
-
await this.cancelQueuedPromptsForAppServerRelease(schedule.agentName);
|
|
5791
|
-
else {
|
|
5792
|
-
const blockingTaskCount = this.appServerReleaseBlockers(schedule.agentName, schedule.runtime).length;
|
|
5793
|
-
if (blockingTaskCount > 0) {
|
|
5794
|
-
schedule.status = "waiting";
|
|
5795
|
-
schedule.blockingTaskCount = blockingTaskCount;
|
|
5796
|
-
schedule.releaseAt = undefined;
|
|
5797
|
-
schedule.releaseCountdownSeconds = undefined;
|
|
5798
|
-
schedule.releaseStarted = false;
|
|
5799
|
-
await this.publishAppServerReleaseSchedule(schedule);
|
|
5800
|
-
this.armAppServerReleaseCheck(schedule);
|
|
5801
|
-
return;
|
|
5802
|
-
}
|
|
5803
|
-
}
|
|
5766
|
+
const interruptedWork = this.appServerReleaseBlockers(schedule.agentName, schedule.runtime).length > 0;
|
|
5767
|
+
await this.cancelQueuedPromptsForAppServerRelease(schedule.agentName);
|
|
5804
5768
|
schedule.status = "releasing";
|
|
5805
5769
|
schedule.blockingTaskCount = 0;
|
|
5806
|
-
schedule.
|
|
5807
|
-
schedule.releaseCountdownSeconds = undefined;
|
|
5770
|
+
schedule.blockingTaskTitles = [];
|
|
5808
5771
|
schedule.releaseStarted = false;
|
|
5809
5772
|
schedule.forced = interruptedWork;
|
|
5810
5773
|
await this.publishAppServerReleaseSchedule(schedule);
|
|
@@ -5813,15 +5776,15 @@ export class ProxySessionController {
|
|
|
5813
5776
|
return;
|
|
5814
5777
|
schedule.releaseStarted = true;
|
|
5815
5778
|
try {
|
|
5816
|
-
const result = await schedule.runtime.release?.({ force });
|
|
5779
|
+
const result = await schedule.runtime.release?.({ force: true });
|
|
5817
5780
|
if (!result)
|
|
5818
5781
|
throw new Error("当前 Agent 不支持释放 App Server。");
|
|
5819
5782
|
if (result.status === "busy") {
|
|
5783
|
+
const blockers = this.appServerReleaseBlockers(schedule.agentName, schedule.runtime);
|
|
5820
5784
|
schedule.status = "waiting";
|
|
5821
|
-
schedule.blockingTaskCount = Math.max(result.activeSessionIds?.length ?? 0,
|
|
5785
|
+
schedule.blockingTaskCount = Math.max(result.activeSessionIds?.length ?? 0, blockers.length, 1);
|
|
5786
|
+
schedule.blockingTaskTitles = this.appServerReleaseTaskTitles(blockers);
|
|
5822
5787
|
schedule.forced = false;
|
|
5823
|
-
schedule.releaseAt = undefined;
|
|
5824
|
-
schedule.releaseCountdownSeconds = undefined;
|
|
5825
5788
|
schedule.releaseStarted = false;
|
|
5826
5789
|
await this.publishAppServerReleaseSchedule(schedule);
|
|
5827
5790
|
this.armAppServerReleaseCheck(schedule);
|
|
@@ -5872,9 +5835,7 @@ export class ProxySessionController {
|
|
|
5872
5835
|
scheduleId: schedule.id,
|
|
5873
5836
|
agentName: schedule.agentName,
|
|
5874
5837
|
...(schedule.blockingTaskCount > 0 ? { blockingTaskCount: schedule.blockingTaskCount } : {}),
|
|
5875
|
-
...(schedule.
|
|
5876
|
-
? { releaseInSeconds: schedule.releaseCountdownSeconds }
|
|
5877
|
-
: {}),
|
|
5838
|
+
...(schedule.blockingTaskTitles.length > 0 ? { blockingTaskTitles: schedule.blockingTaskTitles } : {}),
|
|
5878
5839
|
...(schedule.forced ? { forced: true } : {}),
|
|
5879
5840
|
...(schedule.error ? { error: schedule.error } : {}),
|
|
5880
5841
|
};
|