Skip to content

chore: switch from huma to go-sdk JSON Schema #990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ go 1.24.2

toolchain go1.24.4

replace github.com/danielgtaylor/huma/v2 => github.com/gptscript-ai/huma v0.0.0-20250617131016-b2081da6c65b

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/BurntSushi/locker v0.0.0-20171006230638-a6e239ea1c69
github.com/adrg/xdg v0.4.0
github.com/chzyer/readline v1.5.1
github.com/danielgtaylor/huma/v2 v2.32.1-0.20250509235652-c7ead6f3c67f
github.com/docker/cli v26.0.0+incompatible
github.com/docker/docker-credential-helpers v0.8.1
github.com/fatih/color v1.17.0
Expand All @@ -22,12 +19,13 @@ require (
github.com/gptscript-ai/broadcaster v0.0.0-20240625175512-c43682019b86
github.com/gptscript-ai/chat-completion-client v0.0.0-20250224164718-139cb4507b1d
github.com/gptscript-ai/cmd v0.0.0-20250530150401-bc71fddf8070
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250617131750-9129819aea51
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250714170123-17ad44ae8c54
github.com/gptscript-ai/tui v0.0.0-20250419050840-5e79e16786c9
github.com/hexops/autogold/v2 v2.2.1
github.com/hexops/valast v1.4.4
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056
github.com/mholt/archives v0.1.0
github.com/modelcontextprotocol/go-sdk v0.2.0
github.com/nanobot-ai/nanobot v0.0.6-0.20250623174223-c75713af7a09
github.com/pkoukk/tiktoken-go v0.1.7
github.com/pkoukk/tiktoken-go-loader v0.0.2-0.20240522064338-c17e8bc0f699
Expand All @@ -40,7 +38,7 @@ require (
github.com/tidwall/gjson v1.17.1
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/sync v0.14.0
golang.org/x/sync v0.15.0
golang.org/x/term v0.32.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools/v3 v3.5.1
Expand Down Expand Up @@ -139,12 +137,12 @@ require (
github.com/yuin/goldmark v1.5.4 // indirect
github.com/yuin/goldmark-emoji v1.0.2 // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/crypto v0.38.0 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/crypto v0.39.0 // indirect
golang.org/x/mod v0.25.0 // indirect
golang.org/x/net v0.41.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.25.0 // indirect
golang.org/x/tools v0.23.0 // indirect
golang.org/x/text v0.26.0 // indirect
golang.org/x/tools v0.34.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
mvdan.cc/gofumpt v0.6.0 // indirect
)
40 changes: 20 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,8 @@ github.com/gptscript-ai/chat-completion-client v0.0.0-20250224164718-139cb4507b1
github.com/gptscript-ai/chat-completion-client v0.0.0-20250224164718-139cb4507b1d/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo=
github.com/gptscript-ai/cmd v0.0.0-20250530150401-bc71fddf8070 h1:xm5ZZFraWFwxyE7TBEncCXArubCDZTwG6s5bpMzqhSY=
github.com/gptscript-ai/cmd v0.0.0-20250530150401-bc71fddf8070/go.mod h1:DJAo1xTht1LDkNYFNydVjTHd576TC7MlpsVRl3oloVw=
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250617131750-9129819aea51 h1:9s53UDNVXF+ujMwhg/7LiZlIMYOpn2Ap8WBc1i4Pi/Y=
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250617131750-9129819aea51/go.mod h1:LQ4E2g+t+L/it13Le5m9Hfgn4huS8bO4hcTawFlUzSY=
github.com/gptscript-ai/huma v0.0.0-20250617131016-b2081da6c65b h1:QReUetqY+ep2sj6g83oqldPHzwH2T2TG1sv0IWE2hL0=
github.com/gptscript-ai/huma v0.0.0-20250617131016-b2081da6c65b/go.mod h1:y2Eq35Y5Xy6+MZRPgn81/bjNBiEHqEQba+vY+fLigjU=
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250714170123-17ad44ae8c54 h1:9OAiDBdOQUHVL89wmb38+/XOuewboMhgnk6NqoJiC00=
github.com/gptscript-ai/go-gptscript v0.9.6-0.20250714170123-17ad44ae8c54/go.mod h1:HLPvKBhDtsEkyyUWefJVhPpl98R3tZG6ps7+mQ+EKVI=
github.com/gptscript-ai/tui v0.0.0-20250419050840-5e79e16786c9 h1:wQC8sKyeGA50WnCEG+Jo5FNRIkuX3HX8d3ubyWCCoI8=
github.com/gptscript-ai/tui v0.0.0-20250419050840-5e79e16786c9/go.mod h1:iwHxuueg2paOak7zIg0ESBWx7A0wIHGopAratbgaPNY=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down Expand Up @@ -265,8 +263,8 @@ github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgo
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/klauspost/cpuid/v2 v2.2.3 h1:sxCkb+qR91z4vsqw4vGGZlDgPz3G7gjaLyK3V8y70BU=
github.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU=
github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -307,6 +305,8 @@ github.com/mholt/archives v0.1.0 h1:FacgJyrjiuyomTuNA92X5GyRBRZjE43Y/lrzKIlF35Q=
github.com/mholt/archives v0.1.0/go.mod h1:j/Ire/jm42GN7h90F5kzj6hf6ZFzEH66de+hmjEKu+I=
github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58=
github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs=
github.com/modelcontextprotocol/go-sdk v0.2.0 h1:PESNYOmyM1c369tRkzXLY5hHrazj8x9CY1Xu0fLCryM=
github.com/modelcontextprotocol/go-sdk v0.2.0/go.mod h1:0sL9zUKKs2FTTkeCCVnKqbLJTw5TScefPAzojjU459E=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
Expand Down Expand Up @@ -408,8 +408,8 @@ github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
Expand Down Expand Up @@ -445,8 +445,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -479,8 +479,8 @@ golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -503,8 +503,8 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand All @@ -520,8 +520,8 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -585,8 +585,8 @@ golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down Expand Up @@ -618,8 +618,8 @@ golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
8 changes: 4 additions & 4 deletions pkg/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ func TestHelloWorld(t *testing.T) {
"modelName": "gpt-4o",
"internalPrompt": null,
"arguments": {
"type": "object",
"properties": {
"input": {
"description": "Any string",
"type": "string"
"type": "string",
"description": "Any string"
}
},
"type": "object"
}
},
"instructions": "echo \"${input}\"",
"id": "https://get.gptscript.ai/echo.gpt:",
Expand Down
65 changes: 35 additions & 30 deletions pkg/loader/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"strings"
"time"

humav2 "github.com/danielgtaylor/huma/v2"
"github.com/getkin/kin-openapi/openapi3"
"github.com/gptscript-ai/gptscript/pkg/openapi"
"github.com/gptscript-ai/gptscript/pkg/types"
"github.com/modelcontextprotocol/go-sdk/jsonschema"
)

var toolNameRegex = regexp.MustCompile(`[^a-zA-Z0-9_-]+`)
Expand Down Expand Up @@ -151,9 +151,9 @@ func getOpenAPITools(t *openapi3.T, defaultHost, source, targetToolName string)
Parameters: types.Parameters{
Name: toolName,
Description: toolDesc,
Arguments: &humav2.Schema{
Type: humav2.TypeObject,
Properties: make(map[string]*humav2.Schema),
Arguments: &jsonschema.Schema{
Type: "object",
Properties: make(map[string]*jsonschema.Schema),
},
},
},
Expand All @@ -174,7 +174,7 @@ func getOpenAPITools(t *openapi3.T, defaultHost, source, targetToolName string)
}

