import { REFS_KEY } from "../../constants/artifact-syntax.js";
import { z } from "@hono/zod-openapi";
import { jsonSchema } from "ai";

//#region src/domains/run/agents/tools/ref-aware-schema.d.ts
declare const TOOL_CHAINING_SCHEMA_DESCRIPTIONS: {
  readonly ROOT: string;
  readonly REFS_PROPERTY: string;
  readonly ARTIFACT_REF: "Reference an artifact by id. Shape: { \"_artifact\": \"<artifact_id>\", \"_tool\": \"<tool_call_id>\" }. Optional \"_select\" (JMESPath) to extract a specific field from the artifact data.";
  readonly TOOL_REF: "Reference a prior tool result by its call id. Shape: { \"_tool\": \"<tool_call_id>\" }. Optional \"_select\" (JMESPath) to extract a specific field from that result.";
  readonly ARTIFACT_ID: "The artifact ID — from an artifact:create response or the available_artifacts list.";
  readonly TOOL_CALL_ID: "The exact \"_toolCallId\" value from a prior tool result in this conversation. Never invent one.";
  readonly SELECT: string;
};
/**
 * Transform a tool's JSON Schema for tool chaining support.
 *
 * Instead of wrapping every property with `anyOf` (which bloats the schema
 * and breaks Anthropic's constrained JSON generation), this approach:
 *
 * 1. Makes each property nullable — `type: "string"` → `type: ["string", "null"]`
 * 2. Adds a single `SENTINEL_KEY.REFS` property at the root for tool chaining references
 *
 * The model passes `null` for referenced parameters and includes the reference
 * in `SENTINEL_KEY.REFS`. The resolution logic replaces nulls with resolved data.
 */
declare function makeRefAwareJsonSchema(schema: Record<string, unknown>): Record<string, unknown>;
declare function makeBaseInputSchema(schema: Record<string, unknown>): ReturnType<typeof z.fromJSONSchema>;
/**
 * Build both the ref-aware input schema (for the LLM tool definition) and
 * the base input schema (for post-resolution validation).
 *
 * Accepts either a raw JSON Schema object or a Zod schema. Zod schemas are
 * converted via `convertZodToJsonSchema` from agents-core.
 *
 * Uses `jsonSchema()` from the AI SDK to send the JSON Schema directly to
 * the provider — avoiding the lossy `z.fromJSONSchema()` → `zodToJsonSchema`
 * round-trip.
 */
declare function buildRefAwareSchemas(inputSchema: Record<string, unknown> | z.ZodType): {
  refAwareInputSchema: ReturnType<typeof jsonSchema>;
  baseInputSchema: ReturnType<typeof z.fromJSONSchema> | undefined;
};
//#endregion
export { REFS_KEY, TOOL_CHAINING_SCHEMA_DESCRIPTIONS, buildRefAwareSchemas, makeBaseInputSchema, makeRefAwareJsonSchema };