2026-07-25 14:29:28 +00:00
import { jsonObjectSchema } from "../domain/jsonValue.js" ;
import { enhancedInputSchemas } from "./enhancedInputs.js" ;
import { TOOL_EXAMPLE_OVERRIDES } from "./toolContractExamples.js" ;
import type { ToolContract } from "./toolContractTypes.js" ;
import { toolContractMetadata } from "./toolEffects.js" ;
import { enhancedOutputSchemas } from "./toolOutputSchemas.js" ;
2026-08-10 02:28:11 +08:00
import { requireOutputSchema } from "./toolOutputSchemaPrimitives.js" ;
2026-07-25 14:29:28 +00:00
type FunctionWorkflowName = "analyze_function" | "inspect_native_api" ;
const functionWorkflow = < Name extends FunctionWorkflowName >(
name : Name ,
description : string ,
2026-08-10 02:28:11 +08:00
) => {
2026-07-25 14:29:28 +00:00
const inputSchema = enhancedInputSchemas [ name ];
2026-08-10 02:28:11 +08:00
const outputSchema = requireOutputSchema ( enhancedOutputSchemas , name );
2026-07-25 14:29:28 +00:00
return {
name ,
... toolContractMetadata ( name ),
description ,
kind : "enhanced" ,
inputSchema ,
outputSchema ,
examples : [
{
title : `Example ${ name . replaceAll ( "_" , " " ) } request` ,
input : jsonObjectSchema.parse (
inputSchema . parse ( TOOL_EXAMPLE_OVERRIDES [ name ] ?? {}),
),
},
],
2026-08-10 02:28:11 +08:00
} satisfies ToolContract < Name , typeof inputSchema , typeof outputSchema >;
2026-07-25 14:29:28 +00:00
};
/** Function dossier and native API reconstruction workflow contracts. */
export const FUNCTION_WORKFLOW_TOOL_CONTRACTS = [
functionWorkflow (
"analyze_function" ,
2026-09-29 07:08:46 +08:00
"Return one complete function dossier inline, including identity, provider-specific pseudocode and assembly, comments, calls, references, referenced strings/names, local CFG blocks, and any available native API boundary observations." ,
2026-07-25 14:29:28 +00:00
),
functionWorkflow (
"inspect_native_api" ,
2026-09-29 07:08:46 +08:00
"Reconstruct one native function boundary with structured return/parameter types, confidence, evidence, jump-table dispatch/data/target mappings, unsupported branches, and residual unknowns." ,
2026-07-25 14:29:28 +00:00
),
] as const satisfies readonly ToolContract [];