feat(FN-2701): route OpenClaw runtime sessions through gateway client

- Add a dedicated gateway client seam and wire runtime adapter sessions through the new request path
- Remove legacy engine-guard/pi seam exports and align runtime types with gateway-facing behavior
- Fix gateway request/stream handling by preventing duplicate user turns, stabilizing tool-call callbacks, and adding a no-op session dispose hook
- Expand plugin test coverage for gateway client, adapter, and index behavior and document runtime gateway behavior in the README
This commit is contained in:
Fusion
2026-04-27 09:46:25 -07:00
committed by gsxdsm
parent 205370894e
commit b67d409480
14 changed files with 676 additions and 292 deletions

View File

@@ -1,49 +1,58 @@
import type {
AgentRuntime,
AgentRuntimeOptions,
AgentSession,
AgentSessionResult,
GatewayConfig,
GatewaySession,
} from "./types.js";
import { createFnAgent, describeModel, promptWithFallback } from "./pi-module.js";
const getModelDescription = describeModel;
import {
createGatewaySession,
describeGatewayModel,
promptGateway,
resolveGatewayConfig,
} from "./pi-module.js";
export class OpenClawRuntimeAdapter implements AgentRuntime {
readonly id = "openclaw";
readonly name = "OpenClaw Runtime";
private readonly config: GatewayConfig;
constructor(settings?: Partial<GatewayConfig>) {
this.config = resolveGatewayConfig(settings as Record<string, unknown> | undefined);
}
async createSession(options: AgentRuntimeOptions): Promise<AgentSessionResult> {
return createFnAgent({
cwd: options.cwd,
const session = createGatewaySession({
gatewayUrl: this.config.gatewayUrl,
gatewayToken: this.config.gatewayToken,
agentId: this.config.agentId,
systemPrompt: options.systemPrompt,
tools: options.tools,
customTools: options.customTools,
onText: options.onText,
onThinking: options.onThinking,
onToolStart: options.onToolStart,
onToolEnd: options.onToolEnd,
defaultProvider: options.defaultProvider,
defaultModelId: options.defaultModelId,
fallbackProvider: options.fallbackProvider,
fallbackModelId: options.fallbackModelId,
defaultThinkingLevel: options.defaultThinkingLevel,
sessionManager: options.sessionManager,
skillSelection: options.skillSelection,
skills: options.skills,
callbacks: {
onText: options.onText,
onThinking: options.onThinking,
onToolStart: options.onToolStart,
onToolEnd: options.onToolEnd,
},
});
return {
session,
sessionFile: undefined,
};
}
async promptWithFallback(session: AgentSession, prompt: string, options?: unknown): Promise<void> {
return promptWithFallback(session, prompt, options);
async promptWithFallback(session: GatewaySession, prompt: string, options?: unknown): Promise<void> {
session.messages.push({ role: "user", content: prompt });
await promptGateway(session, prompt, options as Parameters<typeof promptGateway>[2]);
}
describeModel(session: AgentSession): string {
return getModelDescription(session);
describeModel(session: GatewaySession): string {
return describeGatewayModel(session);
}
async dispose(session: AgentSession): Promise<void> {
if (typeof (session as { dispose?: () => Promise<void> }).dispose === "function") {
await (session as { dispose: () => Promise<void> }).dispose();
}
async dispose(_session: GatewaySession): Promise<void> {
// OpenClaw gateway sessions are managed remotely; no local cleanup required.
}
}