From cab8cd7f3263f1922efeb34dbbbb275a7c465a67 Mon Sep 17 00:00:00 2001 From: Hare Date: Fri, 24 Oct 2025 09:53:12 +0900 Subject: [PATCH] =?UTF-8?q?0.4.0:=20=E3=83=AF=E3=83=BC=E3=82=AB=E3=83=BC?= =?UTF-8?q?=E3=81=AE=E5=BB=83=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 648 ++++++++------------------ README.md | 34 +- docs/patch_note/v0.4.0.md | 33 ++ docs/prompt-composer.md | 116 +---- worker/Cargo.toml | 3 +- worker/examples/builder_basic.rs | 44 +- worker/examples/plugin_usage.rs | 23 +- worker/src/builder.rs | 131 ++---- worker/src/config/mod.rs | 2 - worker/src/config/parser.rs | 56 --- worker/src/lib.rs | 80 +--- worker/src/prompt/composer.rs | 355 ++------------ worker/src/prompt/mod.rs | 6 +- worker/src/prompt/types.rs | 74 +-- worker/src/tests/config_tests.rs | 334 ------------- worker/src/tests/integration_tests.rs | 333 ------------- 16 files changed, 409 insertions(+), 1863 deletions(-) create mode 100644 docs/patch_note/v0.4.0.md delete mode 100644 worker/src/config/parser.rs delete mode 100644 worker/src/tests/config_tests.rs delete mode 100644 worker/src/tests/integration_tests.rs diff --git a/Cargo.lock b/Cargo.lock index f79a2db..f065d90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,21 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "addr2line" -version = "0.24.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler2" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" - [[package]] name = "aho-corasick" version = "1.1.3" @@ -26,12 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - [[package]] name = "android_system_properties" version = "0.1.5" @@ -43,9 +22,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.99" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" [[package]] name = "async-stream" @@ -86,21 +65,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" -[[package]] -name = "backtrace" -version = "0.3.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" -dependencies = [ - "addr2line", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", - "windows-targets 0.52.6", -] - [[package]] name = "base64" version = "0.21.7" @@ -115,18 +79,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.3" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d" - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "bumpalo" @@ -142,26 +97,26 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "cc" -version = "1.2.34" +version = "1.2.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc" +checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7" dependencies = [ + "find-msvc-tools", "shlex", ] [[package]] name = "cfg-if" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "chrono" -version = "0.4.41" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" dependencies = [ - "android-tzdata", "iana-time-zone", "js-sys", "num-traits", @@ -186,35 +141,6 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "cpufeatures" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - [[package]] name = "dirs" version = "6.0.0" @@ -233,7 +159,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -270,12 +196,12 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -295,6 +221,12 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "find-msvc-tools" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" + [[package]] name = "fnv" version = "1.0.7" @@ -399,16 +331,6 @@ dependencies = [ "slab", ] -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.16" @@ -417,27 +339,21 @@ checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", - "wasi 0.11.1+wasi-snapshot-preview1", + "wasi", ] [[package]] name = "getrandom" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", "libc", "r-efi", - "wasi 0.14.3+wasi-0.2.4", + "wasip2", ] -[[package]] -name = "gimli" -version = "0.31.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" - [[package]] name = "h2" version = "0.3.27" @@ -457,25 +373,11 @@ dependencies = [ "tracing", ] -[[package]] -name = "handlebars" -version = "5.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" -dependencies = [ - "log", - "pest", - "pest_derive", - "serde", - "serde_json", - "thiserror 1.0.69", -] - [[package]] name = "hashbrown" -version = "0.15.5" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" [[package]] name = "heck" @@ -557,9 +459,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.63" +version = "0.1.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -688,25 +590,14 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.11.0" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" +checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" dependencies = [ "equivalent", "hashbrown", ] -[[package]] -name = "io-uring" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" -dependencies = [ - "bitflags 2.9.3", - "cfg-if", - "libc", -] - [[package]] name = "ipnet" version = "2.11.0" @@ -721,9 +612,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "js-sys" -version = "0.3.77" +version = "0.3.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" dependencies = [ "once_cell", "wasm-bindgen", @@ -737,35 +628,35 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.175" +version = "0.2.177" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" +checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" [[package]] name = "libloading" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" dependencies = [ "cfg-if", - "windows-targets 0.53.3", + "windows-link", ] [[package]] name = "libredox" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" +checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.10.0", "libc", ] [[package]] name = "linux-raw-sys" -version = "0.9.4" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" +checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" [[package]] name = "litemap" @@ -775,25 +666,24 @@ checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" [[package]] name = "lock_api" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" dependencies = [ - "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.27" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" [[package]] name = "memchr" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "mime" @@ -807,24 +697,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "miniz_oxide" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" -dependencies = [ - "adler2", -] - [[package]] name = "mio" -version = "1.0.4" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" +checksum = "69d83b0086dc8ecf3ce9ae2874b2d1290252e2a30720bea58a5c6639b0092873" dependencies = [ "libc", - "wasi 0.11.1+wasi-snapshot-preview1", - "windows-sys 0.59.0", + "wasi", + "windows-sys 0.61.2", ] [[package]] @@ -839,12 +720,11 @@ dependencies = [ [[package]] name = "nu-ansi-term" -version = "0.46.0" +version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "overload", - "winapi", + "windows-sys 0.61.2", ] [[package]] @@ -856,15 +736,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "object" -version = "0.36.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.21.3" @@ -877,17 +748,11 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - [[package]] name = "parking_lot" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" dependencies = [ "lock_api", "parking_lot_core", @@ -895,15 +760,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.11" +version = "0.9.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets 0.52.6", + "windows-link", ] [[package]] @@ -912,50 +777,6 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" -[[package]] -name = "pest" -version = "2.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1db05f56d34358a8b1066f67cbb203ee3e7ed2ba674a6263a1d5ec6db2204323" -dependencies = [ - "memchr", - "thiserror 2.0.16", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb056d9e8ea77922845ec74a1c4e8fb17e7c218cc4fc11a15c5d25e189aa40bc" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87e404e638f781eb3202dc82db6760c8ae8a1eeef7fb3fa8264b2ef280504966" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pest_meta" -version = "2.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edd1101f170f5903fde0914f899bb503d9ff5271d7ba76bbb70bea63690cc0d5" -dependencies = [ - "pest", - "sha2", -] - [[package]] name = "pin-project-lite" version = "0.2.16" @@ -979,18 +800,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.101" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" dependencies = [ "proc-macro2", ] @@ -1003,11 +824,11 @@ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "redox_syscall" -version = "0.5.17" +version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.10.0", ] [[package]] @@ -1018,23 +839,23 @@ checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" dependencies = [ "getrandom 0.2.16", "libredox", - "thiserror 2.0.16", + "thiserror", ] [[package]] name = "ref-cast" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a0ae411dbe946a674d89546582cea4ba2bb8defac896622d6496f14c23ba5cf" +checksum = "f354300ae66f76f1c85c5f84693f0ce81d747e2c3f21a45fef496d89c960bf7d" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1165225c21bff1f3bbce98f5a1f889949bc902d3575308cc7b0de30b4f6d27c7" +checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da" dependencies = [ "proc-macro2", "quote", @@ -1043,9 +864,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.2" +version = "1.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" dependencies = [ "aho-corasick", "memchr", @@ -1055,9 +876,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.10" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" dependencies = [ "aho-corasick", "memchr", @@ -1066,9 +887,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.6" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "reqwest" @@ -1127,23 +948,17 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rustc-demangle" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" - [[package]] name = "rustix" -version = "1.0.8" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" +checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.10.0", "errno", "libc", "linux-raw-sys", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -1232,18 +1047,28 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -1263,14 +1088,15 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.143" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" +checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" dependencies = [ "itoa", "memchr", "ryu", "serde", + "serde_core", ] [[package]] @@ -1307,17 +1133,6 @@ dependencies = [ "unsafe-libyaml", ] -[[package]] -name = "sha2" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "sharded-slab" version = "0.1.7" @@ -1366,19 +1181,19 @@ dependencies = [ [[package]] name = "socket2" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" +checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "stable_deref_trait" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "strum" @@ -1403,9 +1218,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.106" +version = "2.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" +checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" dependencies = [ "proc-macro2", "quote", @@ -1452,51 +1267,31 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.21.0" +version = "3.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15b61f8f20e3a6f7e0649d825294eaf317edce30f82cf6026e7e4cb9222a7d1e" +checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" dependencies = [ "fastrand", - "getrandom 0.3.3", + "getrandom 0.3.4", "once_cell", "rustix", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] name = "thiserror" -version = "1.0.69" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" dependencies = [ - "thiserror-impl 1.0.69", -] - -[[package]] -name = "thiserror" -version = "2.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" -dependencies = [ - "thiserror-impl 2.0.16", + "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.69" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", @@ -1524,29 +1319,26 @@ dependencies = [ [[package]] name = "tokio" -version = "1.47.1" +version = "1.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" +checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" dependencies = [ - "backtrace", "bytes", - "io-uring", "libc", "mio", "parking_lot", "pin-project-lite", "signal-hook-registry", - "slab", - "socket2 0.6.0", + "socket2 0.6.1", "tokio-macros", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] name = "tokio-macros" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" dependencies = [ "proc-macro2", "quote", @@ -1668,9 +1460,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.19" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" +checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5" dependencies = [ "nu-ansi-term", "sharded-slab", @@ -1686,23 +1478,11 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "typenum" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" - -[[package]] -name = "ucd-trie" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" - [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06" [[package]] name = "unsafe-libyaml" @@ -1736,11 +1516,11 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "uuid" -version = "1.18.0" +version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" +checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" dependencies = [ - "getrandom 0.3.3", + "getrandom 0.3.4", "js-sys", "serde", "wasm-bindgen", @@ -1752,12 +1532,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "want" version = "0.3.1" @@ -1774,31 +1548,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] -name = "wasi" -version = "0.14.3+wasi-0.2.4" +name = "wasip2" +version = "1.0.1+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" dependencies = [ "wit-bindgen", ] [[package]] name = "wasm-bindgen" -version = "0.2.100" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" dependencies = [ "cfg-if", "once_cell", "rustversion", "wasm-bindgen-macro", + "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.100" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" dependencies = [ "bumpalo", "log", @@ -1810,9 +1585,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.50" +version = "0.4.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" +checksum = "7e038d41e478cc73bae0ff9b36c60cff1c98b8f38f8d7e8061e79ee63608ac5c" dependencies = [ "cfg-if", "js-sys", @@ -1823,9 +1598,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.100" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1833,9 +1608,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.100" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" dependencies = [ "proc-macro2", "quote", @@ -1846,9 +1621,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.100" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" dependencies = [ "unicode-ident", ] @@ -1868,9 +1643,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.77" +version = "0.3.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120" dependencies = [ "js-sys", "wasm-bindgen", @@ -1882,33 +1657,11 @@ version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows-core" -version = "0.61.2" +version = "0.62.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" dependencies = [ "windows-implement", "windows-interface", @@ -1919,9 +1672,9 @@ dependencies = [ [[package]] name = "windows-implement" -version = "0.60.0" +version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", @@ -1930,9 +1683,9 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.59.1" +version = "0.59.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", @@ -1941,24 +1694,24 @@ dependencies = [ [[package]] name = "windows-link" -version = "0.1.3" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] name = "windows-result" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" dependencies = [ "windows-link", ] [[package]] name = "windows-strings" -version = "0.4.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" dependencies = [ "windows-link", ] @@ -1981,22 +1734,22 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-sys" version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ - "windows-targets 0.53.3", + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", ] [[package]] @@ -2032,19 +1785,19 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.53.3" +version = "0.53.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" dependencies = [ "windows-link", - "windows_aarch64_gnullvm 0.53.0", - "windows_aarch64_msvc 0.53.0", - "windows_i686_gnu 0.53.0", - "windows_i686_gnullvm 0.53.0", - "windows_i686_msvc 0.53.0", - "windows_x86_64_gnu 0.53.0", - "windows_x86_64_gnullvm 0.53.0", - "windows_x86_64_msvc 0.53.0", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", ] [[package]] @@ -2061,9 +1814,9 @@ checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_gnullvm" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" [[package]] name = "windows_aarch64_msvc" @@ -2079,9 +1832,9 @@ checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_aarch64_msvc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" [[package]] name = "windows_i686_gnu" @@ -2097,9 +1850,9 @@ checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnu" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" [[package]] name = "windows_i686_gnullvm" @@ -2109,9 +1862,9 @@ checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_gnullvm" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" [[package]] name = "windows_i686_msvc" @@ -2127,9 +1880,9 @@ checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_i686_msvc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" [[package]] name = "windows_x86_64_gnu" @@ -2145,9 +1898,9 @@ checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnu" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" [[package]] name = "windows_x86_64_gnullvm" @@ -2163,9 +1916,9 @@ checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_gnullvm" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" [[package]] name = "windows_x86_64_msvc" @@ -2181,9 +1934,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "windows_x86_64_msvc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" [[package]] name = "winnow" @@ -2206,13 +1959,13 @@ dependencies = [ [[package]] name = "wit-bindgen" -version = "0.45.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" [[package]] name = "worker" -version = "0.3.0" +version = "0.4.0" dependencies = [ "anyhow", "async-stream", @@ -2223,7 +1976,6 @@ dependencies = [ "eventsource-stream", "futures", "futures-util", - "handlebars", "libloading", "log", "regex", @@ -2235,7 +1987,7 @@ dependencies = [ "strum", "strum_macros", "tempfile", - "thiserror 2.0.16", + "thiserror", "tokio", "tokio-util", "toml", @@ -2269,7 +2021,7 @@ dependencies = [ "schemars", "serde", "serde_json", - "thiserror 2.0.16", + "thiserror", "tracing", "uuid", ] diff --git a/README.md b/README.md index 2c3f7f3..fcf2c41 100644 --- a/README.md +++ b/README.md @@ -4,39 +4,37 @@ ## 特徴 - 主要 LLM プロバイダーを単一のインターフェースで利用 -- プロンプト/パーシャル読み込みを利用者実装の `ResourceLoader` へ委譲 +- システムプロンプトの生成を外部関数として注入可能 - ツール連携とストリーミング応答、フックによるカスタマイズに対応 ## 利用手順 -`worker` のプロンプト/パーシャル解決は利用者側に委譲されています。以下の流れで組み込みます。 +`worker` はシステムプロンプトの生成を外部関数に完全委任します。以下の手順で組み込みます。 -1. `ResourceLoader` を実装して、テンプレートやパーシャルが参照する識別子から文字列を返す。 -2. `Worker::builder()` にプロバイダー・モデル・ロールと合わせて `resource_loader` を渡し、`Worker` を生成。 -3. セッションを初期化し、`process_task_with_history` などの API でイベントストリームを処理。 +1. `fn(&PromptContext, &[Message]) -> Result` 形式の関数(またはクロージャ)でシステムプロンプトを返す。 +2. `Worker::builder()` にプロバイダー・モデル・APIキーと合わせて `system_prompt(...)` を渡し、`Worker` を生成。 +3. セッション初期化後、`process_task_with_history` などでイベントストリームを処理。 ```rust use futures_util::StreamExt; -use worker::{LlmProvider, PromptError, ResourceLoader, Role, Worker}; - -struct FsLoader; - -impl ResourceLoader for FsLoader { - fn load(&self, id: &str) -> Result { - std::fs::read_to_string(id) - .map_err(|e| PromptError::FileNotFound(format!("{}: {}", id, e))) - } -} +use worker::{LlmProvider, PromptContext, PromptError, Worker}; #[tokio::main] async fn main() -> Result<(), Box> { - let role = Role::new("assistant", "Helper", "You are a helpful assistant."); + let system_prompt = |ctx: &PromptContext, _messages: &[worker_types::Message]| { + Ok(format!( + "You are assisting the project: {}", + ctx.workspace + .project_name + .clone() + .unwrap_or_else(|| "unknown".to_string()) + )) + }; let mut worker = Worker::builder() .provider(LlmProvider::Claude) .model("claude-3-sonnet-20240229") - .resource_loader(FsLoader) - .role(role) + .system_prompt(system_prompt) .build()?; worker.initialize_session()?; diff --git a/docs/patch_note/v0.4.0.md b/docs/patch_note/v0.4.0.md new file mode 100644 index 0000000..6df3ec2 --- /dev/null +++ b/docs/patch_note/v0.4.0.md @@ -0,0 +1,33 @@ +# Release Notes - v0.4.0 + +**Release Date**: 2025-??-?? + +v0.4.0 は Worker が `Role` や YAML 設定を扱わず、システムプロンプト生成を完全に利用者へ委譲する大規模リファクタです。これにより、任意のテンプレートエンジンやデータソースを組み合わせてプロンプトを構築できます。 + +## Breaking Changes + +- `Role` / `ConfigParser` / `ResourceLoader` を削除。`WorkerBuilder` はシステムプロンプト生成関数 (`system_prompt(...)`) の指定が必須になりました。 +- `worker/src/config` の Role 関連コードとテストを削除。既存の YAML ベース設定は互換層なし。 + +## 新機能 / 仕様変更 + +- `PromptComposer` は `Arc` を受け取り、`PromptContext` と履歴メッセージからシステムプロンプト文字列を生成するシンプルなラッパーになりました。 +- `WorkerBuilder` は `.system_prompt(...)` で登録した関数を保持し、メッセージ送信時に毎回システムプロンプトを再生成します。 +- README/サンプルコードを刷新し、システムプロンプト関数・マクロベースのツール/フック登録手順のみを掲載。 +- 新しい `docs/prompt-composer.md` を追加し、`PromptComposer` の利用例をサマリー形式で紹介。 + +## 不具合修正 + +- `PromptComposer` が内部でファイルアクセスを行う経路を排除し、生成関数の失敗時は直近のキャッシュを利用するようにしました。 +- Worker から NIA 固有の設定コードを除去し、環境依存の副作用を縮小。 + +## 移行ガイド + +1. 旧 `Role` / `ConfigParser` を利用していた場合、`PromptContext` と会話履歴を引数にシステムプロンプト文字列を返す関数を実装し、`.system_prompt(...)` に渡してください。 +2. `Worker::load_config` やリソースパス解決に依存していたコードは削除してください。必要であればアプリケーション側でファイル読み込みを行い、生成関数内で利用してください。 +3. ツール・フックは引き続き `#[worker::tool]` / `#[worker::hook]` マクロを推奨しています(API に変更はありません)。 + +## 開発者向けメモ + +- README を簡潔化し、RustDocs で確認できる内容の重複を削除しました。 +- `worker/examples/` を更新し、システムプロンプト関数とマクロベースのツール登録のみを扱うよう整理しました。 diff --git a/docs/prompt-composer.md b/docs/prompt-composer.md index 5778f00..43ea294 100644 --- a/docs/prompt-composer.md +++ b/docs/prompt-composer.md @@ -1,106 +1,32 @@ # PromptComposer -テンプレートベースのプロンプト構築システム。Handlebarsテンプレートエンジンによる動的プロンプト生成。 - -## 基本使用方法 +`PromptComposer` は、`PromptContext` と会話履歴からシステムプロンプト文字列を生成するクロージャをラップし、LLM へ送信するメッセージ列を構築します。 ```rust use std::sync::Arc; -use worker::prompt::{PromptComposer, PromptContext, PromptError, ResourceLoader}; +use worker::prompt::{PromptComposer, PromptContext, PromptError, SystemPromptFn}; +use worker_types::Message; -struct FsLoader; - -impl ResourceLoader for FsLoader { - fn load(&self, identifier: &str) -> Result { - std::fs::read_to_string(identifier) - .map_err(|e| PromptError::FileNotFound(format!("{}: {}", identifier, e))) - } +fn build_context() -> PromptContext { + // WorkspaceDetector などからアプリ固有の情報を収集して埋め込む + todo!() } -// 初期化 -let loader = Arc::new(FsLoader); -let mut composer = PromptComposer::from_config_file("role.yaml", context, loader.clone())?; -composer.initialize_session(&messages)?; - -// プロンプト構築 -let messages = composer.compose(&user_messages)?; -``` - -## リソースローダー - -`PromptComposer` はテンプレート内で参照されるパーシャルや `{{include_file}}` の解決をクレート利用者に委ねています。 -`ResourceLoader` トレイトを実装して、任意のストレージや命名規則に基づいて文字列を返してください。 - -```rust -struct MyLoader; - -impl ResourceLoader for MyLoader { - fn load(&self, identifier: &str) -> Result { - match identifier.strip_prefix("#workspace/") { - Some(rest) => { - let path = std::env::current_dir()?.join(".nia").join(rest); - std::fs::read_to_string(path).map_err(|e| PromptError::FileNotFound(e.to_string())) - } - None => std::fs::read_to_string(identifier) - .map_err(|e| PromptError::FileNotFound(e.to_string())), - } - } +fn generator(ctx: &PromptContext, messages: &[Message]) -> Result { + Ok(format!( + "Project {} has {} prior messages.", + ctx.workspace + .project_name + .clone() + .unwrap_or_else(|| \"unknown\".into()), + messages.len() + )) } + +let context = build_context(); +let composer = PromptComposer::new(context, Arc::new(generator)); +let conversation = vec![Message::new(worker_types::Role::User, \"Hello\".into())]; +let final_messages = composer.compose(&conversation)?; ``` -## テンプレート構文 - -### 変数展開 -```handlebars -{{workspace.project_name}} # プロジェクト名 -{{workspace.project_type}} # プロジェクト種別 -{{model.provider}}/{{model.model_name}} # モデル情報 -{{tools_schema}} # ツールスキーマ -``` - -### 条件分岐 -```handlebars -{{#if workspace.has_nia_md}} -Project info: {{workspace_content}} -{{/if}} - -{{#eq workspace.project_type "Rust"}} -Focus on memory safety and performance. -{{/eq}} -``` - -### 繰り返し処理 -```handlebars -{{#each tools}} -- **{{name}}**: {{description}} -{{/each}} -``` - -### パーシャルテンプレート -```handlebars -{{> header}} -{{> coding_guidelines}} -{{> footer}} -``` - -## カスタムヘルパー - -### include_file -外部ファイルを読み込み: -```handlebars -{{include_file "~/.config/nia/templates/guidelines.md"}} -``` - -### workspace_content -ワークスペースのnia.md内容を取得: -```handlebars -{{workspace_content}} -``` - -## 利用可能なコンテキスト変数 - -- `workspace`: プロジェクト情報(root_path、project_type、git_info等) -- `model`: LLMモデル情報(provider、model_name、capabilities) -- `session`: セッション情報(conversation_id、message_count) -- `user_input`: ユーザー入力内容 -- `tools_schema`: ツール定義JSON +`compose_with_tools` を使うと、`tools_schema` をテンプレート変数として渡した上でシステムプロンプトを再生成できます。 diff --git a/worker/Cargo.toml b/worker/Cargo.toml index 5fd15f7..ec7c30e 100644 --- a/worker/Cargo.toml +++ b/worker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "worker" -version = "0.3.0" +version = "0.4.0" edition = "2024" [dependencies] @@ -31,7 +31,6 @@ tracing = "0.1.40" eventsource-stream = "0.2.3" xdg = "3.0.0" chrono = { version = "0.4", features = ["serde"] } -handlebars = "5.1.2" regex = "1.10.2" uuid = { version = "1.10", features = ["v4", "serde"] } tokio-util = { version = "0.7", features = ["codec"] } diff --git a/worker/examples/builder_basic.rs b/worker/examples/builder_basic.rs index 7b041cc..e6c7481 100644 --- a/worker/examples/builder_basic.rs +++ b/worker/examples/builder_basic.rs @@ -1,23 +1,19 @@ use std::collections::HashMap; -use worker::{LlmProvider, PromptError, ResourceLoader, Role, Worker}; - -struct FsLoader; - -impl ResourceLoader for FsLoader { - fn load(&self, identifier: &str) -> Result { - std::fs::read_to_string(identifier) - .map_err(|e| PromptError::FileNotFound(format!("{}: {}", identifier, e))) - } -} +use worker::{LlmProvider, PromptContext, PromptError, Worker}; +use worker_types::Message; #[tokio::main] async fn main() -> Result<(), Box> { - // Example 1: Basic role - let role = Role::new( - "assistant", - "A helpful AI assistant", - "You are a helpful, harmless, and honest AI assistant.", - ); + // Example 1: Basic system prompt generator + fn system_prompt(ctx: &PromptContext, _messages: &[Message]) -> Result { + Ok(format!( + "You are helping with the project: {}", + ctx.workspace + .project_name + .clone() + .unwrap_or_else(|| "unknown".to_string()) + )) + } let mut api_keys = HashMap::new(); api_keys.insert("claude".to_string(), std::env::var("ANTHROPIC_API_KEY")?); @@ -26,27 +22,23 @@ async fn main() -> Result<(), Box> { .provider(LlmProvider::Claude) .model("claude-3-sonnet-20240229") .api_keys(api_keys) - .resource_loader(FsLoader) - .role(role) + .system_prompt(system_prompt) .build()?; println!("✅ Worker created with builder pattern"); println!(" Provider: {:?}", worker.get_provider_name()); println!(" Model: {}", worker.get_model_name()); - // Example 2: Code reviewer role - let code_reviewer_role = Role::new( - "code-reviewer", - "An AI that reviews code for best practices", - "You are an expert code reviewer. Always provide constructive feedback.", - ); + // Example 2: Different prompt generator + fn reviewer_prompt(_ctx: &PromptContext, _messages: &[Message]) -> Result { + Ok("You are an expert code reviewer. Always provide constructive feedback.".to_string()) + } let _worker2 = Worker::builder() .provider(LlmProvider::Claude) .model("claude-3-sonnet-20240229") .api_key("claude", std::env::var("ANTHROPIC_API_KEY")?) - .resource_loader(FsLoader) - .role(code_reviewer_role) + .system_prompt(reviewer_prompt) .build()?; println!("✅ Worker created with custom role"); diff --git a/worker/examples/plugin_usage.rs b/worker/examples/plugin_usage.rs index 636cbb7..5d547aa 100644 --- a/worker/examples/plugin_usage.rs +++ b/worker/examples/plugin_usage.rs @@ -1,18 +1,10 @@ use std::collections::HashMap; use std::sync::{Arc, Mutex}; use worker::{ - PromptError, ResourceLoader, Role, Worker, + PromptContext, PromptError, Worker, plugin::{PluginRegistry, ProviderPlugin, example_provider::CustomProviderPlugin}, }; - -struct FsLoader; - -impl ResourceLoader for FsLoader { - fn load(&self, identifier: &str) -> Result { - std::fs::read_to_string(identifier) - .map_err(|e| PromptError::FileNotFound(format!("{}: {}", identifier, e))) - } -} +use worker_types::Message; #[tokio::main] async fn main() -> Result<(), Box> { @@ -58,18 +50,15 @@ async fn main() -> Result<(), Box> { } // Create a Worker instance using the plugin - let role = Role::new( - "assistant", - "A helpful AI assistant", - "You are a helpful, harmless, and honest AI assistant powered by a custom LLM provider.", - ); + fn plugin_prompt(_ctx: &PromptContext, _messages: &[Message]) -> Result { + Ok("You are a helpful assistant powered by a custom provider.".to_string()) + } let worker = Worker::builder() .plugin("custom-provider", plugin_registry.clone()) .model("custom-turbo") .api_key("__plugin__", "custom-1234567890abcdefghijklmnop") - .resource_loader(FsLoader) - .role(role) + .system_prompt(plugin_prompt) .build()?; println!("\nWorker created successfully with custom provider plugin!"); diff --git a/worker/src/builder.rs b/worker/src/builder.rs index afd5591..c312ca4 100644 --- a/worker/src/builder.rs +++ b/worker/src/builder.rs @@ -1,18 +1,18 @@ use crate::Worker; -use crate::prompt::{ResourceLoader, Role}; +use crate::prompt::{PromptComposer, PromptContext, PromptError, SystemPromptFn}; use crate::types::WorkerError; use std::collections::HashMap; use std::marker::PhantomData; use std::sync::{Arc, Mutex}; -use worker_types::LlmProvider; +use worker_types::{LlmProvider, Message}; // Type-state markers pub struct NoProvider; pub struct WithProvider; pub struct NoModel; pub struct WithModel; -pub struct NoRole; -pub struct WithRole; +pub struct NoSystemPrompt; +pub struct WithSystemPrompt; /// WorkerBuilder with type-state pattern /// @@ -20,51 +20,40 @@ pub struct WithRole; /// /// # Example /// ```no_run -/// use worker::{Worker, LlmProvider, Role, ResourceLoader, PromptError}; +/// use worker::{Worker, LlmProvider, PromptContext, PromptError}; /// -/// struct FsLoader; -/// -/// impl ResourceLoader for FsLoader { -/// fn load(&self, identifier: &str) -> Result { -/// std::fs::read_to_string(identifier) -/// .map_err(|e| PromptError::FileNotFound(format!("{}: {}", identifier, e))) -/// } +/// fn system_prompt( +/// _ctx: &PromptContext, +/// _messages: &[worker_types::Message], +/// ) -> Result { +/// Ok("You are a helpful assistant.".to_string()) /// } /// -/// let role = Role::new("assistant", "AI Assistant", "You are a helpful assistant."); /// let worker = Worker::builder() /// .provider(LlmProvider::Claude) /// .model("claude-3-sonnet-20240229") /// .api_key("claude", "sk-ant-...") -/// .resource_loader(FsLoader) -/// .role(role) +/// .system_prompt(system_prompt) /// .build()?; /// # Ok::<(), worker::WorkerError>(()) /// ``` -pub struct WorkerBuilder { +pub struct WorkerBuilder { provider: Option, model_name: Option, api_keys: HashMap, - - // Role configuration (required) - role: Option, - resource_loader: Option>, - - // Plugin configuration + system_prompt_fn: Option>, plugin_id: Option, plugin_registry: Option>>, - - _phantom: PhantomData<(P, M, R)>, + _phantom: PhantomData<(P, M, S)>, } -impl Default for WorkerBuilder { +impl Default for WorkerBuilder { fn default() -> Self { Self { provider: None, model_name: None, api_keys: HashMap::new(), - role: None, - resource_loader: None, + system_prompt_fn: None, plugin_id: None, plugin_registry: None, _phantom: PhantomData, @@ -72,23 +61,21 @@ impl Default for WorkerBuilder { } } -impl WorkerBuilder { - /// Create a new WorkerBuilder +impl WorkerBuilder { pub fn new() -> Self { Self::default() } } // Step 1: Set provider -impl WorkerBuilder { - pub fn provider(mut self, provider: LlmProvider) -> WorkerBuilder { +impl WorkerBuilder { + pub fn provider(mut self, provider: LlmProvider) -> WorkerBuilder { self.provider = Some(provider); WorkerBuilder { provider: self.provider, model_name: self.model_name, api_keys: self.api_keys, - role: self.role, - resource_loader: self.resource_loader, + system_prompt_fn: self.system_prompt_fn, plugin_id: self.plugin_id, plugin_registry: self.plugin_registry, _phantom: PhantomData, @@ -100,15 +87,14 @@ impl WorkerBuilder { mut self, plugin_id: impl Into, registry: Arc>, - ) -> WorkerBuilder { + ) -> WorkerBuilder { self.plugin_id = Some(plugin_id.into()); self.plugin_registry = Some(registry); WorkerBuilder { provider: None, model_name: self.model_name, api_keys: self.api_keys, - role: self.role, - resource_loader: self.resource_loader, + system_prompt_fn: self.system_prompt_fn, plugin_id: self.plugin_id, plugin_registry: self.plugin_registry, _phantom: PhantomData, @@ -117,18 +103,17 @@ impl WorkerBuilder { } // Step 2: Set model -impl WorkerBuilder { +impl WorkerBuilder { pub fn model( mut self, model_name: impl Into, - ) -> WorkerBuilder { + ) -> WorkerBuilder { self.model_name = Some(model_name.into()); WorkerBuilder { provider: self.provider, model_name: self.model_name, api_keys: self.api_keys, - role: self.role, - resource_loader: self.resource_loader, + system_prompt_fn: self.system_prompt_fn, plugin_id: self.plugin_id, plugin_registry: self.plugin_registry, _phantom: PhantomData, @@ -136,16 +121,21 @@ impl WorkerBuilder { } } -// Step 3: Set role -impl WorkerBuilder { - pub fn role(mut self, role: Role) -> WorkerBuilder { - self.role = Some(role); +// Step 3: Register system prompt generator +impl WorkerBuilder { + pub fn system_prompt( + mut self, + generator: F, + ) -> WorkerBuilder + where + F: Fn(&PromptContext, &[Message]) -> Result + Send + Sync + 'static, + { + self.system_prompt_fn = Some(Arc::new(generator)); WorkerBuilder { provider: self.provider, model_name: self.model_name, api_keys: self.api_keys, - role: self.role, - resource_loader: self.resource_loader, + system_prompt_fn: self.system_prompt_fn, plugin_id: self.plugin_id, plugin_registry: self.plugin_registry, _phantom: PhantomData, @@ -153,45 +143,33 @@ impl WorkerBuilder { } } -// Optional configurations (available at any stage) -impl WorkerBuilder { - /// Add API key for a provider +// Optional configurations +impl WorkerBuilder { pub fn api_key(mut self, provider: impl Into, key: impl Into) -> Self { self.api_keys.insert(provider.into(), key.into()); self } - /// Set multiple API keys at once pub fn api_keys(mut self, keys: HashMap) -> Self { self.api_keys = keys; self } - - /// Provide a resource loader implementation for partial/include resolution - pub fn resource_loader(mut self, loader: L) -> Self - where - L: ResourceLoader + 'static, - { - self.resource_loader = Some(Arc::new(loader)); - self - } } // Build -impl WorkerBuilder { +impl WorkerBuilder { pub fn build(self) -> Result { - use crate::{LlmProviderExt, PromptComposer, WorkspaceDetector, plugin}; + use crate::{LlmProviderExt, WorkspaceDetector, plugin}; - let resource_loader = self.resource_loader.clone().ok_or_else(|| { + let system_prompt_fn = self.system_prompt_fn.ok_or_else(|| { WorkerError::config( - "Resource loader is required. Call resource_loader(...) before build.", + "System prompt generator is required. Call system_prompt(...) before build.", ) })?; - let role = self.role.unwrap(); let model_name = self.model_name.unwrap(); - // Plugin provider + // Plugin-backed provider if let (Some(plugin_id), Some(plugin_registry)) = (self.plugin_id, self.plugin_registry) { let api_key_opt = self .api_keys @@ -215,7 +193,6 @@ impl WorkerBuilder { let provider_str = plugin_id.clone(); let api_key = api_key_opt.map(|s| s.to_string()).unwrap_or_default(); - let workspace_context = WorkspaceDetector::detect_workspace().ok(); let prompt_context = Worker::create_prompt_context_static( @@ -225,23 +202,15 @@ impl WorkerBuilder { &[], ); - tracing::info!("Creating worker with plugin and role: {}", role.name); - - let composer = - PromptComposer::from_config(role.clone(), prompt_context, resource_loader.clone()) - .map_err(|e| WorkerError::config(e.to_string()))?; - drop(registry); let mut worker = Worker { llm_client: Box::new(llm_client), - composer, - resource_loader: resource_loader.clone(), + composer: PromptComposer::new(prompt_context, system_prompt_fn.clone()), tools: Vec::new(), api_key, provider_str, model_name, - role, workspace_context, message_history: Vec::new(), hook_manager: worker_types::HookManager::new(), @@ -256,7 +225,7 @@ impl WorkerBuilder { return Ok(worker); } - // Standard provider + // Built-in provider let provider = self.provider.unwrap(); let provider_str = provider.as_str(); let api_key = self.api_keys.get(provider_str).cloned().unwrap_or_default(); @@ -272,21 +241,13 @@ impl WorkerBuilder { &[], ); - tracing::info!("Creating worker with role: {}", role.name); - - let composer = - PromptComposer::from_config(role.clone(), prompt_context, resource_loader.clone()) - .map_err(|e| WorkerError::config(e.to_string()))?; - let mut worker = Worker { llm_client: Box::new(llm_client), - composer, - resource_loader, + composer: PromptComposer::new(prompt_context, system_prompt_fn.clone()), tools: Vec::new(), api_key, provider_str: provider_str.to_string(), model_name, - role, workspace_context, message_history: Vec::new(), hook_manager: worker_types::HookManager::new(), diff --git a/worker/src/config/mod.rs b/worker/src/config/mod.rs index d5d3926..0510dd8 100644 --- a/worker/src/config/mod.rs +++ b/worker/src/config/mod.rs @@ -1,5 +1,3 @@ -mod parser; mod url; -pub use parser::ConfigParser; pub use url::UrlConfig; diff --git a/worker/src/config/parser.rs b/worker/src/config/parser.rs deleted file mode 100644 index eb36ace..0000000 --- a/worker/src/config/parser.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::prompt::{PromptError, Role}; -use std::fs; -use std::path::Path; - -/// 設定ファイルのパーサー -pub struct ConfigParser; - -impl ConfigParser { - /// YAML設定ファイルを読み込んでパースする - pub fn parse_from_file>(path: P) -> Result { - let content = fs::read_to_string(path.as_ref()).map_err(|e| { - PromptError::FileNotFound(format!("{}: {}", path.as_ref().display(), e)) - })?; - - Self::parse_from_string(&content) - } - - /// YAML文字列をパースしてRoleに変換する - pub fn parse_from_string(content: &str) -> Result { - let config: Role = serde_yaml::from_str(content)?; - - // 基本的なバリデーション - Self::validate_config(&config)?; - - Ok(config) - } - - /// 設定ファイルの基本的なバリデーション - fn validate_config(config: &Role) -> Result<(), PromptError> { - if config.name.is_empty() { - return Err(PromptError::VariableResolution( - "name field cannot be empty".to_string(), - )); - } - - if config.template.is_empty() { - return Err(PromptError::TemplateCompilation( - "template field cannot be empty".to_string(), - )); - } - - // パーシャルのパス検証 - if let Some(partials) = &config.partials { - for (name, partial) in partials { - if partial.path.is_empty() { - return Err(PromptError::PartialLoading(format!( - "partial '{}' has empty path", - name - ))); - } - } - } - - Ok(()) - } -} diff --git a/worker/src/lib.rs b/worker/src/lib.rs index b2d14fa..7bed10d 100644 --- a/worker/src/lib.rs +++ b/worker/src/lib.rs @@ -1,7 +1,4 @@ -use crate::prompt::{ - ModelCapabilities, ModelContext, PromptComposer, PromptContext, SessionContext, - WorkspaceContext, -}; +use crate::prompt::{ModelCapabilities, ModelContext, SessionContext, WorkspaceContext}; use crate::workspace::WorkspaceDetector; use async_stream::stream; use futures_util::{Stream, StreamExt}; @@ -33,17 +30,12 @@ pub mod prompt; pub mod types; pub mod workspace; -pub use crate::prompt::{PromptError, ResourceLoader, Role}; +pub use crate::prompt::{PromptComposer, PromptContext, PromptError, SystemPromptFn}; pub use crate::types::WorkerError; pub use builder::WorkerBuilder; pub use client::LlmClient; pub use core::LlmClientTrait; -#[cfg(test)] -mod tests { - mod config_tests; -} - pub use schemars; pub use serde_json; @@ -442,13 +434,11 @@ pub async fn supports_native_tools( pub struct Worker { pub(crate) llm_client: Box, - pub(crate) composer: PromptComposer, - pub(crate) resource_loader: std::sync::Arc, + pub(crate) composer: crate::prompt::PromptComposer, pub(crate) tools: Vec>, pub(crate) api_key: String, pub(crate) provider_str: String, pub(crate) model_name: String, - pub(crate) role: Role, pub(crate) workspace_context: Option, pub(crate) message_history: Vec, pub(crate) hook_manager: crate::types::HookManager, @@ -461,29 +451,22 @@ impl Worker { /// /// # Example /// ```no_run - /// use worker::{Worker, LlmProvider, Role, PromptError, ResourceLoader}; + /// use worker::{Worker, LlmProvider, PromptContext, PromptError}; /// - /// struct FsLoader; - /// - /// impl ResourceLoader for FsLoader { - /// fn load(&self, identifier: &str) -> Result { - /// std::fs::read_to_string(identifier) - /// .map_err(|e| PromptError::FileNotFound(format!("{}: {}", identifier, e))) - /// } + /// fn system_prompt(_ctx: &PromptContext, _messages: &[worker_types::Message]) -> Result { + /// Ok("You are a helpful assistant.".to_string()) /// } /// - /// let role = Role::new("assistant", "AI Assistant", "You are a helpful assistant."); /// let worker = Worker::builder() /// .provider(LlmProvider::Claude) /// .model("claude-3-sonnet-20240229") /// .api_key("claude", "sk-ant-...") - /// .resource_loader(FsLoader) - /// .role(role) + /// .system_prompt(system_prompt) /// .build()?; /// # Ok::<(), worker::WorkerError>(()) /// ``` pub fn builder() - -> builder::WorkerBuilder { + -> builder::WorkerBuilder { builder::WorkerBuilder::new() } @@ -784,43 +767,13 @@ impl Worker { ) } - /// 設定を読み込む - pub fn load_config>( - &mut self, - config_path: P, - ) -> Result<(), WorkerError> { - use crate::config::ConfigParser; - - // 設定ファイルを読み込み - let role = ConfigParser::parse_from_file(config_path) - .map_err(|e| WorkerError::config(e.to_string()))?; - - // プロンプトコンテキストを構築 - let prompt_context = self.create_prompt_context()?; - - // DynamicPromptComposerを作成 - let composer = - PromptComposer::from_config(role.clone(), prompt_context, self.resource_loader.clone()) - .map_err(|e| WorkerError::config(e.to_string()))?; - - self.role = role; - self.composer = composer; - - // 設定変更後にセッション再初期化 - self.initialize_session() - .map_err(|e| WorkerError::config(e.to_string()))?; - - tracing::info!("Dynamic configuration loaded successfully"); - Ok(()) - } - /// 静的プロンプトコンテキストを作成(構築時用) fn create_prompt_context_static( workspace_context: &Option, provider: LlmProvider, model_name: &str, tools: &[String], - ) -> PromptContext { + ) -> crate::prompt::PromptContext { let supports_native_tools = match provider { LlmProvider::Claude => true, LlmProvider::OpenAI => !model_name.contains("gpt-3.5-turbo-instruct"), @@ -853,7 +806,7 @@ impl Worker { let workspace_context = workspace_context.clone().unwrap_or_default(); - PromptContext { + crate::prompt::PromptContext { workspace: workspace_context, model: model_context, session: session_context, @@ -862,7 +815,7 @@ impl Worker { } /// プロンプトコンテキストを作成 - fn create_prompt_context(&self) -> Result { + fn create_prompt_context(&self) -> Result { let provider = LlmProvider::from_str(&self.provider_str).ok_or_else(|| { WorkerError::config(format!("Unknown provider: {}", self.provider_str)) })?; @@ -902,7 +855,7 @@ impl Worker { let workspace_context = self.workspace_context.clone().unwrap_or_default(); - Ok(PromptContext { + Ok(crate::prompt::PromptContext { workspace: workspace_context, model: model_context, session: session_context, @@ -999,13 +952,8 @@ impl Worker { } /// Get configuration information for task delegation - pub fn get_config(&self) -> (LlmProvider, &str, &str, &Role) { - ( - self.llm_client.provider(), - &self.model_name, - &self.api_key, - &self.role, - ) + pub fn get_config(&self) -> (LlmProvider, &str, &str) { + (self.llm_client.provider(), &self.model_name, &self.api_key) } /// Get tool names (used to filter out specific tools) diff --git a/worker/src/prompt/composer.rs b/worker/src/prompt/composer.rs index d4484ed..0d36f0d 100644 --- a/worker/src/prompt/composer.rs +++ b/worker/src/prompt/composer.rs @@ -1,342 +1,83 @@ -use super::types::*; -use handlebars::{Context, Handlebars, Helper, HelperDef, HelperResult, Output, RenderContext}; -use std::path::Path; +use super::types::{PromptContext, PromptError}; use std::sync::Arc; - -// Import Message and Role enum from worker_types use worker_types::{Message, Role as MessageRole}; -/// プロンプト構築システム +pub type SystemPromptFn = + dyn Fn(&PromptContext, &[Message]) -> Result + Send + Sync; + +/// シンプルなシステムプロンプト生成ラッパー #[derive(Clone)] pub struct PromptComposer { - config: Role, - handlebars: Handlebars<'static>, context: PromptContext, - system_prompt: Option, - resource_loader: Arc, + generator: Arc, + cached_prompt: Arc>>, } impl PromptComposer { - /// 設定ファイルから新しいインスタンスを作成 - pub fn from_config_file>( - config_path: P, - context: PromptContext, - resource_loader: Arc, - ) -> Result { - let config = crate::config::ConfigParser::parse_from_file(config_path)?; - Self::from_config(config, context, resource_loader) - } - - /// 設定オブジェクトから新しいインスタンスを作成 - pub fn from_config( - config: Role, - context: PromptContext, - resource_loader: Arc, - ) -> Result { - let mut handlebars = Handlebars::new(); - - // カスタムヘルパー関数を登録 - Self::register_custom_helpers(&mut handlebars, resource_loader.clone())?; - - let mut composer = Self { - config, - handlebars, + pub fn new(context: PromptContext, generator: Arc) -> Self { + Self { context, - system_prompt: None, - resource_loader, - }; - - // パーシャルテンプレートを読み込み・登録 - composer.load_partials()?; - - Ok(composer) - } - - /// セッション開始時にシステムプロンプトを事前構築 - pub fn initialize_session(&mut self, initial_messages: &[Message]) -> Result<(), PromptError> { - let system_prompt = self.compose_system_prompt(initial_messages)?; - self.system_prompt = Some(system_prompt); - Ok(()) - } - - /// メインのプロンプト構築メソッド - pub fn compose(&self, messages: &[Message]) -> Result, PromptError> { - if let Some(system_prompt) = &self.system_prompt { - // システムプロンプトが既に構築済みの場合、それを使用 - let mut result_messages = - vec![Message::new(MessageRole::System, system_prompt.clone())]; - - // ユーザーメッセージを追加 - for msg in messages { - if msg.role != MessageRole::System { - result_messages.push(msg.clone()); - } - } - - Ok(result_messages) - } else { - // フォールバック: 従来の動的構築 - self.compose_with_context(messages, &self.context) + generator, + cached_prompt: Arc::new(std::sync::Mutex::new(None)), } } - /// ツール情報を含むセッション初期化 - pub fn initialize_session_with_tools( - &mut self, - initial_messages: &[Message], - tools_schema: &serde_json::Value, - ) -> Result<(), PromptError> { - // 一時的にコンテキストをコピーしてツールスキーマを追加 - let mut temp_context = self.context.clone(); - temp_context - .variables - .insert("tools_schema".to_string(), tools_schema.clone()); - - let system_prompt = - self.compose_system_prompt_with_context(initial_messages, &temp_context)?; - self.system_prompt = Some(system_prompt); + /// 初期化時にシステムプロンプトを先行生成してキャッシュ + pub fn initialize_session(&mut self, initial_messages: &[Message]) -> Result<(), PromptError> { + let prompt = (self.generator)(&self.context, initial_messages)?; + if let Ok(mut guard) = self.cached_prompt.lock() { + *guard = Some(prompt); + } Ok(()) } - /// ツール情報を含むプロンプト構築(後方互換性のため保持) + pub fn compose(&self, messages: &[Message]) -> Result, PromptError> { + let system_prompt = self.generate_with_context(&self.context, messages)?; + Ok(self.build_message_list(messages, system_prompt)) + } + pub fn compose_with_tools( &self, messages: &[Message], tools_schema: &serde_json::Value, ) -> Result, PromptError> { - if let Some(system_prompt) = &self.system_prompt { - // システムプロンプトが既に構築済みの場合、それを使用 - let mut result_messages = - vec![Message::new(MessageRole::System, system_prompt.clone())]; + let mut context = self.context.clone(); + context + .variables + .insert("tools_schema".to_string(), tools_schema.clone()); + let system_prompt = self.generate_with_context(&context, messages)?; + Ok(self.build_message_list(messages, system_prompt)) + } - // ユーザーメッセージを追加 - for msg in messages { - if msg.role != MessageRole::System { - result_messages.push(msg.clone()); + fn generate_with_context( + &self, + context: &PromptContext, + messages: &[Message], + ) -> Result { + match (self.generator)(context, messages) { + Ok(prompt) => { + if let Ok(mut guard) = self.cached_prompt.lock() { + *guard = Some(prompt.clone()); } + Ok(prompt) } - - Ok(result_messages) - } else { - // フォールバック: 従来の動的構築 - let mut temp_context = self.context.clone(); - temp_context - .variables - .insert("tools_schema".to_string(), tools_schema.clone()); - - self.compose_with_context(messages, &temp_context) + Err(err) => match self.cached_prompt.lock() { + Ok(cache) => cache.as_ref().cloned().ok_or(err), + Err(_) => Err(err), + }, } } - /// システムプロンプトのみを構築(セッション初期化用) - fn compose_system_prompt(&self, messages: &[Message]) -> Result { - self.compose_system_prompt_with_context(messages, &self.context) - } + fn build_message_list(&self, messages: &[Message], system_prompt: String) -> Vec { + let mut result = Vec::with_capacity(messages.len() + 1); + result.push(Message::new(MessageRole::System, system_prompt)); - /// コンテキストを指定してシステムプロンプトを構築 - fn compose_system_prompt_with_context( - &self, - messages: &[Message], - context: &PromptContext, - ) -> Result { - // コンテキスト変数を準備 - let mut template_data = self.prepare_template_data_with_context(messages, context)?; - - // 条件評価と変数の動的設定 - self.apply_conditions(&mut template_data)?; - - // メインテンプレートを実行 - let system_prompt = self - .handlebars - .render_template(&self.config.template, &template_data) - .map_err(PromptError::Handlebars)?; - - Ok(system_prompt) - } - - /// コンテキストを指定してプロンプトを構築(後方互換性のため保持) - fn compose_with_context( - &self, - messages: &[Message], - context: &PromptContext, - ) -> Result, PromptError> { - let system_prompt = self.compose_system_prompt_with_context(messages, context)?; - - // システムメッセージとユーザーメッセージを結合 - let mut result_messages = vec![Message::new(MessageRole::System, system_prompt)]; - - // ユーザーメッセージを追加 for msg in messages { if msg.role != MessageRole::System { - result_messages.push(msg.clone()); + result.push(msg.clone()); } } - Ok(result_messages) - } - - /// カスタムヘルパー関数を登録 - fn register_custom_helpers( - handlebars: &mut Handlebars<'static>, - resource_loader: Arc, - ) -> Result<(), PromptError> { - handlebars.register_helper( - "include_file", - Box::new(IncludeFileHelper { - loader: resource_loader.clone(), - }), - ); - handlebars.register_helper("workspace_content", Box::new(workspace_content_helper)); - - Ok(()) - } - - /// パーシャルテンプレートを読み込み・登録 - fn load_partials(&mut self) -> Result<(), PromptError> { - if let Some(partials) = &self.config.partials { - for (name, partial_config) in partials { - let content = self.load_partial_content(partial_config)?; - self.handlebars - .register_partial(name, content) - .map_err(|e| PromptError::PartialLoading(e.to_string()))?; - } - } - Ok(()) - } - - /// パーシャルの内容を読み込み(フォールバック対応) - fn load_partial_content(&self, partial_config: &PartialConfig) -> Result { - match self.resource_loader.load(&partial_config.path) { - Ok(content) => Ok(content), - Err(primary_err) => { - if let Some(fallback) = &partial_config.fallback { - match self.resource_loader.load(fallback) { - Ok(content) => Ok(content), - Err(fallback_err) => Err(PromptError::PartialLoading(format!( - "Could not load partial '{}' (fallback: {:?}): primary error={}, fallback error={}", - partial_config.path, partial_config.fallback, primary_err, fallback_err - ))), - } - } else { - Err(primary_err) - } - } - } - } - - /// コンテキストを指定してテンプレート用のデータを準備 - fn prepare_template_data_with_context( - &self, - messages: &[Message], - context: &PromptContext, - ) -> Result { - let user_input = messages - .iter() - .filter(|m| m.role == MessageRole::User) - .map(|m| m.content.as_str()) - .collect::>() - .join("\n\n"); - - let mut data = serde_json::json!({ - "workspace": context.workspace, - "model": context.model, - "session": context.session, - "user_input": user_input, - "tools": context.variables.get("tools_schema").unwrap_or(&serde_json::Value::Null), - "tools_schema": context.variables.get("tools_schema").unwrap_or(&serde_json::Value::Null), - }); - - // 設定ファイルの変数を追加 - if let Some(variables) = &self.config.variables { - for (key, value_template) in variables { - // 変数値もHandlebarsテンプレートとして処理 - let resolved_value = self - .handlebars - .render_template(value_template, &data) - .map_err(PromptError::Handlebars)?; - data[key] = serde_json::Value::String(resolved_value); - } - } - - // コンテキストの追加変数をマージ - for (key, value) in &context.variables { - data[key] = value.clone(); - } - - Ok(data) - } - - /// 条件評価と動的変数設定 - fn apply_conditions(&self, data: &mut serde_json::Value) -> Result<(), PromptError> { - if let Some(conditions) = &self.config.conditions { - for (_condition_name, condition_config) in conditions { - // 条件式を評価 - let condition_result = self - .handlebars - .render_template(&condition_config.when, data) - .map_err(PromptError::Handlebars)?; - - // 条件が真の場合、変数を適用 - if condition_result.trim() == "true" { - if let Some(variables) = &condition_config.variables { - for (key, value_template) in variables { - let resolved_value = self - .handlebars - .render_template(value_template, data) - .map_err(PromptError::Handlebars)?; - data[key] = serde_json::Value::String(resolved_value); - } - } - } - } - } - Ok(()) + result } } - -// カスタムヘルパー関数の実装 - -struct IncludeFileHelper { - loader: Arc, -} - -impl HelperDef for IncludeFileHelper { - fn call<'reg: 'rc, 'rc>( - &self, - h: &Helper<'rc>, - _handlebars: &Handlebars<'reg>, - _context: &Context, - _rc: &mut RenderContext<'reg, 'rc>, - out: &mut dyn Output, - ) -> HelperResult { - let file_path = h.param(0).and_then(|v| v.value().as_str()).unwrap_or(""); - - match self.loader.load(file_path) { - Ok(content) => { - out.write(&content)?; - } - Err(_) => { - // ファイルが見つからない場合は空文字を出力 - out.write("")?; - } - } - Ok(()) - } -} - -fn workspace_content_helper( - _h: &Helper, - _hbs: &Handlebars, - ctx: &Context, - _rc: &mut RenderContext, - out: &mut dyn Output, -) -> HelperResult { - if let Some(workspace) = ctx.data().get("workspace") { - if let Some(content) = workspace.get("nia_md_content") { - if let Some(content_str) = content.as_str() { - out.write(content_str)?; - } - } - } - Ok(()) -} diff --git a/worker/src/prompt/mod.rs b/worker/src/prompt/mod.rs index 5d612cf..7d12a04 100644 --- a/worker/src/prompt/mod.rs +++ b/worker/src/prompt/mod.rs @@ -1,8 +1,8 @@ mod composer; mod types; -pub use composer::PromptComposer; +pub use composer::{PromptComposer, SystemPromptFn}; pub use types::{ - ConditionConfig, GitInfo, ModelCapabilities, ModelContext, PartialConfig, ProjectType, - PromptContext, PromptError, ResourceLoader, Role, SessionContext, SystemInfo, WorkspaceContext, + GitInfo, ModelCapabilities, ModelContext, ProjectType, PromptContext, PromptError, + SessionContext, SystemInfo, WorkspaceContext, }; diff --git a/worker/src/prompt/types.rs b/worker/src/prompt/types.rs index 6f8a820..598917c 100644 --- a/worker/src/prompt/types.rs +++ b/worker/src/prompt/types.rs @@ -2,37 +2,6 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::path::PathBuf; -/// Role configuration - defines the system instructions for the LLM -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Role { - pub name: String, - pub description: String, - pub version: Option, - pub template: String, - pub partials: Option>, - pub variables: Option>, - pub conditions: Option>, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct PartialConfig { - pub path: String, - pub fallback: Option, - pub description: Option, -} - -/// External resource loader used to resolve template includes/partials -pub trait ResourceLoader: Send + Sync { - fn load(&self, identifier: &str) -> Result; -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ConditionConfig { - pub when: String, - pub variables: Option>, - pub template_override: Option, -} - /// システム情報 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SystemInfo { @@ -116,35 +85,17 @@ pub struct PromptContext { pub variables: HashMap, } -/// プロンプト構築エラー +/// システムプロンプト生成時のエラー #[derive(Debug, thiserror::Error)] pub enum PromptError { - #[error("Template compilation error: {0}")] - TemplateCompilation(String), - - #[error("Variable resolution error: {0}")] - VariableResolution(String), - - #[error("Partial loading error: {0}")] - PartialLoading(String), - - #[error("File not found: {0}")] - FileNotFound(String), + #[error("System prompt generation error: {0}")] + Generation(String), #[error("Workspace detection error: {0}")] WorkspaceDetection(String), - #[error("Git information error: {0}")] - GitInfo(String), - - #[error("Handlebars error: {0}")] - Handlebars(#[from] handlebars::RenderError), - #[error("IO error: {0}")] Io(#[from] std::io::Error), - - #[error("YAML parsing error: {0}")] - YamlParsing(#[from] serde_yaml::Error), } impl SystemInfo { @@ -356,22 +307,3 @@ impl Default for SessionContext { } } } - -impl Role { - /// Create a new Role with name, description, and template - pub fn new( - name: impl Into, - description: impl Into, - template: impl Into, - ) -> Self { - Self { - name: name.into(), - description: description.into(), - version: Some("1.0.0".to_string()), - template: template.into(), - partials: None, - variables: None, - conditions: None, - } - } -} diff --git a/worker/src/tests/config_tests.rs b/worker/src/tests/config_tests.rs deleted file mode 100644 index 4c9eb31..0000000 --- a/worker/src/tests/config_tests.rs +++ /dev/null @@ -1,334 +0,0 @@ -use crate::config::ConfigParser; -use crate::prompt::{ - ModelCapabilities, ModelContext, PromptComposer, PromptContext, PromptError, ResourceLoader, - SessionContext, SystemInfo, WorkspaceContext, -}; -use crate::types::LlmProvider; -use std::collections::HashMap; -use std::io::Write; -use std::path::PathBuf; -use std::sync::Arc; -use tempfile::NamedTempFile; - -#[test] -fn test_parse_basic_config() { - let yaml_content = r##" -name: "Test Assistant" -description: "A test configuration" -version: "1.0" -template: | - # Test Role - {{>role_header}} - - {{#if workspace.has_nia_md}} - # Project Context - {{workspace.nia_md_content}} - {{/if}} - -partials: - role_header: - path: "#nia/prompts/headers/role.md" - description: "Basic role definition" - -variables: - max_context_length: "{{model.context_length}}" - project_name: "{{workspace.project_name}}" -"##; - - let config = - ConfigParser::parse_from_string(yaml_content).expect("Failed to parse basic config"); - - assert_eq!(config.name, "Test Assistant"); - assert_eq!(config.description, "A test configuration"); - assert_eq!(config.version, Some("1.0".to_string())); - assert!(!config.template.is_empty()); - - // パーシャルのテスト - let partials = config.partials.expect("Partials should be present"); - assert!(partials.contains_key("role_header")); - let role_header = &partials["role_header"]; - assert_eq!(role_header.path, "#nia/prompts/headers/role.md"); - assert_eq!( - role_header.description, - Some("Basic role definition".to_string()) - ); - - // 変数のテスト - let variables = config.variables.expect("Variables should be present"); - assert!(variables.contains_key("max_context_length")); - assert!(variables.contains_key("project_name")); -} - -#[test] -fn test_parse_minimal_config() { - let yaml_content = r##" -name: "Minimal Assistant" -description: "A minimal configuration" -template: "Hello {{user_input}}" -"##; - - let config = - ConfigParser::parse_from_string(yaml_content).expect("Failed to parse minimal config"); - - assert_eq!(config.name, "Minimal Assistant"); - assert_eq!(config.description, "A minimal configuration"); - assert_eq!(config.template, "Hello {{user_input}}"); - assert!(config.partials.is_none()); - assert!(config.variables.is_none()); - assert!(config.conditions.is_none()); -} - -#[test] -fn test_parse_with_conditions() { - let yaml_content = r##" -name: "Conditional Assistant" -description: "Configuration with conditions" -template: "Base template" - -conditions: - native_tools_enabled: - when: "{{model.supports_native_tools}}" - variables: - tool_format: "native" - include_tool_schemas: false - - xml_tools_enabled: - when: "{{not model.supports_native_tools}}" - variables: - tool_format: "xml" - include_tool_schemas: true -"##; - - let config = ConfigParser::parse_from_string(yaml_content) - .expect("Failed to parse config with conditions"); - - let conditions = config.conditions.expect("Conditions should be present"); - assert!(conditions.contains_key("native_tools_enabled")); - assert!(conditions.contains_key("xml_tools_enabled")); - - let native_condition = &conditions["native_tools_enabled"]; - assert_eq!(native_condition.when, "{{model.supports_native_tools}}"); - - let variables = native_condition - .variables - .as_ref() - .expect("Variables should be present"); - assert_eq!(variables.get("tool_format"), Some(&"native".to_string())); - assert_eq!( - variables.get("include_tool_schemas"), - Some(&"false".to_string()) - ); -} - -#[test] -fn test_validation_errors() { - // 空の名前 - let invalid_yaml = r##" -name: "" -description: "Test" -template: "Test template" -"##; - let result = ConfigParser::parse_from_string(invalid_yaml); - assert!(result.is_err()); - - // 空のテンプレート - let invalid_yaml = r##" -name: "Test" -description: "Test" -template: "" -"##; - let result = ConfigParser::parse_from_string(invalid_yaml); - assert!(result.is_err()); - - // 空のパーシャルパス - let invalid_yaml = r##" -name: "Test" -description: "Test" -template: "Test template" -partials: - empty_path: - path: "" -"##; - let result = ConfigParser::parse_from_string(invalid_yaml); - assert!(result.is_err()); -} - -#[test] -fn test_parse_from_file() { - let yaml_content = r##" -name: "File Test Assistant" -description: "Testing file parsing" -template: "File content {{user_input}}" -"##; - - let mut temp_file = NamedTempFile::new().expect("Failed to create temp file"); - temp_file - .write_all(yaml_content.as_bytes()) - .expect("Failed to write to temp file"); - - let config = - ConfigParser::parse_from_file(temp_file.path()).expect("Failed to parse config from file"); - - assert_eq!(config.name, "File Test Assistant"); - assert_eq!(config.description, "Testing file parsing"); - assert_eq!(config.template, "File content {{user_input}}"); -} - -struct InMemoryLoader { - data: HashMap, -} - -impl InMemoryLoader { - fn new(data: HashMap) -> Self { - Self { data } - } -} - -impl ResourceLoader for InMemoryLoader { - fn load(&self, identifier: &str) -> Result { - self.data - .get(identifier) - .cloned() - .ok_or_else(|| PromptError::FileNotFound(format!("not found: {}", identifier))) - } -} - -fn build_prompt_context() -> PromptContext { - let workspace = WorkspaceContext { - root_path: PathBuf::from("."), - nia_md_content: None, - project_type: None, - git_info: None, - has_nia_md: false, - project_name: None, - system_info: SystemInfo::collect(), - }; - - let capabilities = ModelCapabilities { - supports_tools: false, - supports_function_calling: false, - supports_vision: false, - supports_multimodal: None, - context_length: None, - capabilities: vec![], - needs_verification: None, - }; - - let model_context = ModelContext { - provider: LlmProvider::Claude, - model_name: "test-model".to_string(), - capabilities, - supports_native_tools: false, - }; - - let session_context = SessionContext { - conversation_id: None, - message_count: 0, - active_tools: vec![], - user_preferences: None, - }; - - PromptContext { - workspace, - model: model_context, - session: session_context, - variables: HashMap::new(), - } -} - -#[test] -fn test_prompt_composer_uses_resource_loader() { - let yaml_content = r##" -name: "Loader Test" -description: "Ensure resource loader is used" -template: | - {{>header}} - {{include_file "include.md"}} - -partials: - header: - path: "missing.md" - fallback: "fallback.md" -"##; - - let role = - ConfigParser::parse_from_string(yaml_content).expect("Failed to parse loader test config"); - - let loader = Arc::new(InMemoryLoader::new(HashMap::from([ - ("fallback.md".to_string(), "Fallback Partial".to_string()), - ("include.md".to_string(), "Included Content".to_string()), - ]))); - - let prompt_context = build_prompt_context(); - - let composer = PromptComposer::from_config(role, prompt_context, loader) - .expect("Composer should use provided loader"); - - let messages = composer - .compose(&[]) - .expect("Composer should build system prompt"); - - assert!(!messages.is_empty()); - let system_message = &messages[0]; - assert!(system_message.content.contains("Fallback Partial")); - assert!(system_message.content.contains("Included Content")); -} - -#[test] -fn test_complex_template_syntax() { - let yaml_content = r##" -name: "Complex Template Assistant" -description: "Testing complex Handlebars syntax" -template: | - # Dynamic Role - {{>role_header}} - - {{#if workspace.has_nia_md}} - # Project: {{workspace.project_name}} - {{workspace.nia_md_content}} - {{/if}} - - {{#if_native_tools model.supports_native_tools}} - Native tools are supported. - {{else}} - Using XML-based tool calls. - Available tools: - ```json - {{tools_schema}} - ``` - {{/if_native_tools}} - - {{#model_specific model.provider}} - {{#case "Claude"}} - Claude-specific instructions here. - {{/case}} - {{#case "Gemini"}} - Gemini-specific instructions here. - {{/case}} - {{#default}} - Generic model instructions. - {{/default}} - {{/model_specific}} - -partials: - role_header: - path: "#nia/prompts/headers/role.md" -"##; - - let config = - ConfigParser::parse_from_string(yaml_content).expect("Failed to parse complex template"); - - assert!(!config.template.is_empty()); - assert!(config.template.contains("{{>role_header}}")); - assert!(config.template.contains("{{#if workspace.has_nia_md}}")); - assert!( - config - .template - .contains("{{#if_native_tools model.supports_native_tools}}") - ); - assert!( - config - .template - .contains("{{#model_specific model.provider}}") - ); -} diff --git a/worker/src/tests/integration_tests.rs b/worker/src/tests/integration_tests.rs deleted file mode 100644 index a0e2798..0000000 --- a/worker/src/tests/integration_tests.rs +++ /dev/null @@ -1,333 +0,0 @@ -use crate::types::{LlmProvider, Message, Role}; -use crate::workspace_detector::WorkspaceDetector; -use std::collections::HashMap; -use std::fs; -use tempfile::TempDir; - -#[test] -#[ignore] // Temporarily disabled due to missing dependencies -fn test_full_dynamic_prompt_composition() { - // テスト用の一時ディレクトリを作成 - let temp_dir = TempDir::new().expect("Failed to create temp dir"); - let temp_path = temp_dir.path(); - - // テスト用のNIA.mdファイルを作成 - let nia_md_content = r#"# Test Project - -This is a test project for dynamic prompt composition. - -## Features -- Dynamic prompt generation -- Workspace detection -- Model-specific optimizations -"#; - fs::write(temp_path.join("NIA.md"), nia_md_content).expect("Failed to write NIA.md"); - - // テスト用のCargoファイルを作成(Rustプロジェクトとして認識させる) - let cargo_toml = r#"[package] -name = "test-project" -version = "0.1.0" -edition = "2021" -"#; - fs::write(temp_path.join("Cargo.toml"), cargo_toml).expect("Failed to write Cargo.toml"); - - // ワークスペースコンテキストを取得 - let workspace = WorkspaceDetector::detect_workspace_from_path(temp_path) - .expect("Failed to detect workspace"); - - assert!(workspace.has_nia_md); - assert_eq!(workspace.project_type, Some(ProjectType::Rust)); - assert!(workspace.nia_md_content.is_some()); - assert_eq!(workspace.project_name, Some("test-project".to_string())); - - // モデルコンテキストを作成 - let model_context = ModelContext { - provider: LlmProvider::Claude, - model_name: "claude-3-sonnet".to_string(), - capabilities: ModelCapabilities { - supports_tools: true, - supports_function_calling: true, - ..Default::default() - }, - supports_native_tools: true, - }; - - // セッションコンテキストを作成 - let session_context = SessionContext { - conversation_id: Some("test-conv".to_string()), - message_count: 1, - active_tools: vec!["file_read".to_string(), "file_write".to_string()], - user_preferences: None, - }; - - // 全体的なプロンプトコンテキストを作成 - let prompt_context = PromptContext { - workspace, - model: model_context, - session: session_context, - variables: HashMap::new(), - }; - - // 動的設定を作成 - let config = create_test_dynamic_config(); - - // DynamicPromptComposerを作成 - let mut composer = DynamicPromptComposer::from_config(config, prompt_context) - .expect("Failed to create composer"); - - // テストメッセージ - let messages = vec![Message { - role: Role::User, - content: "Please help me understand the project structure".to_string(), - }]; - - // プロンプトを構築 - let result = composer - .compose(&messages) - .expect("Failed to compose prompt"); - - assert!(!result.is_empty()); - assert_eq!(result[0].role, Role::System); - - // 生成されたプロンプトにワークスペース情報が含まれていることを確認 - let system_prompt = &result[0].content; - assert!(system_prompt.contains("Test Project")); - assert!(system_prompt.contains("dynamic prompt generation")); - assert!(system_prompt.contains("test-project")); -} - -#[test] -#[ignore] // Temporarily disabled due to missing dependencies -fn test_native_tools_vs_xml_tools() { - let temp_dir = TempDir::new().expect("Failed to create temp dir"); - let workspace = WorkspaceDetector::detect_workspace_from_path(temp_dir.path()) - .expect("Failed to detect workspace"); - - // ネイティブツールサポートありのモデル - let native_model = ModelContext { - provider: LlmProvider::Claude, - model_name: "claude-3-sonnet".to_string(), - capabilities: ModelCapabilities { - supports_tools: true, - supports_function_calling: true, - ..Default::default() - }, - supports_native_tools: true, - }; - - // XMLツールのみのモデル - let xml_model = ModelContext { - provider: LlmProvider::Ollama, - model_name: "llama3".to_string(), - capabilities: ModelCapabilities { - supports_tools: false, - supports_function_calling: false, - ..Default::default() - }, - supports_native_tools: false, - }; - - let session = SessionContext::default(); - - // 両方のモデルでプロンプトを生成 - let native_context = PromptContext { - workspace: workspace.clone(), - model: native_model, - session: session.clone(), - variables: HashMap::new(), - }; - - let xml_context = PromptContext { - workspace: workspace.clone(), - model: xml_model, - session: session.clone(), - variables: HashMap::new(), - }; - - let config = create_test_dynamic_config(); - - let mut native_composer = DynamicPromptComposer::from_config(config.clone(), native_context) - .expect("Failed to create native composer"); - - let mut xml_composer = DynamicPromptComposer::from_config(config, xml_context) - .expect("Failed to create xml composer"); - - let messages = vec![Message { - role: Role::User, - content: "Test message".to_string(), - }]; - - let native_result = native_composer - .compose(&messages) - .expect("Failed to compose native prompt"); - - let xml_result = xml_composer - .compose(&messages) - .expect("Failed to compose xml prompt"); - - // 両方のプロンプトが生成されることを確認 - assert!(!native_result.is_empty()); - assert!(!xml_result.is_empty()); - - // ネイティブツール用プロンプトとXMLツール用プロンプトが異なることを確認 - assert_ne!(native_result[0].content, xml_result[0].content); -} - -#[test] -#[ignore] // Temporarily disabled due to missing dependencies -fn test_workspace_detection_without_nia_md() { - let temp_dir = TempDir::new().expect("Failed to create temp dir"); - - // .nia ディレクトリのみ作成(NIA.mdなし) - fs::create_dir(temp_dir.path().join(".nia")).expect("Failed to create .nia dir"); - - let workspace = WorkspaceDetector::detect_workspace_from_path(temp_dir.path()) - .expect("Failed to detect workspace"); - - assert!(!workspace.has_nia_md); - assert!(workspace.nia_md_content.is_none()); - assert_eq!(workspace.project_type, Some(ProjectType::Unknown)); -} - -#[test] -#[ignore] // Temporarily disabled due to missing dependencies -fn test_project_type_detection() { - let temp_dir = TempDir::new().expect("Failed to create temp dir"); - let temp_path = temp_dir.path(); - - // TypeScriptプロジェクト - fs::write(temp_path.join("package.json"), r#"{"name": "test"}"#) - .expect("Failed to write package.json"); - fs::write(temp_path.join("tsconfig.json"), "{}").expect("Failed to write tsconfig.json"); - - let workspace = WorkspaceDetector::detect_workspace_from_path(temp_path) - .expect("Failed to detect workspace"); - - assert_eq!(workspace.project_type, Some(ProjectType::TypeScript)); -} - -#[test] -#[ignore] // Temporarily disabled due to missing dependencies -fn test_tools_schema_integration() { - let temp_dir = TempDir::new().expect("Failed to create temp dir"); - let workspace = WorkspaceDetector::detect_workspace_from_path(temp_dir.path()) - .expect("Failed to detect workspace"); - - let model_context = ModelContext { - provider: LlmProvider::Gemini, - model_name: "gemini-1.5-flash".to_string(), - capabilities: ModelCapabilities { - supports_tools: false, - supports_function_calling: false, - ..Default::default() - }, - supports_native_tools: false, - }; - - let session_context = SessionContext::default(); - let prompt_context = PromptContext { - workspace, - model: model_context, - session: session_context, - variables: HashMap::new(), - }; - - let config = create_test_dynamic_config(); - let mut composer = DynamicPromptComposer::from_config(config, prompt_context) - .expect("Failed to create composer"); - - // ツールスキーマを作成 - let tools_schema = serde_json::json!([ - { - "name": "file_read", - "description": "Read a file", - "parameters": { - "type": "object", - "properties": { - "path": {"type": "string"} - } - } - } - ]); - - let messages = vec![Message { - role: Role::User, - content: "Read a file for me".to_string(), - }]; - - // ツール情報付きでプロンプトを構築 - let result = composer - .compose_with_tools(&messages, &tools_schema) - .expect("Failed to compose with tools"); - - assert!(!result.is_empty()); - - // XMLツールモデルなので、ツール情報がプロンプトに含まれるはず - let system_prompt = &result[0].content; - assert!(system_prompt.contains("file_read")); -} - -// テスト用の動的設定を作成 -fn create_test_dynamic_config() -> DynamicRoleConfig { - let mut variables = HashMap::new(); - variables.insert( - "project_name".to_string(), - "{{workspace.project_name}}".to_string(), - ); - variables.insert("model_name".to_string(), "{{model.model_name}}".to_string()); - - let mut conditions = HashMap::new(); - - // ネイティブツール条件 - let mut native_vars = HashMap::new(); - native_vars.insert("tool_format".to_string(), "native".to_string()); - conditions.insert( - "native_tools".to_string(), - ConditionConfig { - when: "{{model.supports_native_tools}}".to_string(), - variables: Some(native_vars), - template_override: None, - }, - ); - - // XMLツール条件 - let mut xml_vars = HashMap::new(); - xml_vars.insert("tool_format".to_string(), "xml".to_string()); - conditions.insert( - "xml_tools".to_string(), - ConditionConfig { - when: "{{not model.supports_native_tools}}".to_string(), - variables: Some(xml_vars), - template_override: None, - }, - ); - - DynamicRoleConfig { - name: "Test Assistant".to_string(), - description: "A test configuration".to_string(), - version: Some("1.0".to_string()), - template: r#"# Test Role - -{{#if workspace.has_nia_md}} -# Project Context -Project: {{workspace.project_name}} -{{workspace.nia_md_content}} -{{/if}} - -{{#if model.supports_native_tools}} -Native tools are supported for {{model.model_name}}. -{{else}} -Using XML-based tool calls for {{model.model_name}}. -{{#if tools_schema}} -Available tools: {{tools_schema}} -{{/if}} -{{/if}} - -User request: {{user_input}} -"# - .to_string(), - partials: None, // パーシャルを使わない - variables: Some(variables), - conditions: Some(conditions), - } -}