mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-11 08:10:48 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
153
openclaw/extensions/acpx/src/runtime.ts
Normal file
153
openclaw/extensions/acpx/src/runtime.ts
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
import {
|
||||
ACPX_BACKEND_ID,
|
||||
AcpxRuntime as BaseAcpxRuntime,
|
||||
createAcpRuntime,
|
||||
createAgentRegistry,
|
||||
createFileSessionStore,
|
||||
decodeAcpxRuntimeHandleState,
|
||||
encodeAcpxRuntimeHandleState,
|
||||
type AcpAgentRegistry,
|
||||
type AcpRuntimeDoctorReport,
|
||||
type AcpRuntimeEvent,
|
||||
type AcpRuntimeHandle,
|
||||
type AcpRuntimeOptions,
|
||||
type AcpRuntimeStatus,
|
||||
} from "acpx/runtime";
|
||||
import type { AcpRuntime } from "../runtime-api.js";
|
||||
|
||||
type AcpSessionStore = AcpRuntimeOptions["sessionStore"];
|
||||
type AcpSessionRecord = Parameters<AcpSessionStore["save"]>[0];
|
||||
type AcpLoadedSessionRecord = Awaited<ReturnType<AcpSessionStore["load"]>>;
|
||||
|
||||
type ResetAwareSessionStore = AcpSessionStore & {
|
||||
markFresh: (sessionKey: string) => void;
|
||||
};
|
||||
|
||||
function readSessionRecordName(record: AcpSessionRecord): string {
|
||||
if (typeof record !== "object" || record === null) {
|
||||
return "";
|
||||
}
|
||||
const { name } = record as { name?: unknown };
|
||||
return typeof name === "string" ? name.trim() : "";
|
||||
}
|
||||
|
||||
function createResetAwareSessionStore(baseStore: AcpSessionStore): ResetAwareSessionStore {
|
||||
const freshSessionKeys = new Set<string>();
|
||||
|
||||
return {
|
||||
async load(sessionId: string): Promise<AcpLoadedSessionRecord> {
|
||||
const normalized = sessionId.trim();
|
||||
if (normalized && freshSessionKeys.has(normalized)) {
|
||||
return undefined;
|
||||
}
|
||||
return await baseStore.load(sessionId);
|
||||
},
|
||||
async save(record: AcpSessionRecord): Promise<void> {
|
||||
await baseStore.save(record);
|
||||
const sessionName = readSessionRecordName(record);
|
||||
if (sessionName) {
|
||||
freshSessionKeys.delete(sessionName);
|
||||
}
|
||||
},
|
||||
markFresh(sessionKey: string): void {
|
||||
const normalized = sessionKey.trim();
|
||||
if (normalized) {
|
||||
freshSessionKeys.add(normalized);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
type AcpxRuntimeLike = AcpRuntime & {
|
||||
probeAvailability(): Promise<void>;
|
||||
isHealthy(): boolean;
|
||||
doctor(): Promise<AcpRuntimeDoctorReport>;
|
||||
};
|
||||
|
||||
export class AcpxRuntime implements AcpxRuntimeLike {
|
||||
private readonly sessionStore: ResetAwareSessionStore;
|
||||
private readonly delegate: BaseAcpxRuntime;
|
||||
|
||||
constructor(
|
||||
options: AcpRuntimeOptions,
|
||||
testOptions?: ConstructorParameters<typeof BaseAcpxRuntime>[1],
|
||||
) {
|
||||
this.sessionStore = createResetAwareSessionStore(options.sessionStore);
|
||||
this.delegate = new BaseAcpxRuntime(
|
||||
{
|
||||
...options,
|
||||
sessionStore: this.sessionStore,
|
||||
},
|
||||
testOptions,
|
||||
);
|
||||
}
|
||||
|
||||
isHealthy(): boolean {
|
||||
return this.delegate.isHealthy();
|
||||
}
|
||||
|
||||
probeAvailability(): Promise<void> {
|
||||
return this.delegate.probeAvailability();
|
||||
}
|
||||
|
||||
doctor(): Promise<AcpRuntimeDoctorReport> {
|
||||
return this.delegate.doctor();
|
||||
}
|
||||
|
||||
ensureSession(input: Parameters<AcpRuntime["ensureSession"]>[0]): Promise<AcpRuntimeHandle> {
|
||||
return this.delegate.ensureSession(input);
|
||||
}
|
||||
|
||||
runTurn(input: Parameters<AcpRuntime["runTurn"]>[0]): AsyncIterable<AcpRuntimeEvent> {
|
||||
return this.delegate.runTurn(input);
|
||||
}
|
||||
|
||||
getCapabilities(): ReturnType<BaseAcpxRuntime["getCapabilities"]> {
|
||||
return this.delegate.getCapabilities();
|
||||
}
|
||||
|
||||
getStatus(input: Parameters<NonNullable<AcpRuntime["getStatus"]>>[0]): Promise<AcpRuntimeStatus> {
|
||||
return this.delegate.getStatus(input);
|
||||
}
|
||||
|
||||
setMode(input: Parameters<NonNullable<AcpRuntime["setMode"]>>[0]): Promise<void> {
|
||||
return this.delegate.setMode(input);
|
||||
}
|
||||
|
||||
setConfigOption(input: Parameters<NonNullable<AcpRuntime["setConfigOption"]>>[0]): Promise<void> {
|
||||
return this.delegate.setConfigOption(input);
|
||||
}
|
||||
|
||||
cancel(input: Parameters<AcpRuntime["cancel"]>[0]): Promise<void> {
|
||||
return this.delegate.cancel(input);
|
||||
}
|
||||
|
||||
async prepareFreshSession(input: { sessionKey: string }): Promise<void> {
|
||||
this.sessionStore.markFresh(input.sessionKey);
|
||||
}
|
||||
|
||||
close(input: Parameters<AcpRuntime["close"]>[0]): Promise<void> {
|
||||
return this.delegate
|
||||
.close({
|
||||
handle: input.handle,
|
||||
reason: input.reason,
|
||||
discardPersistentState: input.discardPersistentState,
|
||||
})
|
||||
.then(() => {
|
||||
if (input.discardPersistentState) {
|
||||
this.sessionStore.markFresh(input.handle.sessionKey);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
ACPX_BACKEND_ID,
|
||||
createAcpRuntime,
|
||||
createAgentRegistry,
|
||||
createFileSessionStore,
|
||||
decodeAcpxRuntimeHandleState,
|
||||
encodeAcpxRuntimeHandleState,
|
||||
};
|
||||
|
||||
export type { AcpAgentRegistry, AcpRuntimeOptions, AcpSessionRecord, AcpSessionStore };
|
||||
Loading…
Add table
Add a link
Reference in a new issue