mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:10:41 +00:00
* refactor: centralize runtime plan policy surface * refactor: route embedded attempts through runtime plan * feat: add agent harness v2 lifecycle adapter * docs: document agent harness runtime plan --------- Co-authored-by: Eva <eva@100yen.org> Co-authored-by: Peter Steinberger <steipete@gmail.com>
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
import type { TSchema } from "typebox";
|
|
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
|
import type { ProviderRuntimeModel } from "../../plugins/provider-runtime-model.types.js";
|
|
import {
|
|
logProviderToolSchemaDiagnostics,
|
|
normalizeProviderToolSchemas,
|
|
} from "../pi-embedded-runner/tool-schema-runtime.js";
|
|
import type { AgentRuntimePlan } from "./types.js";
|
|
|
|
type AgentRuntimeToolPolicyParams<TSchemaType extends TSchema = TSchema, TResult = unknown> = {
|
|
runtimePlan?: AgentRuntimePlan;
|
|
tools: AgentTool<TSchemaType, TResult>[];
|
|
provider: string;
|
|
config?: OpenClawConfig;
|
|
workspaceDir?: string;
|
|
env?: NodeJS.ProcessEnv;
|
|
modelId?: string;
|
|
modelApi?: string | null;
|
|
model?: ProviderRuntimeModel;
|
|
};
|
|
|
|
function runtimePlanToolContext(params: {
|
|
workspaceDir?: string;
|
|
modelApi?: string | null;
|
|
model?: ProviderRuntimeModel;
|
|
}) {
|
|
return {
|
|
workspaceDir: params.workspaceDir,
|
|
modelApi: params.modelApi ?? undefined,
|
|
model: params.model,
|
|
};
|
|
}
|
|
|
|
export function normalizeAgentRuntimeTools<
|
|
TSchemaType extends TSchema = TSchema,
|
|
TResult = unknown,
|
|
>(params: AgentRuntimeToolPolicyParams<TSchemaType, TResult>): AgentTool<TSchemaType, TResult>[] {
|
|
const planContext = runtimePlanToolContext(params);
|
|
return (
|
|
params.runtimePlan?.tools.normalize(params.tools, planContext) ??
|
|
normalizeProviderToolSchemas({
|
|
tools: params.tools,
|
|
provider: params.provider,
|
|
config: params.config,
|
|
workspaceDir: params.workspaceDir,
|
|
env: params.env ?? process.env,
|
|
modelId: params.modelId,
|
|
modelApi: params.modelApi,
|
|
model: params.model,
|
|
})
|
|
);
|
|
}
|
|
|
|
export function logAgentRuntimeToolDiagnostics(params: AgentRuntimeToolPolicyParams): void {
|
|
const planContext = runtimePlanToolContext(params);
|
|
if (params.runtimePlan) {
|
|
params.runtimePlan.tools.logDiagnostics(params.tools, planContext);
|
|
return;
|
|
}
|
|
logProviderToolSchemaDiagnostics({
|
|
tools: params.tools,
|
|
provider: params.provider,
|
|
config: params.config,
|
|
workspaceDir: params.workspaceDir,
|
|
env: params.env ?? process.env,
|
|
modelId: params.modelId,
|
|
modelApi: params.modelApi,
|
|
model: params.model,
|
|
});
|
|
}
|