// Add the new arg to the tool's arguments
tool.Arguments.Properties[param.Value.Name] = openAPI3SchemaToHumaV2Schema(arg)
tool.Arguments.Properties[param.Value.Name] = openAPI3SchemaToJSONSchema(arg)

// Check whether it is required
if param.Value.Required {
Expand Down Expand Up @@ -227,7 +227,7 @@ func getOpenAPITools(t *openapi3.T, defaultHost, source, targetToolName string)
}
// Unfortunately, the request body doesn't contain any good descriptor for it,
// so we just use "requestBodyContent" as the name of the arg.
tool.Arguments.Properties["requestBodyContent"] = openAPI3SchemaToHumaV2Schema(arg)
tool.Arguments.Properties["requestBodyContent"] = openAPI3SchemaToJSONSchema(arg)
break
}

Expand Down Expand Up @@ -373,22 +373,27 @@ func parseServer(server *openapi3.Server) (string, error) {
return s, nil
}

// openAPI3SchemaToHumaV2Schema converts an openapi3.Schema to a humav2.Schema
func openAPI3SchemaToHumaV2Schema(schema *openapi3.Schema) *humav2.Schema {
// openAPI3SchemaToJSONSchema converts an openapi3.Schema to a jsonschema.Schema
func openAPI3SchemaToJSONSchema(schema *openapi3.Schema) *jsonschema.Schema {
if schema == nil {
return nil
}

result := &humav2.Schema{
result := &jsonschema.Schema{
Title: schema.Title,
Description: schema.Description,
Format: schema.Format,
Nullable: schema.Nullable,
}

// Convert type
if schema.Type != nil && len(*schema.Type) > 0 {
result.Type = (*schema.Type)[0]
result.Types = *schema.Type
}

// In OpenAPI v3.0, there is a nullable field.
// In OpenAPI v3.1, nullable is specified by providing a separate type.
if schema.Nullable && !slices.Contains(result.Types, "null") {
result.Types = append(result.Types, "null")
}

// Convert enum
Expand Down Expand Up @@ -463,52 +468,52 @@ func openAPI3SchemaToHumaV2Schema(schema *openapi3.Schema) *humav2.Schema {

// Convert properties
if schema.Properties != nil {
result.Properties = make(map[string]*humav2.Schema, len(schema.Properties))
result.Properties = make(map[string]*jsonschema.Schema, len(schema.Properties))
for name, propRef := range schema.Properties {
if propRef != nil && propRef.Value != nil {
result.Properties[name] = openAPI3SchemaToHumaV2Schema(propRef.Value)
result.Properties[name] = openAPI3SchemaToJSONSchema(propRef.Value)
}
}
}

// Convert items
if schema.Items != nil && schema.Items.Value != nil {
result.Items = openAPI3SchemaToHumaV2Schema(schema.Items.Value)
result.Items = openAPI3SchemaToJSONSchema(schema.Items.Value)
}

// Convert oneOf
if schema.OneOf != nil {
result.OneOf = make([]*humav2.Schema, len(schema.OneOf))
result.OneOf = make([]*jsonschema.Schema, len(schema.OneOf))
for i, oneOfRef := range schema.OneOf {
if oneOfRef != nil && oneOfRef.Value != nil {
result.OneOf[i] = openAPI3SchemaToHumaV2Schema(oneOfRef.Value)
result.OneOf[i] = openAPI3SchemaToJSONSchema(oneOfRef.Value)
}
}
}

// Convert anyOf
if schema.AnyOf != nil {
result.AnyOf = make([]*humav2.Schema, len(schema.AnyOf))
result.AnyOf = make([]*jsonschema.Schema, len(schema.AnyOf))
for i, anyOfRef := range schema.AnyOf {
if anyOfRef != nil && anyOfRef.Value != nil {
result.AnyOf[i] = openAPI3SchemaToHumaV2Schema(anyOfRef.Value)
result.AnyOf[i] = openAPI3SchemaToJSONSchema(anyOfRef.Value)
}
}
}

// Convert allOf
if schema.AllOf != nil {
result.AllOf = make([]*humav2.Schema, len(schema.AllOf))
result.AllOf = make([]*jsonschema.Schema, len(schema.AllOf))
for i, allOfRef := range schema.AllOf {
if allOfRef != nil && allOfRef.Value != nil {
result.AllOf[i] = openAPI3SchemaToHumaV2Schema(allOfRef.Value)
result.AllOf[i] = openAPI3SchemaToJSONSchema(allOfRef.Value)
}
}
}

// Convert not
if schema.Not != nil && schema.Not.Value != nil {
result.Not = openAPI3SchemaToHumaV2Schema(schema.Not.Value)
result.Not = openAPI3SchemaToJSONSchema(schema.Not.Value)
}

return result
Expand Down Expand Up @@ -543,11 +548,11 @@ func getOpenAPIToolsRevamp(t *openapi3.T, source, targetToolName string) ([]type
Parameters: types.Parameters{
Name: types.ToolNormalizer("get-schema-" + t.Info.Title),
Description: fmt.Sprintf("Get the JSONSchema for the arguments for an operation for %s. You must do this before you run the operation.", t.Info.Title),
Arguments: &humav2.Schema{
Type: humav2.TypeObject,
Properties: map[string]*humav2.Schema{
Arguments: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"operation": {
Type: humav2.TypeString,
Type: "string",
Title: "operation",
Description: "the name of the operation to get the schema for",
Required: []string{"operation"},
Expand All @@ -567,17 +572,17 @@ func getOpenAPIToolsRevamp(t *openapi3.T, source, targetToolName string) ([]type
Parameters: types.Parameters{
Name: types.ToolNormalizer("run-operation-" + t.Info.Title),
Description: fmt.Sprintf("Run an operation for %s. You MUST call %s for the operation before you use this tool.", t.Info.Title, openapi.GetSchemaTool),
Arguments: &humav2.Schema{
Type: humav2.TypeObject,
Properties: map[string]*humav2.Schema{
Arguments: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"operation": {
Type: humav2.TypeString,
Type: "string",
Title: "operation",
Description: "the name of the operation to run",
Required: []string{"operation"},
},
"args": {
Type: humav2.TypeString,
Type: "string",
Title: "args",
Description: "the JSON string containing arguments; must match the JSONSchema for the operation",
Required: []string{"args"},
Expand Down
Loading