From 79c02553cdf4a7a45b9ce4d0ec2cad5343d3a73f Mon Sep 17 00:00:00 2001 From: Mohammad Amir Date: Wed, 22 May 2024 16:20:56 +0530 Subject: [PATCH] Proxy Support Added --- README.md | 1 + helpers/proxy.ts | 10 ++++++ index.ts | 4 +++ package.json | 7 +++-- pnpm-lock.yaml | 69 ++++++++++++++++++++++++++++++++++++++--- scripts/build.bat | 13 ++++++++ scripts/pack.bat | 3 ++ tsconfig.json | 6 ++-- types/global-agent.d.ts | 5 +++ 9 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 helpers/proxy.ts create mode 100644 scripts/build.bat create mode 100644 scripts/pack.bat create mode 100644 types/global-agent.d.ts diff --git a/README.md b/README.md index 3c10f9fe..edc7145f 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ AI Applications generated by `create-tsi`, use LLMs hosted by T-Systems on Open The purpose of `create-tsi` is to make the AI Application creation process easy, flexible and fast. With `create-tsi` you can generate bots, write agents and customize them for specific use cases. ### Please Note + To get started with `create-tsi`, you need a T-Systems API key. You can request trial access via [this form](https://forms.gle/1HzUGWGG12CmCnbk6). Once you have the key, just run diff --git a/helpers/proxy.ts b/helpers/proxy.ts new file mode 100644 index 00000000..2973926c --- /dev/null +++ b/helpers/proxy.ts @@ -0,0 +1,10 @@ +/* Function to conditionally load the global-agent/bootstrap module */ +export async function initializeGlobalAgent() { + if (process.env.GLOBAL_AGENT_HTTP_PROXY) { + /* Dynamically import global-agent/bootstrap */ + await import("global-agent/bootstrap"); + console.log("Proxy enabled via global-agent."); + } else { + console.log("No proxy configuration found. Continuing without proxy."); + } +} diff --git a/index.ts b/index.ts index 3bd961ab..002676cf 100644 --- a/index.ts +++ b/index.ts @@ -16,12 +16,16 @@ import { createApp } from "./create-app"; import { getDataSources } from "./helpers/datasources"; import { getPkgManager } from "./helpers/get-pkg-manager"; import { isFolderEmpty } from "./helpers/is-folder-empty"; +import { initializeGlobalAgent } from "./helpers/proxy"; import { runApp } from "./helpers/run-app"; import { getTools } from "./helpers/tools"; import { validateNpmName } from "./helpers/validate-pkg"; import packageJson from "./package.json"; import { QuestionArgs, askQuestions, onPromptState } from "./questions"; +// Run the initialization function +initializeGlobalAgent(); + let projectPath: string = ""; const handleSigTerm = () => process.exit(0); diff --git a/package.json b/package.json index 85ddf176..d6d6824d 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "format:write": "prettier --ignore-unknown --write .", "dev": "ncc build ./index.ts -w -o dist/", "build": "bash ./scripts/build.sh", + "build:win": "scripts\\build.bat", "build:ncc": "pnpm run clean && ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register", "lint": "eslint . --ignore-pattern dist --ignore-pattern e2e/cache", "e2e": "playwright test", @@ -28,7 +29,8 @@ "new-version": "pnpm run build && changeset version", "release-snapshot": "pnpm run build && changeset publish --tag snapshot", "new-snapshot": "pnpm run build && changeset version --snapshot", - "pack-install": "bash ./scripts/pack.sh" + "pack-install": "bash ./scripts/pack.sh", + "pack-install:win": "scripts\\pack.bat" }, "devDependencies": { "@playwright/test": "^1.41.1", @@ -67,7 +69,8 @@ "eslint-config-prettier": "^8.10.0", "ora": "^8.0.1", "fs-extra": "11.2.0", - "yaml": "2.4.1" + "yaml": "2.4.1", + "global-agent": "^3.0.0" }, "engines": { "node": ">=16.14.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 69d5d513..cbf71adc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,7 +1,3 @@ -# SPDX-FileCopyrightText: 2024 Deutsche Telekom AG, LlamaIndex, Vercel, Inc. -# -# SPDX-License-Identifier: MIT - lockfileVersion: '6.0' settings: @@ -72,6 +68,9 @@ devDependencies: fs-extra: specifier: 11.2.0 version: 11.2.0 + global-agent: + specifier: ^3.0.0 + version: 3.0.0 got: specifier: 10.7.0 version: 10.7.0 @@ -750,6 +749,10 @@ packages: is-windows: 1.0.2 dev: true + /boolean@3.2.0: + resolution: {integrity: sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw==} + dev: true + /brace-expansion@1.1.11: resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} dependencies: @@ -1078,6 +1081,10 @@ packages: engines: {node: '>=8'} dev: true + /detect-node@2.1.0: + resolution: {integrity: sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==} + dev: true + /dir-glob@3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} @@ -1227,6 +1234,10 @@ packages: is-symbol: 1.0.4 dev: true + /es6-error@4.1.1: + resolution: {integrity: sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==} + dev: true + /escalade@3.1.2: resolution: {integrity: sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==} engines: {node: '>=6'} @@ -1601,6 +1612,18 @@ packages: path-is-absolute: 1.0.1 dev: true + /global-agent@3.0.0: + resolution: {integrity: sha512-PT6XReJ+D07JvGoxQMkT6qji/jVNfX/h364XHZOWeRzy64sSFr+xJ5OX7LI3b4MPQzdL4H8Y8M0xzPpsVMwA8Q==} + engines: {node: '>=10.0'} + dependencies: + boolean: 3.2.0 + es6-error: 4.1.1 + matcher: 3.0.0 + roarr: 2.15.4 + semver: 7.6.0 + serialize-error: 7.0.1 + dev: true + /globals@13.24.0: resolution: {integrity: sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==} engines: {node: '>=8'} @@ -2011,6 +2034,10 @@ packages: resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==} dev: true + /json-stringify-safe@5.0.1: + resolution: {integrity: sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==} + dev: true + /jsonfile@4.0.0: resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==} optionalDependencies: @@ -2140,6 +2167,13 @@ packages: engines: {node: '>=8'} dev: true + /matcher@3.0.0: + resolution: {integrity: sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng==} + engines: {node: '>=10'} + dependencies: + escape-string-regexp: 4.0.0 + dev: true + /meow@6.1.1: resolution: {integrity: sha512-3YffViIt2QWgTy6Pale5QpopX/IvU3LPL03jOTqp6pGj3VjesdO/U8CuHMKpnQr4shCNCM5fd5XFFvIIl6JBHg==} engines: {node: '>=8'} @@ -2755,6 +2789,18 @@ packages: glob: 10.3.10 dev: true + /roarr@2.15.4: + resolution: {integrity: sha512-CHhPh+UNHD2GTXNYhPWLnU8ONHdI+5DI+4EYIAOaiD63rHeYlZvyh8P+in5999TTSFgUYuKUAjzRI4mdh/p+2A==} + engines: {node: '>=8.0'} + dependencies: + boolean: 3.2.0 + detect-node: 2.1.0 + globalthis: 1.0.3 + json-stringify-safe: 5.0.1 + semver-compare: 1.0.0 + sprintf-js: 1.1.3 + dev: true + /run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} dependencies: @@ -2788,6 +2834,10 @@ packages: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} dev: true + /semver-compare@1.0.0: + resolution: {integrity: sha512-YM3/ITh2MJ5MtzaM429anh+x2jiLVjqILF4m4oyQB18W7Ggea7BfqdH/wGMK7dDiMghv/6WG7znWMwUDzJiXow==} + dev: true + /semver@5.7.2: resolution: {integrity: sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==} hasBin: true @@ -2801,6 +2851,13 @@ packages: lru-cache: 6.0.0 dev: true + /serialize-error@7.0.1: + resolution: {integrity: sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==} + engines: {node: '>=10'} + dependencies: + type-fest: 0.13.1 + dev: true + /set-blocking@2.0.0: resolution: {integrity: sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==} dev: true @@ -2930,6 +2987,10 @@ packages: resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==} dev: true + /sprintf-js@1.1.3: + resolution: {integrity: sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==} + dev: true + /stdin-discarder@0.2.2: resolution: {integrity: sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==} engines: {node: '>=18'} diff --git a/scripts/build.bat b/scripts/build.bat new file mode 100644 index 00000000..968651c4 --- /dev/null +++ b/scripts/build.bat @@ -0,0 +1,13 @@ +@echo off + +rem Build dist/index.js file +pnpm run build:ncc + +rem Add shebang to the top of dist/index.js +rem Note: Windows doesn't use shebangs, so this step is optional +echo // #!/usr/bin/env node > temp +type dist\index.js >> temp +move /y temp dist\index.js + +rem Make dist/index.js executable (not needed on Windows) +rem chmod +x dist/index.js \ No newline at end of file diff --git a/scripts/pack.bat b/scripts/pack.bat new file mode 100644 index 00000000..b721b08e --- /dev/null +++ b/scripts/pack.bat @@ -0,0 +1,3 @@ +pnpm pack +for /f %%i in ('dir /b /s *.tgz') do set "package=%%i" +npm install -g %package% \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 5d804d06..b3991dd1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,14 +11,16 @@ "forceConsistentCasingInFileNames": true, "incremental": true, "outDir": "./lib", - "tsBuildInfoFile": "./lib/.tsbuildinfo" + "tsBuildInfoFile": "./lib/.tsbuildinfo", + "typeRoots": ["./types", "./node_modules/@types"] }, "include": [ "create-app.ts", "index.ts", "./helpers", "questions.ts", - "package.json" + "package.json", + "./types" ], "exclude": ["dist"] } diff --git a/types/global-agent.d.ts b/types/global-agent.d.ts new file mode 100644 index 00000000..72260bfa --- /dev/null +++ b/types/global-agent.d.ts @@ -0,0 +1,5 @@ +/*types/global-agent.d.ts */ +declare module "global-agent/bootstrap" { + const anyType: any; + export = anyType; +}