feat: js/py generate declarations from comments (#30)

This commit is contained in:
sigoden
2024-06-07 15:16:31 +08:00
committed by GitHub
parent 2b07fc2c7e
commit 739a832d87
14 changed files with 717 additions and 272 deletions
+16
View File
@@ -0,0 +1,16 @@
/**
* Demonstrate how to create a tool using Javascript and how to use comments.
* @typedef {Object} Args
* @property {string} string - Define a required string property
* @property {'foo'|'bar'} string_enum - Define a required string property with enum
* @property {string} [string_optional] - Define a optional string property
* @property {boolean} boolean - Define a required boolean property
* @property {Integer} integer - Define a required integer property
* @property {number} number - Define a required number property
* @property {string[]} array - Define a required string array property
* @property {string[]} [array_optional] - Define a optional string array property
* @param {Args} args
*/
exports.main = function main(args) {
console.log(args);
}
+32
View File
@@ -0,0 +1,32 @@
from typing import List, Literal, Optional
def main(
boolean: bool,
string: str,
string_enum: Literal["foo", "bar"],
integer: int,
number: float,
array: List[str],
string_optional: Optional[str] = None,
array_optional: Optional[List[str]] = None,
) -> None:
"""Demonstrate how to create a tool using Python and how to use comments.
Args:
boolean: Define a required boolean property
string: Define a required string property
string_enum: Define a required string property with enum
integer: Define a required integer property
number: Define a required number property
array: Define a required string array property
string_optional: Define a optional string property
array_optional: Define a optional string array property
"""
print(f"boolean: {boolean}")
print(f"string: {string}")
print(f"string_enum: {string_enum}")
print(f"integer: {integer}")
print(f"number: {number}")
print(f"array: {array}")
print(f"string_optional: {string_optional}")
print(f"array_optional: {array_optional}")
+15
View File
@@ -0,0 +1,15 @@
# @describe Demonstrate how to create a tool using Bash and how to use comment tags.
# @option --string! Define a required string property
# @option --string-enum![foo|bar] Define a required string property with enum
# @option --string-optional Define a optional string property
# @flag --boolean Define a boolean property
# @option --integer! <INT> Define a required integer property
# @option --number! <NUM> Define a required number property
# @option --array+ <VALUE> Define a required string array property
# @option --array-optional* Define a optional string array property
main() {
( set -o posix ; set ) | grep ^argc_ # inspect all argc variables
}
eval "$(argc --argc-eval "$0" "$@")"
+8 -21
View File
@@ -1,22 +1,9 @@
exports.declarate = function declarate() {
return {
"name": "may_execute_js_code",
"description": "Runs the javascript code in node.js.",
"parameters": {
"type": "object",
"properties": {
"code": {
"type": "string",
"description": "Javascript code to execute, such as `console.log(\"hello world\")`"
}
},
"required": [
"code"
]
}
}
}
exports.execute = function execute(data) {
eval(data.code)
/**
* Runs the javascript code in node.js.
* @typedef {Object} Args
* @property {string} code - Javascript code to execute, such as `console.log("hello world")`
* @param {Args} args
*/
exports.main = function main({ code }) {
eval(code);
}
+6 -21
View File
@@ -1,21 +1,6 @@
def declarate():
return {
"name": "may_execute_py_code",
"description": "Runs the python code.",
"parameters": {
"type": "object",
"properties": {
"code": {
"type": "string",
"description": "Python code to execute, such as `print(\"hello world\")`"
}
},
"required": [
"code"
]
}
}
def execute(data):
exec(data["code"])
def main(code: str):
"""Runs the python code.
Args:
code: Python code to execute, such as `print("hello world")`
"""
exec(code)