Skip to content

Commit ce1ef04

Browse files
committed
docs: document schema media planning helpers
1 parent 79f6c5a commit ce1ef04

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/agents/models-config.providers.source-managed.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import {
88
} from "./model-auth-markers.js";
99
import type { ProviderConfig, SecretDefaults } from "./models-config.providers.secrets.js";
1010

11+
/**
12+
* Reapplies source-managed secret markers to normalized provider config.
13+
*
14+
* This keeps runtime snapshots from materializing secret refs as plain values after config
15+
* normalization rewrites provider entries.
16+
*/
1117
type ModelsConfig = NonNullable<OpenClawConfig["models"]>;
1218

1319
function normalizeSourceProviderLookup(
@@ -70,6 +76,7 @@ function resolveSourceManagedHeaderMarkers(params: {
7076
return markers;
7177
}
7278

79+
/** Preserves source-managed apiKey/header markers from the original provider config. */
7380
export function enforceSourceManagedProviderSecrets(params: {
7481
providers: ModelsConfig["providers"];
7582
sourceProviders: ModelsConfig["providers"] | undefined;
@@ -120,6 +127,8 @@ export function enforceSourceManagedProviderSecrets(params: {
120127
const currentHeaders = isRecord(nextProvider.headers)
121128
? (nextProvider.headers as Record<string, unknown>)
122129
: undefined;
130+
// Merge marker headers over normalized headers so auth metadata remains managed while
131+
// unrelated provider headers survive normalization.
123132
const nextHeaders = {
124133
...(currentHeaders as Record<string, NonNullable<ProviderConfig["headers"]>[string]>),
125134
};

src/agents/openai-tool-schema.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import type { ModelCompatConfig } from "../config/types.models.js";
22
import { shouldOmitEmptyArrayItems } from "../plugins/provider-model-compat.js";
33
import { normalizeToolParameterSchema } from "./agent-tools-parameter-schema.js";
44

5+
/**
6+
* OpenAI strict-tool-schema normalization and diagnostics.
7+
*
8+
* Strict schemas need all object properties required and `additionalProperties: false`; model
9+
* compatibility settings can also remove unsupported schema constructs before strict checks run.
10+
*/
511
type ToolSchemaCompatInput = {
612
unsupportedToolSchemaKeywords?: unknown;
713
omitEmptyArrayItems?: unknown;
@@ -65,6 +71,7 @@ export function clearOpenAIToolSchemaCacheForTest(): void {
6571
strictOpenAISchemaCache = new WeakMap();
6672
}
6773

74+
/** Normalizes a tool parameter schema into the OpenAI strict JSON-schema subset. */
6875
export function normalizeStrictOpenAIJsonSchema(
6976
schema: unknown,
7077
modelCompat?: ToolSchemaCompatInput | null,
@@ -86,6 +93,8 @@ export function normalizeStrictOpenAIJsonSchema(
8693
return rememberStrictOpenAISchema(
8794
schemaInput,
8895
cacheKey,
96+
// Cache by input object and compatibility key so repeated inventory generation preserves object
97+
// identity without mixing schemas normalized for different provider limitations.
8998
normalizeStrictOpenAIJsonSchemaRecursive(
9099
normalizeToolParameterSchema(schemaInput, {
91100
modelCompat: resolveToolSchemaModelCompat(modelCompat),
@@ -141,6 +150,7 @@ function normalizeStrictOpenAIJsonSchemaRecursive(schema: unknown, depth: number
141150
return changed ? normalized : schema;
142151
}
143152

153+
/** Normalizes tool parameters using strict OpenAI rules only when strict mode is active. */
144154
export function normalizeOpenAIStrictToolParameters<T>(
145155
schema: T,
146156
strict: boolean,
@@ -153,6 +163,7 @@ export function normalizeOpenAIStrictToolParameters<T>(
153163
return normalizeStrictOpenAIJsonSchema(schema, toolSchemaCompat) as T;
154164
}
155165

166+
/** Returns whether a schema already satisfies OpenAI strict tool-schema constraints. */
156167
export function isStrictOpenAIJsonSchemaCompatible(schema: unknown): boolean {
157168
return isStrictOpenAIJsonSchemaCompatibleRecursive(normalizeStrictOpenAIJsonSchema(schema));
158169
}
@@ -163,6 +174,7 @@ type OpenAIStrictToolSchemaDiagnostic = {
163174
violations: string[];
164175
};
165176

177+
/** Returns strict-schema violation paths for each incompatible tool definition. */
166178
export function findOpenAIStrictToolSchemaDiagnostics(
167179
tools: readonly ToolWithParameters[],
168180
): OpenAIStrictToolSchemaDiagnostic[] {
@@ -297,6 +309,7 @@ function findStrictOpenAIJsonSchemaViolations(schema: unknown, path: string): st
297309
return violations;
298310
}
299311

312+
/** Resolves the strict flag to advertise for a tool inventory after compatibility checks. */
300313
export function resolveOpenAIStrictToolFlagForInventory(
301314
tools: readonly ToolWithParameters[],
302315
strict: boolean | null | undefined,

src/agents/openclaw-tools.media-factory-plan.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import {
1616
loadCapabilityMetadataSnapshot,
1717
} from "./tools/manifest-capability-availability.js";
1818

19+
/**
20+
* Plans optional media-tool factory registration from config, policy, capabilities, and auth.
21+
*/
1922
export type OptionalMediaToolFactoryPlan = {
2023
imageGenerate: boolean;
2124
videoGenerate: boolean;
@@ -66,6 +69,7 @@ function isToolAllowedByFactoryPolicy(params: {
6669
});
6770
}
6871

72+
/** Returns true only when an allowlist explicitly enables the requested tool. */
6973
export function isToolExplicitlyAllowedByFactoryPolicy(params: {
7074
toolName: string;
7175
allowlist?: string[];
@@ -77,6 +81,7 @@ export function isToolExplicitlyAllowedByFactoryPolicy(params: {
7781
return isToolAllowedByFactoryPolicy(params);
7882
}
7983

84+
/** Merges factory policy lists while preserving stable unique entries. */
8085
export function mergeFactoryPolicyList(
8186
...lists: Array<string[] | undefined>
8287
): string[] | undefined {
@@ -99,6 +104,7 @@ function mergeBuiltInFactoryAllowlist(...lists: Array<string[] | undefined>): st
99104
return uniqueStrings(["*", ...withoutDefaultPluginMarker]);
100105
}
101106

107+
/** Returns whether the image understanding tool can be constructed for this agent context. */
102108
export function resolveImageToolFactoryAvailable(params: {
103109
config?: OpenClawConfig;
104110
agentDir?: string;
@@ -164,6 +170,7 @@ function hasConfiguredVisionModelAuthSignal(params: {
164170
return false;
165171
}
166172

173+
/** Resolves which optional media tools should be created for the current tool factory call. */
167174
export function resolveOptionalMediaToolFactoryPlan(params: {
168175
config?: OpenClawConfig;
169176
workspaceDir?: string;
@@ -202,6 +209,8 @@ export function resolveOptionalMediaToolFactoryPlan(params: {
202209
const explicitMusicGeneration = hasExplicitToolModelConfig(defaults?.musicGenerationModel);
203210
const explicitPdf = hasExplicitPdfModelConfig(params.config);
204211
if (params.config?.plugins?.enabled === false) {
212+
// Optional media tools are plugin/capability backed. Disabling plugins shuts them off even when
213+
// stale defaults or env availability would otherwise appear to make a tool available.
205214
return {
206215
imageGenerate: false,
207216
videoGenerate: false,

src/agents/prompt-surface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { isOpenClawMainPromptSurface } from "../plugins/agent-prompt-surface-kin
22
import type { AgentPromptSurfaceKind } from "../plugins/types.js";
33
import { isAcpSessionKey, isSubagentSessionKey } from "../routing/session-key.js";
44

5+
/**
6+
* Prompt-surface helpers for deciding which OpenClaw tool guidance belongs in a session prompt.
7+
*/
8+
/** Builds fallback tool guidance when a runtime cannot render the structured tool list. */
59
export function buildOpenClawToolFallbackText(params: {
610
surface: AgentPromptSurfaceKind;
711
execToolName: string;
@@ -33,13 +37,15 @@ export function buildOpenClawToolFallbackText(params: {
3337
return "No OpenClaw tool list is injected for this runtime prompt surface. Use only tools exposed directly by the active backend.";
3438
}
3539

40+
/** Returns whether the main OpenClaw prompt should include workflow hints around the tool list. */
3641
export function shouldRenderOpenClawToolWorkflowHints(params: {
3742
surface: AgentPromptSurfaceKind;
3843
hasToolList: boolean;
3944
}): boolean {
4045
return isOpenClawMainPromptSurface(params.surface);
4146
}
4247

48+
/** Maps a session key to the prompt surface used for tool guidance and runtime behavior. */
4349
export function resolveAgentPromptSurfaceForSessionKey(
4450
sessionKey?: string,
4551
): AgentPromptSurfaceKind {

0 commit comments

Comments
 (0)