In agent development, when dealing with JSON data returned by models, manually defining interfaces or Pydantic models is both tedious and error-prone. # dsh–types plugin provides a set of local type conversion tools that can automatically generate corresponding code structures from sample data.
The plugin is maintained by uckkk and belongs to the model inference category. Its core function is to convert a JSON payload into TypeScript interfaces, JSON Schema, or Python Pydantic models with one click, automatically inferring field types, nested objects, and array element types.
The plugin provides the following three tool functions:
_to_ts: Converts JSON to TypeScript interfaces._to_schema: Converts JSON to JSON Schema (draft-07 standard)._to_python: Converts JSON to Python Pydantic models.
Run the following command to install the plugin:
dsh plugin add dsh--types
After installation, the plugin starts with DSH sessions, and the registered tools can be called directly in conversations.
After installation, call the corresponding tool functions in a DSH session. Suppose you have the following JSON data:
{
"id": 1,
"name": "example",
"tags": ["tag1", "tag2"],
"meta": { "status": "active" }
}
You can generate types in the following ways:
- Call _to_ts(data=<JSON>) to get a TypeScript interface.
- Call _to_schema(data=<JSON>) to get a JSON Schema.
- Call _to_python(data=<JSON>) to get a Pydantic model.
- Applicable scenarios: When you need to quickly define strong types for data returned by models, or when you need to build data validation models for a Python project, you can use this plugin to generate baseline code directly, reducing the amount of manual work.
- Notes:
1. This plugin is implemented purely in Node. Installing it runs third-party code on your local machine, so it is recommended to review the source code before installing.
2. Type inference is based on sample data and may produce misclassifications (for example, a string may be inferred as an enum or a date). In complex scenarios, it is recommended to adjust the generated code manually.
In summary, # dsh–types solves the tedious type definition problem in agent development. To view the full documentation or source code, visit its GitHub repository.