diff --git a/THIRD_PARTY_LICENSES.md b/THIRD_PARTY_LICENSES.md index 8230ef8b80..f56c4be357 100644 --- a/THIRD_PARTY_LICENSES.md +++ b/THIRD_PARTY_LICENSES.md @@ -1099,7 +1099,7 @@ MIT License The following npm package may be included in this product: - - genaiscript-vscode@1.54.4 + - genaiscript-vscode@1.54.5 This package contains the following license and notice below: @@ -1844,7 +1844,7 @@ Apache License The following npm package may be included in this product: - - typescript@5.5.4 + - typescript@5.6.2 This package contains the following license and notice below: @@ -4188,9 +4188,9 @@ The following npm packages may be included in this product: - @tokenizer/token@0.3.0 - agent-base@6.0.2 - canvas@2.11.2 - - genaiscript-core-internal@1.54.4 - - genaiscript-sample@1.54.4 - - genaiscript@1.54.4 + - genaiscript-core-internal@1.54.5 + - genaiscript-sample@1.54.5 + - genaiscript@1.54.5 - https-proxy-agent@5.0.1 - isarray@1.0.0 - javascript-natural-sort@0.7.1 @@ -4962,7 +4962,7 @@ SOFTWARE. The following npm package may be included in this product: - - tsx@4.19.0 + - tsx@4.19.1 This package contains the following license and notice below: @@ -4992,7 +4992,7 @@ SOFTWARE. The following npm packages may be included in this product: - - get-tsconfig@4.8.0 + - get-tsconfig@4.8.1 - resolve-pkg-maps@1.0.0 These packages each contain the following license and notice below: @@ -6412,7 +6412,7 @@ SOFTWARE. The following npm packages may be included in this product: - end-of-stream@1.4.4 - - pump@3.0.0 + - pump@3.0.2 - tar-fs@2.0.1 - tar-stream@2.2.0 @@ -7314,7 +7314,7 @@ For more information, please refer to The following npm package may be included in this product: - - tree-sitter-wasms@0.1.11 + - tree-sitter-wasms@0.1.12 This package contains the following license and notice below: diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index e5cf104f11..535b44f32e 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -2108,6 +2108,8 @@ interface BrowseResponse { url(): string } +interface BrowserJSHandle {} + /** * A playwright Page instance * @link https://playwright.dev/docs/api/class-page @@ -2160,6 +2162,25 @@ interface BrowserPage extends BrowserLocatorSelector { * Closes the browser page, context and other resources */ close(): Promise + + /** + * Returns the value of the pageFunction evaluation. + * @param fn + * @param args serializable object + * @link https://playwright.dev/docs/api/class-page#page-evaluate + */ + evaluate(pageFunction: Function | string, arg?: any): Promise + + /** + * Returns the value of the pageFunction evaluation as a JSHandle. + * @param fn + * @param args serializable object + * @link https://playwright.dev/docs/api/class-page#page-evaluate-handle + */ + evaluateHandle( + selector: string, + arg?: any + ): Promise } interface ShellSelectOptions {} diff --git a/docs/package.json b/docs/package.json index 737db719d7..88d1480e27 100644 --- a/docs/package.json +++ b/docs/package.json @@ -22,7 +22,7 @@ "@astrojs/check": "^0.9.3", "@astrojs/starlight": "^0.27.0", "astro": "^4.15.4", - "typescript": "5.5.4" + "typescript": "5.6.2" }, "devDependencies": { "starlight-blog": "^0.12.0", diff --git a/docs/yarn.lock b/docs/yarn.lock index 360ea063db..d0f2f4cbf1 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -800,97 +800,124 @@ estree-walker "^2.0.2" picomatch "^2.3.1" -"@rollup/rollup-android-arm-eabi@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.21.2.tgz#0412834dc423d1ff7be4cb1fc13a86a0cd262c11" - integrity sha512-fSuPrt0ZO8uXeS+xP3b+yYTCBUd05MoSp2N/MFOgjhhUhMmchXlpTQrTpI8T+YAwAQuK7MafsCOxW7VrPMrJcg== - -"@rollup/rollup-android-arm64@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.21.2.tgz#baf1a014b13654f3b9e835388df9caf8c35389cb" - integrity sha512-xGU5ZQmPlsjQS6tzTTGwMsnKUtu0WVbl0hYpTPauvbRAnmIvpInhJtgjj3mcuJpEiuUw4v1s4BimkdfDWlh7gA== - -"@rollup/rollup-darwin-arm64@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.21.2.tgz#0a2c364e775acdf1172fe3327662eec7c46e55b1" - integrity sha512-99AhQ3/ZMxU7jw34Sq8brzXqWH/bMnf7ZVhvLk9QU2cOepbQSVTns6qoErJmSiAvU3InRqC2RRZ5ovh1KN0d0Q== - -"@rollup/rollup-darwin-x64@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.21.2.tgz#a972db75890dfab8df0da228c28993220a468c42" - integrity sha512-ZbRaUvw2iN/y37x6dY50D8m2BnDbBjlnMPotDi/qITMJ4sIxNY33HArjikDyakhSv0+ybdUxhWxE6kTI4oX26w== - -"@rollup/rollup-linux-arm-gnueabihf@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.21.2.tgz#1609d0630ef61109dd19a278353e5176d92e30a1" - integrity sha512-ztRJJMiE8nnU1YFcdbd9BcH6bGWG1z+jP+IPW2oDUAPxPjo9dverIOyXz76m6IPA6udEL12reYeLojzW2cYL7w== - -"@rollup/rollup-linux-arm-musleabihf@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.21.2.tgz#3c1dca5f160aa2e79e4b20ff6395eab21804f266" - integrity sha512-flOcGHDZajGKYpLV0JNc0VFH361M7rnV1ee+NTeC/BQQ1/0pllYcFmxpagltANYt8FYf9+kL6RSk80Ziwyhr7w== - -"@rollup/rollup-linux-arm64-gnu@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.21.2.tgz#c2fe376e8b04eafb52a286668a8df7c761470ac7" - integrity sha512-69CF19Kp3TdMopyteO/LJbWufOzqqXzkrv4L2sP8kfMaAQ6iwky7NoXTp7bD6/irKgknDKM0P9E/1l5XxVQAhw== - -"@rollup/rollup-linux-arm64-musl@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.21.2.tgz#e62a4235f01e0f66dbba587c087ca6db8008ec80" - integrity sha512-48pD/fJkTiHAZTnZwR0VzHrao70/4MlzJrq0ZsILjLW/Ab/1XlVUStYyGt7tdyIiVSlGZbnliqmult/QGA2O2w== - -"@rollup/rollup-linux-powerpc64le-gnu@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.21.2.tgz#24b3457e75ee9ae5b1c198bd39eea53222a74e54" - integrity sha512-cZdyuInj0ofc7mAQpKcPR2a2iu4YM4FQfuUzCVA2u4HI95lCwzjoPtdWjdpDKyHxI0UO82bLDoOaLfpZ/wviyQ== - -"@rollup/rollup-linux-riscv64-gnu@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.21.2.tgz#38edfba9620fe2ca8116c97e02bd9f2d606bde09" - integrity sha512-RL56JMT6NwQ0lXIQmMIWr1SW28z4E4pOhRRNqwWZeXpRlykRIlEpSWdsgNWJbYBEWD84eocjSGDu/XxbYeCmwg== - -"@rollup/rollup-linux-s390x-gnu@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.21.2.tgz#a3bfb8bc5f1e802f8c76cff4a4be2e9f9ac36a18" - integrity sha512-PMxkrWS9z38bCr3rWvDFVGD6sFeZJw4iQlhrup7ReGmfn7Oukrr/zweLhYX6v2/8J6Cep9IEA/SmjXjCmSbrMQ== - -"@rollup/rollup-linux-x64-gnu@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.21.2.tgz#0dadf34be9199fcdda44b5985a086326344f30ad" - integrity sha512-B90tYAUoLhU22olrafY3JQCFLnT3NglazdwkHyxNDYF/zAxJt5fJUB/yBoWFoIQ7SQj+KLe3iL4BhOMa9fzgpw== - -"@rollup/rollup-linux-x64-musl@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.21.2.tgz#7b7deddce240400eb87f2406a445061b4fed99a8" - integrity sha512-7twFizNXudESmC9oneLGIUmoHiiLppz/Xs5uJQ4ShvE6234K0VB1/aJYU3f/4g7PhssLGKBVCC37uRkkOi8wjg== - -"@rollup/rollup-win32-arm64-msvc@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.21.2.tgz#a0ca0c5149c2cfb26fab32e6ba3f16996fbdb504" - integrity sha512-9rRero0E7qTeYf6+rFh3AErTNU1VCQg2mn7CQcI44vNUWM9Ze7MSRS/9RFuSsox+vstRt97+x3sOhEey024FRQ== - -"@rollup/rollup-win32-ia32-msvc@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.21.2.tgz#aae2886beec3024203dbb5569db3a137bc385f8e" - integrity sha512-5rA4vjlqgrpbFVVHX3qkrCo/fZTj1q0Xxpg+Z7yIo3J2AilW7t2+n6Q8Jrx+4MrYpAnjttTYF8rr7bP46BPzRw== - -"@rollup/rollup-win32-x64-msvc@4.21.2": - version "4.21.2" - resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.21.2.tgz#e4291e3c1bc637083f87936c333cdbcad22af63b" - integrity sha512-6UUxd0+SKomjdzuAcp+HAmxw1FlGBnl1v2yEPSabtx4lBfdXHDVsW7+lQkgz9cNFJGY3AWR7+V8P5BqkD9L9nA== - -"@shikijs/core@1.16.3": - version "1.16.3" - resolved "https://registry.yarnpkg.com/@shikijs/core/-/core-1.16.3.tgz#082b53928bf201a8d7cfbe0b5540dc1c609d0a5e" - integrity sha512-yETIvrETCeC39gSPIiSADmjri9FwKmxz0QvONMtTIUYlKZe90CJkvcjPksayC2VQOtzOJonEiULUa8v8crUQvA== - dependencies: - "@shikijs/vscode-textmate" "^9.2.0" +"@rollup/rollup-android-arm-eabi@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.21.3.tgz#155c7d82c1b36c3ad84d9adf9b3cd520cba81a0f" + integrity sha512-MmKSfaB9GX+zXl6E8z4koOr/xU63AMVleLEa64v7R0QF/ZloMs5vcD1sHgM64GXXS1csaJutG+ddtzcueI/BLg== + +"@rollup/rollup-android-arm64@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.21.3.tgz#b94b6fa002bd94a9cbd8f9e47e23b25e5bd113ba" + integrity sha512-zrt8ecH07PE3sB4jPOggweBjJMzI1JG5xI2DIsUbkA+7K+Gkjys6eV7i9pOenNSDJH3eOr/jLb/PzqtmdwDq5g== + +"@rollup/rollup-darwin-arm64@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.21.3.tgz#0934126cf9cbeadfe0eb7471ab5d1517e8cd8dcc" + integrity sha512-P0UxIOrKNBFTQaXTxOH4RxuEBVCgEA5UTNV6Yz7z9QHnUJ7eLX9reOd/NYMO3+XZO2cco19mXTxDMXxit4R/eQ== + +"@rollup/rollup-darwin-x64@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.21.3.tgz#0ce8e1e0f349778938c7c90e4bdc730640e0a13e" + integrity sha512-L1M0vKGO5ASKntqtsFEjTq/fD91vAqnzeaF6sfNAy55aD+Hi2pBI5DKwCO+UNDQHWsDViJLqshxOahXyLSh3EA== + +"@rollup/rollup-linux-arm-gnueabihf@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.21.3.tgz#5669d34775ad5d71e4f29ade99d0ff4df523afb6" + integrity sha512-btVgIsCjuYFKUjopPoWiDqmoUXQDiW2A4C3Mtmp5vACm7/GnyuprqIDPNczeyR5W8rTXEbkmrJux7cJmD99D2g== + +"@rollup/rollup-linux-arm-musleabihf@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.21.3.tgz#f6d1a0e1da4061370cb2f4244fbdd727c806dd88" + integrity sha512-zmjbSphplZlau6ZTkxd3+NMtE4UKVy7U4aVFMmHcgO5CUbw17ZP6QCgyxhzGaU/wFFdTfiojjbLG3/0p9HhAqA== + +"@rollup/rollup-linux-arm64-gnu@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.21.3.tgz#ed96a05e99743dee4d23cc4913fc6e01a0089c88" + integrity sha512-nSZfcZtAnQPRZmUkUQwZq2OjQciR6tEoJaZVFvLHsj0MF6QhNMg0fQ6mUOsiCUpTqxTx0/O6gX0V/nYc7LrgPw== + +"@rollup/rollup-linux-arm64-musl@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.21.3.tgz#057ea26eaa7e537a06ded617d23d57eab3cecb58" + integrity sha512-MnvSPGO8KJXIMGlQDYfvYS3IosFN2rKsvxRpPO2l2cum+Z3exiExLwVU+GExL96pn8IP+GdH8Tz70EpBhO0sIQ== + +"@rollup/rollup-linux-powerpc64le-gnu@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.21.3.tgz#6e6e1f9404c9bf3fbd7d51cd11cd288a9a2843aa" + integrity sha512-+W+p/9QNDr2vE2AXU0qIy0qQE75E8RTwTwgqS2G5CRQ11vzq0tbnfBd6brWhS9bCRjAjepJe2fvvkvS3dno+iw== + +"@rollup/rollup-linux-riscv64-gnu@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.21.3.tgz#eef1536a53f6e6658a2a778130e6b1a4a41cb439" + integrity sha512-yXH6K6KfqGXaxHrtr+Uoy+JpNlUlI46BKVyonGiaD74ravdnF9BUNC+vV+SIuB96hUMGShhKV693rF9QDfO6nQ== + +"@rollup/rollup-linux-s390x-gnu@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.21.3.tgz#2b28fb89ca084efaf8086f435025d96b4a966957" + integrity sha512-R8cwY9wcnApN/KDYWTH4gV/ypvy9yZUHlbJvfaiXSB48JO3KpwSpjOGqO4jnGkLDSk1hgjYkTbTt6Q7uvPf8eg== + +"@rollup/rollup-linux-x64-gnu@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.21.3.tgz#5226cde6c6b495b04a3392c1d2c572844e42f06b" + integrity sha512-kZPbX/NOPh0vhS5sI+dR8L1bU2cSO9FgxwM8r7wHzGydzfSjLRCFAT87GR5U9scj2rhzN3JPYVC7NoBbl4FZ0g== + +"@rollup/rollup-linux-x64-musl@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.21.3.tgz#2c2412982e6c2a00a2ecac6d548ebb02f0aa6ca4" + integrity sha512-S0Yq+xA1VEH66uiMNhijsWAafffydd2X5b77eLHfRmfLsRSpbiAWiRHV6DEpz6aOToPsgid7TI9rGd6zB1rhbg== + +"@rollup/rollup-win32-arm64-msvc@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.21.3.tgz#fbb6ef5379199e2ec0103ef32877b0985c773a55" + integrity sha512-9isNzeL34yquCPyerog+IMCNxKR8XYmGd0tHSV+OVx0TmE0aJOo9uw4fZfUuk2qxobP5sug6vNdZR6u7Mw7Q+Q== + +"@rollup/rollup-win32-ia32-msvc@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.21.3.tgz#d50e2082e147e24d87fe34abbf6246525ec3845a" + integrity sha512-nMIdKnfZfzn1Vsk+RuOvl43ONTZXoAPUUxgcU0tXooqg4YrAqzfKzVenqqk2g5efWh46/D28cKFrOzDSW28gTA== + +"@rollup/rollup-win32-x64-msvc@4.21.3": + version "4.21.3" + resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.21.3.tgz#4115233aa1bd5a2060214f96d8511f6247093212" + integrity sha512-fOvu7PCQjAj4eWDEuD8Xz5gpzFqXzGlxHZozHP4b9Jxv9APtdxL6STqztDzMLuRXEc4UpXGGhx029Xgm91QBeA== + +"@shikijs/core@1.17.0": + version "1.17.0" + resolved "https://registry.yarnpkg.com/@shikijs/core/-/core-1.17.0.tgz#a5b1c2a381b7293841e0bd0e89fe1f27ae8be28e" + integrity sha512-Mkk4Mp4bNnW1kytU8I7S5PK5teNSe0iKlfqxPss4sdwnlcU8a2N62Z3te2gVmZfU9t1HF6L3wyWuM43IvEeEsg== + dependencies: + "@shikijs/engine-javascript" "1.17.0" + "@shikijs/engine-oniguruma" "1.17.0" + "@shikijs/types" "1.17.0" + "@shikijs/vscode-textmate" "^9.2.2" "@types/hast" "^3.0.4" + hast-util-to-html "^9.0.2" + +"@shikijs/engine-javascript@1.17.0": + version "1.17.0" + resolved "https://registry.yarnpkg.com/@shikijs/engine-javascript/-/engine-javascript-1.17.0.tgz#ad178da7336472a335b398eb3c42f4b1abbe994d" + integrity sha512-EiBVlxmzJZdC2ypzn8k+vxLngbBNgHLS4RilwrFOABGRc72kUZubbD/6Chrq2RcVtD3yq1GtiiIdFMGd9BTX3Q== + dependencies: + "@shikijs/types" "1.17.0" oniguruma-to-js "0.3.3" regex "4.3.2" -"@shikijs/vscode-textmate@^9.2.0": +"@shikijs/engine-oniguruma@1.17.0": + version "1.17.0" + resolved "https://registry.yarnpkg.com/@shikijs/engine-oniguruma/-/engine-oniguruma-1.17.0.tgz#30285fc388b0d3750949edc2a75eedf5cfb2db0d" + integrity sha512-nsXzJGLQ0fhKmA4Gwt1cF7vC8VuZ1HSDrTRuj48h/qDeX/TzmOlTDXQ3uPtyuhyg/2rbZRzNhN8UFU4fSnQfXg== + dependencies: + "@shikijs/types" "1.17.0" + "@shikijs/vscode-textmate" "^9.2.2" + +"@shikijs/types@1.17.0": + version "1.17.0" + resolved "https://registry.yarnpkg.com/@shikijs/types/-/types-1.17.0.tgz#19381192fac5700dec4be4b9c5a56f881c0338fe" + integrity sha512-Tvu2pA69lbpXB+MmgIaROP1tio8y0uYvKb5Foh3q0TJBTAJuaoa5eDEtS/0LquyveacsiVrYF4uEZILju+7Ybg== + dependencies: + "@shikijs/vscode-textmate" "^9.2.2" + "@types/hast" "^3.0.4" + +"@shikijs/vscode-textmate@^9.2.2": version "9.2.2" resolved "https://registry.yarnpkg.com/@shikijs/vscode-textmate/-/vscode-textmate-9.2.2.tgz#24571f50625c7cd075f9efe0def8b9d2c0930ada" integrity sha512-TMp15K+GGYrWlZM8+Lnj9EaHEFmOen0WJBrfa17hF7taDOYthuPPV0GWzfd/9iMij0akS/8Yw2ikquH7uVi/fg== @@ -1378,9 +1405,9 @@ camelcase@^7.0.1: integrity sha512-xlx1yCK2Oc1APsPXDL2LdlNP6+uu8OCDdhOBSVT279M/S+y75O30C2VuD8T2ogdePBBl7PfPF4504tnLgX3zfw== caniuse-lite@^1.0.30001646: - version "1.0.30001659" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001659.tgz#f370c311ffbc19c4965d8ec0064a3625c8aaa7af" - integrity sha512-Qxxyfv3RdHAfJcXelgf0hU4DFUVXBGTjqrBUZLUh8AtlGnsDo+CnncYtTd95+ZKfnANUOzxyIQCuU/UeBZBYoA== + version "1.0.30001660" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001660.tgz#31218de3463fabb44d0b7607b652e56edf2e2355" + integrity sha512-GacvNTTuATm26qC74pt+ad1fW15mlQ/zuTzzY1ZoIzECTP8HURDfF43kNxPgf7H1jmelCBQTTbBNxdSXOA7Bqg== ccount@^2.0.0: version "2.0.1" @@ -1616,9 +1643,9 @@ eastasianwidth@^0.2.0: integrity sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA== electron-to-chromium@^1.5.4: - version "1.5.18" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.18.tgz#5fe62b9d21efbcfa26571066502d94f3ed97e495" - integrity sha512-1OfuVACu+zKlmjsNdcJuVQuVE61sZOLbNM4JAQ1Rvh6EOj0/EUKhMJjRH73InPlXSh8HIJk1cVZ8pyOV/FMdUQ== + version "1.5.20" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.20.tgz#2914e42cfc5cc992cbee5538b500ddaf7c2c7091" + integrity sha512-74mdl6Fs1HHzK9SUX4CKFxAtAe3nUns48y79TskHNAG6fGOlLfyKA4j855x+0b5u8rWJIrlaG9tcTPstMlwjIw== emmet@^2.4.3: version "2.4.7" @@ -2168,10 +2195,10 @@ inline-style-parser@0.1.1: resolved "https://registry.yarnpkg.com/inline-style-parser/-/inline-style-parser-0.1.1.tgz#ec8a3b429274e9c0a1f1c4ffa9453a7fef72cea1" integrity sha512-7NXolsK4CAS5+xvdj5OMMbI962hU/wvwoxk+LWR9Ek9bVtyuuYScDN6eS0rUm6TxApFpw7CX1o4uJzcd4AyD3Q== -inline-style-parser@0.2.3: - version "0.2.3" - resolved "https://registry.yarnpkg.com/inline-style-parser/-/inline-style-parser-0.2.3.tgz#e35c5fb45f3a83ed7849fe487336eb7efa25971c" - integrity sha512-qlD8YNDqyTKTyuITrDOffsl6Tdhv+UC4hcdAVuQsK4IMQ99nSgd1MIA/Q+jQYoh9r3hVUXhYh7urSRmXPkW04g== +inline-style-parser@0.2.4: + version "0.2.4" + resolved "https://registry.yarnpkg.com/inline-style-parser/-/inline-style-parser-0.2.4.tgz#f4af5fe72e612839fcd453d989a586566d695f22" + integrity sha512-0aO8FkhNZlj/ZIbNi7Lxxr12obT7cL1moPfE4tg1LkX7LlLfC6DeX4l2ZEud1ukP9jNQyNnfzQVqwbwmAATY4Q== is-alphabetical@^2.0.0: version "2.0.1" @@ -3219,9 +3246,9 @@ path-exists@^4.0.0: integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== path-to-regexp@^6.2.2: - version "6.2.2" - resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.2.2.tgz#324377a83e5049cbecadc5554d6a63a9a4866b36" - integrity sha512-GQX3SSMokngb36+whdpRXE+3f9V8UzyAorlYvOGx87ufGHehNTn5lCxrKtLyZ4Yl/wEKnNnr98ZzOwwDZV5ogw== + version "6.3.0" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.3.0.tgz#2b6a26a337737a8e1416f9272ed0766b1c0389f4" + integrity sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ== periscopic@^3.0.0: version "3.1.0" @@ -3537,28 +3564,28 @@ reusify@^1.0.4: integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== rollup@^4.20.0: - version "4.21.2" - resolved "https://registry.yarnpkg.com/rollup/-/rollup-4.21.2.tgz#f41f277a448d6264e923dd1ea179f0a926aaf9b7" - integrity sha512-e3TapAgYf9xjdLvKQCkQTnbTKd4a6jwlpQSJJFokHGaX2IVjoEqkIIhiQfqsi0cdwlOD+tQGuOd5AJkc5RngBw== + version "4.21.3" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-4.21.3.tgz#c64ba119e6aeb913798a6f7eef2780a0df5a0821" + integrity sha512-7sqRtBNnEbcBtMeRVc6VRsJMmpI+JU1z9VTvW8D4gXIYQFz0aLcsE6rRkyghZkLfEgUZgVvOG7A5CVz/VW5GIA== dependencies: "@types/estree" "1.0.5" optionalDependencies: - "@rollup/rollup-android-arm-eabi" "4.21.2" - "@rollup/rollup-android-arm64" "4.21.2" - "@rollup/rollup-darwin-arm64" "4.21.2" - "@rollup/rollup-darwin-x64" "4.21.2" - "@rollup/rollup-linux-arm-gnueabihf" "4.21.2" - "@rollup/rollup-linux-arm-musleabihf" "4.21.2" - "@rollup/rollup-linux-arm64-gnu" "4.21.2" - "@rollup/rollup-linux-arm64-musl" "4.21.2" - "@rollup/rollup-linux-powerpc64le-gnu" "4.21.2" - "@rollup/rollup-linux-riscv64-gnu" "4.21.2" - "@rollup/rollup-linux-s390x-gnu" "4.21.2" - "@rollup/rollup-linux-x64-gnu" "4.21.2" - "@rollup/rollup-linux-x64-musl" "4.21.2" - "@rollup/rollup-win32-arm64-msvc" "4.21.2" - "@rollup/rollup-win32-ia32-msvc" "4.21.2" - "@rollup/rollup-win32-x64-msvc" "4.21.2" + "@rollup/rollup-android-arm-eabi" "4.21.3" + "@rollup/rollup-android-arm64" "4.21.3" + "@rollup/rollup-darwin-arm64" "4.21.3" + "@rollup/rollup-darwin-x64" "4.21.3" + "@rollup/rollup-linux-arm-gnueabihf" "4.21.3" + "@rollup/rollup-linux-arm-musleabihf" "4.21.3" + "@rollup/rollup-linux-arm64-gnu" "4.21.3" + "@rollup/rollup-linux-arm64-musl" "4.21.3" + "@rollup/rollup-linux-powerpc64le-gnu" "4.21.3" + "@rollup/rollup-linux-riscv64-gnu" "4.21.3" + "@rollup/rollup-linux-s390x-gnu" "4.21.3" + "@rollup/rollup-linux-x64-gnu" "4.21.3" + "@rollup/rollup-linux-x64-musl" "4.21.3" + "@rollup/rollup-win32-arm64-msvc" "4.21.3" + "@rollup/rollup-win32-ia32-msvc" "4.21.3" + "@rollup/rollup-win32-x64-msvc" "4.21.3" fsevents "~2.3.2" run-parallel@^1.1.9: @@ -3621,12 +3648,13 @@ sharp@^0.33.3: "@img/sharp-win32-x64" "0.33.5" shiki@^1.1.7, shiki@^1.10.3, shiki@^1.16.1: - version "1.16.3" - resolved "https://registry.yarnpkg.com/shiki/-/shiki-1.16.3.tgz#d78b0c644c2a46b25ec638a9a58861999bd3495c" - integrity sha512-GypUE+fEd06FqDs63LSAVlmq7WsahhPQU62cgZxGF+TJT5LjD2k7HTxXj4/CKOVuMM3+wWQ1t4Y5oooeJFRRBQ== + version "1.17.0" + resolved "https://registry.yarnpkg.com/shiki/-/shiki-1.17.0.tgz#5f3230f244d3024b9d1ae17c7a76f3b69be5c73d" + integrity sha512-VZf8cPShRwfzPcaswv81+YP7qJEoFwRT+Ehy6bizim7M0zG9bk8Egug550C+xS9g7rKIOPhzAlp2uEyuCxbk/A== dependencies: - "@shikijs/core" "1.16.3" - "@shikijs/vscode-textmate" "^9.2.0" + "@shikijs/core" "1.17.0" + "@shikijs/types" "1.17.0" + "@shikijs/vscode-textmate" "^9.2.2" "@types/hast" "^3.0.4" signal-exit@^4.1.0: @@ -3775,11 +3803,11 @@ style-to-object@^0.4.0: inline-style-parser "0.1.1" style-to-object@^1.0.0: - version "1.0.7" - resolved "https://registry.yarnpkg.com/style-to-object/-/style-to-object-1.0.7.tgz#8604fb6018ac3db83e97207a4f85f579068f661c" - integrity sha512-uSjr59G5u6fbxUfKbb8GcqMGT3Xs9v5IbPkjb0S16GyOeBLAzSRK0CixBv5YrYvzO6TDLzIS6QCn78tkqWngPw== + version "1.0.8" + resolved "https://registry.yarnpkg.com/style-to-object/-/style-to-object-1.0.8.tgz#67a29bca47eaa587db18118d68f9d95955e81292" + integrity sha512-xT47I/Eo0rwJmaXC4oilDGDWLohVhR6o/xAQcPQN8q6QBuZVL8qMYL85kLmST5cPjAorwvqIA4qXTRQoYHaL6g== dependencies: - inline-style-parser "0.2.3" + inline-style-parser "0.2.4" supports-color@^5.3.0: version "5.5.0" @@ -3842,10 +3870,10 @@ typescript-auto-import-cache@^0.3.3: dependencies: semver "^7.3.8" -typescript@5.5.4: - version "5.5.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba" - integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q== +typescript@5.6.2: + version "5.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0" + integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw== ultrahtml@1.5.3, ultrahtml@^1.5.3: version "1.5.3" @@ -3984,9 +4012,9 @@ vfile@^6.0.0, vfile@^6.0.2, vfile@^6.0.3: vfile-message "^4.0.0" vite@^5.4.2: - version "5.4.3" - resolved "https://registry.yarnpkg.com/vite/-/vite-5.4.3.tgz#771c470e808cb6732f204e1ee96c2ed65b97a0eb" - integrity sha512-IH+nl64eq9lJjFqU+/yrRnrHPVTlgy42/+IzbOdaFDVlyLgI/wDlf+FCobXLX1cT0X5+7LMyH1mIy2xJdLfo8Q== + version "5.4.4" + resolved "https://registry.yarnpkg.com/vite/-/vite-5.4.4.tgz#3da90314b617047366459443320ea78f39111008" + integrity sha512-RHFCkULitycHVTtelJ6jQLd+KSAAzOgEYorV32R2q++M6COBjKJR6BxqClwp5sf0XaBDjVMuJ9wnNfyAJwjMkA== dependencies: esbuild "^0.21.3" postcss "^8.4.43" @@ -4271,9 +4299,9 @@ yocto-queue@^1.1.1: integrity sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g== zod-to-json-schema@^3.23.2: - version "3.23.2" - resolved "https://registry.yarnpkg.com/zod-to-json-schema/-/zod-to-json-schema-3.23.2.tgz#bc7e379c8050462538383e382964c03d8fe008f9" - integrity sha512-uSt90Gzc/tUfyNqxnjlfBs8W6WSGpNBv0rVsNxP/BVSMHMKGdthPYff4xtCHYloJGM0CFxFsb3NbC0eqPhfImw== + version "3.23.3" + resolved "https://registry.yarnpkg.com/zod-to-json-schema/-/zod-to-json-schema-3.23.3.tgz#56cf4e0bd5c4096ab46e63159e20998ec7b19c39" + integrity sha512-TYWChTxKQbRJp5ST22o/Irt9KC5nj7CdBKYB/AosCRdj/wxEMvv4NNaj9XVUHDOIp53ZxArGhnw5HMZziPFjog== zod-to-ts@^1.2.0: version "1.2.0" @@ -4291,9 +4319,9 @@ zwitch@^2.0.0, zwitch@^2.0.4: integrity sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A== zx@^8.1.5: - version "8.1.5" - resolved "https://registry.yarnpkg.com/zx/-/zx-8.1.5.tgz#c51de2f9be06b85fe89dd688e6ba2664dd3e1204" - integrity sha512-gvmiYPvDDEz2Gcc37x7pJkipTKcFIE18q9QlSI1p5qoPDtoSn3jmGuWD0eEb7HuxEH5aDD7N/RVgH8BqSxbKzA== + version "8.1.6" + resolved "https://registry.yarnpkg.com/zx/-/zx-8.1.6.tgz#e0f1c7a38a55729541c22fbab233d0cd60d3a3f4" + integrity sha512-SYAriWG+i2CFqMOJcF8QayI8wprlMYQsrmP6tFD7rSPnDLcImNSW7n/8crOYvNVrB2EFgz8LAQk23U1+Y7WrKA== optionalDependencies: "@types/fs-extra" ">=11" "@types/node" ">=20" diff --git a/genaisrc/docs-sample-generator.genai.mts b/genaisrc/docs-sample-generator.genai.mts index 7b890c751e..ba32622c61 100644 --- a/genaisrc/docs-sample-generator.genai.mts +++ b/genaisrc/docs-sample-generator.genai.mts @@ -1,7 +1,7 @@ script({ model: "openai:gpt-4", title: "generating tests from samples", - system: ["system"], + system: ["system", "system.files"], parameters: { api: { type: "string", @@ -15,8 +15,9 @@ const api = env.vars.api + "" console.log(`generating sample for ${api}`) const scripts = ( - await workspace.findFiles("packages/*/src/**/*genai.{js,mjs}") + await workspace.findFiles("packages/**/*genai.{js,mjs}", { readText: true }) ).filter((f) => f.content?.includes(api)) +if (!scripts.length) cancel("No samples found") const samples = await retrieval.vectorSearch(api, scripts) console.debug(samples) @@ -27,7 +28,7 @@ const docsSamples = await retrieval.vectorSearch(api, docs, { topK: 3 }) console.debug(docsSamples) const sn = def("SAMPLES", samples, { maxTokens: 10000 }) -const dc = def("DOCS", docsSamples, { maxTokens: 10000 }) +const dc = def("DOCS", docsSamples, { maxTokens: 10000, ignoreEmpty: true }) $` You are an expert at writing GenAIScript programs. @@ -46,4 +47,7 @@ using the information found in ${sn} and ${dc}. - Do not use any external services - The example should have less than 5 lines of code - Use pseudo code if necessary +- use descriptive file names +- The script runs in node.js ` +defFileOutput("packages/auto/*.genai.mts", "Generated genaiscript programs") \ No newline at end of file diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index e5cf104f11..535b44f32e 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -2108,6 +2108,8 @@ interface BrowseResponse { url(): string } +interface BrowserJSHandle {} + /** * A playwright Page instance * @link https://playwright.dev/docs/api/class-page @@ -2160,6 +2162,25 @@ interface BrowserPage extends BrowserLocatorSelector { * Closes the browser page, context and other resources */ close(): Promise + + /** + * Returns the value of the pageFunction evaluation. + * @param fn + * @param args serializable object + * @link https://playwright.dev/docs/api/class-page#page-evaluate + */ + evaluate(pageFunction: Function | string, arg?: any): Promise + + /** + * Returns the value of the pageFunction evaluation as a JSHandle. + * @param fn + * @param args serializable object + * @link https://playwright.dev/docs/api/class-page#page-evaluate-handle + */ + evaluateHandle( + selector: string, + arg?: any + ): Promise } interface ShellSelectOptions {} diff --git a/packages/auto/.gitattributes b/packages/auto/.gitattributes new file mode 100644 index 0000000000..b89350c92b --- /dev/null +++ b/packages/auto/.gitattributes @@ -0,0 +1 @@ +genaiscript.d.ts -diff merge=ours linguist-generated \ No newline at end of file diff --git a/packages/auto/capture_screenshot.genai.mts b/packages/auto/capture_screenshot.genai.mts new file mode 100644 index 0000000000..428270bf86 --- /dev/null +++ b/packages/auto/capture_screenshot.genai.mts @@ -0,0 +1,6 @@ +// Launch a browser instance and navigate to a specified URL +const page = await host.browse('https://example.com'); +// Take a screenshot of the current page view +const screenshot = await page.screenshot(); +// Register the screenshot for subsequent analysis +defImages(screenshot); diff --git a/packages/auto/genaiscript.d.ts b/packages/auto/genaiscript.d.ts new file mode 100644 index 0000000000..535b44f32e --- /dev/null +++ b/packages/auto/genaiscript.d.ts @@ -0,0 +1,2603 @@ +type OptionsOrString = (string & {}) | TOptions + +type ElementOrArray = T | T[] + +interface PromptGenerationConsole { + log(...data: any[]): void + warn(...data: any[]): void + debug(...data: any[]): void + error(...data: any[]): void +} + +type DiagnosticSeverity = "error" | "warning" | "info" + +interface Diagnostic { + filename: string + range: CharRange + severity: DiagnosticSeverity + message: string + /** + * error or warning code + */ + code?: string +} + +type Awaitable = T | PromiseLike + +interface SerializedError { + name?: string + message?: string + stack?: string + cause?: unknown + code?: string + line?: number + column?: number +} + +interface PromptDefinition { + /** + * Based on file name. + */ + id: string + + /** + * Something like "Summarize children", show in UI. + */ + title?: string + + /** + * Longer description of the prompt. Shows in UI grayed-out. + */ + description?: string +} + +interface PromptLike extends PromptDefinition { + /** + * File where the prompt comes from (if any). + */ + filename?: string + + /** + * The text of the prompt JS source code. + */ + jsSource: string + + /** + * The actual text of the prompt template. + * Only used for system prompts. + */ + text?: string +} + +type SystemPromptId = OptionsOrString< + | "system" + | "system.annotations" + | "system.changelog" + | "system.diagrams" + | "system.diff" + | "system.explanations" + | "system.files" + | "system.files_schema" + | "system.fs_find_files" + | "system.fs_read_file" + | "system.math" + | "system.md_frontmatter" + | "system.python" + | "system.python_code_interpreter" + | "system.retrieval_fuzz_search" + | "system.retrieval_vector_search" + | "system.retrieval_web_search" + | "system.schema" + | "system.tasks" + | "system.technical" + | "system.tools" + | "system.typescript" + | "system.zero_shot_cot" +> + +type SystemToolId = OptionsOrString< + | "fs_find_files" + | "fs_read_file" + | "math_eval" + | "md_read_frontmatter" + | "python_code_interpreter" + | "retrieval_fuzz_search" + | "retrieval_vector_search" + | "retrieval_web_search" +> + +type FileMergeHandler = ( + filename: string, + label: string, + before: string, + generated: string +) => Awaitable + +interface PromptOutputProcessorResult { + /** + * Updated text + */ + text?: string + /** + * Generated files from the output + */ + files?: Record + + /** + * User defined errors + */ + annotations?: Diagnostic[] +} + +type PromptOutputProcessorHandler = ( + output: GenerationOutput +) => + | PromptOutputProcessorResult + | Promise + | undefined + | Promise + | void + | Promise + +type PromptTemplateResponseType = "json_object" | "json_schema" | undefined + +interface ModelConnectionOptions { + /** + * Which LLM model to use. + * + * @default gpt-4 + * @example gpt-4 + */ + model?: + | "openai:gpt-4" + | "openai:gpt-4-turbo" + | "openai:gpt-4o" + | "openai:gpt-4o-mini" + | "openai:gpt-3.5-turbo" + | "ollama:phi3" + | "ollama:llama3" + | "ollama:mixtral" + | string +} + +interface ModelOptions extends ModelConnectionOptions { + /** + * Temperature to use. Higher temperature means more hallucination/creativity. + * Range 0.0-2.0. + * + * @default 0.2 + */ + temperature?: number + + /** + * Specifies the type of output. Default is plain text. + * - `json_object` enables JSON mode + * - `json_schema` enables structured outputs + * Use `responseSchema` to specify an output schema. + */ + responseType?: PromptTemplateResponseType + + /** + * JSON object schema for the output. Enables the `JSON` output mode by default. + */ + responseSchema?: PromptParametersSchema | JSONSchemaObject + + /** + * “Top_p” or nucleus sampling is a setting that decides how many possible words to consider. + * A high “top_p” value means the model looks at more possible words, even the less likely ones, + * which makes the generated text more diverse. + */ + topP?: number + + /** + * When to stop producing output. + * + */ + maxTokens?: number + + /** + * Maximum number of tool calls to make. + */ + maxToolCalls?: number + + /** + * Maximum number of data repairs to attempt. + */ + maxDataRepairs?: number + + /** + * A deterministic integer seed to use for the model. + */ + seed?: number + + /** + * By default, LLM queries are not cached. If true, the LLM request will be cached. Use a string to override the default cache name + */ + cache?: boolean | string + + /** + * Custom cache name. If not set, the default cache is used. + * @deprecated Use `cache` instead with a string + */ + cacheName?: string + + /** + * Budget of tokens to apply the prompt flex renderer. + */ + flexTokens?: number +} + +interface EmbeddingsModelConnectionOptions { + /** + * LLM model to use for embeddings. + */ + embeddingsModel?: OptionsOrString< + "openai:text-embedding-3-small", + "openai:text-embedding-3-large", + "openai:text-embedding-ada-002", + "github:text-embedding-3-small", + "github:text-embedding-3-large", + "ollama:nomic-embed-text" + > +} + +interface EmbeddingsModelOptions extends EmbeddingsModelConnectionOptions {} + +interface PromptSystemOptions { + /** + * List of system script ids used by the prompt. + */ + system?: SystemPromptId | SystemPromptId[] + + /** + * List of tools used by the prompt. + */ + tools?: SystemToolId | SystemToolId[] +} + +interface ScriptRuntimeOptions { + /** + * Secrets required by the prompt + */ + secrets?: string[] + + /** + * Default value for emitting line numbers in fenced code blocks. + */ + lineNumbers?: boolean +} + +type PromptParameterType = + | string + | number + | boolean + | object + | JSONSchemaNumber + | JSONSchemaString + | JSONSchemaBoolean +type PromptParametersSchema = Record< + string, + PromptParameterType | PromptParameterType[] +> +type PromptParameters = Record + +type PromptAssertion = { + // How heavily to weigh the assertion. Defaults to 1.0 + weight?: number + /** + * The transformation to apply to the output before checking the assertion. + */ + transform?: string +} & ( + | { + // type of assertion + type: + | "icontains" + | "not-icontains" + | "equals" + | "not-equals" + | "starts-with" + | "not-starts-with" + // The expected value + value: string + } + | { + // type of assertion + type: + | "contains-all" + | "not-contains-all" + | "contains-any" + | "not-contains-any" + | "icontains-all" + | "not-icontains-all" + // The expected values + value: string[] + } + | { + // type of assertion + type: "levenshtein" | "not-levenshtein" + // The expected value + value: string + // The threshold value + threshold?: number + } + | { + type: "javascript" + /** + * JavaScript expression to evaluate. + */ + value: string + /** + * Optional threshold if the javascript expression returns a number + */ + threshold?: number + } +) + +interface PromptTest { + /** + * Short name of the test + */ + name?: string + /** + * Description of the test. + */ + description?: string + /** + * List of files to apply the test to. + */ + files?: string | string[] + /** + * Extra set of variables for this scenario + */ + vars?: Record + /** + * LLM output matches a given rubric, using a Language Model to grade output. + */ + rubrics?: string | string[] + /** + * LLM output adheres to the given facts, using Factuality method from OpenAI evaluation. + */ + facts?: string | string[] + /** + * List of keywords that should be contained in the LLM output. + */ + keywords?: string | string[] + /** + * List of keywords that should not be contained in the LLM output. + */ + forbidden?: string | string[] + /** + * Additional deterministic assertions. + */ + asserts?: PromptAssertion | PromptAssertion[] +} + +interface PromptScript + extends PromptLike, + ModelOptions, + PromptSystemOptions, + EmbeddingsModelOptions, + ScriptRuntimeOptions { + /** + * Groups template in UI + */ + group?: string + + /** + * Additional template parameters that will populate `env.vars` + */ + parameters?: PromptParametersSchema + + /** + * A file path or list of file paths or globs. + * The content of these files will be by the files selected in the UI by the user or the cli arguments. + */ + files?: string | string[] + + /** + * Extra variable values that can be used to configure system prompts. + */ + vars?: Record + + /** + * Tests to validate this script. + */ + tests?: PromptTest | PromptTest[] + + /** + * Don't show it to the user in lists. Template `system.*` are automatically unlisted. + */ + unlisted?: boolean + + /** + * Set if this is a system prompt. + */ + isSystem?: boolean +} + +/** + * Represent a file linked from a `.gpsec.md` document. + */ +interface WorkspaceFile { + /** + * Name of the file, relative to project root. + */ + filename: string + + /** + * Content of the file. + */ + content?: string +} + +interface WorkspaceFileWithScore extends WorkspaceFile { + /** + * Score allocated by search algorithm + */ + score?: number +} + +interface ToolDefinition { + /** + * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain + * underscores and dashes, with a maximum length of 64. + */ + name: string + + /** + * A description of what the function does, used by the model to choose when and + * how to call the function. + */ + description?: string + + /** + * The parameters the functions accepts, described as a JSON Schema object. See the + * [guide](https://platform.openai.com/docs/guides/text-generation/function-calling) + * for examples, and the + * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for + * documentation about the format. + * + * Omitting `parameters` defines a function with an empty parameter list. + */ + parameters?: JSONSchema +} + +interface ToolCallTrace { + log(message: string): void + item(message: string): void + tip(message: string): void + fence(message: string, contentType?: string): void +} + +/** + * Position (line, character) in a file. Both are 0-based. + */ +type CharPosition = [number, number] + +/** + * Describes a run of text. + */ +type CharRange = [CharPosition, CharPosition] + +/** + * 0-based line numbers. + */ +type LineRange = [number, number] + +interface FileEdit { + type: string + filename: string + label?: string + validated?: boolean +} + +interface ReplaceEdit extends FileEdit { + type: "replace" + range: CharRange | LineRange + text: string +} + +interface InsertEdit extends FileEdit { + type: "insert" + pos: CharPosition | number + text: string +} + +interface DeleteEdit extends FileEdit { + type: "delete" + range: CharRange | LineRange +} + +interface CreateFileEdit extends FileEdit { + type: "createfile" + overwrite?: boolean + ignoreIfExists?: boolean + text: string +} + +type Edits = InsertEdit | ReplaceEdit | DeleteEdit | CreateFileEdit + +interface ToolCallContent { + type?: "content" + content: string + edits?: Edits[] +} + +type ToolCallOutput = + | string + | number + | boolean + | ToolCallContent + | ShellOutput + | WorkspaceFile + | RunPromptResult + | undefined + +interface WorkspaceFileCache { + /** + * Gets the value associated with the key, or undefined if there is none. + * @param key + */ + get(key: K): Promise + /** + * Sets the value associated with the key. + * @param key + * @param value + */ + set(key: K, value: V): Promise + + /** + * List of keys + */ + keys(): Promise + + /** + * List the values in the cache. + */ + values(): Promise +} + +interface WorkspaceFileSystem { + /** + * Searches for files using the glob pattern and returns a list of files. + * Ignore `.env` files and apply `.gitignore` if present. + * @param glob + */ + findFiles( + glob: string, + options?: { + /** + * Set to false to skip read text content. True by default + */ + readText?: boolean + } + ): Promise + + /** + * Performs a grep search over the files in the workspace + * @param query + * @param globs + */ + grep( + query: string | RegExp, + globs: string | string[], + options?: { + /** + * Set to false to skip read text content. True by default + */ + readText?: boolean + } + ): Promise<{ files: WorkspaceFile[] }> + + /** + * Reads the content of a file as text + * @param path + */ + readText(path: string | Awaitable): Promise + + /** + * Reads the content of a file and parses to JSON, using the JSON5 parser. + * @param path + */ + readJSON(path: string | Awaitable): Promise + + /** + * Reads the content of a file and parses to XML, using the XML parser. + */ + readXML(path: string | Awaitable): Promise + + /** + * Writes a file as text to the file system + * @param path + * @param content + */ + writeText(path: string, content: string): Promise + + /** + * Opens a key-value cache for the given cache name. + * The cache is persisted accross runs of the script. Entries are dropped when the cache grows too large. + * @param cacheName + */ + cache( + cacheName: string + ): Promise> +} + +interface ToolCallContext { + trace: ToolCallTrace +} + +interface ToolCallback { + spec: ToolDefinition + impl: ( + args: { context: ToolCallContext } & Record + ) => Awaitable +} + +type AgenticToolCallback = Omit & { + spec: Omit & { + parameters: Record + } +} + +interface AgenticToolProviderCallback { + functions: Iterable +} + +type ChatParticipantHandler = ( + context: ChatTurnGenerationContext, + messages: ChatCompletionMessageParam[] +) => Awaitable + +interface ChatParticipantOptions { + label?: string +} + +interface ChatParticipant { + generator: ChatParticipantHandler + options: ChatParticipantOptions +} + +/** + * A set of text extracted from the context of the prompt execution + */ +interface ExpansionVariables { + /** + * Directory where the prompt is executed + */ + dir: string + + /** + * List of linked files parsed in context + */ + files: WorkspaceFile[] + + /** + * current prompt template + */ + template: PromptDefinition + + /** + * User defined variables + */ + vars?: Record + + /** + * List of secrets used by the prompt, must be registered in `genaiscript`. + */ + secrets?: Record + + /** + * Root prompt generation context + */ + generator: ChatGenerationContext +} + +type MakeOptional = Partial> & Omit + +type PromptArgs = Omit + +type PromptSystemArgs = Omit< + PromptArgs, + | "model" + | "embeddingsModel" + | "temperature" + | "topP" + | "maxTokens" + | "seed" + | "tests" + | "responseLanguage" + | "responseType" + | "responseSchema" + | "files" +> + +type StringLike = string | WorkspaceFile | WorkspaceFile[] + +interface FenceOptions { + /** + * Language of the fenced code block. Defaults to "markdown". + */ + language?: + | "markdown" + | "json" + | "yaml" + | "javascript" + | "typescript" + | "python" + | "shell" + | "toml" + | string + + /** + * Prepend each line with a line numbers. Helps with generating diffs. + */ + lineNumbers?: boolean + + /** + * JSON schema identifier + */ + schema?: string +} + +interface ContextExpansionOptions { + /** + * Specifies an maximum of estimated tokesn for this entry; after which it will be truncated. + */ + maxTokens?: number + /* + * Value that is conceptually similar to a zIndex (higher number == higher priority). + * If a rendered prompt has more message tokens than can fit into the available context window, the prompt renderer prunes messages with the lowest priority from the ChatMessages result, preserving the order in which they were declared. This means your extension code can safely declare TSX components for potentially large pieces of context like conversation history and codebase context. + */ + priority?: number + /** + * Controls the proportion of tokens allocated from the container's budget to this element. + * It defaults to 1 on all elements. + */ + flex?: number +} + +interface DefOptions extends FenceOptions, ContextExpansionOptions, DataFilter { + /** + * Filename filter based on file suffix. Case insensitive. + */ + endsWith?: string + + /** + * Filename filter using glob syntax. + */ + glob?: string + + /** + * By default, throws an error if the value in def is empty. + */ + ignoreEmpty?: boolean +} + +interface DefImagesOptions { + detail?: "high" | "low" + /** + * Maximum width of the image + */ + maxWidth?: number + /** + * Maximum height of the image + */ + maxHeight?: number + /** + * Auto cropping same color on the edges of the image + */ + autoCrop?: boolean +} + +interface ChatTaskOptions { + command: string + cwd?: string + env?: Record + args?: string[] +} + +type JSONSchemaTypeName = + | "string" + | "number" + | "integer" + | "boolean" + | "object" + | "array" + | "null" + +type JSONSchemaType = + | JSONSchemaString + | JSONSchemaNumber + | JSONSchemaBoolean + | JSONSchemaObject + | JSONSchemaArray + | null + +interface JSONSchemaString { + type: "string" + description?: string + default?: string +} + +interface JSONSchemaNumber { + type: "number" | "integer" + description?: string + default?: number + minimum?: number + exclusiveMinimum?: number + maximum?: number + exclusiveMaximum?: number +} + +interface JSONSchemaBoolean { + type: "boolean" + description?: string + default?: boolean +} + +interface JSONSchemaObject { + $schema?: string + type: "object" + description?: string + properties?: { + [key: string]: JSONSchemaType + } + required?: string[] + additionalProperties?: boolean +} + +interface JSONSchemaArray { + $schema?: string + type: "array" + description?: string + items?: JSONSchemaType +} + +type JSONSchema = JSONSchemaObject | JSONSchemaArray + +interface JSONSchemaValidation { + schema?: JSONSchema + valid: boolean + error?: string +} + +interface DataFrame { + schema?: string + data: unknown + validation?: JSONSchemaValidation +} + +interface RunPromptResult { + text: string + annotations?: Diagnostic[] + fences?: Fenced[] + frames?: DataFrame[] + json?: any + error?: SerializedError + genVars?: Record + schemas?: Record + finishReason: + | "stop" + | "length" + | "tool_calls" + | "content_filter" + | "cancel" + | "fail" +} + +/** + * Path manipulation functions. + */ +interface Path { + /** + * Returns the last portion of a path. Similar to the Unix basename command. + * @param path + */ + dirname(path: string): string + + /** + * Returns the extension of the path, from the last '.' to end of string in the last portion of the path. + * @param path + */ + extname(path: string): string + + /** + * Returns the last portion of a path, similar to the Unix basename command. + */ + basename(path: string, suffix?: string): string + + /** + * The path.join() method joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path. + * @param paths + */ + join(...paths: string[]): string + + /** + * The path.normalize() method normalizes the given path, resolving '..' and '.' segments. + */ + normalize(...paths: string[]): string + + /** + * The path.relative() method returns the relative path from from to to based on the current working directory. If from and to each resolve to the same path (after calling path.resolve() on each), a zero-length string is returned. + */ + relative(from: string, to: string): string + + /** + * The path.resolve() method resolves a sequence of paths or path segments into an absolute path. + * @param pathSegments + */ + resolve(...pathSegments: string[]): string + + /** + * Determines whether the path is an absolute path. + * @param path + */ + isAbsolute(path: string): boolean +} + +interface Fenced { + label: string + language?: string + content: string + args?: { schema?: string } & Record + + validation?: JSONSchemaValidation +} + +interface XMLParseOptions { + allowBooleanAttributes?: boolean + ignoreAttributes?: boolean + ignoreDeclaration?: boolean + ignorePiTags?: boolean + parseAttributeValue?: boolean + removeNSPrefix?: boolean + unpairedTags?: string[] +} + +interface ParsePDFOptions { + filter?: (pageIndex: number, text?: string) => boolean +} + +interface HTMLToTextOptions { + /** + * After how many chars a line break should follow in `p` elements. + * + * Set to `null` or `false` to disable word-wrapping. + */ + wordwrap?: number | false | null | undefined +} + +interface ParseXLSXOptions { + // specific worksheet name + sheet?: string + // Use specified range (A1-style bounded range string) + range?: string +} + +interface WorkbookSheet { + name: string + rows: object[] +} + +interface ParseZipOptions { + glob?: string +} + +type TokenEncoder = (text: string) => number[] + +interface Parsers { + /** + * Parses text as a JSON5 payload + */ + JSON5( + content: string | WorkspaceFile, + options?: { defaultValue?: any } + ): any | undefined + + /** + * Parses text or file as a JSONL payload. Empty lines are ignore, and JSON5 is used for parsing. + * @param content + */ + JSONL(content: string | WorkspaceFile): any[] | undefined + + /** + * Parses text as a YAML paylaod + */ + YAML( + content: string | WorkspaceFile, + options?: { defaultValue?: any } + ): any | undefined + + /** + * Parses text as TOML payload + * @param text text as TOML payload + */ + TOML( + content: string | WorkspaceFile, + options?: { defaultValue?: any } + ): any | undefined + + /** + * Parses the front matter of a markdown file + * @param content + * @param defaultValue + */ + frontmatter( + content: string | WorkspaceFile, + options?: { defaultValue?: any; format: "yaml" | "json" | "toml" } + ): any | undefined + + /** + * Parses a file or URL as PDF + * @param content + */ + PDF( + content: string | WorkspaceFile, + options?: ParsePDFOptions + ): Promise<{ file: WorkspaceFile; pages: string[] } | undefined> + + /** + * Parses a .docx file + * @param content + */ + DOCX( + content: string | WorkspaceFile + ): Promise<{ file: WorkspaceFile } | undefined> + + /** + * Parses a CSV file or text + * @param content + */ + CSV( + content: string | WorkspaceFile, + options?: { delimiter?: string; headers?: string[] } + ): object[] | undefined + + /** + * Parses a XLSX file and a given worksheet + * @param content + */ + XLSX( + content: WorkspaceFile, + options?: ParseXLSXOptions + ): Promise + + /** + * Parses a .env file + * @param content + */ + dotEnv(content: string | WorkspaceFile): Record + + /** + * Parses a .ini file + * @param content + */ + INI( + content: string | WorkspaceFile, + options?: { defaultValue?: any } + ): any | undefined + + /** + * Parses a .xml file + * @param content + */ + XML( + content: string | WorkspaceFile, + options?: { defaultValue?: any } & XMLParseOptions + ): any | undefined + + /** + * Convert HTML to text + * @param content html string or file + * @param options + */ + HTMLToText( + content: string | WorkspaceFile, + options?: HTMLToTextOptions + ): string + + /** + * Convert HTML to markdown + * @param content html string or file + * @param options + */ + HTMLToMarkdown(content: string | WorkspaceFile): string + + /** + * Extracts the contents of a zip archive file + * @param file + * @param options + */ + unzip( + file: WorkspaceFile, + options?: ParseZipOptions + ): Promise + + /** + * Estimates the number of tokens in the content. + * @param content content to tokenize + */ + tokens(content: string | WorkspaceFile): number + + /** + * Parses fenced code sections in a markdown text + */ + fences(content: string | WorkspaceFile): Fenced[] + + /** + * Parses various format of annotations (error, warning, ...) + * @param content + */ + annotations(content: string | WorkspaceFile): Diagnostic[] + + /** + * Executes a tree-sitter query on a code file + * @param file + * @param query tree sitter query; if missing, returns the entire tree + */ + code(file: WorkspaceFile, query?: string): Promise + + /** + * Parses and evaluates a math expression + * @param expression math expression compatible with mathjs + */ + math(expression: string): Promise + + /** + * Using the JSON schema, validates the content + * @param schema JSON schema instance + * @param content object to validate + */ + validateJSON(schema: JSONSchema, content: any): JSONSchemaValidation + + /** + * Renders a mustache template + * @param text template text + * @param data data to render + */ + mustache(text: string | WorkspaceFile, data: Record): str + /** + * Renders a jinja template + */ + jinja(text: string | WorkspaceFile, data: Record): string +} + +interface AICIGenOptions { + /** + * Make sure the generated text is one of the options. + */ + options?: string[] + /** + * Make sure the generated text matches given regular expression. + */ + regex?: string | RegExp + /** + * Make sure the generated text matches given yacc-like grammar. + */ + yacc?: string + /** + * Make sure the generated text is a substring of the given string. + */ + substring?: string + /** + * Used together with `substring` - treat the substring as ending the substring + * (typically '"' or similar). + */ + substringEnd?: string + /** + * Store result of the generation (as bytes) into a shared variable. + */ + storeVar?: string + /** + * Stop generation when the string is generated (the result includes the string and any following bytes (from the same token)). + */ + stopAt?: string + /** + * Stop generation when the given number of tokens have been generated. + */ + maxTokens?: number +} + +interface AICINode { + type: "aici" + name: "gen" +} + +interface AICIGenNode extends AICINode { + name: "gen" + options: AICIGenOptions +} + +interface AICI { + /** + * Generate a string that matches given constraints. + * If the tokens do not map cleanly into strings, it will contain Unicode replacement characters. + */ + gen(options: AICIGenOptions): AICIGenNode +} + +interface YAML { + /** + * Converts an object to its YAML representation + * @param obj + */ + stringify(obj: any): string + /** + * Parses a YAML string to object + */ + parse(text: string): any +} + +interface XML { + /** + * Parses an XML payload to an object + * @param text + */ + parse(text: string, options?: XMLParseOptions): any +} + +interface HTMLTableToJSONOptions { + useFirstRowForHeadings?: boolean + headers?: HeaderRows + stripHtmlFromHeadings?: boolean + stripHtmlFromCells?: boolean + stripHtml?: boolean | null + forceIndexAsNumber?: boolean + countDuplicateHeadings?: boolean + ignoreColumns?: number[] | null + onlyColumns?: number[] | null + ignoreHiddenRows?: boolean + id?: string[] | null + headings?: string[] | null + containsClasses?: string[] | null + limitrows?: number | null +} + +interface HTML { + /** + * Converts all HTML tables to JSON. + * @param html + * @param options + */ + convertTablesToJSON( + html: string, + options?: HTMLTableToJSONOptions + ): object[][] + /** + * Converts HTML markup to plain text + * @param html + */ + convertToText(html: string): string + /** + * Converts HTML markup to markdown + * @param html + */ + convertToMarkdown(html: string): string +} + +interface MD { + /** + * Parses front matter from markdown + * @param text + */ + frontmatter(text: string, format?: "yaml" | "json" | "toml" | "text"): any + + /** + * Removes the front matter from the markdown text + */ + content(text: string): string + + /** + * Merges frontmatter with the existing text + * @param text + * @param frontmatter + * @param format + */ + updateFrontmatter( + text: string, + frontmatter: any, + format?: "yaml" | "json" + ): string +} + +interface JSONL { + /** + * Parses a JSONL string to an array of objects + * @param text + */ + parse(text: string): any[] + /** + * Converts objects to JSONL format + * @param objs + */ + stringify(objs: any[]): string +} + +interface INI { + /** + * Parses a .ini file + * @param text + */ + parse(text: string): any + + /** + * Converts an object to.ini string + * @param value + */ + stringify(value: any): string +} + +interface CSV { + /** + * Parses a CSV string to an array of objects + * @param text + * @param options + */ + parse( + text: string, + options?: { + delimiter?: string + headers?: string[] + } + ): object[] + + /** + * Converts an array of object that represents a data table to a markdown table + * @param csv + * @param options + */ + markdownify(csv: object[], options?: { headers?: string[] }): string +} + +interface HighlightOptions { + maxLength?: number +} + +interface WebSearchResult { + webPages: WorkspaceFile[] +} + +interface VectorSearchOptions extends EmbeddingsModelOptions { + /** + * Maximum number of embeddings to use + */ + topK?: number + /** + * Minimum similarity score + */ + minScore?: number +} + +interface FuzzSearchOptions { + /** + * Controls whether to perform prefix search. It can be a simple boolean, or a + * function. + * + * If a boolean is passed, prefix search is performed if true. + * + * If a function is passed, it is called upon search with a search term, the + * positional index of that search term in the tokenized search query, and the + * tokenized search query. + */ + prefix?: boolean + /** + * Controls whether to perform fuzzy search. It can be a simple boolean, or a + * number, or a function. + * + * If a boolean is given, fuzzy search with a default fuzziness parameter is + * performed if true. + * + * If a number higher or equal to 1 is given, fuzzy search is performed, with + * a maximum edit distance (Levenshtein) equal to the number. + * + * If a number between 0 and 1 is given, fuzzy search is performed within a + * maximum edit distance corresponding to that fraction of the term length, + * approximated to the nearest integer. For example, 0.2 would mean an edit + * distance of 20% of the term length, so 1 character in a 5-characters term. + * The calculated fuzziness value is limited by the `maxFuzzy` option, to + * prevent slowdown for very long queries. + */ + fuzzy?: boolean | number + /** + * Controls the maximum fuzziness when using a fractional fuzzy value. This is + * set to 6 by default. Very high edit distances usually don't produce + * meaningful results, but can excessively impact search performance. + */ + maxFuzzy?: number + /** + * Maximum number of results to return + */ + topK?: number +} + +interface Retrieval { + /** + * Executers a Bing web search. Requires to configure the BING_SEARCH_API_KEY secret. + * @param query + */ + webSearch(query: string): Promise + + /** + * Search using similarity distance on embeddings + */ + vectorSearch( + query: string, + files: (string | WorkspaceFile) | (string | WorkspaceFile)[], + options?: VectorSearchOptions + ): Promise + + /** + * Performs a fuzzy search over the files + * @param query keywords to search + * @param files list of files + * @param options fuzzing configuration + */ + fuzzSearch( + query: string, + files: WorkspaceFile | WorkspaceFile[], + options?: FuzzSearchOptions + ): Promise +} + +type FetchTextOptions = Omit + +interface DataFilter { + /** + * The keys to select from the object. + * If a key is prefixed with -, it will be removed from the object. + */ + headers?: string[] + /** + * Selects the first N elements from the data + */ + sliceHead?: number + /** + * Selects the last N elements from the data + */ + sliceTail?: number + /** + * Selects the a random sample of N items in the collection. + */ + sliceSample?: number + + /** + * Removes items with duplicate values for the specified keys. + */ + distinct?: string[] +} + +interface DefDataOptions + extends Omit, + DataFilter { + /** + * Output format in the prompt. Defaults to markdownified CSV + */ + format?: "json" | "yaml" | "csv" +} + +interface DefSchemaOptions { + /** + * Output format in the prompt. + */ + format?: "typescript" | "json" | "yaml" +} + +type ChatFunctionHandler = ( + args: { context: ToolCallContext } & Record +) => Awaitable + +interface WriteTextOptions extends ContextExpansionOptions { + /** + * Append text to the assistant response + */ + assistant?: boolean +} + +type PromptGenerator = (ctx: ChatGenerationContext) => Awaitable + +interface PromptGeneratorOptions extends ModelOptions, PromptSystemOptions { + /** + * Label for trace + */ + label?: string +} + +interface FileOutputOptions { + /** + * Schema identifier to validate the generated file + */ + schema?: string +} + +interface FileOutput { + pattern: string + description?: string + options?: FileOutputOptions +} + +interface ImportTemplateOptions {} + +interface PromptTemplateString { + /** + * Set a priority similar to CSS z-index + * to control the trimming of the prompt when the context is full + * @param priority + */ + priority(value: number): PromptTemplateString + /** + * Sets the context layout flex weight + */ + flex(value: number): PromptTemplateString + /** + * Applies jinja template to the string lazily + * @param data jinja data + */ + jinja(data: Record): PromptTemplateString + /** + * Applies mustache template to the string lazily + * @param data mustache data + */ + mustache(data: Record): PromptTemplateString + /** + * Sets the max tokens for this string + * @param tokens + */ + maxTokens(tokens: number): PromptTemplateString +} + +interface ChatTurnGenerationContext { + importTemplate( + files: string | string[], + arguments?: Record< + string | number | boolean | (() => string | number | boolean) + >, + options?: ImportTemplateOptions + ): void + writeText(body: Awaitable, options?: WriteTextOptions): void + $(strings: TemplateStringsArray, ...args: any[]): PromptTemplateString + fence(body: StringLike, options?: FenceOptions): void + def( + name: string, + body: string | WorkspaceFile | WorkspaceFile[] | ShellOutput | Fenced, + options?: DefOptions + ): string + defData( + name: string, + data: object[] | object, + options?: DefDataOptions + ): string + console: PromptGenerationConsole +} + +interface FileUpdate { + before: string + after: string + validation?: JSONSchemaValidation +} + +interface ChatGenerationContext extends ChatTurnGenerationContext { + defSchema( + name: string, + schema: JSONSchema, + options?: DefSchemaOptions + ): string + defImages( + files: ElementOrArray, + options?: DefImagesOptions + ): void + defTool( + tool: ToolCallback | AgenticToolCallback | AgenticToolProviderCallback + ): void + defTool( + name: string, + description: string, + parameters: PromptParametersSchema | JSONSchema, + fn: ChatFunctionHandler + ): void + defChatParticipant( + participant: ChatParticipantHandler, + options?: ChatParticipantOptions + ): void + defFileOutput( + pattern: string, + description?: string, + options?: FileOutputOptions + ): void + runPrompt( + generator: string | PromptGenerator, + options?: PromptGeneratorOptions + ): Promise +} + +interface GenerationOutput { + /** + * LLM output. + */ + text: string + + /** + * Parsed fence sections + */ + fences: Fenced[] + + /** + * Parsed data sections + */ + frames: DataFrame[] + + /** + * A map of file updates + */ + fileEdits: Record + + /** + * Generated variables, typically from AICI.gen + */ + genVars: Record + + /** + * Generated annotations + */ + annotations: Diagnostic[] + + /** + * Schema definition used in the generation + */ + schemas: Record + + /** + * Output as JSON if parsable + */ + json?: any +} + +type Point = { + row: number + column: number +} + +interface SyntaxNode { + id: number + typeId: number + grammarId: number + type: string + grammarType: string + isNamed: boolean + isMissing: boolean + isExtra: boolean + hasChanges: boolean + hasError: boolean + isError: boolean + text: string + parseState: number + nextParseState: number + startPosition: Point + endPosition: Point + startIndex: number + endIndex: number + parent: SyntaxNode | null + children: Array + namedChildren: Array + childCount: number + namedChildCount: number + firstChild: SyntaxNode | null + firstNamedChild: SyntaxNode | null + lastChild: SyntaxNode | null + lastNamedChild: SyntaxNode | null + nextSibling: SyntaxNode | null + nextNamedSibling: SyntaxNode | null + previousSibling: SyntaxNode | null + previousNamedSibling: SyntaxNode | null + descendantCount: number + + equals(other: SyntaxNode): boolean + toString(): string + child(index: number): SyntaxNode | null + namedChild(index: number): SyntaxNode | null + childForFieldName(fieldName: string): SyntaxNode | null + childForFieldId(fieldId: number): SyntaxNode | null + fieldNameForChild(childIndex: number): string | null + childrenForFieldName( + fieldName: string, + cursor: TreeCursor + ): Array + childrenForFieldId(fieldId: number, cursor: TreeCursor): Array + firstChildForIndex(index: number): SyntaxNode | null + firstNamedChildForIndex(index: number): SyntaxNode | null + + descendantForIndex(index: number): SyntaxNode + descendantForIndex(startIndex: number, endIndex: number): SyntaxNode + namedDescendantForIndex(index: number): SyntaxNode + namedDescendantForIndex(startIndex: number, endIndex: number): SyntaxNode + descendantForPosition(position: Point): SyntaxNode + descendantForPosition(startPosition: Point, endPosition: Point): SyntaxNode + namedDescendantForPosition(position: Point): SyntaxNode + namedDescendantForPosition( + startPosition: Point, + endPosition: Point + ): SyntaxNode + descendantsOfType( + types: String | Array, + startPosition?: Point, + endPosition?: Point + ): Array + + walk(): TreeCursor +} + +interface TreeCursor { + nodeType: string + nodeTypeId: number + nodeStateId: number + nodeText: string + nodeId: number + nodeIsNamed: boolean + nodeIsMissing: boolean + startPosition: Point + endPosition: Point + startIndex: number + endIndex: number + readonly currentNode: SyntaxNode + readonly currentFieldName: string + readonly currentFieldId: number + readonly currentDepth: number + readonly currentDescendantIndex: number + + reset(node: SyntaxNode): void + resetTo(cursor: TreeCursor): void + gotoParent(): boolean + gotoFirstChild(): boolean + gotoLastChild(): boolean + gotoFirstChildForIndex(goalIndex: number): boolean + gotoFirstChildForPosition(goalPosition: Point): boolean + gotoNextSibling(): boolean + gotoPreviousSibling(): boolean + gotoDescendant(goalDescendantIndex: number): void +} + +interface QueryCapture { + name: string + node: SyntaxNode +} + +interface ShellOptions { + cwd?: string + stdin?: string + /** + * Process timeout in milliseconds, default is 60s + */ + timeout?: number + /** + * trace label + */ + label?: string +} + +interface ShellOutput { + stdout?: string + stderr?: string + exitCode: number + failed: boolean +} + +interface BrowserOptions { + /** + * Browser engine for this page. Defaults to chromium + * + */ + browser?: "chromium" | "firefox" | "webkit" + + /** + * If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in is closed. + */ + downloadsPath?: string + + /** + * Whether to run browser in headless mode. More details for Chromium and Firefox. Defaults to true unless the devtools option is true. + */ + headless?: boolean + + /** + * Specify environment variables that will be visible to the browser. Defaults to process.env. + */ + env?: Record +} + +interface BrowseSessionOptions extends BrowserOptions, TimeoutOptions { + /** + * Creates a new context for the browser session + */ + incognito?: boolean + + /** + * Base url to use for relative urls + * @link https://playwright.dev/docs/api/class-browser#browser-new-context-option-base-url + */ + baseUrl?: string + + /** + * Toggles bypassing page's Content-Security-Policy. Defaults to false. + * @link https://playwright.dev/docs/api/class-browser#browser-new-context-option-bypass-csp + */ + bypassCSP?: boolean + + /** + * Whether to ignore HTTPS errors when sending network requests. Defaults to false. + * @link https://playwright.dev/docs/api/class-browser#browser-new-context-option-ignore-https-errors + */ + ignoreHTTPSErrors?: boolean + + /** + * Whether or not to enable JavaScript in the context. Defaults to true. + * @link https://playwright.dev/docs/api/class-browser#browser-new-context-option-java-script-enabled + */ + javaScriptEnabled?: boolean +} + +interface TimeoutOptions { + /** + * Maximum time in milliseconds. Default to no timeout + */ + timeout?: number +} + +interface ScreenshotOptions extends TimeoutOptions { + quality?: number + scale?: "css" | "device" + type?: "png" | "jpeg" + style?: string +} + +interface PageScreenshotOptions extends ScreenshotOptions { + fullPage?: boolean + omitBackground?: boolean + clip?: { + x: number + y: number + width: number + height: number + } +} + +interface BrowserLocatorSelector { + /** + * Allows locating elements by their ARIA role, ARIA attributes and accessible name. + * @param role + * @param options + */ + getByRole( + role: + | "alert" + | "alertdialog" + | "application" + | "article" + | "banner" + | "blockquote" + | "button" + | "caption" + | "cell" + | "checkbox" + | "code" + | "columnheader" + | "combobox" + | "complementary" + | "contentinfo" + | "definition" + | "deletion" + | "dialog" + | "directory" + | "document" + | "emphasis" + | "feed" + | "figure" + | "form" + | "generic" + | "grid" + | "gridcell" + | "group" + | "heading" + | "img" + | "insertion" + | "link" + | "list" + | "listbox" + | "listitem" + | "log" + | "main" + | "marquee" + | "math" + | "meter" + | "menu" + | "menubar" + | "menuitem" + | "menuitemcheckbox" + | "menuitemradio" + | "navigation" + | "none" + | "note" + | "option" + | "paragraph" + | "presentation" + | "progressbar" + | "radio" + | "radiogroup" + | "region" + | "row" + | "rowgroup" + | "rowheader" + | "scrollbar" + | "search" + | "searchbox" + | "separator" + | "slider" + | "spinbutton" + | "status" + | "strong" + | "subscript" + | "superscript" + | "switch" + | "tab" + | "table" + | "tablist" + | "tabpanel" + | "term" + | "textbox" + | "time" + | "timer" + | "toolbar" + | "tooltip" + | "tree" + | "treegrid" + | "treeitem", + options?: { + checked?: boolean + disabled?: boolean + exact?: boolean + expanded?: boolean + name?: string + selected?: boolean + } & TimeoutOptions + ): Locator + + /** + * Allows locating input elements by the text of the associated