Files
openclaw/src/gateway/server-plugin-subagent-runtime.ts
T
Vincent Koc 8530edb057 fix(plugins): deliver subagent completion to current requester (#116091)
* fix(plugins): deliver subagent completion to requester

Co-authored-by: ambitioncn <36698505+ambitioncn@users.noreply.github.com>

* test(qa): register current-requester plugin fixture

* fix(plugins): scope requester authority per hook

---------

Co-authored-by: ambitioncn <36698505+ambitioncn@users.noreply.github.com>
2026-07-30 07:06:17 +08:00

52 lines
1.8 KiB
TypeScript

import { parseModelCatalogRef } from "@openclaw/model-catalog-core/model-catalog-refs";
import { normalizeModelRef, parseModelRef } from "../agents/model-selection.js";
import type { PluginRuntime } from "../plugins/runtime/types.js";
export function normalizePluginSubagentAllowedModelRef(raw: string): string | null {
const trimmed = raw.trim();
if (!trimmed) {
return null;
}
if (trimmed === "*") {
return "*";
}
const parsed = parseModelCatalogRef(trimmed);
if (!parsed) {
return null;
}
const normalized = normalizeModelRef(parsed.provider, parsed.modelId);
return `${normalized.provider}/${normalized.model}`;
}
export function resolvePluginSubagentRequestedModelRef(params: {
provider?: string;
model?: string;
}): string | null {
if (params.provider && params.model) {
const normalizedRequest = normalizeModelRef(params.provider, params.model);
return `${normalizedRequest.provider}/${normalizedRequest.model}`;
}
const rawModel = params.model?.trim();
if (!rawModel || !rawModel.includes("/")) {
return null;
}
const parsed = parseModelRef(rawModel, "");
if (!parsed?.provider || !parsed.model) {
return null;
}
return `${parsed.provider}/${parsed.model}`;
}
export function normalizePluginSubagentRunRuntime(
value: unknown,
): Awaited<ReturnType<PluginRuntime["subagent"]["run"]>>["runtime"] {
if (!value || typeof value !== "object" || Array.isArray(value)) {
return undefined;
}
const record = value as Record<string, unknown>;
const harness = typeof record.harness === "string" ? record.harness.trim() : "";
const provider = typeof record.provider === "string" ? record.provider.trim() : "";
const model = typeof record.model === "string" ? record.model.trim() : "";
return harness && provider && model ? { harness, provider, model } : undefined;
}