Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): tool validation - unify schemas on one eve-owned ToolSchema boundary (#908)

Andrew Barba14501dc5665b
diff --git a/.changeset/validate-framework-tool-inputs.md b/.changeset/validate-framework-tool-inputs.md
new file mode 100644
index 000000000..4638b551f
--- /dev/null
+++ b/.changeset/validate-framework-tool-inputs.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Every eve-owned tool input is now validated against its schema before execution, so invalid calls are returned to the model for retry instead of failing the run. Subagent calls treat an empty `outputSchema` as absent, and OpenAPI operations with invalid schemas are omitted with a warning.
diff --git a/packages/eve/src/client/output-schema.test.ts b/packages/eve/src/client/output-schema.test.ts
index b538bd1f8..ad2bd0fe7 100644
--- a/packages/eve/src/client/output-schema.test.ts
+++ b/packages/eve/src/client/output-schema.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
-import { extractCompletedResult, normalizeOutputSchemaForRequest } from "#client/output-schema.js";
+import { extractCompletedResult } from "#client/output-schema.js";
import {
createResultCompletedEvent,
createTurnCompletedEvent,
@@ -8,18 +8,6 @@ import {
} from "#protocol/message.js";
describe("output schema client helpers", () => {
- it("normalizes raw JSON Schema objects for request bodies", () => {
- const schema = {
- properties: {
- title: { type: "string" },
- },
- required: ["title"],
- type: "object",
- } as const;
-
- expect(normalizeOutputSchemaForRequest(schema)).toEqual(schema);
- });
-
it("extracts the most recent completed structured result", () => {
const events: HandleMessageStreamEvent[] = [
createResultCompletedEvent({
diff --git a/packages/eve/src/client/output-schema.ts b/packages/eve/src/client/output-schema.ts
index b758b9125..f0e48cbde 100644
--- a/packages/eve/src/client/output-schema.ts
+++ b/packages/eve/src/client/output-schema.ts
@@ -1,18 +1,4 @@
-import type { StandardJSONSchemaV1 } from "#compiled/@standard-schema/spec/index.js";
-
import type { HandleMessageStreamEvent, ResultCompletedStreamEvent } from "#protocol/message.js";
-import { normalizeJsonSchemaDefinition } from "#shared/json-schema.js";
-import type { JsonObject } from "#shared/json.js";
-
-/**
- * Normalizes a client-supplied output schema into the wire-safe JSON Schema
- * representation accepted by eve message routes.
- */
-export function normalizeOutputSchemaForRequest<TOutput>(
- schema: StandardJSONSchemaV1<unknown, TOutput> | JsonObject | undefined,
-): JsonObject | undefined {
- return schema === undefined ? undefined : normalizeJsonSchemaDefinition(schema, "output");
-}
/**
* Extracts the most recent finalized structured result from a turn event list.
diff --git a/packages/eve/src/client/session.ts b/packages/eve/src/client/session.ts
index 04940a4b0..d49447a13 100644
--- a/packages/eve/src/client/session.ts
+++ b/packages/eve/src/client/session.ts
@@ -10,8 +10,8 @@ import { ClientError } from "#client/client-error.js";
import { MessageResponse } from "#client/message-response.js";
import { isStreamDisconnectError, readNdjsonStream } from "#client/ndjson.js";
import { openStreamBody, openStreamIterable } from "#client/open-stream.js";
-import { normalizeOutputSchemaForRequest } from "#client/output-schema.js";
import { advanceSession } from "#client/session-utils.js";
+import { serializeOutputSchema } from "#shared/tool-schema.js";
import { createClientUrl } from "#client/url.js";
import type {
CancelSessionResult,
@@ -182,7 +182,7 @@ export class ClientSession {
const body = createHandleMessageBody({
input,
- outputSchema: normalizeOutputSchemaForRequest(input.outputSchema),
+ outputSchema: serializeOutputSchema(input.outputSchema),
session,
});
diff --git a/packages/eve/src/compiler/normalize-agent-config.ts b/packages/eve/src/compiler/normalize-agent-config.ts
index 757cb48ae..ffa999e02 100644
--- a/packages/eve/src/compiler/normalize-agent-config.ts
+++ b/packages/eve/src/compiler/normalize-agent-config.ts
@@ -3,7 +3,7 @@ import { isAbsolute, join, relative, resolve } from "node:path";
import type { AgentSourceManifest } from "#discover/manifest.js";
import { normalizeLogicalPath } from "#discover/filesystem.js";
import { normalizeAgentDefinition } from "#internal/authored-definition/core.js";
-import { normalizeJsonSchemaDefinition } from "#shared/json-schema.js";
+import { serializeOutputSchema } from "#shared/tool-schema.js";
import { formatLanguageModelGatewayId } from "#internal/runtime-model.js";
import { classifyModelRouting } from "#internal/classify-model-routing.js";
import { DEFAULT_AGENT_MODEL_ID } from "#shared/default-agent-model.js";
@@ -118,7 +118,7 @@ export async function compileAgentConfig(
}
if (definition.outputSchema !== undefined) {
- compiledConfig.outputSchema = normalizeJsonSchemaDefinition(definition.outputSchema, "output");
+ compiledConfig.outputSchema = serializeOutputSchema(definition.outputSchema);
}
if (definition.reasoning !== undefined) {
diff --git a/packages/eve/src/compiler/normalize-subagent.ts b/packages/eve/src/compiler/normalize-subagent.ts
index 11458ffdf..c50802b21 100644
--- a/packages/eve/src/compiler/normalize-subagent.ts
+++ b/packages/eve/src/compiler/normalize-subagent.ts
@@ -20,7 +20,7 @@ import {
expectString,
} from "#internal/authored-module.js";
import { EVE_CREATE_SESSION_ROUTE_PATH } from "#protocol/routes.js";
-import { normalizeJsonSchemaDefinition } from "#shared/json-schema.js";
+import { serializeOutputSchema, type ToolSchemaSource } from "#shared/tool-schema.js";
import type { JsonObject } from "#shared/json.js";
/**
@@ -305,10 +305,7 @@ function normalizeRemoteAgentDefinition(
return {
description: expectString(record.description, message),
- outputSchema:
- record.outputSchema === undefined
- ? undefined
- : normalizeJsonSchemaDefinition(record.outputSchema, "output"),
+ outputSchema: serializeOutputSchema(record.outputSchema as ToolSchemaSource | undefined),
path:
record.path === undefined
? EVE_CREATE_SESSION_ROUTE_PATH
diff --git a/packages/eve/src/context/build-dynamic-tools.ts b/packages/eve/src/context/build-dynamic-tools.ts
index c424ef814..c96ecba7a 100644
--- a/packages/eve/src/context/build-dynamic-tools.ts
+++ b/packages/eve/src/context/build-dynamic-tools.ts
@@ -1,5 +1,3 @@
-import { jsonSchema } from "ai";
-
import type { HarnessToolDefinition } from "#harness/execute-tool.js";
import type { ContextKey } from "#context/key.js";
import {
@@ -11,6 +9,7 @@ import type { DurableDynamicToolMetadata } from "#context/keys.js";
import { buildBaseToolContext } from "#context/build-base-tool-context.js";
import { createLogger } from "#internal/logging.js";
import type { ApprovalContext, ApprovalStatus } from "#public/definitions/approval.js";
+import { toInputSchema, toOutputSchema } from "#shared/tool-schema.js";
const log = createLogger("dynamic-tools");
@@ -52,10 +51,10 @@ function replayTools(metadata: readonly DurableDynamicToolMetadata[]): HarnessTo
description: m.description,
execute: (input: unknown, options) =>
stepFn(m.closureVars, input, buildBaseToolContext({ options, toolName: m.name })),
- inputSchema: jsonSchema(m.inputSchema),
+ inputSchema: toInputSchema(m.inputSchema),
name: m.name,
approval: buildReplayedApproval(m),
- outputSchema: m.outputSchema === undefined ? undefined : jsonSchema(m.outputSchema),
+ outputSchema: toOutputSchema(m.outputSchema),
});
}
diff --git a/packages/eve/src/context/dynamic-tool-lifecycle.test.ts b/packages/eve/src/context/dynamic-tool-lifecycle.test.ts
index b389f04c1..55d16d49c 100644
--- a/packages/eve/src/context/dynamic-tool-lifecycle.test.ts
+++ b/packages/eve/src/context/dynamic-tool-lifecycle.test.ts
@@ -4,6 +4,7 @@ import type { DynamicToolEntry } from "#shared/dynamic-tool-definition.js";
import type { DurableDynamicToolMetadata } from "#context/keys.js";
import type { ApprovalContext } from "#public/definitions/approval.js";
import { defineTool } from "#public/definitions/tool.js";
+import { serializeOutputSchema, type ToolSchema } from "#shared/tool-schema.js";
vi.mock("#context/build-callback-context.js", () => ({
buildCallbackContext: () => ({
@@ -1002,7 +1003,7 @@ describe("framework dynamic tools (no bundler transform)", () => {
const tools = buildDynamicTools(ctx);
expect(tools).toHaveLength(1);
- expect((tools[0]!.outputSchema as { jsonSchema: unknown }).jsonSchema).toEqual(outputSchema);
+ expect(serializeOutputSchema(tools[0]!.outputSchema as ToolSchema)).toEqual(outputSchema);
});
it("leaves approval undefined when a step-scoped entry omits it", async () => {
diff --git a/packages/eve/src/context/dynamic-tool-lifecycle.ts b/packages/eve/src/context/dynamic-tool-lifecycle.ts
index c2166d787..deeea44be 100644
--- a/packages/eve/src/context/dynamic-tool-lifecycle.ts
+++ b/packages/eve/src/context/dynamic-tool-lifecycle.ts
@@ -1,4 +1,4 @@
-import { jsonSchema, zodSchema, type FlexibleSchema, type ModelMessage } from "ai";
+import type { ModelMessage } from "ai";
import type { HarnessToolDefinition } from "#harness/execute-tool.js";
import type { ApprovalContext } from "#public/definitions/approval.js";
@@ -10,7 +10,12 @@ import {
} from "#shared/dynamic-tool-definition.js";
import type { ResolvedDynamicToolResolver } from "#runtime/types.js";
import { createLogger } from "#internal/logging.js";
-import { normalizeJsonSchemaDefinition } from "#internal/json-schema.js";
+import {
+ serializeInputSchema,
+ serializeOutputSchema,
+ toInputSchema,
+ toOutputSchema,
+} from "#shared/tool-schema.js";
import { toErrorMessage } from "#shared/errors.js";
import { buildBaseToolContext } from "#context/build-base-tool-context.js";
import type { ContextContainer } from "#context/container.js";
@@ -37,31 +42,16 @@ function toHarnessToolDefinition(name: string, entry: DynamicToolEntry): Harness
input as Record<string, unknown>,
buildBaseToolContext({ options, toolName: name }),
),
- inputSchema: convertInputSchema(entry.inputSchema),
+ inputSchema: toInputSchema(entry.inputSchema),
name,
approval: entry.approval,
- outputSchema: convertOptionalOutputSchema(entry.outputSchema),
+ outputSchema: toOutputSchema(entry.outputSchema),
...(entry.toModelOutput !== undefined
? { toModelOutput: entry.toModelOutput as (output: unknown) => unknown }
: {}),
};
}
-function convertInputSchema(schema: unknown): FlexibleSchema {
- if (typeof schema === "object" && schema !== null && "~standard" in schema) {
- return zodSchema(schema as Parameters<typeof zodSchema>[0]);
- }
- return jsonSchema(schema as Parameters<typeof jsonSchema>[0]);
-}
-
-function convertOptionalOutputSchema(schema: unknown): FlexibleSchema | undefined {
- if (schema === undefined) return undefined;
- if (typeof schema === "object" && schema !== null && "~standard" in schema) {
- return zodSchema(schema as Parameters<typeof zodSchema>[0]);
- }
- return jsonSchema(schema as Parameters<typeof jsonSchema>[0]);
-}
-
function qualifyDynamicToolNames(
resolver: ResolvedDynamicToolResolver,
isSingle: boolean,
@@ -128,9 +118,9 @@ export function replayDynamicSessionTools(
description: m.description,
execute: (input: unknown, options) =>
stepFn(m.closureVars, input, buildBaseToolContext({ options, toolName: m.name })),
- inputSchema: jsonSchema(m.inputSchema),
+ inputSchema: toInputSchema(m.inputSchema),
name: m.name,
- outputSchema: m.outputSchema === undefined ? undefined : jsonSchema(m.outputSchema),
+ outputSchema: toOutputSchema(m.outputSchema),
});
}
@@ -312,11 +302,8 @@ async function resolveToolsFromEvent(
metadata.push({
name,
description: entry.description,
- inputSchema: normalizeJsonSchemaDefinition(entry.inputSchema),
- outputSchema:
- entry.outputSchema === undefined
- ? undefined
- : normalizeJsonSchemaDefinition(entry.outputSchema, "output"),
+ inputSchema: serializeInputSchema(entry.inputSchema),
+ outputSchema: serializeOutputSchema(entry.outputSchema),
resolverSlug: resolver.slug,
entryKey,
executeStepFnName,
diff --git a/packages/eve/src/evals/autoevals-client.ts b/packages/eve/src/evals/autoevals-client.ts
index ce1da5e48..7920f0846 100644
--- a/packages/eve/src/evals/autoevals-client.ts
+++ b/packages/eve/src/evals/autoevals-client.ts
@@ -1,6 +1,5 @@
import {
generateText,
- jsonSchema,
type LanguageModel,
type ModelMessage,
type ToolChoice,
@@ -8,6 +7,8 @@ import {
} from "ai";
import { Factuality } from "autoevals";
+import { toInputSchema } from "#shared/tool-schema.js";
+
/**
* The OpenAI-shaped client surface autoevals expects. Extracted from the
* library so we don't take a direct dependency on `openai` types.
@@ -130,7 +131,7 @@ function convertTools(tools: readonly ChatTool[] | undefined): ToolSet {
if (item.type !== "function" || item.function?.name === undefined) continue;
result[item.function.name] = {
description: item.function.description,
- inputSchema: jsonSchema(item.function.parameters ?? {}),
+ inputSchema: toInputSchema(item.function.parameters ?? {}),
};
}
return result;
diff --git a/packages/eve/src/execution/node-step.test.ts b/packages/eve/src/execution/node-step.test.ts
index ef962133d..6a77eb283 100644
--- a/packages/eve/src/execution/node-step.test.ts
+++ b/packages/eve/src/execution/node-step.test.ts
@@ -15,6 +15,7 @@ import { createRuntimeToolRegistry } from "#runtime/tools/registry.js";
import { createExecutionNodeStep, createNodeHarnessTools } from "#execution/node-step.js";
import { createSession } from "#execution/session.js";
import { createStubSandboxRegistry } from "#internal/testing/stub-sandbox-registry.js";
+import { toInputSchema } from "#shared/tool-schema.js";
vi.mock("ai", () => ({
ToolLoopAgent: vi.fn(),
@@ -275,7 +276,7 @@ describe("createExecutionNodeStep", () => {
{
description: "A regular tool.",
execute: async () => "tool-output",
- inputSchema: { type: "object" },
+ inputSchema: toInputSchema({ type: "object" }),
logicalPath: "tools/regular-tool.ts",
name: "regular-tool",
sourceId: "tools/regular-tool.ts",
diff --git a/packages/eve/src/execution/node-step.ts b/packages/eve/src/execution/node-step.ts
index f5b7f265e..1a9060851 100644
--- a/packages/eve/src/execution/node-step.ts
+++ b/packages/eve/src/execution/node-step.ts
@@ -1,4 +1,4 @@
-import { jsonSchema, type FlexibleSchema, type LanguageModel } from "ai";
+import type { LanguageModel } from "ai";
import type { Runtime, SessionCapabilities } from "#channel/types.js";
import { dispatchDynamicModelEvent } from "#context/dynamic-model-lifecycle.js";
@@ -8,6 +8,7 @@ import type { HandleEventFn, HarnessToolMap, StepFn } from "#harness/types.js";
import { resolveInstalledPackageInfo } from "#internal/application/package.js";
import { createLogger } from "#internal/logging.js";
import type { RuntimeIdentity } from "#protocol/message.js";
+import { UNSPECIFIED_INPUT_SCHEMA, toInputSchema, toOutputSchema } from "#shared/tool-schema.js";
import type { RunMode } from "#shared/run-mode.js";
import {
resolveRuntimeModelReference,
@@ -182,7 +183,7 @@ export function createNodeHarnessTools(input: {
) {
tools.set(AGENT_TOOL_NAME, {
description: AGENT_TOOL_DESCRIPTION,
- inputSchema: jsonSchema(SUBAGENT_TOOL_INPUT_SCHEMA),
+ inputSchema: SUBAGENT_TOOL_INPUT_SCHEMA,
name: AGENT_TOOL_NAME,
runtimeAction: {
kind: "subagent-call",
@@ -199,34 +200,26 @@ function resolveHarnessToolDefinition(input: {
readonly node: ResolvedRuntimeAgentNode;
readonly tool: PreparedRuntimeTool;
}): HarnessToolDefinition | null {
- if (input.tool.kind === "subagent") {
+ if (input.tool.kind === "subagent" || input.tool.kind === "remote") {
+ const runtimeAction: HarnessToolDefinition["runtimeAction"] =
+ input.tool.kind === "remote"
+ ? {
+ kind: "remote-agent-call",
+ nodeId: input.tool.nodeId,
+ remoteAgentName: input.tool.name,
+ subagentName: input.tool.name,
+ }
+ : {
+ kind: "subagent-call",
+ nodeId: input.tool.nodeId,
+ subagentName: input.tool.name,
+ };
return {
description: input.tool.description ?? "",
- inputSchema: jsonSchema(input.tool.inputSchema ?? {}),
+ inputSchema: toInputSchema(input.tool.inputSchema) ?? UNSPECIFIED_INPUT_SCHEMA,
name: input.tool.name,
- outputSchema:
- input.tool.outputSchema === undefined ? undefined : jsonSchema(input.tool.outputSchema),
- runtimeAction: {
- kind: "subagent-call",
- nodeId: input.tool.nodeId,
- subagentName: input.tool.name,
- },
- };
- }
-
- if (input.tool.kind === "remote") {
- return {
- description: input.tool.description ?? "",
- inputSchema: jsonSchema(input.tool.inputSchema ?? {}),
- name: input.tool.name,
- outputSchema:
- input.tool.outputSchema === undefined ? undefined : jsonSchema(input.tool.outputSchema),
- runtimeAction: {
- kind: "remote-agent-call",
- nodeId: input.tool.nodeId,
- remoteAgentName: input.tool.name,
- subagentName: input.tool.name,
- },
+ outputSchema: toOutputSchema(input.tool.outputSchema),
+ runtimeAction,
};
}
@@ -253,10 +246,10 @@ function resolveHarnessToolDefinition(input: {
rawExecute,
scope: def.name,
}),
- inputSchema: def.inputStandardSchema ?? jsonSchema(def.inputSchema ?? {}),
+ inputSchema: def.inputSchema ?? UNSPECIFIED_INPUT_SCHEMA,
name: def.name,
approval: def.approval,
- outputSchema: def.outputStandardSchema ?? maybeJsonSchema(def.outputSchema),
+ outputSchema: def.outputSchema,
toModelOutput: def.toModelOutput,
};
}
@@ -287,9 +280,3 @@ function resolveAuthoredExecute(input: {
const authored = rawExecute as (toolInput: unknown, ctx: unknown) => unknown;
return createToolExecuteWithAuth({ execute: authored, scope });
}
-
-function maybeJsonSchema(
- schema: ResolvedToolDefinition["outputSchema"],
-): FlexibleSchema | undefined {
- return schema === undefined ? undefined : jsonSchema(schema);
-}
diff --git a/packages/eve/src/execution/subagent-tool.test.ts b/packages/eve/src/execution/subagent-tool.test.ts
index 83cdad7b8..d18f05f92 100644
--- a/packages/eve/src/execution/subagent-tool.test.ts
+++ b/packages/eve/src/execution/subagent-tool.test.ts
@@ -276,6 +276,22 @@ describe("buildSubagentRunInput", () => {
expect(runInput.input.outputSchema).toBeUndefined();
});
+ it("treats an empty outputSchema as absent", () => {
+ const action: RuntimeSubagentCallActionRequest = {
+ ...makeAction(),
+ input: { message: "do something", outputSchema: {} },
+ };
+ const { runInput } = buildRuntimeSubagentRunInput({
+ action,
+ auth: null,
+ batchEvent: { sequence: 0, turnId: "turn-0" },
+ initiatorAuth: null,
+ session: makeSession(),
+ });
+
+ expect(runInput.input.outputSchema).toBeUndefined();
+ });
+
it("includes parentSandboxState and sandboxSessionId for self-delegation", () => {
const sandboxState = { initialized: true, session: null };
const session = { ...makeSession(), sandboxState };
diff --git a/packages/eve/src/execution/subagent-tool.ts b/packages/eve/src/execution/subagent-tool.ts
index b02974a08..b4bfd26e5 100644
--- a/packages/eve/src/execution/subagent-tool.ts
+++ b/packages/eve/src/execution/subagent-tool.ts
@@ -8,7 +8,7 @@ import type {
SessionCapabilities,
} from "#channel/types.js";
import type { HarnessSession } from "#harness/types.js";
-import type { JsonObject } from "#shared/json.js";
+import { isJsonObjectValue } from "#shared/json.js";
import type { RuntimeSubagentCallActionRequest } from "#runtime/actions/types.js";
import { mintSubagentContinuationToken } from "#execution/session.js";
import { resolveSubagentDepth } from "#harness/subagent-depth.js";
@@ -97,6 +97,11 @@ export function buildSubagentRunInput(input: {
const inheritedLimits: {
-readonly [K in keyof RunSessionLimits]: RunSessionLimits[K];
} = resolveRemainingSessionTokenLimits(session, input.fanoutSize);
+ const outputSchema = action.input.outputSchema;
+ const requestedOutputSchema =
+ isJsonObjectValue(outputSchema) && Object.keys(outputSchema).length > 0
+ ? outputSchema
+ : undefined;
const runInput: {
-readonly [K in keyof RunInput]: RunInput[K];
@@ -120,7 +125,7 @@ export function buildSubagentRunInput(input: {
initiatorAuth,
input: {
message: formatSubagentCallInputMessage({ action, source }),
- outputSchema: action.input.outputSchema as JsonObject | undefined,
+ outputSchema: requestedOutputSchema,
},
limits: inheritedLimits,
mode: "task",
diff --git a/packages/eve/src/execution/turn-cancellation.integration.test.ts b/packages/eve/src/execution/turn-cancellation.integration.test.ts
index 8f02a74a8..1446de8ab 100644
--- a/packages/eve/src/execution/turn-cancellation.integration.test.ts
+++ b/packages/eve/src/execution/turn-cancellation.integration.test.ts
@@ -24,6 +24,7 @@ import type { Agent } from "#public/definitions/channel.js";
import type { ToolContext } from "#public/definitions/tool.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
import { attachRouteAgent } from "#internal/nitro/routes/channel-route-context.js";
+import { toInputSchema } from "#shared/tool-schema.js";
/**
* Turn cancellation settles as `turn.cancelled` → `session.waiting` with
@@ -73,7 +74,7 @@ function buildWaitForCancelTool(onStart: () => void, onAbort: () => void): Resol
ctx.abortSignal.addEventListener("abort", abort, { once: true });
});
},
- inputSchema: { additionalProperties: false, properties: {}, type: "object" },
+ inputSchema: toInputSchema({ additionalProperties: false, properties: {}, type: "object" }),
logicalPath: `tools/${WAIT_TOOL_NAME}.ts`,
name: WAIT_TOOL_NAME,
sourceId: `tools/${WAIT_TOOL_NAME}.ts`,
diff --git a/packages/eve/src/execution/workflow-entry.integration.test.ts b/packages/eve/src/execution/workflow-entry.integration.test.ts
index c580d7995..0c61a0693 100644
--- a/packages/eve/src/execution/workflow-entry.integration.test.ts
+++ b/packages/eve/src/execution/workflow-entry.integration.test.ts
@@ -19,6 +19,7 @@ import type { HandleMessageStreamEvent } from "#protocol/message.js";
import type { ToolContext } from "#public/definitions/tool.js";
import type { AuthorizationDefinition, TokenResult } from "#runtime/connections/types.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
+import { toInputSchema } from "#shared/tool-schema.js";
function buildSerializedContext(overrides: {
auth?: Record<string, unknown>;
@@ -97,14 +98,14 @@ describe("workflowEntry integration", () => {
};
},
}),
- inputSchema: {
+ inputSchema: toInputSchema({
additionalProperties: false,
properties: {
city: { type: "string" },
},
required: ["city"],
type: "object",
- },
+ }),
logicalPath: "tools/get_weather.ts",
name: "get_weather",
sourceId: "tools/get_weather.ts",
diff --git a/packages/eve/src/harness/emission.ts b/packages/eve/src/harness/emission.ts
index c86250c48..69197f0e1 100644
--- a/packages/eve/src/harness/emission.ts
+++ b/packages/eve/src/harness/emission.ts
@@ -41,7 +41,10 @@ import {
createRuntimeActionRequestFromToolCall,
resolveToolCallInputObject,
} from "#harness/runtime-actions.js";
-import { createInvalidToolCallInputError } from "#harness/tool-call-input-errors.js";
+import {
+ createInvalidToolCallInputError,
+ isInvalidToolCall,
+} from "#harness/tool-call-input-errors.js";
import type {
RuntimeActionRequest,
RuntimeToolResultActionResult,
@@ -479,11 +482,11 @@ async function consumeStreamContent(
};
const emitToolCall = async (toolCall: TypedToolCall<ToolSet>): Promise<void> => {
- if (
- options === undefined ||
- toolCall.invalid === true ||
- options.excludedActionToolNames.has(toolCall.toolName)
- ) {
+ if (isInvalidToolCall(toolCall)) {
+ invalidInputToolCallIds.add(toolCall.toolCallId);
+ return;
+ }
+ if (options === undefined || options.excludedActionToolNames.has(toolCall.toolName)) {
return;
}
diff --git a/packages/eve/src/harness/step-hooks.ts b/packages/eve/src/harness/step-hooks.ts
index 0f7c9da98..cacbb5b56 100644
--- a/packages/eve/src/harness/step-hooks.ts
+++ b/packages/eve/src/harness/step-hooks.ts
@@ -31,6 +31,7 @@ import {
type PromptCachePath,
} from "#harness/prompt-cache.js";
import { createRuntimeActionRequestFromToolCall } from "#harness/runtime-actions.js";
+import { isInvalidToolCall } from "#harness/tool-call-input-errors.js";
import type { RuntimeToolResultActionResult } from "#runtime/actions/types.js";
import type { HarnessEmitFn, HarnessSession, ToolLoopHarnessConfig } from "#harness/types.js";
import { contextStorage } from "#context/container.js";
@@ -315,20 +316,6 @@ export async function emitStepActions(
// Helpers
// ---------------------------------------------------------------------------
-/**
- * Returns true when the AI SDK marked the tool call `invalid` (typically
- * because the model emitted unparsable JSON or targeted an unknown tool).
- *
- * Invalid calls have a raw-string or partial `input` payload that cannot
- * satisfy the runtime-action contract. The AI SDK synthesizes a tool-error
- * result for the next model step automatically; callers must skip invalid
- * calls when projecting to `RuntimeActionRequest` values or the harness
- * will throw on the JSON-object invariant.
- */
-export function isInvalidToolCall(toolCall: TypedToolCall<ToolSet>): boolean {
- return toolCall.invalid === true;
-}
-
function isProviderExecutedToolCall(toolCall: TypedToolCall<ToolSet>): boolean {
return toolCall.providerExecuted === true;
}
diff --git a/packages/eve/src/harness/tool-call-input-errors.ts b/packages/eve/src/harness/tool-call-input-errors.ts
index 33e6a432f..d6a3f199f 100644
--- a/packages/eve/src/harness/tool-call-input-errors.ts
+++ b/packages/eve/src/harness/tool-call-input-errors.ts
@@ -2,6 +2,20 @@ import type { ToolSet, TypedToolCall, TypedToolError } from "ai";
import { resolveToolCallInputObject } from "#harness/runtime-actions.js";
+/**
+ * Returns true when the AI SDK marked the tool call `invalid` (typically
+ * because the model emitted unparsable JSON or targeted an unknown tool).
+ *
+ * Invalid calls have a raw-string or partial `input` payload that cannot
+ * satisfy the runtime-action contract. The AI SDK synthesizes a tool-error
+ * result for the next model step automatically; callers must skip invalid
+ * calls when projecting to `RuntimeActionRequest` values or the harness
+ * will throw on the JSON-object invariant.
+ */
+export function isInvalidToolCall(toolCall: TypedToolCall<ToolSet>): boolean {
+ return toolCall.invalid === true;
+}
+
export function createInvalidToolCallInputError(input: {
readonly error: unknown;
readonly toolCall: TypedToolCall<ToolSet>;
@@ -47,7 +61,7 @@ export function getInvalidToolCallInputError(input: {
}): TypedToolError<ToolSet> | undefined {
const { toolCall } = input;
- if (toolCall.invalid === true) {
+ if (isInvalidToolCall(toolCall)) {
return undefined;
}
diff --git a/packages/eve/src/harness/tool-input-validation.integration.test.ts b/packages/eve/src/harness/tool-input-validation.integration.test.ts
new file mode 100644
index 000000000..b6ec9d5ae
--- /dev/null
+++ b/packages/eve/src/harness/tool-input-validation.integration.test.ts
@@ -0,0 +1,234 @@
+import type { LanguageModel, ModelMessage } from "ai";
+import { MockLanguageModelV4 } from "ai/test";
+import { describe, expect, it } from "vitest";
+
+import { getPendingInputRequestIds } from "#harness/input-requests.js";
+import { createToolLoopHarness } from "#harness/tool-loop.js";
+import type { HarnessSession, ToolLoopHarnessConfig } from "#harness/types.js";
+import {
+ ASK_QUESTION_INPUT_SCHEMA,
+ ASK_QUESTION_TOOL_DEFINITION,
+} from "#runtime/framework-tools/ask-question.js";
+import { serializeInputSchema } from "#shared/tool-schema.js";
+
+const usage = {
+ inputTokens: {
+ cacheRead: undefined,
+ cacheWrite: undefined,
+ noCache: 1,
+ total: 1,
+ },
+ outputTokens: {
+ reasoning: undefined,
+ text: 1,
+ total: 1,
+ },
+};
+
+function findToolResult(messages: readonly ModelMessage[], toolCallId: string): unknown {
+ for (const message of messages) {
+ if (message.role !== "tool" || !Array.isArray(message.content)) continue;
+ const result = message.content.find(
+ (part) => part.type === "tool-result" && part.toolCallId === toolCallId,
+ );
+ if (result !== undefined) return result;
+ }
+ return undefined;
+}
+
+describe("framework tool input validation (real AI SDK)", () => {
+ it("returns malformed and schema-invalid ask_question input to the model before accepting a retry", async () => {
+ const malformedCallId = "question-malformed";
+ const invalidCallId = "question-invalid";
+ const validCallId = "question-valid";
+ const model = new MockLanguageModelV4({
+ doGenerate: [
+ {
+ content: [
+ {
+ input: '{"prompt":',
+ toolCallId: malformedCallId,
+ toolName: "ask_question",
+ type: "tool-call",
+ },
+ ],
+ finishReason: { raw: undefined, unified: "tool-calls" },
+ usage,
+ warnings: [],
+ },
+ {
+ content: [
+ {
+ input: JSON.stringify({ prompt: 42 }),
+ toolCallId: invalidCallId,
+ toolName: "ask_question",
+ type: "tool-call",
+ },
+ ],
+ finishReason: { raw: undefined, unified: "tool-calls" },
+ usage,
+ warnings: [],
+ },
+ {
+ content: [
+ {
+ input: JSON.stringify({ prompt: "Which option should I use?" }),
+ toolCallId: validCallId,
+ toolName: "ask_question",
+ type: "tool-call",
+ },
+ ],
+ finishReason: { raw: undefined, unified: "tool-calls" },
+ usage,
+ warnings: [],
+ },
+ ],
+ modelId: "tool-validation-model",
+ provider: "eve-integration-mock",
+ });
+ const tools: ToolLoopHarnessConfig["tools"] = new Map([
+ [
+ "ask_question",
+ {
+ description: ASK_QUESTION_TOOL_DEFINITION.description,
+ inputSchema: ASK_QUESTION_INPUT_SCHEMA,
+ name: "ask_question",
+ },
+ ],
+ ]);
+ const config: ToolLoopHarnessConfig = {
+ capabilities: { requestInput: true },
+ mode: "conversation",
+ resolveModel: async (): Promise<LanguageModel> => model,
+ tools,
+ };
+ const session: HarnessSession = {
+ agent: {
+ modelReference: { id: "tool-validation-model" },
+ system: "You are a test assistant.",
+ tools: [
+ {
+ description: ASK_QUESTION_TOOL_DEFINITION.description,
+ inputSchema: serializeInputSchema(ASK_QUESTION_INPUT_SCHEMA),
+ name: "ask_question",
+ },
+ ],
+ },
+ compaction: { recentWindowSize: 10, threshold: 100_000 },
+ continuationToken: "http:tool-validation-session",
+ history: [],
+ sessionId: "tool-validation-session",
+ };
+ const runStep = createToolLoopHarness(config);
+
+ const malformedStep = await runStep(session, { message: "Ask me which option to use." });
+
+ expect(typeof malformedStep.next).toBe("function");
+ expect(getPendingInputRequestIds(malformedStep.session.state)).toEqual(new Set());
+ expect(findToolResult(malformedStep.session.history, malformedCallId)).toMatchObject({
+ output: expect.objectContaining({ type: "error-text" }),
+ toolName: "ask_question",
+ });
+
+ if (typeof malformedStep.next !== "function") {
+ throw new TypeError("Expected the malformed tool call to continue the tool loop.");
+ }
+ const invalidStep = await malformedStep.next(malformedStep.session);
+
+ expect(typeof invalidStep.next).toBe("function");
+ expect(getPendingInputRequestIds(invalidStep.session.state)).toEqual(new Set());
+ expect(findToolResult(invalidStep.session.history, invalidCallId)).toMatchObject({
+ output: expect.objectContaining({ type: "error-text" }),
+ toolName: "ask_question",
+ });
+
+ if (typeof invalidStep.next !== "function") {
+ throw new TypeError("Expected the invalid tool call to continue the tool loop.");
+ }
+ const validStep = await invalidStep.next(invalidStep.session);
+
+ expect(model.doGenerateCalls).toHaveLength(3);
+ expect(findToolResult(model.doGenerateCalls[1]?.prompt ?? [], malformedCallId)).toBeDefined();
+ expect(findToolResult(model.doGenerateCalls[2]?.prompt ?? [], invalidCallId)).toBeDefined();
+ expect(validStep.next).toBeNull();
+ expect(getPendingInputRequestIds(validStep.session.state)).toEqual(new Set([validCallId]));
+ });
+
+ it("rejects invalid final_output input instead of terminating the task", async () => {
+ const invalidCallId = "final-invalid";
+ const validCallId = "final-valid";
+ const outputSchema = {
+ additionalProperties: false,
+ properties: { answer: { type: "string" } },
+ required: ["answer"],
+ type: "object",
+ } as const;
+ const model = new MockLanguageModelV4({
+ doGenerate: [
+ {
+ content: [
+ {
+ input: JSON.stringify({ answer: 42 }),
+ toolCallId: invalidCallId,
+ toolName: "final_output",
+ type: "tool-call",
+ },
+ ],
+ finishReason: { raw: undefined, unified: "tool-calls" },
+ usage,
+ warnings: [],
+ },
+ {
+ content: [
+ {
+ input: JSON.stringify({ answer: "done" }),
+ toolCallId: validCallId,
+ toolName: "final_output",
+ type: "tool-call",
+ },
+ ],
+ finishReason: { raw: undefined, unified: "tool-calls" },
+ usage,
+ warnings: [],
+ },
+ ],
+ modelId: "final-output-validation-model",
+ provider: "eve-integration-mock",
+ });
+ const config: ToolLoopHarnessConfig = {
+ mode: "task",
+ resolveModel: async (): Promise<LanguageModel> => model,
+ tools: new Map(),
+ };
+ const session: HarnessSession = {
+ agent: {
+ modelReference: { id: "final-output-validation-model" },
+ system: "Return structured output.",
+ tools: [],
+ },
+ compaction: { recentWindowSize: 10, threshold: 100_000 },
+ continuationToken: "task:final-output-validation-session",
+ history: [],
+ outputSchema,
+ sessionId: "final-output-validation-session",
+ };
+ const runStep = createToolLoopHarness(config);
+
+ const invalidStep = await runStep(session, { message: "Finish the task." });
+
+ expect(typeof invalidStep.next).toBe("function");
+ expect(findToolResult(invalidStep.session.history, invalidCallId)).toMatchObject({
+ output: expect.objectContaining({ type: "error-text" }),
+ toolName: "final_output",
+ });
+
+ if (typeof invalidStep.next !== "function") {
+ throw new TypeError("Expected invalid final output to continue the tool loop.");
+ }
+ const validStep = await invalidStep.next(invalidStep.session);
+
+ expect(model.doGenerateCalls).toHaveLength(2);
+ expect(findToolResult(model.doGenerateCalls[1]?.prompt ?? [], invalidCallId)).toBeDefined();
+ expect(validStep.next).toEqual({ done: true, output: { answer: "done" } });
+ });
+});
diff --git a/packages/eve/src/harness/tool-loop.test.ts b/packages/eve/src/harness/tool-loop.test.ts
index db3d624ff..b743e0c61 100644
--- a/packages/eve/src/harness/tool-loop.test.ts
+++ b/packages/eve/src/harness/tool-loop.test.ts
@@ -2445,6 +2445,87 @@ describe("createToolLoopHarness", () => {
});
});
+ it("does not park an invalid ask_question call and continues with its tool error", async () => {
+ setupMockAgent({
+ finishReason: "tool-calls",
+ response: {
+ messages: [
+ {
+ content: [
+ {
+ input: { prompt: 42 },
+ toolCallId: "question-invalid",
+ toolName: "ask_question",
+ type: "tool-call",
+ },
+ ],
+ role: "assistant",
+ },
+ {
+ content: [
+ {
+ output: { type: "error-text", value: "Expected string, received number" },
+ toolCallId: "question-invalid",
+ toolName: "ask_question",
+ type: "tool-result",
+ },
+ ],
+ role: "tool",
+ },
+ ],
+ },
+ toolCalls: [
+ {
+ dynamic: true,
+ error: new Error("Expected string, received number"),
+ input: { prompt: 42 },
+ invalid: true,
+ toolCallId: "question-invalid",
+ toolName: "ask_question",
+ type: "tool-call",
+ },
+ ],
+ toolResults: [],
+ });
+
+ const { emit, events } = createEventCollector();
+ const runStep = createToolLoopHarness(
+ createTestConfig("conversation", emit, {
+ capabilities: { requestInput: true },
+ tools: new Map([
+ [
+ "ask_question",
+ {
+ description: "Ask the user a question.",
+ inputSchema: jsonSchema({ type: "object" }),
+ name: "ask_question",
+ },
+ ],
+ ]),
+ }),
+ );
+ const session = createTestSession({
+ agent: {
+ modelReference: { id: "test-model" },
+ system: "You are a test assistant.",
+ tools: [
+ {
+ description: "Ask the user a question.",
+ inputSchema: { type: "object" },
+ name: "ask_question",
+ },
+ ],
+ },
+ });
+
+ const result = await runStep(session, { message: "Ask me a question." });
+
+ expect(typeof result.next).toBe("function");
+ expect(hasPendingInputBatch(result.session.state)).toBe(false);
+ expect(events.some((event) => event.type === "input.requested")).toBe(false);
+ expect(result.session.history.at(-1)?.role).toBe("tool");
+ });
+
it("feeds non-object tool call input back to the model as a failed tool result", async () => {
const invalidInput = "not an object";
const errorMessage =
diff --git a/packages/eve/src/harness/tool-loop.ts b/packages/eve/src/harness/tool-loop.ts
index c1ef01486..5cb21afe2 100644
--- a/packages/eve/src/harness/tool-loop.ts
+++ b/packages/eve/src/harness/tool-loop.ts
@@ -150,13 +150,11 @@ import {
resolvePendingRuntimeActions,
setPendingRuntimeActionBatch,
} from "#harness/runtime-actions.js";
-import { getInvalidToolCallInputError } from "#harness/tool-call-input-errors.js";
import {
- buildStepHooks,
- emitStepActions,
- type HarnessStepResult,
+ getInvalidToolCallInputError,
isInvalidToolCall,
-} from "#harness/step-hooks.js";
+} from "#harness/tool-call-input-errors.js";
+import { buildStepHooks, emitStepActions, type HarnessStepResult } from "#harness/step-hooks.js";
import {
buildToolApproval,
buildToolSetFromDefinitions,
@@ -1788,8 +1786,12 @@ async function handleStepResult(input: {
const invalidInputToolErrors = getInvalidToolCallInputErrors({
toolCalls: result.toolCalls as TypedToolCall<ToolSet>[],
});
+ // Unions every invalid-input signal: SDK-marked invalid calls (which get
+ // SDK-synthesized tool errors), non-object inputs caught by
+ // getInvalidToolCallInputErrors, and ids the stream consumer observed.
const invalidInputToolCallIds = new Set([
...(result.invalidInputToolCallIds ?? []),
+ ...result.toolCalls.filter(isInvalidToolCall).map((toolCall) => toolCall.toolCallId),
...invalidInputToolErrors.map((toolError) => toolError.toolCallId),
]);
const rawResponseMessages = emptyDelivery
@@ -1859,7 +1861,6 @@ async function handleStepResult(input: {
tools: config.tools,
});
const pendingRuntimeActions = ((result.toolCalls ?? []) as TypedToolCall<ToolSet>[])
- .filter((toolCall) => !isInvalidToolCall(toolCall))
.filter((toolCall) => !invalidInputToolCallIds.has(toolCall.toolCallId))
.filter((toolCall) => config.tools.get(toolCall.toolName)?.runtimeAction !== undefined)
.filter((toolCall) => {
@@ -2044,8 +2045,9 @@ const OUTPUT_SCHEMA_NOT_FULFILLED = {
* `final_output` tool, or `undefined` when the terminal turn ended in prose.
*/
function extractFinalOutput(result: HarnessStepResult): JsonValue | undefined {
- return (result.toolCalls ?? []).find((call) => call.toolName === FINAL_OUTPUT_TOOL_NAME)
- ?.input as JsonValue | undefined;
+ return (result.toolCalls ?? []).find(
+ (call) => call.toolName === FINAL_OUTPUT_TOOL_NAME && !isInvalidToolCall(call),
+ )?.input as JsonValue | undefined;
}
/**
diff --git a/packages/eve/src/harness/workflow-sandbox.ts b/packages/eve/src/harness/workflow-sandbox.ts
index 1e8d5aad7..638c7d3cf 100644
--- a/packages/eve/src/harness/workflow-sandbox.ts
+++ b/packages/eve/src/harness/workflow-sandbox.ts
@@ -1,4 +1,5 @@
-import { jsonSchema, type ToolSet } from "ai";
+import type { ToolSet } from "ai";
+import { z } from "#compiled/zod/index.js";
import type { HarnessToolDefinition } from "#harness/execute-tool.js";
import type { HarnessToolMap } from "#harness/types.js";
@@ -18,6 +19,14 @@ interface WorkflowToolSet {
readonly modelTools: ToolSet;
}
+const workflowInputSchema = z.strictObject({
+ js: z
+ .string()
+ .describe(
+ "Complete JavaScript orchestration program. Call only the agents listed in the Workflow description and return one JSON-serializable result.",
+ ),
+});
+
/**
* Adds the dynamic `Workflow` tool while leaving every ordinary model tool
* untouched. Only subagent and remote-agent runtime actions enter the sandbox.
@@ -49,18 +58,7 @@ export async function applyWorkflowTool(input: {
modelTools[WORKFLOW_TOOL_NAME] = {
...workflowTool,
description: apiReference.length > 0 ? `${framing}\n\n${apiReference}` : framing,
- inputSchema: jsonSchema({
- type: "object",
- properties: {
- js: {
- type: "string",
- description:
- "Complete JavaScript orchestration program. Call only the agents listed in the Workflow description and return one JSON-serializable result.",
- },
- },
- required: ["js"],
- additionalProperties: false,
- }),
+ inputSchema: workflowInputSchema,
} as ToolSet[string];
return {
diff --git a/packages/eve/src/internal/authored-definition/schema-backed.ts b/packages/eve/src/internal/authored-definition/schema-backed.ts
index 5a3545fb1..af0569b36 100644
--- a/packages/eve/src/internal/authored-definition/schema-backed.ts
+++ b/packages/eve/src/internal/authored-definition/schema-backed.ts
@@ -10,7 +10,11 @@ import {
expectString,
} from "#internal/authored-module.js";
import type { InternalToolDefinitionWithExecuteFn } from "#shared/tool-definition.js";
-import { normalizeJsonSchemaDefinition } from "#internal/json-schema.js";
+import {
+ serializeInputSchema,
+ serializeOutputSchema,
+ type ToolSchemaSource,
+} from "#shared/tool-schema.js";
import {
isDynamicSentinel,
rejectDynamicSentinelFallback,
@@ -81,11 +85,10 @@ export function normalizeToolDefinition(value: unknown, message: string): Normal
message,
);
const inputSchema =
- record.inputSchema === undefined ? null : normalizeJsonSchemaDefinition(record.inputSchema);
- const outputSchema =
- record.outputSchema === undefined
- ? undefined
- : normalizeJsonSchemaDefinition(record.outputSchema, "output");
+ record.inputSchema === undefined
+ ? null
+ : serializeInputSchema(record.inputSchema as ToolSchemaSource);
+ const outputSchema = serializeOutputSchema(record.outputSchema as ToolSchemaSource | undefined);
const definition: MutableNormalizedAuthoredTool = {
description: expectString(record.description, message),
execute: expectFunction(record.execute, message),
diff --git a/packages/eve/src/internal/json-schema.ts b/packages/eve/src/internal/json-schema.ts
deleted file mode 100644
index 25b34c540..000000000
--- a/packages/eve/src/internal/json-schema.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { normalizeJsonSchemaDefinition } from "#shared/json-schema.js";
diff --git a/packages/eve/src/internal/nitro/routes/agent-info/build-agent-info-response.ts b/packages/eve/src/internal/nitro/routes/agent-info/build-agent-info-response.ts
index 5504bf7f4..5a4218a33 100644
--- a/packages/eve/src/internal/nitro/routes/agent-info/build-agent-info-response.ts
+++ b/packages/eve/src/internal/nitro/routes/agent-info/build-agent-info-response.ts
@@ -21,6 +21,7 @@ import type {
ResolvedChannelDefinition,
ResolvedToolDefinition,
} from "#runtime/types.js";
+import { serializeInputSchema, serializeOutputSchema } from "#shared/tool-schema.js";
import { LOAD_SKILL_TOOL_NAME } from "#runtime/skills/fragment-context.js";
import { WORKFLOW_TOOL_NAME } from "#shared/workflow-sandbox.js";
import type { ModelRouting } from "#shared/agent-definition.js";
@@ -458,17 +459,20 @@ export function renderTool(
readonly replacesFrameworkTool: boolean;
},
): AgentInfoToolEntry {
+ const inputSchema = serializeInputSchema(tool.inputSchema);
+ const outputSchema = serializeOutputSchema(tool.outputSchema);
+
return {
...toSource(tool),
description: tool.description,
hasAuth: false,
hasExecute: tool.execute !== undefined,
hasModelOutputProjection: tool.toModelOutput !== undefined,
- hasOutputSchema: tool.outputSchema !== undefined && tool.outputSchema !== null,
- inputSchema: tool.inputSchema,
+ hasOutputSchema: outputSchema !== undefined,
+ inputSchema,
name: tool.name,
origin: input.origin,
- outputSchema: tool.outputSchema,
+ outputSchema,
replacesFrameworkTool: input.replacesFrameworkTool,
requiresApproval: tool.approval !== undefined,
};
diff --git a/packages/eve/src/internal/testing/app-harness.ts b/packages/eve/src/internal/testing/app-harness.ts
index f10f75951..94eb222c4 100644
--- a/packages/eve/src/internal/testing/app-harness.ts
+++ b/packages/eve/src/internal/testing/app-harness.ts
@@ -13,6 +13,7 @@ import {
} from "#runtime/sessions/runtime-session.js";
import { createRuntimeToolRegistry } from "#runtime/tools/registry.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
+import { serializeInputSchema } from "#shared/tool-schema.js";
import {
buildActiveSessionContext,
type ActiveSessionInit,
@@ -152,7 +153,7 @@ export function createTestRuntime(descriptor: TestAppDescriptor = {}): TestRunti
compileInput.tools = descriptor.tools.map((tool) => ({
name: tool.name,
description: tool.description,
- inputSchema: tool.inputSchema,
+ inputSchema: serializeInputSchema(tool.inputSchema),
}));
}
diff --git a/packages/eve/src/internal/testing/mocks/mock-tool.ts b/packages/eve/src/internal/testing/mocks/mock-tool.ts
index 3a3dc29a9..61aa98373 100644
--- a/packages/eve/src/internal/testing/mocks/mock-tool.ts
+++ b/packages/eve/src/internal/testing/mocks/mock-tool.ts
@@ -2,6 +2,7 @@ import type { SessionContext } from "#public/definitions/callback-context.js";
import { buildCallbackContext } from "#context/build-callback-context.js";
import type { JsonObject } from "#shared/json.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
+import { toInputSchema } from "#shared/tool-schema.js";
/**
* Declarative description of one synthetic authored tool used by the
@@ -48,7 +49,7 @@ export function mockTool(input: MockToolInput): ResolvedToolDefinition {
const logicalPath = input.logicalPath ?? `tools/${sanitizeLogicalPathSegment(input.name)}.ts`;
const definition: ResolvedToolDefinition = {
description: input.description ?? `${input.name} mock tool.`,
- inputSchema: input.inputSchema ?? null,
+ inputSchema: toInputSchema(input.inputSchema ?? null),
logicalPath,
name: input.name,
sourceId: logicalPath,
diff --git a/packages/eve/src/public/tools/define-bash-tool.ts b/packages/eve/src/public/tools/define-bash-tool.ts
index db741382d..b30c10c83 100644
--- a/packages/eve/src/public/tools/define-bash-tool.ts
+++ b/packages/eve/src/public/tools/define-bash-tool.ts
@@ -1,5 +1,3 @@
-import type { StandardJSONSchemaV1 } from "#compiled/@standard-schema/spec/index.js";
-
import { type BashInput, executeBashOnSandbox } from "#execution/sandbox/bash-tool.js";
import { BASH_INPUT_SCHEMA, BASH_OUTPUT_SCHEMA } from "#runtime/framework-tools/bash.js";
import type { ToolDefinition } from "#public/definitions/tool.js";
@@ -30,7 +28,7 @@ export function defineBashTool(input: DefineBashToolInput = {}): ToolDefinition
async execute(args, ctx) {
return executeBashOnSandbox(await ctx.getSandbox(), args as BashInput);
},
- inputSchema: BASH_INPUT_SCHEMA as unknown as StandardJSONSchemaV1<unknown>,
+ inputSchema: BASH_INPUT_SCHEMA,
outputSchema: BASH_OUTPUT_SCHEMA,
};
}
diff --git a/packages/eve/src/public/tools/define-glob-tool.ts b/packages/eve/src/public/tools/define-glob-tool.ts
index d4cda22c4..31969527c 100644
--- a/packages/eve/src/public/tools/define-glob-tool.ts
+++ b/packages/eve/src/public/tools/define-glob-tool.ts
@@ -1,5 +1,3 @@
-import type { StandardJSONSchemaV1 } from "#compiled/@standard-schema/spec/index.js";
-
import { executeGlobOnSandbox, type GlobInput } from "#execution/sandbox/glob-tool.js";
import { GLOB_INPUT_SCHEMA, GLOB_OUTPUT_SCHEMA } from "#runtime/framework-tools/glob.js";
import type { ToolDefinition } from "#public/definitions/tool.js";
@@ -31,7 +29,7 @@ export function defineGlobTool(input: DefineGlobToolInput = {}): ToolDefinition
async execute(args, ctx) {
return executeGlobOnSandbox(await ctx.getSandbox(), args as GlobInput);
},
- inputSchema: GLOB_INPUT_SCHEMA as unknown as StandardJSONSchemaV1<unknown>,
+ inputSchema: GLOB_INPUT_SCHEMA,
outputSchema: GLOB_OUTPUT_SCHEMA,
};
}
diff --git a/packages/eve/src/public/tools/define-grep-tool.ts b/packages/eve/src/public/tools/define-grep-tool.ts
index 6e4abebfd..e3f435c2b 100644
--- a/packages/eve/src/public/tools/define-grep-tool.ts
+++ b/packages/eve/src/public/tools/define-grep-tool.ts
@@ -1,5 +1,3 @@
-import type { StandardJSONSchemaV1 } from "#compiled/@standard-schema/spec/index.js";
-
import { executeGrepOnSandbox, type GrepInput } from "#execution/sandbox/grep-tool.js";
import { GREP_INPUT_SCHEMA, GREP_OUTPUT_SCHEMA } from "#runtime/framework-tools/grep.js";
import type { ToolDefinition } from "#public/definitions/tool.js";
@@ -31,7 +29,7 @@ export function defineGrepTool(input: DefineGrepToolInput = {}): ToolDefinition
async execute(args, ctx) {
return executeGrepOnSandbox(await ctx.getSandbox(), args as GrepInput);
},
- inputSchema: GREP_INPUT_SCHEMA as unknown as StandardJSONSchemaV1<unknown>,
+ inputSchema: GREP_INPUT_SCHEMA,
outputSchema: GREP_OUTPUT_SCHEMA,
};
}
diff --git a/packages/eve/src/public/tools/define-read-file-tool.ts b/packages/eve/src/public/tools/define-read-file-tool.ts
index 10b9238c6..718ab8773 100644
--- a/packages/eve/src/public/tools/define-read-file-tool.ts
+++ b/packages/eve/src/public/tools/define-read-file-tool.ts
@@ -1,5 +1,3 @@
-import type { StandardJSONSchemaV1 } from "#compiled/@standard-schema/spec/index.js";
-
import { executeReadFileOnSandbox, type ReadFileInput } from "#execution/sandbox/read-file-tool.js";
import {
READ_FILE_INPUT_SCHEMA,
@@ -33,7 +31,7 @@ export function defineReadFileTool(input: DefineReadFileToolInput = {}): ToolDef
async execute(args, ctx) {
return executeReadFileOnSandbox(await ctx.getSandbox(), args as ReadFileInput);
},
- inputSchema: READ_FILE_INPUT_SCHEMA as unknown as StandardJSONSchemaV1<unknown>,
+ inputSchema: READ_FILE_INPUT_SCHEMA,
outputSchema: READ_FILE_OUTPUT_SCHEMA,
};
}
diff --git a/packages/eve/src/public/tools/define-write-file-tool.ts b/packages/eve/src/public/tools/define-write-file-tool.ts
index 8659143af..e4e56444b 100644
--- a/packages/eve/src/public/tools/define-write-file-tool.ts
+++ b/packages/eve/src/public/tools/define-write-file-tool.ts
@@ -1,5 +1,3 @@
-import type { StandardJSONSchemaV1 } from "#compiled/@standard-schema/spec/index.js";
-
import {
executeWriteFileOnSandbox,
type WriteFileInput,
@@ -37,7 +35,7 @@ export function defineWriteFileTool(input: DefineWriteFileToolInput = {}): ToolD
async execute(args, ctx) {
return executeWriteFileOnSandbox(await ctx.getSandbox(), args as WriteFileInput);
},
- inputSchema: WRITE_FILE_INPUT_SCHEMA as unknown as StandardJSONSchemaV1<unknown>,
+ inputSchema: WRITE_FILE_INPUT_SCHEMA,
outputSchema: WRITE_FILE_OUTPUT_SCHEMA,
};
}
diff --git a/packages/eve/src/public/tools/internal.ts b/packages/eve/src/public/tools/internal.ts
index 3a9cfbcfa..46a4e222b 100644
--- a/packages/eve/src/public/tools/internal.ts
+++ b/packages/eve/src/public/tools/internal.ts
@@ -1,5 +1,3 @@
-import type { StandardJSONSchemaV1 } from "#compiled/@standard-schema/spec/index.js";
-
import type { ResolvedToolDefinition } from "#runtime/types.js";
import type { ToolDefinition } from "#public/definitions/tool.js";
@@ -19,7 +17,6 @@ export function toPublicToolDefinition(definition: ResolvedToolDefinition): Tool
}
const internalExecute = definition.execute;
- const inputSchema = definition.inputSchema;
const publicDefinition: ToolDefinition = {
description: definition.description,
execute: (input, ctx) =>
@@ -30,7 +27,7 @@ export function toPublicToolDefinition(definition: ResolvedToolDefinition): Tool
messages: [],
toolCallId: ctx.callId,
}),
- inputSchema: (inputSchema ?? {}) as unknown as StandardJSONSchemaV1<unknown>,
+ inputSchema: definition.inputSchema ?? {},
outputSchema: definition.outputSchema,
};
diff --git a/packages/eve/src/runtime/agent/mock-model-adapter.test.ts b/packages/eve/src/runtime/agent/mock-model-adapter.test.ts
index d922a6592..62383a839 100644
--- a/packages/eve/src/runtime/agent/mock-model-adapter.test.ts
+++ b/packages/eve/src/runtime/agent/mock-model-adapter.test.ts
@@ -414,6 +414,37 @@ describe("createMockAuthoredRuntimeModel", () => {
]);
});
+ it("builds empty input for an explicitly empty object schema", async () => {
+ const result = await generateWithPrompt(
+ [
+ {
+ content: "Use the wait_for_cancel tool.",
+ role: "user",
+ },
+ ],
+ [
+ {
+ inputSchema: {
+ additionalProperties: false,
+ properties: {},
+ type: "object",
+ },
+ name: "wait_for_cancel",
+ type: "function",
+ },
+ ],
+ );
+
+ expect(result.content).toEqual([
+ {
+ input: JSON.stringify({}),
+ toolCallId: "call_wait_for_cancel",
+ toolName: "wait_for_cancel",
+ type: "tool-call",
+ },
+ ]);
+ });
+
it("replies with exact fixture text from system context", async () => {
const result = await generateWithPrompt([
{
diff --git a/packages/eve/src/runtime/agent/mock-model-fixtures.ts b/packages/eve/src/runtime/agent/mock-model-fixtures.ts
index dec64a94c..13f4829e2 100644
--- a/packages/eve/src/runtime/agent/mock-model-fixtures.ts
+++ b/packages/eve/src/runtime/agent/mock-model-fixtures.ts
@@ -1,5 +1,6 @@
import type { BootstrapPrompt } from "#runtime/agent/bootstrap-model-utils.js";
import { getPromptContentText } from "#runtime/agent/bootstrap-model-utils.js";
+import { createJsonSchemaSample } from "#runtime/agent/mock-structured-output.js";
import { LOAD_SKILL_TOOL_NAME } from "#runtime/skills/fragment-context.js";
export interface AvailableBootstrapTool {
@@ -23,7 +24,10 @@ export function createMockAuthoredToolInput(
return { command: resolveShellCommand(message) };
}
- if (inputPropertyNames.includes("topic") || /\btopic\b/u.test(normalizeText(message))) {
+ if (
+ inputPropertyNames.includes("topic") ||
+ (!hasDeclaredInputProperties(tool.inputSchema) && /\btopic\b/u.test(normalizeText(message)))
+ ) {
return { topic: resolveLookupTopic(message) };
}
@@ -36,7 +40,12 @@ export function createMockAuthoredToolInput(
return { message };
}
- return { city };
+ if (inputPropertyNames.includes("city") || !hasDeclaredInputProperties(tool.inputSchema)) {
+ return { city };
+ }
+
+ const sample = createJsonSchemaSample(tool.inputSchema);
+ return isRecord(sample) ? sample : {};
}
/**
@@ -218,6 +227,10 @@ function getToolInputPropertyNames(schema: unknown): readonly string[] {
return Object.keys(schema.properties);
}
+function hasDeclaredInputProperties(schema: unknown): boolean {
+ return isRecord(schema) && isRecord(schema.properties);
+}
+
function hasProperties(actual: readonly string[], expected: readonly string[]): boolean {
return expected.every((property) => actual.includes(property));
}
diff --git a/packages/eve/src/runtime/connections/openapi-client.test.ts b/packages/eve/src/runtime/connections/openapi-client.test.ts
index e193fdc5f..e7c5d09a1 100644
--- a/packages/eve/src/runtime/connections/openapi-client.test.ts
+++ b/packages/eve/src/runtime/connections/openapi-client.test.ts
@@ -667,6 +667,36 @@ describe("OpenApiConnectionClient", () => {
expect(props.mix?.type).toEqual(["string", "null"]);
});
+ it("omits only operations whose input schemas cannot be rehydrated", async () => {
+ const spec: Record<string, unknown> = {
+ openapi: "3.0.3",
+ info: { title: "T", version: "1" },
+ servers: [{ url: "https://api.example.com" }],
+ paths: {
+ "/valid": {
+ get: {
+ operationId: "getValid",
+ parameters: [{ name: "id", in: "query", schema: { type: "string" } }],
+ responses: { "200": { description: "ok" } },
+ },
+ },
+ "/invalid": {
+ get: {
+ operationId: "getInvalid",
+ parameters: [{ name: "state", in: "query", schema: { enum: "not-an-array" } }],
+ responses: { "200": { description: "ok" } },
+ },
+ },
+ },
+ };
+ const client = new OpenApiConnectionClient(makeConnection({ spec }));
+
+ await expect(client.getToolMetadata()).resolves.toMatchObject([{ name: "getValid" }]);
+ await expect(client.getTools()).resolves.toHaveProperty("getValid");
+ await expect(client.getTools()).resolves.not.toHaveProperty("getInvalid");
+ await expect(client.executeTool("getInvalid", {})).rejects.toThrow(/not found/);
+ });
+
it("parses a YAML spec fetched from a URL", async () => {
const yamlSpec = [
"openapi: 3.0.3",
diff --git a/packages/eve/src/runtime/connections/openapi-client.ts b/packages/eve/src/runtime/connections/openapi-client.ts
index bdb6a475c..ef4d7706e 100644
--- a/packages/eve/src/runtime/connections/openapi-client.ts
+++ b/packages/eve/src/runtime/connections/openapi-client.ts
@@ -1,5 +1,6 @@
-import { jsonSchema, tool, type ToolSet } from "ai";
+import { tool, type ToolSet } from "ai";
+import { createLogger } from "#internal/logging.js";
import type { ResolvedConnectionDefinition } from "#runtime/types.js";
import { passesToolFilter, resolveHeaders } from "#runtime/connections/mcp-client.js";
import {
@@ -25,8 +26,11 @@ import type {
ConnectionToolMetadata,
} from "#runtime/connections/types.js";
import { isObject } from "#shared/guards.js";
+import { toInputSchema, type ToolSchema } from "#shared/tool-schema.js";
import { isLoopbackHostname } from "#shared/network-address.js";
+const log = createLogger("runtime.connections.openapi-client");
+
interface OpenApiToolCache {
readonly metadata: readonly ConnectionToolMetadata[];
readonly operations: ReadonlyMap<string, OpenApiOperation>;
@@ -155,6 +159,18 @@ export class OpenApiConnectionClient implements ConnectionClient {
const tools: ToolSet = {};
for (const operation of selected) {
+ let inputSchema: ToolSchema;
+ try {
+ inputSchema = toInputSchema(operation.inputSchema);
+ } catch (error) {
+ log.warn("omitting OpenAPI operation with an invalid input schema", {
+ connectionName: this.#connection.connectionName,
+ error,
+ toolName: operation.toolName,
+ });
+ continue;
+ }
+
operationMap.set(operation.toolName, operation);
metadata.push({
description: operation.description,
@@ -163,7 +179,7 @@ export class OpenApiConnectionClient implements ConnectionClient {
});
tools[operation.toolName] = tool({
description: operation.description,
- inputSchema: jsonSchema(operation.inputSchema),
+ inputSchema,
execute: async (input: unknown, toolOptions) =>
this.#request(operation, baseUrl, isObject(input) ? input : {}, {
abortSignal: toolOptions?.abortSignal,
diff --git a/packages/eve/src/runtime/framework-tools/ask-question.test.ts b/packages/eve/src/runtime/framework-tools/ask-question.test.ts
index 8f0b3c5bd..571f9afd0 100644
--- a/packages/eve/src/runtime/framework-tools/ask-question.test.ts
+++ b/packages/eve/src/runtime/framework-tools/ask-question.test.ts
@@ -4,10 +4,11 @@ import {
ASK_QUESTION_INPUT_SCHEMA,
ASK_QUESTION_TOOL_DEFINITION,
} from "#runtime/framework-tools/ask-question.js";
+import { serializeInputSchema } from "#shared/tool-schema.js";
describe("ASK_QUESTION_INPUT_SCHEMA", () => {
it("is derived from the input request schema", () => {
- expect(ASK_QUESTION_INPUT_SCHEMA).toEqual({
+ expect(serializeInputSchema(ASK_QUESTION_INPUT_SCHEMA)).toEqual({
additionalProperties: false,
properties: {
allowFreeform: {
diff --git a/packages/eve/src/runtime/framework-tools/ask-question.ts b/packages/eve/src/runtime/framework-tools/ask-question.ts
index 11ceaa2ed..21a38d0f6 100644
--- a/packages/eve/src/runtime/framework-tools/ask-question.ts
+++ b/packages/eve/src/runtime/framework-tools/ask-question.ts
@@ -1,7 +1,6 @@
import { z } from "#compiled/zod/index.js";
import { inputRequestSchema } from "#runtime/input/types.js";
-import type { JsonObject } from "#shared/json.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
/**
@@ -9,34 +8,18 @@ import type { ResolvedToolDefinition } from "#runtime/types.js";
*/
export const ASK_QUESTION_TOOL_NAME = "ask_question";
-const askQuestionToolInputSchema = inputRequestSchema.omit({
+export const ASK_QUESTION_INPUT_SCHEMA = inputRequestSchema.omit({
action: true,
display: true,
requestId: true,
});
-const { $schema: _jsonSchemaVersion, ...askQuestionInputSchema } = z.toJSONSchema(
- askQuestionToolInputSchema,
-);
-const askQuestionToolOutputSchema = z
+export const ASK_QUESTION_OUTPUT_SCHEMA = z
.object({
optionId: z.string().optional(),
status: z.enum(["answered", "ignored"]),
text: z.string().optional(),
})
.strict();
-const { $schema: _outputJsonSchemaVersion, ...askQuestionOutputSchema } = z.toJSONSchema(
- askQuestionToolOutputSchema,
-);
-
-/**
- * Shared input schema used by the framework `ask_question` tool.
- */
-export const ASK_QUESTION_INPUT_SCHEMA = askQuestionInputSchema as JsonObject;
-
-/**
- * Shared output schema used by the framework `ask_question` tool.
- */
-export const ASK_QUESTION_OUTPUT_SCHEMA = askQuestionOutputSchema as JsonObject;
/**
* Root-only framework tool that lets the agent request structured user input.
diff --git a/packages/eve/src/runtime/framework-tools/bash.ts b/packages/eve/src/runtime/framework-tools/bash.ts
index a45df4dc5..e3d775e00 100644
--- a/packages/eve/src/runtime/framework-tools/bash.ts
+++ b/packages/eve/src/runtime/framework-tools/bash.ts
@@ -1,6 +1,7 @@
+import { z } from "#compiled/zod/index.js";
+
import { type BashInput, executeBashOnSandbox } from "#execution/sandbox/bash-tool.js";
import { requireSandboxSession } from "#execution/sandbox/require-sandbox.js";
-import type { JsonObject } from "#shared/json.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
import type { ToolExecuteOptions } from "#shared/tool-definition.js";
@@ -12,33 +13,20 @@ import type { ToolExecuteOptions } from "#shared/tool-definition.js";
* `BASH_TOOL_DEFINITION` use the exact same schema object — keeping model
* input contracts in sync without duplication.
*/
-export const BASH_INPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- command: {
- description: "The shell command to execute.",
- type: "string",
- },
- },
- required: ["command"],
- type: "object",
-};
+export const BASH_INPUT_SCHEMA = z.strictObject({
+ command: z.string().describe("The shell command to execute."),
+});
/**
* Shared output schema used by the framework `bash` tool and any author tool
* constructed via {@link defineBashTool}.
*/
-export const BASH_OUTPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- exitCode: { type: "number" },
- stderr: { type: "string" },
- stdout: { type: "string" },
- truncated: { type: "boolean" },
- },
- required: ["exitCode", "stderr", "stdout", "truncated"],
- type: "object",
-};
+export const BASH_OUTPUT_SCHEMA = z.strictObject({
+ exitCode: z.number(),
+ stderr: z.string(),
+ stdout: z.string(),
+ truncated: z.boolean(),
+});
/**
* Framework-owned executors stay statically imported so hosted server bundles
diff --git a/packages/eve/src/runtime/framework-tools/connection-search-dynamic.ts b/packages/eve/src/runtime/framework-tools/connection-search-dynamic.ts
index e4ad4cf38..682f12f71 100644
--- a/packages/eve/src/runtime/framework-tools/connection-search-dynamic.ts
+++ b/packages/eve/src/runtime/framework-tools/connection-search-dynamic.ts
@@ -1,3 +1,5 @@
+import { z } from "#compiled/zod/index.js";
+
import { loadContext } from "#context/container.js";
import { ContextKey } from "#context/key.js";
import {
@@ -36,26 +38,32 @@ import { ConnectionRegistryKey } from "#context/providers/connection-key.js";
const logger = createLogger("framework.connection-search-dynamic");
-const CONNECTION_SEARCH_RESULT_ITEM_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- connection: { type: "string" },
- description: { type: "string" },
- error: { type: "string" },
- inputSchema: { type: "object" },
- needsAuthorization: { type: "boolean" },
- outputSchema: { type: "object" },
- qualifiedName: { type: "string" },
- tool: { type: "string" },
- },
- required: ["connection", "description"],
- type: "object",
-};
-
-const CONNECTION_SEARCH_OUTPUT_SCHEMA: JsonObject = {
- items: CONNECTION_SEARCH_RESULT_ITEM_SCHEMA,
- type: "array",
-};
+const CONNECTION_SEARCH_INPUT_SCHEMA = z.strictObject({
+ connection: z
+ .string()
+ .describe("Optional: limit search to a specific connection name.")
+ .optional(),
+ keywords: z
+ .string()
+ .describe(
+ "Search keywords and expanded aliases. Distill intent into keywords; avoid stop words like 'a', 'the', 'in'.",
+ ),
+ limit: z.number().describe("Max results to return. Default 10.").optional(),
+});
+
+const connectionSchema = z.looseObject({});
+const CONNECTION_SEARCH_RESULT_ITEM_SCHEMA = z.strictObject({
+ connection: z.string(),
+ description: z.string(),
+ error: z.string().optional(),
+ inputSchema: connectionSchema.optional(),
+ needsAuthorization: z.boolean().optional(),
+ outputSchema: connectionSchema.optional(),
+ qualifiedName: z.string().optional(),
+ tool: z.string().optional(),
+});
+
+const CONNECTION_SEARCH_OUTPUT_SCHEMA = z.array(CONNECTION_SEARCH_RESULT_ITEM_SCHEMA);
/**
* Durable context key for connection search results. Written by
@@ -395,26 +403,7 @@ export function createConnectionSearchEvents(): DynamicToolEvents {
"Discovered tools become directly callable by their qualified name " +
"(e.g. `linear__list_issues`) in your next response. " +
`Available connections: ${connectionNames.join(", ")}.`,
- inputSchema: {
- type: "object" as const,
- additionalProperties: false,
- properties: {
- keywords: {
- description:
- "Search keywords and expanded aliases. Distill intent into keywords; avoid stop words like 'a', 'the', 'in'.",
- type: "string",
- },
- connection: {
- description: "Optional: limit search to a specific connection name.",
- type: "string",
- },
- limit: {
- description: "Max results to return. Default 10.",
- type: "number",
- },
- },
- required: ["keywords"],
- },
+ inputSchema: CONNECTION_SEARCH_INPUT_SCHEMA,
async execute(input: ConnectionSearchInput) {
return executeConnectionSearch(input);
},
diff --git a/packages/eve/src/runtime/framework-tools/final-output.ts b/packages/eve/src/runtime/framework-tools/final-output.ts
index f7be8749b..ec2aaa5bf 100644
--- a/packages/eve/src/runtime/framework-tools/final-output.ts
+++ b/packages/eve/src/runtime/framework-tools/final-output.ts
@@ -1,5 +1,6 @@
-import { jsonSchema, type Tool } from "ai";
+import type { Tool } from "ai";
+import { toInputSchema } from "#shared/tool-schema.js";
import type { JsonObject } from "#shared/json.js";
/**
@@ -19,9 +20,10 @@ const FINAL_OUTPUT_TOOL_DESCRIPTION =
* to the schema during generation, exactly like every other eve tool input.
*/
export function buildFinalOutputTool(schema: JsonObject): Tool {
+ const runtimeSchema = toInputSchema(schema);
return {
description: FINAL_OUTPUT_TOOL_DESCRIPTION,
- inputSchema: jsonSchema(schema),
- outputSchema: jsonSchema(schema),
+ inputSchema: runtimeSchema,
+ outputSchema: runtimeSchema,
};
}
diff --git a/packages/eve/src/runtime/framework-tools/glob.ts b/packages/eve/src/runtime/framework-tools/glob.ts
index fbf095573..1c0e18175 100644
--- a/packages/eve/src/runtime/framework-tools/glob.ts
+++ b/packages/eve/src/runtime/framework-tools/glob.ts
@@ -1,6 +1,7 @@
+import { z } from "#compiled/zod/index.js";
+
import { executeGlobOnSandbox, type GlobInput } from "#execution/sandbox/glob-tool.js";
import { requireSandboxSession } from "#execution/sandbox/require-sandbox.js";
-import type { JsonObject } from "#shared/json.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
import type { ToolExecuteOptions } from "#shared/tool-definition.js";
@@ -12,45 +13,36 @@ import type { ToolExecuteOptions } from "#shared/tool-definition.js";
* `GLOB_TOOL_DEFINITION` use the exact same schema object — keeping model
* input contracts in sync without duplication.
*/
-export const GLOB_INPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- limit: {
- description: "Maximum number of results to return. Defaults to 100.",
- maximum: 1000,
- minimum: 1,
- type: "integer",
- },
- path: {
- description:
- "The directory to search in. Defaults to /workspace. " +
+export const GLOB_INPUT_SCHEMA = z.strictObject({
+ limit: z
+ .number()
+ .int()
+ .min(1)
+ .max(1000)
+ .describe("Maximum number of results to return. Defaults to 100.")
+ .optional(),
+ path: z
+ .string()
+ .describe(
+ "The directory to search in. Defaults to /workspace. " +
"Must be an absolute path. Omit to use the default.",
- type: "string",
- },
- pattern: {
- description: 'The glob pattern to match files against (e.g. "**/*.ts", "src/**/*.js").',
- type: "string",
- },
- },
- required: ["pattern"],
- type: "object",
-};
+ )
+ .optional(),
+ pattern: z
+ .string()
+ .describe('The glob pattern to match files against (e.g. "**/*.ts", "src/**/*.js").'),
+});
/**
* Shared output schema used by the framework `glob` tool and any author tool
* constructed via {@link defineGlobTool}.
*/
-export const GLOB_OUTPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- content: { type: "string" },
- count: { type: "integer" },
- path: { type: "string" },
- truncated: { type: "boolean" },
- },
- required: ["content", "count", "path", "truncated"],
- type: "object",
-};
+export const GLOB_OUTPUT_SCHEMA = z.strictObject({
+ content: z.string(),
+ count: z.number().int(),
+ path: z.string(),
+ truncated: z.boolean(),
+});
/**
* Framework-owned executor that delegates to the default sandbox.
diff --git a/packages/eve/src/runtime/framework-tools/grep.ts b/packages/eve/src/runtime/framework-tools/grep.ts
index 80ea630fb..ce987a6c3 100644
--- a/packages/eve/src/runtime/framework-tools/grep.ts
+++ b/packages/eve/src/runtime/framework-tools/grep.ts
@@ -1,6 +1,7 @@
+import { z } from "#compiled/zod/index.js";
+
import { executeGrepOnSandbox, type GrepInput } from "#execution/sandbox/grep-tool.js";
import { requireSandboxSession } from "#execution/sandbox/require-sandbox.js";
-import type { JsonObject } from "#shared/json.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
import type { ToolExecuteOptions } from "#shared/tool-definition.js";
@@ -12,65 +13,57 @@ import type { ToolExecuteOptions } from "#shared/tool-definition.js";
* `GREP_TOOL_DEFINITION` use the exact same schema object — keeping model
* input contracts in sync without duplication.
*/
-export const GREP_INPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- context: {
- description:
- "Number of surrounding context lines to include before and after each match. Defaults to 0.",
- minimum: 0,
- type: "integer",
- },
- glob: {
- description: 'Filter files by glob pattern (e.g. "*.ts", "*.{ts,tsx}").',
- type: "string",
- },
- ignoreCase: {
- description: "Perform case-insensitive search. Defaults to false.",
- type: "boolean",
- },
- limit: {
- description: "Maximum number of matches to return per file. Defaults to 100.",
- maximum: 1000,
- minimum: 1,
- type: "integer",
- },
- literal: {
- description:
- "Treat the pattern as a literal string instead of a regular expression. Defaults to false.",
- type: "boolean",
- },
- path: {
- description:
- "The directory or file to search in. Defaults to /workspace. " +
+export const GREP_INPUT_SCHEMA = z.strictObject({
+ context: z
+ .number()
+ .int()
+ .min(0)
+ .describe(
+ "Number of surrounding context lines to include before and after each match. Defaults to 0.",
+ )
+ .optional(),
+ glob: z.string().describe('Filter files by glob pattern (e.g. "*.ts", "*.{ts,tsx}").').optional(),
+ ignoreCase: z
+ .boolean()
+ .describe("Perform case-insensitive search. Defaults to false.")
+ .optional(),
+ limit: z
+ .number()
+ .int()
+ .min(1)
+ .max(1000)
+ .describe("Maximum number of matches to return per file. Defaults to 100.")
+ .optional(),
+ literal: z
+ .boolean()
+ .describe(
+ "Treat the pattern as a literal string instead of a regular expression. Defaults to false.",
+ )
+ .optional(),
+ path: z
+ .string()
+ .describe(
+ "The directory or file to search in. Defaults to /workspace. " +
"Must be an absolute path. Omit to use the default.",
- type: "string",
- },
- pattern: {
- description:
- 'The regex pattern to search for in file contents (e.g. "log.*Error", "function\\s+\\w+").',
- type: "string",
- },
- },
- required: ["pattern"],
- type: "object",
-};
+ )
+ .optional(),
+ pattern: z
+ .string()
+ .describe(
+ 'The regex pattern to search for in file contents (e.g. "log.*Error", "function\\s+\\w+").',
+ ),
+});
/**
* Shared output schema used by the framework `grep` tool and any author tool
* constructed via {@link defineGrepTool}.
*/
-export const GREP_OUTPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- content: { type: "string" },
- matchCount: { type: "integer" },
- path: { type: "string" },
- truncated: { type: "boolean" },
- },
- required: ["content", "matchCount", "path", "truncated"],
- type: "object",
-};
+export const GREP_OUTPUT_SCHEMA = z.strictObject({
+ content: z.string(),
+ matchCount: z.number().int(),
+ path: z.string(),
+ truncated: z.boolean(),
+});
/**
* Framework-owned executor that delegates to the default sandbox.
diff --git a/packages/eve/src/runtime/framework-tools/index.test.ts b/packages/eve/src/runtime/framework-tools/index.test.ts
index c82c1cccd..269d039da 100644
--- a/packages/eve/src/runtime/framework-tools/index.test.ts
+++ b/packages/eve/src/runtime/framework-tools/index.test.ts
@@ -5,6 +5,7 @@ import {
getAllFrameworkToolNames,
getFrameworkToolDefinitions,
} from "#runtime/framework-tools/index.js";
+import { isToolSchema } from "#shared/tool-schema.js";
describe("framework-tools/index", () => {
it("returns every known framework tool name regardless of config", () => {
@@ -38,6 +39,16 @@ describe("framework-tools/index", () => {
expect(getFrameworkToolDefinitions().map((tool) => tool.name)).not.toContain("agent");
});
+ it("uses one validated runtime schema for every framework-defined input", () => {
+ for (const tool of getAllFrameworkToolDefinitions()) {
+ if (tool.inputSchema !== null) {
+ expect(isToolSchema(tool.inputSchema), `${tool.name} has a validated input schema`).toBe(
+ true,
+ );
+ }
+ }
+ });
+
it("declares an output schema for every statically shaped registered tool", () => {
const tools = getFrameworkToolDefinitions();
for (const tool of tools) {
diff --git a/packages/eve/src/runtime/framework-tools/read-file.ts b/packages/eve/src/runtime/framework-tools/read-file.ts
index cb9a8b00b..1a3aef167 100644
--- a/packages/eve/src/runtime/framework-tools/read-file.ts
+++ b/packages/eve/src/runtime/framework-tools/read-file.ts
@@ -1,6 +1,7 @@
+import { z } from "#compiled/zod/index.js";
+
import { executeReadFileOnSandbox, type ReadFileInput } from "#execution/sandbox/read-file-tool.js";
import { requireSandboxSession } from "#execution/sandbox/require-sandbox.js";
-import type { JsonObject } from "#shared/json.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
import type { ToolExecuteOptions } from "#shared/tool-definition.js";
@@ -12,44 +13,33 @@ import type { ToolExecuteOptions } from "#shared/tool-definition.js";
* `READ_FILE_TOOL_DEFINITION` use the exact same schema object — keeping
* model input contracts in sync without duplication.
*/
-export const READ_FILE_INPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- filePath: {
- description: "The absolute path to the file to read.",
- type: "string",
- },
- limit: {
- description: "Maximum number of lines to return. Defaults to 2000.",
- minimum: 1,
- type: "integer",
- },
- offset: {
- description: "1-based line number to start from. Defaults to 1.",
- minimum: 1,
- type: "integer",
- },
- },
- required: ["filePath"],
- type: "object",
-};
+export const READ_FILE_INPUT_SCHEMA = z.strictObject({
+ filePath: z.string().describe("The absolute path to the file to read."),
+ limit: z
+ .number()
+ .int()
+ .min(1)
+ .describe("Maximum number of lines to return. Defaults to 2000.")
+ .optional(),
+ offset: z
+ .number()
+ .int()
+ .min(1)
+ .describe("1-based line number to start from. Defaults to 1.")
+ .optional(),
+});
/**
* Shared output schema used by the framework `read_file` tool and any author
* tool constructed via {@link defineReadFileTool}.
*/
-export const READ_FILE_OUTPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- content: { type: "string" },
- nextOffset: { minimum: 1, type: "integer" },
- path: { type: "string" },
- totalLines: { minimum: 0, type: "integer" },
- truncated: { type: "boolean" },
- },
- required: ["content", "path", "totalLines", "truncated"],
- type: "object",
-};
+export const READ_FILE_OUTPUT_SCHEMA = z.strictObject({
+ content: z.string(),
+ nextOffset: z.number().int().min(1).optional(),
+ path: z.string(),
+ totalLines: z.number().int().min(0),
+ truncated: z.boolean(),
+});
/**
* Framework-owned executor that delegates to the default sandbox.
diff --git a/packages/eve/src/runtime/framework-tools/skill.ts b/packages/eve/src/runtime/framework-tools/skill.ts
index 21f32c16b..b43c3a645 100644
--- a/packages/eve/src/runtime/framework-tools/skill.ts
+++ b/packages/eve/src/runtime/framework-tools/skill.ts
@@ -1,16 +1,15 @@
+import { z } from "#compiled/zod/index.js";
+
import { loadContext } from "#context/container.js";
import { DynamicSkillManifestKey, SandboxKey } from "#context/keys.js";
import { ConnectionRegistryKey } from "#context/providers/connection-key.js";
import { loadSkillFromSandbox } from "#runtime/skills/sandbox-access.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
-import type { JsonObject } from "#shared/json.js";
/**
* Typed input accepted by {@link executeLoadSkillTool}.
*/
-interface LoadSkillInput {
- readonly skill: string;
-}
+type LoadSkillInput = z.infer<typeof SKILL_INPUT_SCHEMA>;
/**
* Executes the `load_skill` tool.
@@ -63,7 +62,10 @@ function availableSkillNames(ctx: ReturnType<typeof loadContext>): string[] {
// Tool definition
// ---------------------------------------------------------------------------
-export const SKILL_OUTPUT_SCHEMA: JsonObject = { type: "string" };
+export const SKILL_INPUT_SCHEMA = z.strictObject({
+ skill: z.string().describe("Available skill name or id."),
+});
+export const SKILL_OUTPUT_SCHEMA = z.string();
export const SKILL_TOOL_DEFINITION: ResolvedToolDefinition = {
description: [
@@ -74,17 +76,7 @@ export const SKILL_TOOL_DEFINITION: ResolvedToolDefinition = {
'Choose the "skill" value from the Available skills block.',
].join(" "),
execute: (input) => executeLoadSkillTool(input as LoadSkillInput),
- inputSchema: {
- additionalProperties: false,
- properties: {
- skill: {
- description: "Available skill name or id.",
- type: "string",
- },
- },
- required: ["skill"],
- type: "object",
- },
+ inputSchema: SKILL_INPUT_SCHEMA,
logicalPath: "eve:framework/load-skill",
name: "load_skill",
outputSchema: SKILL_OUTPUT_SCHEMA,
diff --git a/packages/eve/src/runtime/framework-tools/todo.ts b/packages/eve/src/runtime/framework-tools/todo.ts
index bd0e5edd3..b1acf6550 100644
--- a/packages/eve/src/runtime/framework-tools/todo.ts
+++ b/packages/eve/src/runtime/framework-tools/todo.ts
@@ -1,9 +1,9 @@
import type { ModelMessage } from "ai";
+import { z } from "#compiled/zod/index.js";
import { loadContext } from "#context/container.js";
import { ContextKey } from "#context/key.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
-import type { JsonObject } from "#shared/json.js";
// ---------------------------------------------------------------------------
// Durable context key
@@ -12,11 +12,7 @@ import type { JsonObject } from "#shared/json.js";
/**
* Single item in the todo list.
*/
-export interface TodoItem {
- readonly content: string;
- readonly priority: "high" | "medium" | "low";
- readonly status: "pending" | "in_progress" | "completed" | "cancelled";
-}
+export type TodoItem = z.infer<typeof TODO_ITEM_SCHEMA>;
/**
* Durable state for the framework todo tool.
@@ -33,9 +29,7 @@ export const TodoStateKey = new ContextKey<TodoState>("eve.todo");
* When `todos` is provided, the list is replaced (full replacement write).
* When `todos` is omitted, the current list is returned without modification.
*/
-export interface TodoToolInput {
- readonly todos?: readonly TodoItem[];
-}
+export type TodoToolInput = z.infer<typeof TODO_INPUT_SCHEMA>;
function formatTodoSummary(state: TodoState): string | undefined {
if (state.items.length === 0) return undefined;
@@ -109,51 +103,32 @@ export function executeTodoTool(input: TodoToolInput): unknown {
// Tool definition
// ---------------------------------------------------------------------------
-const TODO_ITEM_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- content: {
- description: "Brief description of the task.",
- type: "string",
- },
- priority: {
- description: "Priority level of the task.",
- enum: ["high", "medium", "low"],
- type: "string",
- },
- status: {
- description: "Current status of the task.",
- enum: ["pending", "in_progress", "completed", "cancelled"],
- type: "string",
- },
- },
- required: ["content", "status", "priority"],
- type: "object",
-};
-
-export const TODO_OUTPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- counts: {
- additionalProperties: false,
- properties: {
- cancelled: { minimum: 0, type: "integer" },
- completed: { minimum: 0, type: "integer" },
- in_progress: { minimum: 0, type: "integer" },
- pending: { minimum: 0, type: "integer" },
- total: { minimum: 0, type: "integer" },
- },
- required: ["cancelled", "completed", "in_progress", "pending", "total"],
- type: "object",
- },
- todos: {
- items: TODO_ITEM_SCHEMA,
- type: "array",
- },
- },
- required: ["counts", "todos"],
- type: "object",
-};
+const TODO_ITEM_SCHEMA = z.strictObject({
+ content: z.string().describe("Brief description of the task."),
+ priority: z.enum(["high", "medium", "low"]).describe("Priority level of the task."),
+ status: z
+ .enum(["pending", "in_progress", "completed", "cancelled"])
+ .describe("Current status of the task."),
+});
+
+export const TODO_INPUT_SCHEMA = z.strictObject({
+ todos: z
+ .array(TODO_ITEM_SCHEMA)
+ .describe("The updated todo list. Omit to read the current list without modifying it.")
+ .optional(),
+});
+
+const countSchema = z.number().int().min(0);
+export const TODO_OUTPUT_SCHEMA = z.strictObject({
+ counts: z.strictObject({
+ cancelled: countSchema,
+ completed: countSchema,
+ in_progress: countSchema,
+ pending: countSchema,
+ total: countSchema,
+ }),
+ todos: z.array(TODO_ITEM_SCHEMA),
+});
export const TODO_TOOL_DEFINITION: ResolvedToolDefinition = {
description: [
@@ -178,17 +153,7 @@ export const TODO_TOOL_DEFINITION: ResolvedToolDefinition = {
"- Only have ONE task in_progress at a time",
].join("\n"),
execute: async (input) => executeTodoTool((input ?? {}) as TodoToolInput),
- inputSchema: {
- additionalProperties: false,
- properties: {
- todos: {
- description: "The updated todo list. Omit to read the current list without modifying it.",
- items: TODO_ITEM_SCHEMA,
- type: "array",
- },
- },
- type: "object",
- },
+ inputSchema: TODO_INPUT_SCHEMA,
logicalPath: "eve:framework/todo",
name: "todo",
outputSchema: TODO_OUTPUT_SCHEMA,
diff --git a/packages/eve/src/runtime/framework-tools/web-fetch.ts b/packages/eve/src/runtime/framework-tools/web-fetch.ts
index f7cfeb19a..ab252db71 100644
--- a/packages/eve/src/runtime/framework-tools/web-fetch.ts
+++ b/packages/eve/src/runtime/framework-tools/web-fetch.ts
@@ -1,46 +1,32 @@
+import { z } from "#compiled/zod/index.js";
+
import { executeWebFetchTool, type WebFetchInput } from "#execution/web-fetch/tool.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
import type { ToolExecuteOptions } from "#shared/tool-definition.js";
-import type { JsonObject } from "#shared/json.js";
async function executeWebFetch(input: unknown, options?: ToolExecuteOptions): Promise<unknown> {
return executeWebFetchTool(input as WebFetchInput, { abortSignal: options?.abortSignal });
}
-export const WEB_FETCH_INPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- format: {
- description:
- 'The format to return the content in (text, markdown, or html). HTML responses are automatically converted to the requested format. Defaults to "markdown".',
- enum: ["markdown", "text", "html"],
- type: "string",
- },
- timeout: {
- description: "Optional timeout in seconds. Defaults to 30, max 120.",
- type: "number",
- },
- url: {
- description:
- "The fully-formed URL to fetch content from. Must start with http:// or https://.",
- type: "string",
- },
- },
- required: ["url"],
- type: "object",
-};
+export const WEB_FETCH_INPUT_SCHEMA = z.strictObject({
+ format: z
+ .enum(["markdown", "text", "html"])
+ .describe(
+ 'The format to return the content in (text, markdown, or html). HTML responses are automatically converted to the requested format. Defaults to "markdown".',
+ )
+ .optional(),
+ timeout: z.number().describe("Optional timeout in seconds. Defaults to 30, max 120.").optional(),
+ url: z
+ .string()
+ .describe("The fully-formed URL to fetch content from. Must start with http:// or https://."),
+});
-export const WEB_FETCH_OUTPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- content: { type: "string" },
- contentType: { type: "string" },
- truncated: { type: "boolean" },
- url: { type: "string" },
- },
- required: ["content", "contentType", "url", "truncated"],
- type: "object",
-};
+export const WEB_FETCH_OUTPUT_SCHEMA = z.strictObject({
+ content: z.string(),
+ contentType: z.string(),
+ truncated: z.boolean(),
+ url: z.string(),
+});
export const WEB_FETCH_TOOL_DEFINITION: ResolvedToolDefinition = {
description: [
diff --git a/packages/eve/src/runtime/framework-tools/write-file.ts b/packages/eve/src/runtime/framework-tools/write-file.ts
index 170574f5e..e2e12506d 100644
--- a/packages/eve/src/runtime/framework-tools/write-file.ts
+++ b/packages/eve/src/runtime/framework-tools/write-file.ts
@@ -1,9 +1,10 @@
+import { z } from "#compiled/zod/index.js";
+
import {
executeWriteFileOnSandbox,
type WriteFileInput,
} from "#execution/sandbox/write-file-tool.js";
import { requireSandboxSession } from "#execution/sandbox/require-sandbox.js";
-import type { JsonObject } from "#shared/json.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
import type { ToolExecuteOptions } from "#shared/tool-definition.js";
@@ -15,35 +16,21 @@ import type { ToolExecuteOptions } from "#shared/tool-definition.js";
* `WRITE_FILE_TOOL_DEFINITION` use the exact same schema object — keeping
* model input contracts in sync without duplication.
*/
-export const WRITE_FILE_INPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- content: {
- description: "Complete replacement file contents.",
- type: "string",
- },
- filePath: {
- description: "The absolute path to the file to write (must be absolute, not relative).",
- type: "string",
- },
- },
- required: ["filePath", "content"],
- type: "object",
-};
+export const WRITE_FILE_INPUT_SCHEMA = z.strictObject({
+ content: z.string().describe("Complete replacement file contents."),
+ filePath: z
+ .string()
+ .describe("The absolute path to the file to write (must be absolute, not relative)."),
+});
/**
* Shared output schema used by the framework `write_file` tool and any author
* tool constructed via {@link defineWriteFileTool}.
*/
-export const WRITE_FILE_OUTPUT_SCHEMA: JsonObject = {
- additionalProperties: false,
- properties: {
- existed: { type: "boolean" },
- path: { type: "string" },
- },
- required: ["existed", "path"],
- type: "object",
-};
+export const WRITE_FILE_OUTPUT_SCHEMA = z.strictObject({
+ existed: z.boolean(),
+ path: z.string(),
+});
/**
* Framework-owned executor that delegates to the default sandbox.
diff --git a/packages/eve/src/runtime/resolve-tool.ts b/packages/eve/src/runtime/resolve-tool.ts
index 93e8b69c0..138bd5df3 100644
--- a/packages/eve/src/runtime/resolve-tool.ts
+++ b/packages/eve/src/runtime/resolve-tool.ts
@@ -1,9 +1,8 @@
-import type { FlexibleSchema } from "ai";
-
import type { CompiledToolDefinition } from "#compiler/manifest.js";
import type { CompiledModuleMap } from "#compiler/module-map.js";
import { expectFunction, expectObjectRecord } from "#internal/authored-module.js";
import { registerDefinitionSource, stampDefinitionKey } from "#public/tool-result-narrowing.js";
+import { isToolSchema, toInputSchema, toOutputSchema } from "#shared/tool-schema.js";
import { toErrorMessage } from "#shared/errors.js";
import { loadResolvedModuleExport, ResolveAgentError } from "#runtime/resolve-helpers.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
@@ -12,11 +11,10 @@ import type { ResolvedToolDefinition } from "#runtime/types.js";
* Resolves one compiled authored tool into a runtime-owned definition
* with live callbacks reattached from the authored module.
*
- * Optional hooks (`approval`, plus an optional Standard Schema
- * `inputSchema`) are extracted when
- * declared and validated to have the expected shape; any type mismatch
- * raises a {@link ResolveAgentError} so typos surface at resolve time
- * instead of at first tool call.
+ * Schema-bearing module exports are retained when they implement the validated
+ * runtime contract; serialized schemas from the compiled manifest are
+ * otherwise rehydrated into live validators. Optional hooks are reattached
+ * from the live module export.
*/
export async function resolveToolDefinition(
definition: CompiledToolDefinition,
@@ -50,15 +48,21 @@ export async function resolveToolDefinition(
resolvedRecord.execute,
describe(definition, "to provide an execute function"),
) as ResolvedToolDefinition["execute"];
+ const inputSchema = isToolSchema(resolvedRecord.inputSchema)
+ ? resolvedRecord.inputSchema
+ : toInputSchema(definition.inputSchema);
+ const outputSchema = isToolSchema(resolvedRecord.outputSchema)
+ ? resolvedRecord.outputSchema
+ : toOutputSchema(definition.outputSchema);
return {
description: definition.description,
execute,
exportName: definition.exportName,
- inputSchema: definition.inputSchema,
+ inputSchema,
logicalPath: definition.logicalPath,
name: definition.name,
- outputSchema: definition.outputSchema,
+ outputSchema,
sourceId: definition.sourceId,
sourceKind: "module",
...extractOptionalHooks(resolvedRecord, definition),
@@ -84,11 +88,7 @@ export async function resolveToolDefinition(
* result without clobbering required fields with `undefined`.
*/
type OptionalResolvedFields = {
- -readonly [K in
- | "approval"
- | "toModelOutput"
- | "inputStandardSchema"
- | "outputStandardSchema"]?: ResolvedToolDefinition[K];
+ -readonly [K in "approval" | "toModelOutput"]?: ResolvedToolDefinition[K];
};
/**
@@ -116,14 +116,6 @@ function extractOptionalHooks(
) as ResolvedToolDefinition["toModelOutput"];
}
- if (record.inputSchema !== undefined && isFlexibleSchema(record.inputSchema)) {
- optional.inputStandardSchema = record.inputSchema;
- }
-
- if (record.outputSchema !== undefined && isFlexibleSchema(record.outputSchema)) {
- optional.outputStandardSchema = record.outputSchema;
- }
-
return optional;
}
@@ -134,12 +126,3 @@ function extractOptionalHooks(
function describe(definition: CompiledToolDefinition, predicate: string): string {
return `Expected the tool export "${definition.exportName ?? "default"}" from "${definition.logicalPath}" ${predicate}.`;
}
-
-function isFlexibleSchema(value: unknown): value is FlexibleSchema {
- return (
- typeof value === "object" &&
- value !== null &&
- "~standard" in value &&
- typeof (value as Record<string, unknown>)["~standard"] === "object"
- );
-}
diff --git a/packages/eve/src/runtime/subagents/registry.ts b/packages/eve/src/runtime/subagents/registry.ts
index 9a47590a9..bd1348a50 100644
--- a/packages/eve/src/runtime/subagents/registry.ts
+++ b/packages/eve/src/runtime/subagents/registry.ts
@@ -1,7 +1,9 @@
+import { z } from "#compiled/zod/index.js";
+
import { RuntimeRegistry, RuntimeRegistryError } from "#internal/runtime-registry.js";
-import type { JsonObject } from "#shared/json.js";
import type { PreparedRuntimeDelegationTool } from "#runtime/sessions/turn.js";
import type { ResolvedRuntimeDelegationNode } from "#runtime/types.js";
+import { serializeInputSchema } from "#shared/tool-schema.js";
/**
* One runtime-owned subagent tracked by the prepared registry.
@@ -21,26 +23,24 @@ export interface RuntimeSubagentRegistry {
}
/**
- * Stable JSON Schema lowered onto every subagent tool. Subagents always
+ * Stable input schema lowered onto every subagent tool. Subagents always
* accept one free-form `message` string from the parent agent.
*/
-export const SUBAGENT_TOOL_INPUT_SCHEMA: JsonObject = Object.freeze({
- type: "object",
- properties: Object.freeze({
- message: Object.freeze({
- type: "string",
- description:
- "The message to send to the subagent. Provide all context the subagent needs to complete the task; the subagent does not see the parent's history.",
- }),
- outputSchema: Object.freeze({
- type: "object",
- description:
- "When provided, the subagent runs in task mode and must produce structured output matching this JSON Schema. The structured output becomes the tool result.",
- }),
- }),
- required: Object.freeze(["message"]),
- additionalProperties: false,
-}) as JsonObject;
+export const SUBAGENT_TOOL_INPUT_SCHEMA = z.strictObject({
+ message: z
+ .string()
+ .describe(
+ "The message to send to the subagent. Provide all context the subagent needs to complete the task; the subagent does not see the parent's history.",
+ ),
+ outputSchema: z
+ .looseObject({})
+ .describe(
+ "Only provide a non-empty JSON Schema when the caller explicitly requests structured output; otherwise omit this field. The subagent must match a provided schema, and that structured output becomes the tool result.",
+ )
+ .optional(),
+});
+
+const SUBAGENT_TOOL_INPUT_JSON_SCHEMA = serializeInputSchema(SUBAGENT_TOOL_INPUT_SCHEMA);
/**
* Builds the runtime-owned registry for the resolved subagents visible from one
@@ -99,7 +99,7 @@ function createPreparedRuntimeSubagentTool(
): PreparedRuntimeDelegationTool {
return {
description: definition.description,
- inputSchema: SUBAGENT_TOOL_INPUT_SCHEMA,
+ inputSchema: SUBAGENT_TOOL_INPUT_JSON_SCHEMA,
kind: definition.kind,
logicalPath: definition.logicalPath,
name: definition.name,
diff --git a/packages/eve/src/runtime/tools/registry.ts b/packages/eve/src/runtime/tools/registry.ts
index b06600753..5495ee112 100644
--- a/packages/eve/src/runtime/tools/registry.ts
+++ b/packages/eve/src/runtime/tools/registry.ts
@@ -1,6 +1,7 @@
import { RuntimeRegistry } from "#internal/runtime-registry.js";
import type { PreparedRuntimeAuthoredTool } from "#runtime/sessions/turn.js";
import type { ResolvedToolDefinition } from "#runtime/types.js";
+import { serializeInputSchema, serializeOutputSchema } from "#shared/tool-schema.js";
/**
* One executable authored tool tracked by the runtime-owned registry.
@@ -74,11 +75,11 @@ async function createPreparedRuntimeTool(
): Promise<PreparedRuntimeAuthoredTool> {
return {
description: definition.description,
- inputSchema: definition.inputSchema,
+ inputSchema: serializeInputSchema(definition.inputSchema),
kind: "authored-tool",
logicalPath: definition.logicalPath,
name: definition.name,
- outputSchema: definition.outputSchema,
+ outputSchema: serializeOutputSchema(definition.outputSchema),
sourceId: definition.sourceId,
};
}
diff --git a/packages/eve/src/runtime/types.ts b/packages/eve/src/runtime/types.ts
index 9b494a81e..8805d52b0 100644
--- a/packages/eve/src/runtime/types.ts
+++ b/packages/eve/src/runtime/types.ts
@@ -1,5 +1,3 @@
-import type { FlexibleSchema } from "ai";
-
import type { ChannelAdapter } from "#channel/adapter.js";
import type { CompiledChannel } from "#channel/compiled-channel.js";
import type { NormalizedChannelCorsOptions } from "#channel/cors.js";
@@ -37,6 +35,7 @@ import type { RuntimeDynamicModelReference } from "#runtime/agent/bootstrap.js";
import type { InternalToolDefinitionWithExecuteFn } from "#shared/tool-definition.js";
import type { SandboxBackend } from "#shared/sandbox-backend.js";
import type { SandboxBootstrapContext, SandboxSessionContext } from "#shared/sandbox-definition.js";
+import type { ToolSchema } from "#shared/tool-schema.js";
/**
* Runtime-owned source ref describing one additive config module import.
@@ -151,20 +150,21 @@ export type ResolvedSandboxDefinition = ResolvedModuleSourceRef & {
* A tool without `execute` is surfaced to the client and never executed by eve.
*/
export type ResolvedToolDefinition = Readonly<
- Optional<InternalToolDefinitionWithExecuteFn<unknown, unknown>, "execute">
+ Omit<
+ Optional<InternalToolDefinitionWithExecuteFn<unknown, unknown>, "execute">,
+ "inputSchema" | "outputSchema"
+ >
> &
ResolvedModuleSourceRef & {
/**
- * Optional live Standard Schema reattached from the authored module at
- * resolve time. When present, the AI SDK uses it for both JSON schema
- * extraction and runtime validation with transforms/defaults.
+ * Validated runtime input schema. Compiled and durable JSON Schemas are
+ * rehydrated before entering this runtime-owned definition.
*/
- readonly inputStandardSchema?: FlexibleSchema;
+ readonly inputSchema: ToolSchema | null;
/**
- * Optional live Standard Schema reattached from the authored module at
- * resolve time for tool output typing/validation.
+ * Optional validated runtime output schema.
*/
- readonly outputStandardSchema?: FlexibleSchema;
+ readonly outputSchema?: ToolSchema;
/**
* Optional per-tool approval gate. When set, determines whether user
* approval is required before executing this tool. See
diff --git a/packages/eve/src/shared/json-schema.ts b/packages/eve/src/shared/json-schema.ts
deleted file mode 100644
index aef6b9d32..000000000
--- a/packages/eve/src/shared/json-schema.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import type { StandardJSONSchemaV1 } from "#compiled/@standard-schema/spec/index.js";
-
-import { parseJsonObject, type JsonObject } from "#shared/json.js";
-
-const STANDARD_JSON_SCHEMA_TARGET: StandardJSONSchemaV1.Target = "draft-07";
-
-type JsonSchemaDirection = "input" | "output";
-
-/**
- * Normalizes one Standard Schema or JSON Schema definition into plain JSON
- * Schema data that can cross eve runtime and client boundaries.
- */
-export function normalizeJsonSchemaDefinition(
- value: StandardJSONSchemaV1 | Record<string, unknown> | unknown,
- direction: JsonSchemaDirection = "input",
-): JsonObject {
- if (isStandardSchema(value)) {
- return parseJsonObject(
- value["~standard"].jsonSchema[direction]({
- target: STANDARD_JSON_SCHEMA_TARGET,
- }),
- );
- }
-
- return parseJsonObject(value);
-}
-
-function isStandardSchema(value: unknown): value is StandardJSONSchemaV1 {
- return value !== null && typeof value === "object" && "~standard" in value;
-}
diff --git a/packages/eve/src/shared/json.ts b/packages/eve/src/shared/json.ts
index f40321230..1239c9e0a 100644
--- a/packages/eve/src/shared/json.ts
+++ b/packages/eve/src/shared/json.ts
@@ -121,7 +121,10 @@ function normalizeJsonValueCandidate(
return normalized;
}
-function isJsonObjectValue(value: JsonValue): value is JsonObject {
+/**
+ * Narrows an already-normalized {@link JsonValue} to a {@link JsonObject}.
+ */
+export function isJsonObjectValue(value: JsonValue | undefined): value is JsonObject {
return value !== null && !Array.isArray(value) && typeof value === "object";
}
diff --git a/packages/eve/src/shared/tool-schema.test.ts b/packages/eve/src/shared/tool-schema.test.ts
new file mode 100644
index 000000000..23eef4c35
--- /dev/null
+++ b/packages/eve/src/shared/tool-schema.test.ts
@@ -0,0 +1,127 @@
+import { asSchema } from "ai";
+import { describe, expect, it } from "vitest";
+import { z } from "zod";
+
+import {
+ UNSPECIFIED_INPUT_SCHEMA,
+ isToolSchema,
+ serializeInputSchema,
+ serializeOutputSchema,
+ toInputSchema,
+ toOutputSchema,
+} from "#shared/tool-schema.js";
+
+describe("ToolSchema", () => {
+ it("rehydrates and validates serialized JSON Schema", async () => {
+ const schema = toInputSchema({
+ additionalProperties: false,
+ properties: {
+ prompt: { type: "string" },
+ },
+ required: ["prompt"],
+ type: "object",
+ });
+ const validate = asSchema(schema).validate;
+
+ await expect(validate?.({})).resolves.toMatchObject({ success: false });
+ await expect(validate?.({ prompt: 42 })).resolves.toMatchObject({ success: false });
+ await expect(validate?.({ extra: true, prompt: "Choose." })).resolves.toMatchObject({
+ success: false,
+ });
+ await expect(validate?.({ prompt: "Choose." })).resolves.toEqual({
+ success: true,
+ value: { prompt: "Choose." },
+ });
+ });
+
+ it("preserves JSON Schema constraints", async () => {
+ const schema = toInputSchema({
+ items: { type: "string" },
+ maxItems: 1,
+ type: "array",
+ });
+
+ await expect(asSchema(schema).validate?.(["one", "too many"])).resolves.toMatchObject({
+ success: false,
+ });
+ });
+
+ it("rejects malformed serialized schemas at the runtime boundary", () => {
+ expect(() => toInputSchema({ type: "not-a-json-schema-type" })).toThrow();
+ });
+
+ it("preserves a live validated schema", () => {
+ const schema = z.object({ prompt: z.string() });
+
+ expect(toInputSchema(schema)).toBe(schema);
+ expect(toOutputSchema(schema)).toBe(schema);
+ });
+
+ it("rehydrates one validator per serialized source object", () => {
+ const source = {
+ properties: { prompt: { type: "string" } },
+ type: "object",
+ };
+
+ expect(toInputSchema(source)).toBe(toInputSchema(source));
+ });
+
+ it("passes null and undefined through every conversion", () => {
+ expect(toInputSchema(null)).toBeNull();
+ expect(toInputSchema(undefined)).toBeUndefined();
+ expect(toOutputSchema(undefined)).toBeUndefined();
+ expect(serializeInputSchema(null)).toBeNull();
+ expect(serializeInputSchema(undefined)).toBeUndefined();
+ expect(serializeOutputSchema(undefined)).toBeUndefined();
+ });
+
+ it("serializes a live schema to canonical JSON Schema data", () => {
+ const schema = z.strictObject({ prompt: z.string() });
+
+ expect(serializeInputSchema(schema)).toEqual({
+ additionalProperties: false,
+ properties: { prompt: { type: "string" } },
+ required: ["prompt"],
+ type: "object",
+ });
+ });
+
+ it("strips the $schema version key from serialized data", () => {
+ expect(
+ serializeInputSchema({
+ $schema: "http://json-schema.org/draft-07/schema#",
+ type: "object",
+ }),
+ ).toEqual({ type: "object" });
+ });
+
+ it("serializes each direction of a transforming schema", () => {
+ const schema = z.strictObject({
+ count: z
+ .string()
+ .transform((value) => Number.parseInt(value, 10))
+ .pipe(z.number().int()),
+ });
+
+ expect(serializeInputSchema(schema)).toMatchObject({
+ properties: { count: { type: "string" } },
+ });
+ expect(serializeOutputSchema(schema)).toMatchObject({
+ properties: { count: expect.objectContaining({ type: "integer" }) },
+ });
+ });
+
+ it("identifies validating JSON-Schema-capable values", () => {
+ expect(isToolSchema(z.object({}))).toBe(true);
+ expect(isToolSchema(UNSPECIFIED_INPUT_SCHEMA)).toBe(true);
+ expect(isToolSchema({ type: "object" })).toBe(false);
+ expect(isToolSchema(null)).toBe(false);
+ });
+
+ it("accepts any input via UNSPECIFIED_INPUT_SCHEMA", async () => {
+ const validate = asSchema(UNSPECIFIED_INPUT_SCHEMA).validate;
+
+ await expect(validate?.({})).resolves.toMatchObject({ success: true });
+ await expect(validate?.({ extra: true })).resolves.toMatchObject({ success: true });
+ });
+});
diff --git a/packages/eve/src/shared/tool-schema.ts b/packages/eve/src/shared/tool-schema.ts
new file mode 100644
index 000000000..b7f11f11f
--- /dev/null
+++ b/packages/eve/src/shared/tool-schema.ts
@@ -0,0 +1,156 @@
+import type {
+ StandardJSONSchemaV1,
+ StandardSchemaV1,
+} from "#compiled/@standard-schema/spec/index.js";
+import { z } from "#compiled/zod/index.js";
+
+import { parseJsonObject, type JsonObject } from "#shared/json.js";
+
+/**
+ * eve-owned schema contract for tool input and output schemas: a Standard
+ * Schema validator that can also emit JSON Schema. Zod implements both
+ * constituent protocols without exposing Zod through runtime-owned types.
+ */
+export type ToolSchema<Input = unknown, Output = Input> = StandardSchemaV1<Input, Output> &
+ StandardJSONSchemaV1<Input, Output>;
+
+/**
+ * Any value accepted at a schema boundary: a live {@link ToolSchema}, a
+ * JSON-Schema-capable Standard Schema, or plain JSON Schema data. Plain data
+ * is runtime-validated by {@link parseJsonObject} during conversion.
+ */
+export type ToolSchemaSource = StandardJSONSchemaV1 | Record<string, unknown>;
+
+type SchemaDirection = "input" | "output";
+
+/** `null` and `undefined` pass through every conversion untouched. */
+type SchemaResult<TSource, TResult> = TSource extends null | undefined ? TSource : TResult;
+
+const JSON_SCHEMA_TARGET: StandardJSONSchemaV1.Target = "draft-07";
+
+// Keyed on source identity so replayed durable schemas rehydrate once.
+const rehydratedSchemas: Record<SchemaDirection, WeakMap<object, ToolSchema>> = {
+ input: new WeakMap(),
+ output: new WeakMap(),
+};
+
+/**
+ * Resolves a source into a live input {@link ToolSchema}. Live schemas pass
+ * through unchanged; serialized JSON Schemas are rehydrated into vendored Zod
+ * validators. `null` and `undefined` pass through untouched.
+ */
+export function toInputSchema<T extends ToolSchemaSource | null | undefined>(
+ source: T,
+): SchemaResult<T, ToolSchema> {
+ return toSchema(source, "input") as SchemaResult<T, ToolSchema>;
+}
+
+/**
+ * Resolves a source into a live output {@link ToolSchema}. Live schemas pass
+ * through unchanged; serialized JSON Schemas are rehydrated into vendored Zod
+ * validators. `null` and `undefined` pass through untouched.
+ */
+export function toOutputSchema<T extends ToolSchemaSource | null | undefined>(
+ source: T,
+): SchemaResult<T, ToolSchema> {
+ return toSchema(source, "output") as SchemaResult<T, ToolSchema>;
+}
+
+/**
+ * Serializes an input schema source into canonical JSON Schema data (no
+ * `$schema` key) for compiled artifacts, durable state, and protocol
+ * responses. `null` and `undefined` pass through untouched.
+ */
+export function serializeInputSchema<T extends ToolSchemaSource | null | undefined>(
+ source: T,
+): SchemaResult<T, JsonObject> {
+ return serializeSchema(source, "input") as SchemaResult<T, JsonObject>;
+}
+
+/**
+ * Serializes an output schema source into canonical JSON Schema data (no
+ * `$schema` key) for compiled artifacts, durable state, and protocol
+ * responses. `null` and `undefined` pass through untouched.
+ */
+export function serializeOutputSchema<T extends ToolSchemaSource | null | undefined>(
+ source: T,
+): SchemaResult<T, JsonObject> {
+ return serializeSchema(source, "output") as SchemaResult<T, JsonObject>;
+}
+
+/**
+ * Returns whether a value implements the full {@link ToolSchema} contract:
+ * Standard Schema validation plus JSON Schema emission.
+ */
+export function isToolSchema(value: unknown): value is ToolSchema {
+ if (typeof value !== "object" || value === null || !("~standard" in value)) {
+ return false;
+ }
+
+ const standard = (value as Record<string, unknown>)["~standard"];
+ if (typeof standard !== "object" || standard === null) return false;
+
+ const properties = standard as Record<string, unknown>;
+ const jsonSchema = properties.jsonSchema;
+ return (
+ typeof properties.validate === "function" &&
+ typeof jsonSchema === "object" &&
+ jsonSchema !== null &&
+ typeof (jsonSchema as Record<string, unknown>).input === "function" &&
+ typeof (jsonSchema as Record<string, unknown>).output === "function"
+ );
+}
+
+/**
+ * Permissive schema lowered onto model-visible tools whose definitions
+ * declare no input schema. Accepts any input — an absent schema declares no
+ * contract, so rejecting stray properties would only force needless retries.
+ */
+export const UNSPECIFIED_INPUT_SCHEMA: ToolSchema = z.fromJSONSchema({}) as ToolSchema;
+
+function toSchema(
+ source: ToolSchemaSource | null | undefined,
+ direction: SchemaDirection,
+): ToolSchema | null | undefined {
+ if (source === null || source === undefined) return source;
+ if (isToolSchema(source)) return source;
+
+ const cache = rehydratedSchemas[direction];
+ let resolved = cache.get(source);
+ if (resolved === undefined) {
+ const jsonSchema = toJsonObject(source, direction);
+ // The rehydration target must match JSON_SCHEMA_TARGET: serialized
+ // schemas strip `$schema`, so zod would otherwise assume draft-2020-12.
+ resolved = z.fromJSONSchema(jsonSchema as Parameters<typeof z.fromJSONSchema>[0], {
+ defaultTarget: "draft-7",
+ }) as ToolSchema;
+ cache.set(source, resolved);
+ }
+ return resolved;
+}
+
+function serializeSchema(
+ source: ToolSchemaSource | null | undefined,
+ direction: SchemaDirection,
+): JsonObject | null | undefined {
+ if (source === null || source === undefined) return source;
+ return toJsonObject(source, direction);
+}
+
+/**
+ * Normalizes one source into canonical JSON Schema data. Standard Schemas
+ * emit their requested direction; plain data passes through. The `$schema`
+ * version key is always stripped so every eve boundary carries one canonical
+ * wire form.
+ */
+function toJsonObject(source: ToolSchemaSource, direction: SchemaDirection): JsonObject {
+ const raw = isStandardJsonSchema(source)
+ ? parseJsonObject(source["~standard"].jsonSchema[direction]({ target: JSON_SCHEMA_TARGET }))
+ : parseJsonObject(source);
+ const { $schema: _schemaVersion, ...canonical } = raw;
+ return canonical;
+}
+
+function isStandardJsonSchema(value: unknown): value is StandardJSONSchemaV1 {
+ return value !== null && typeof value === "object" && "~standard" in value;
+}
diff --git a/packages/eve/test/define-bash-tool.test.ts b/packages/eve/test/define-bash-tool.test.ts
index 9fd212f1d..2429251f7 100644
--- a/packages/eve/test/define-bash-tool.test.ts
+++ b/packages/eve/test/define-bash-tool.test.ts
@@ -6,6 +6,7 @@ import { ContextContainer, contextStorage } from "../src/context/container.js";
import { SandboxKey } from "../src/context/keys.js";
import type { SandboxAccess } from "../src/sandbox/state.js";
import { defineBashTool } from "../src/public/tools/define-bash-tool.js";
+import { serializeInputSchema } from "../src/shared/tool-schema.js";
describe("defineBashTool", () => {
it("produces a schema that never exposes a sandbox property to the model", () => {
@@ -15,7 +16,7 @@ describe("defineBashTool", () => {
expect(tool.description).toBe("Execute a shell command in the workspace sandbox.");
expect(typeof tool.execute).toBe("function");
- const schema = tool.inputSchema as unknown as Record<string, unknown>;
+ const schema = serializeInputSchema(tool.inputSchema);
expect(schema).toMatchObject({
properties: { command: { type: "string" } },
required: ["command"],
diff --git a/packages/eve/test/define-glob-tool.test.ts b/packages/eve/test/define-glob-tool.test.ts
index 5c56b4162..6e106c809 100644
--- a/packages/eve/test/define-glob-tool.test.ts
+++ b/packages/eve/test/define-glob-tool.test.ts
@@ -6,6 +6,7 @@ import { ContextContainer, contextStorage } from "../src/context/container.js";
import { SandboxKey } from "../src/context/keys.js";
import type { SandboxAccess } from "../src/sandbox/state.js";
import { defineGlobTool } from "../src/public/tools/define-glob-tool.js";
+import { serializeInputSchema } from "../src/shared/tool-schema.js";
function createFakeAccess(
handler: (command: string) => { exitCode: number; stderr: string; stdout: string } | null,
@@ -60,7 +61,7 @@ describe("defineGlobTool", () => {
expect(tool.description).toBe("Search for files by glob pattern in the workspace sandbox.");
expect(typeof tool.execute).toBe("function");
- const schema = tool.inputSchema as unknown as Record<string, unknown>;
+ const schema = serializeInputSchema(tool.inputSchema);
expect(schema).toMatchObject({
properties: { pattern: { type: "string" } },
required: ["pattern"],
diff --git a/packages/eve/test/define-grep-tool.test.ts b/packages/eve/test/define-grep-tool.test.ts
index 4ad00d8f5..3e0c05c88 100644
--- a/packages/eve/test/define-grep-tool.test.ts
+++ b/packages/eve/test/define-grep-tool.test.ts
@@ -6,6 +6,7 @@ import { ContextContainer, contextStorage } from "../src/context/container.js";
import { SandboxKey } from "../src/context/keys.js";
import type { SandboxAccess } from "../src/sandbox/state.js";
import { defineGrepTool } from "../src/public/tools/define-grep-tool.js";
+import { serializeInputSchema } from "../src/shared/tool-schema.js";
function createFakeAccess(
handler: (command: string) => { exitCode: number; stderr: string; stdout: string } | null,
@@ -60,7 +61,7 @@ describe("defineGrepTool", () => {
expect(tool.description).toBe("Search file contents by pattern in the workspace sandbox.");
expect(typeof tool.execute).toBe("function");
- const schema = tool.inputSchema as unknown as Record<string, unknown>;
+ const schema = serializeInputSchema(tool.inputSchema);
expect(schema).toMatchObject({
properties: { pattern: { type: "string" } },
required: ["pattern"],
diff --git a/packages/eve/test/define-read-file-tool.test.ts b/packages/eve/test/define-read-file-tool.test.ts
index 8952c5471..811110b40 100644
--- a/packages/eve/test/define-read-file-tool.test.ts
+++ b/packages/eve/test/define-read-file-tool.test.ts
@@ -6,6 +6,7 @@ import { ContextContainer, contextStorage } from "../src/context/container.js";
import { SandboxKey } from "../src/context/keys.js";
import type { SandboxAccess } from "../src/sandbox/state.js";
import { defineReadFileTool } from "../src/public/tools/define-read-file-tool.js";
+import { serializeInputSchema } from "../src/shared/tool-schema.js";
import { ReadFileStateKey } from "../src/runtime/framework-tools/file-state.js";
function createFakeAccess(files: Record<string, string>): SandboxAccess {
@@ -53,7 +54,7 @@ describe("defineReadFileTool", () => {
expect(tool.description).toBe("Read a file from the workspace sandbox.");
expect(typeof tool.execute).toBe("function");
- const schema = tool.inputSchema as unknown as Record<string, unknown>;
+ const schema = serializeInputSchema(tool.inputSchema);
expect(schema).toMatchObject({
properties: { filePath: { type: "string" } },
required: ["filePath"],
diff --git a/packages/eve/test/define-write-file-tool.test.ts b/packages/eve/test/define-write-file-tool.test.ts
index a974419d1..dbc394445 100644
--- a/packages/eve/test/define-write-file-tool.test.ts
+++ b/packages/eve/test/define-write-file-tool.test.ts
@@ -6,6 +6,7 @@ import { ContextContainer, contextStorage } from "../src/context/container.js";
import { SandboxKey } from "../src/context/keys.js";
import type { SandboxAccess } from "../src/sandbox/state.js";
import { defineWriteFileTool } from "../src/public/tools/define-write-file-tool.js";
+import { serializeInputSchema } from "../src/shared/tool-schema.js";
import {
createReadFileStamp,
ReadFileStateKey,
@@ -58,15 +59,15 @@ describe("defineWriteFileTool", () => {
expect(tool.description).toBe("Write a file to the workspace sandbox.");
expect(typeof tool.execute).toBe("function");
- const schema = tool.inputSchema as unknown as Record<string, unknown>;
+ const schema = serializeInputSchema(tool.inputSchema);
expect(schema).toMatchObject({
properties: {
content: { type: "string" },
filePath: { type: "string" },
},
- required: ["filePath", "content"],
type: "object",
});
+ expect(new Set(schema.required as string[])).toEqual(new Set(["filePath", "content"]));
expect((schema.properties as Record<string, unknown>).sandbox).toBeUndefined();
});
diff --git a/packages/eve/test/resolve-agent.test.ts b/packages/eve/test/resolve-agent.test.ts
index 55a483140..36e86539f 100644
--- a/packages/eve/test/resolve-agent.test.ts
+++ b/packages/eve/test/resolve-agent.test.ts
@@ -9,6 +9,7 @@ import {
import type { CompiledModuleMap } from "../src/compiler/module-map.js";
import { TEST_DEFAULT_MODEL_ID } from "../src/internal/testing/app-harness.js";
import { ResolveAgentError, resolveAgent } from "../src/runtime/resolve-agent.js";
+import { serializeInputSchema } from "../src/shared/tool-schema.js";
describe("resolveAgent", () => {
it("hydrates compiled authored metadata and attaches tool execute functions", async () => {
@@ -255,20 +256,20 @@ describe("resolveAgent", () => {
expect(resolved.tools).toHaveLength(1);
expect(resolved.tools[0]).toMatchObject({
description: "Get the current weather for a city.",
- inputSchema: {
- properties: {
- city: {
- type: "string",
- },
- },
- required: ["city"],
- type: "object",
- },
logicalPath: "tools/get-weather.mjs",
name: "get_weather",
sourceId: "tools/get-weather.mjs",
sourceKind: "module",
});
+ expect(serializeInputSchema(resolved.tools[0]!.inputSchema!)).toMatchObject({
+ properties: {
+ city: {
+ type: "string",
+ },
+ },
+ required: ["city"],
+ type: "object",
+ });
expect(
resolved.tools[0]?.execute?.({ city: "Brooklyn" }, { messages: [], toolCallId: "call_1" }),
).toEqual({
@@ -338,10 +339,10 @@ describe("resolveAgent", () => {
manifest,
moduleMap,
});
- const inputStandardSchema = resolved.tools[0]?.inputStandardSchema;
- expect(inputStandardSchema).toBeDefined();
+ const inputSchema = resolved.tools[0]?.inputSchema;
+ expect(inputSchema).toBeDefined();
- const sdkSchema = asSchema(inputStandardSchema);
+ const sdkSchema = asSchema(inputSchema!);
const result = await sdkSchema.validate!({});
expect(result).toEqual({
diff --git a/packages/eve/test/runtime-tool-registry.test.ts b/packages/eve/test/runtime-tool-registry.test.ts
index 806a90012..10b6363fd 100644
--- a/packages/eve/test/runtime-tool-registry.test.ts
+++ b/packages/eve/test/runtime-tool-registry.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
import { RuntimeRegistryError } from "../src/internal/runtime-registry.js";
import { createRuntimeToolRegistry } from "../src/runtime/tools/registry.js";
import type { ResolvedToolDefinition } from "../src/runtime/types.js";
+import { toInputSchema } from "../src/shared/tool-schema.js";
describe("createRuntimeToolRegistry", () => {
it("lowers authored tool schemas into serializable runtime descriptors", async () => {
@@ -10,7 +11,7 @@ describe("createRuntimeToolRegistry", () => {
tools: [
createResolvedToolDefinition({
description: "Get the current weather for one city.",
- inputSchema: {
+ inputSchema: toInputSchema({
properties: {
city: {
type: "string",
@@ -18,7 +19,7 @@ describe("createRuntimeToolRegistry", () => {
},
required: ["city"],
type: "object",
- },
+ }),
logicalPath: "tools/get-weather.ts",
name: "get_weather",
sourceId: "tools/get-weather.ts",