├── .env.example ├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── docker ├── Dockerfile └── runner.py ├── use_cases ├── __init__.py └── quickstart │ ├── __init__.py │ ├── quickstart.ipynb │ ├── quickstart.py │ └── screens_config.json └── vue-gui ├── .pnp.cjs ├── .pnp.loader.mjs ├── Dockerfile ├── README.md ├── babel.config.js ├── default.conf ├── jsconfig.json ├── package.json ├── postcss.config.js ├── public ├── favicon.ico └── index.html ├── server.js ├── src ├── App.vue ├── assets │ └── logo.png ├── components │ ├── ChatRoom.vue │ ├── ChatRoomSelector.vue │ ├── MockedWorldAlert.vue │ ├── SendMessageBox.vue │ ├── WorldChatRooms.vue │ ├── WorldInfo.vue │ ├── WorldLayout.vue │ └── WorldSettings.vue ├── main.js ├── modules │ ├── api │ │ └── resources │ │ │ └── TTS.js │ ├── downloadEventHistory.js │ └── worldSocketHandler.js ├── router.js ├── stores │ ├── screensStore.js │ ├── settingsStore.js │ ├── worldActionsStore.js │ └── worldStateStore.js └── tailwind.css ├── tailwind.config.js ├── vue.config.js └── yarn.lock /.env.example: -------------------------------------------------------------------------------- 1 | OPENAI_API_KEY= 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | .DS_Store 3 | node_modules 4 | **/build 5 | **/dist 6 | 7 | # replit files 8 | **/replit-build 9 | replit-build.zip 10 | 11 | # local env files 12 | .env 13 | .env.local 14 | .env.*.local 15 | 16 | # Log files 17 | npm-debug.log* 18 | yarn-debug.log* 19 | yarn-error.log* 20 | pnpm-debug.log* 21 | 22 | /.conda 23 | 24 | .ipynb_checkpoints -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Attach to FastAPI: World Instance", 6 | "type": "python", 7 | "request": "attach", 8 | "connect": { 9 | "host": "localhost", 10 | "port": 5678 11 | }, 12 | "pathMappings": [ 13 | { 14 | "localRoot": "${workspaceFolder}/packages/world-instance", 15 | "remoteRoot": "/app" 16 | } 17 | ] 18 | }, 19 | { 20 | "name": "Attach to FastAPI: Real WS", 21 | "type": "python", 22 | "request": "attach", 23 | "connect": { 24 | "host": "localhost", 25 | "port": 5679 26 | }, 27 | "pathMappings": [ 28 | { 29 | "localRoot": "${workspaceFolder}/packages/real-ws", 30 | "remoteRoot": "/app" 31 | } 32 | ] 33 | }, 34 | { 35 | "name": "Attach to FastAPI: Mocked WS", 36 | "type": "python", 37 | "request": "attach", 38 | "connect": { 39 | "host": "localhost", 40 | "port": 5680 41 | }, 42 | "pathMappings": [ 43 | { 44 | "localRoot": "${workspaceFolder}/packages/mocked-ws", 45 | "remoteRoot": "/app" 46 | } 47 | ] 48 | }, 49 | { 50 | "type": "chrome", 51 | "request": "launch", 52 | "name": "Launch Chrome against Vue", 53 | "url": "http://localhost:80", 54 | "webRoot": "${workspaceFolder}/packages/nano-vue" 55 | } 56 | ], 57 | "compounds": [ 58 | { 59 | "name": "Debug All", 60 | "configurations": [ 61 | "Attach to FastAPI: World Instance", 62 | "Attach to FastAPI: Real WS", 63 | "Attach to FastAPI: Mocked WS", 64 | "Launch Chrome against Vue" 65 | ], 66 | "preLaunchTask": "start-docker-compose" 67 | } 68 | ] 69 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "start-docker-compose", 6 | "type": "shell", 7 | "command": "docker-compose up --build", 8 | "options": { 9 | "cwd": "${workspaceFolder}" 10 | }, 11 | "isBackground": true, 12 | "problemMatcher": { 13 | "pattern": { 14 | "regexp": "^[^\\s].*" 15 | }, 16 | "background": { 17 | "activeOnStart": true, 18 | "beginsPattern": ".*[+] Building.*", 19 | "endsPattern": ".*genworlds-community-world-instance-1 \\| INFO: Application startup complete\\..*" 20 | } 21 | } 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to GenWorlds Community 2 | 3 | Hi there! Thank you for even being interested in contributing to GenWorlds Community. 4 | As an open source project in a rapidly developing field, we are extremely open to contributions, whether they be in the form of new features, improved infra, better documentation, or bug fixes. 5 | 6 | ## 🚧 This page is under construction 7 | 8 | ## 🚩 GitHub Issues 9 | 10 | Our [issues](https://github.com/yeagerai/genworlds-community/issues) page is kept up to date 11 | with bugs, improvements, and feature requests. 12 | 13 | There is a taxonomy of labels to help with sorting and discovery of issues of interest. Please use these to help 14 | organize issues. 15 | 16 | If you start working on an issue, please assign it to yourself. 17 | 18 | If you are adding an issue, please try to keep it focused on a single, modular bug/improvement/feature. 19 | If two issues are related, or blocking, please link them rather than combining them. 20 | 21 | We will try to keep these issues as up to date as possible, though 22 | with the rapid rate of develop in this field some may get out of date. 23 | If you notice this happening, please let us know. 24 | 25 | ## 🚀 Running it with Docker Compose (dev mode) 26 | 27 | This is the recommended way to run the framework in development mode. It will run all the services in the framework and will allow you to modify the code and see the changes in real time. Also to change the framework, if you have it in the same parent folder as the community edition, it will also be updated in real time. 28 | 29 | It takes a while to build the first time, and some disk space, but it's worth it. 30 | 31 | ```sh 32 | docker compose up 33 | ``` 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 YeagerAI 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Genworlds Community Edition 2 | 3 | [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit/) [![Discord](https://dcbadge.vercel.app/api/server/VpfmXEMN66?compact=true&style=flat)](https://discord.gg/VpfmXEMN66) [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/yeagerai.svg?style=social&label=Follow%20%40YeagerAI)](https://twitter.com/yeagerai) [![GitHub star chart](https://img.shields.io/github/stars/yeagerai/genworlds-community?style=social)](https://star-history.com/#yeagerai/genworlds-community) 4 | 5 | **Yeager Support:** We are standing by to provide extensive support as your GenWorlds project transitions to the production phase or If you are an enterprise looking to work directly with Yeager.ai to build custom GenAI applications. Please complete [this short form](https://share.hsforms.com/1EO76EZ_CTDGCiqRYtdpkJwc4zk8) and we will get back to you shortly. 6 | 7 | ## About GenWorlds Community Edition 8 | 9 | GenWorlds Community Edition is your toolkit for building and fine-tuning unique multi-agent systems using [the genworlds framework](https://github.com/yeagerai/genworlds). It consists of a frontend developed in Vue, that can be connected to any world that is a `ChatInterfaceWorld`, provided in the basic utility layer of genworlds. More info about `ChatInterfaceWorld` can be found [here](https://github.com/yeagerai/genworlds/blob/main/genworlds/worlds/concrete/community_chat_interface/world.py). 10 | 11 | GenWorlds Community uses The GenWorlds Framework as its core. For more information please visit [The Docs](https://genworlds.com/docs/get-started/intro). 12 | 13 | ### Chat Interface World: A Novel Approach to Multi-User Chat Environments 14 | 15 | The Chat Interface World is not only a basic world that can contain all sorts of objects, and agents but also manages a series of actions that send events transmitting configurations for chat rooms to the frontend. 16 | 17 | In a professional protocol environment, like the one utilized by GenWorlds-Community, a frontend - `vue-gui/` - is provided, which enables rendering of content while staying connected to a Chat Interface World. 18 | 19 | To develop using this new strategy: 20 | 21 | 1. Clone the repo. 22 | 2. Launch your world using Python or Jupyter Notebook. 23 | 3. Go to the vue-gui folder and execute `yarn install` if is the first time you use the repo. 24 | 4. Execute `yarn serve` to launch the frontend which will, in turn, try to connect to the world, receiving the event with the screen configurations and subsequently displaying them. 25 | 26 | Check out the `use-cases/` folder of this repository for examples. 27 | 28 | ## Key Features 29 | 30 | - **Full Stack for your custom multi-agent system:** Use your GenWorld as a backend, and the provided vue-gui as your frontend. 31 | - **Run Anywhere:** Easily launch GenWorlds Community Edition through Docker or just plain from your terminal. 32 | - **Fine-tune Your World:** Create more [custom agents](https://genworlds.com/docs/tutorials/first_custom_agent) and [objects](https://genworlds.com/docs/genworlds-framework/objects) and attach it to you world to find the perfect mix between deterministic and non-deterministic processes. 33 | 34 | ## 🛠️ Getting Started 35 | 36 | ### Running it locally 37 | 38 | To set up and run GenWorlds Community Edition locally, use the following commands: 39 | 40 | ```sh 41 | git clone git@github.com:yeagerai/genworlds-community.git 42 | ``` 43 | 44 | Then create a file called `.env` and copy the content of the `.env.example` and replace the corresponding API keys. 45 | 46 | Then open a `jupyter-notebook` and go to `use_cases/quickstart/quickstart.ipynb` and run all the cells. 47 | 48 | After that, to install the dependencies and run the frontend server: 49 | 50 | ```sh 51 | cd vue-gui 52 | yarn install 53 | yarn serve 54 | ``` 55 | 56 | Finally, you can open your browser and go to `http://localhost:8080/`. Start interacting with your world typing `/` on the textbox. 57 | 58 | Here is a video of the process, after we have executed the `git clone` command: 59 | 60 | [![GenWorlds Community Initial Setup](https://img.youtube.com/vi/0amH15NkAb8/maxresdefault.jpg 61 | )](https://www.youtube.com/watch?v=0amH15NkAb8) 62 | 63 | And you can create new `ChatInterfaceWorld`(s) inside the `use_cases/` folder to adapt it to your particular use-case. 64 | 65 | For more detailed information of how to use the framework, you can check the [GenWorlds Docs](https://genworlds.com/docs/get-started/intro). 66 | 67 | ### Running with Docker (under development, so not working yet) 68 | 69 | To set up and run GenWorlds Community Edition with Docker, use the following commands: 70 | 71 | ```sh 72 | git clone git@github.com:yeagerai/genworlds-community.git 73 | ``` 74 | 75 | Then create a file called `.env` and copy the content of the `.env.example` and replace the corresponding API keys. 76 | 77 | After that, to build and run the image: 78 | 79 | ```sh 80 | docker build -t genworlds-world-app -f ./docker/Dockerfile . 81 | docker run -p 80:80 -p 7456:7456 -d genworlds-world-app 82 | ``` 83 | 84 | Finally, you can open your browser and go to `http://localhost/` 85 | 86 | #### Setting the API keys 87 | 88 | ##### OpenAI 89 | 90 | When you first run a use_case, you will see a pre-recorded history of a conversation. 91 | 92 | To run a real simulation, you need to set your OpenAI API key. It can be found at [OpenAI Platform](https://platform.openai.com/account/api-keys). The RoundTable uses GPT4. 93 | 94 | Set the OpenAI API key by clicking the cog icon at top right. 95 | 96 | ## Creating your own Worlds 97 | 98 | The [GenWorlds framework](https://github.com/yeagerai/genworlds) is a powerful set of tools for creating your own worlds of agents and objects that go far beyond the RoundTable use case. 99 | 100 | See the [Tutorials](https://genworlds.com/docs/category/tutorials) to get started with some examples. 101 | 102 | ## Contributing 103 | 104 | As an open-source project in a rapidly developing field, we are extremely open to contributions, whether it be in the form of a new feature, improved infrastructure, or better documentation. Please read our [CONTRIBUTING](https://github.com/yeagerai/genworlds-community/blob/main/CONTRIBUTING.md) for guidelines on how to submit your contributions. 105 | 106 | As the framework is in alpha, expect large changes to the codebase. 107 | 108 | ## License 109 | 110 | 🧬🌍 GenWorlds is released under the MIT License. Please see the [LICENSE file](https://github.com/yeagerai/genworlds-community/blob/main/LICENSE) for more information. 111 | 112 | ## Disclaimer 113 | 114 | This software is provided 'as-is', without any guarantees or warranties. By using GenWorlds Community, you agree to assume all associated risks, including but not limited to data loss, system issues, or any unforeseen challenges. 115 | 116 | The developers and contributors of GenWorlds Community are not responsible for any damages, losses, or consequences that may arise from its use. You alone are responsible for any decisions and actions taken based on the information or results produced by GenWorlds Community. 117 | 118 | Be mindful that usage of AI models, like GPT-4, can be costly due to their token usage. By using GenWorlds Community, you acknowledge that you are responsible for managing your own token usage and related costs. 119 | 120 | As an autonomous system, GenWorlds Community may produce content or execute actions that may not align with real-world business practices or legal requirements. You are responsible for ensuring all actions or decisions align with all applicable laws, regulations, and ethical standards. 121 | 122 | By using GenWorlds Community, you agree to indemnify, defend, and hold harmless the developers, contributors, and any associated parties from any claims, damages, losses, liabilities, costs, and expenses (including attorney's fees) that might arise from your use of this software or violation of these terms. 123 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # STAGE 1: Build dependencies and compile src 3 | #------------------------------------------------------------------------------- 4 | 5 | FROM node:18-alpine as node-builder-16bit-back 6 | 7 | # Allow packages to compile from source 8 | #RUN apk add --no-cache python3 make g++ git 9 | 10 | # Create build directories 11 | RUN mkdir -p /root/build/dep-modules \ 12 | /root/build/dep-tsc 13 | 14 | # Copy package.json 15 | COPY packages/16bit-back/package.json packages/16bit-back/package-lock.json /root/build/dep-modules/ 16 | 17 | # Install dependencies and compile ts code 18 | RUN set -ex; \ 19 | cp /root/build/dep-modules/package.json /root/build/dep-tsc/package.json; \ 20 | cp /root/build/dep-modules/package-lock.json /root/build/dep-tsc/package-lock.json; \ 21 | \ 22 | cd /root/build/dep-modules; \ 23 | NODE_ENV=production npm ci; \ 24 | \ 25 | cd /root/build/dep-tsc; \ 26 | npm ci 27 | 28 | # Copy src 29 | COPY packages/16bit-back/tsconfig.json packages/16bit-back/tsconfig.build.json /root/build/dep-tsc/ 30 | COPY packages/16bit-back/shared /root/build/dep-tsc/shared 31 | COPY packages/16bit-back/src /root/build/dep-tsc/src 32 | 33 | # Compile ts code 34 | RUN set -ex; \ 35 | cd /root/build/dep-tsc; \ 36 | ./node_modules/.bin/tsc -p ./tsconfig.build.json 37 | 38 | # Fix chown issues 39 | RUN set -ex; \ 40 | chown -R root:root /root/build/dep-modules/node_modules; \ 41 | chown -R root:root /root/build/dep-tsc/dist 42 | 43 | # ---- Stage 2: Build 16bit-front using Node ---- 44 | FROM node:18-alpine AS node-builder-16bit-front 45 | WORKDIR /app 46 | COPY packages/16bit-front/ ./ 47 | RUN apk add --no-cache python3 make g++ 48 | RUN npm install yarn 49 | RUN yarn install 50 | RUN yarn build 51 | 52 | # ---- Stage 3: Build nano-vue using Node ---- 53 | FROM node:18-alpine AS node-builder-nano-vue 54 | WORKDIR /app 55 | COPY packages/nano-vue/package*.json ./ 56 | RUN apk add --no-cache python3 make g++ 57 | RUN npm install yarn 58 | RUN yarn install 59 | COPY packages/nano-vue/ ./ 60 | COPY .env ./.env 61 | RUN yarn build 62 | 63 | # ---- Stage 4: Copy artifacts to the final Python image ---- 64 | FROM python:3.10.8 AS python-stage 65 | WORKDIR /app 66 | 67 | # Install Redis 68 | RUN apt-get update && \ 69 | apt-get install -y curl && \ 70 | curl -sL https://deb.nodesource.com/setup_18.x | bash - && \ 71 | apt-get install -y redis-server nodejs 72 | 73 | RUN npm install express http-proxy dotenv 74 | # Copy build artifacts from each stage 75 | COPY packages/16bit-back/package.json packages/16bit-back/package-lock.json ./ 76 | COPY --from=node-builder-16bit-back --chown=root:root /root/build/dep-tsc/dist ./ 77 | COPY --from=node-builder-16bit-back --chown=root:root /root/build/dep-modules/node_modules ./node_modules 78 | 79 | COPY --from=node-builder-16bit-front /app/projects/tank-viewer-web/dist ./16bit-front 80 | COPY packages/16bit-front/server.js ./16bit-front/server.js 81 | 82 | COPY --from=node-builder-nano-vue /app/dist ./nano-vue 83 | COPY packages/nano-vue/server.js ./nano-vue/server.js 84 | 85 | COPY packages/gateway/server.js ./gateway/server.js 86 | 87 | # ---- Stage 5: Copy all Python scripts and pip install all dependencies ---- 88 | COPY packages/world-instance/requirements.txt ./ 89 | RUN pip install --no-cache-dir -r requirements.txt 90 | 91 | COPY packages/world-instance ./world-instance 92 | COPY packages/real-ws ./real-ws 93 | COPY packages/mocked-ws ./mocked-ws 94 | 95 | COPY use_cases ./use_cases 96 | 97 | COPY .env ./.env 98 | 99 | COPY deployments/docker/runner.py ./runner.py 100 | 101 | ENV GENWORLDS_WEBSOCKET_URL=ws://localhost:7456/ws 102 | 103 | EXPOSE 80 104 | EXPOSE 9000 105 | 106 | # ---- Stage 6: Execute the runner ---- 107 | CMD ["python", "runner.py"] -------------------------------------------------------------------------------- /docker/runner.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import threading 3 | from time import sleep 4 | 5 | def run_service(service): 6 | print(f"Starting {service['name']}") 7 | try: 8 | # If 'cwd' is specified in the service, use it as the current working directory 9 | cwd = service.get('cwd') 10 | process = subprocess.Popen(service['command'], shell=True, cwd=cwd) 11 | process.wait() 12 | except Exception as e: 13 | print(f"Error in {service['name']}: {e}") 14 | 15 | 16 | # Example services, replace the command for the other services with the actual commands to start them 17 | services = [ 18 | { 19 | 'name': 'real-ws', 20 | 'command': 'python ./real-ws/main.py', 21 | }, 22 | { 23 | 'name': 'mocked-ws', 24 | 'command': 'python -u -m uvicorn --reload --host 0.0.0.0 --port 7455 mocked-ws.app.main:app', 25 | }, 26 | { 27 | 'name': 'world-instance', 28 | 'command': 'python -u -m uvicorn --reload --host 0.0.0.0 --port 7457 world-instance.main:app', 29 | }, 30 | { 31 | 'name': 'redis', 32 | 'command': 'redis-server', 33 | }, 34 | { 35 | 'name': '16bit-back', 36 | 'command': 'node ./src/server.js', 37 | }, 38 | { 39 | 'name': '16-bit-front', 40 | 'command': 'node ./16bit-front/server.js', 41 | }, 42 | { 43 | 'name': 'vue-frontend', 44 | 'command': 'node ./nano-vue/server.js', 45 | }, 46 | { 47 | 'name': 'gateway', 48 | 'command': 'node ./gateway/server.js', 49 | }, 50 | ] 51 | 52 | # List to keep track of running threads 53 | threads = [] 54 | 55 | # Launch services 56 | for service in services: 57 | thread = threading.Thread(target=run_service, args=(service, )) 58 | # Set the thread as daemon for all services except vue-frontend 59 | thread.daemon = True 60 | thread.start() 61 | threads.append(thread) 62 | print(f"Started {service['name']}" + (' (daemon)' if thread.daemon else '')) 63 | sleep(2) 64 | 65 | # Wait for all threads to complete 66 | for thread in threads: 67 | thread.join() -------------------------------------------------------------------------------- /use_cases/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeagerai/genworlds-community/9318fb88ecf132f344e433a978a165329df603f8/use_cases/__init__.py -------------------------------------------------------------------------------- /use_cases/quickstart/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeagerai/genworlds-community/9318fb88ecf132f344e433a978a165329df603f8/use_cases/quickstart/__init__.py -------------------------------------------------------------------------------- /use_cases/quickstart/quickstart.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeagerai/genworlds-community/9318fb88ecf132f344e433a978a165329df603f8/use_cases/quickstart/quickstart.py -------------------------------------------------------------------------------- /use_cases/quickstart/screens_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RAG World", 3 | "screens": [ 4 | { 5 | "name": "Chat Room", 6 | "has_input": false, 7 | "screen_type": "event_history", 8 | "tracked_events": [ 9 | { 10 | "event_type": "user_speaks_with_agent_event" 11 | }, 12 | { 13 | "event_type": "agent_goes_to_sleep" 14 | }, 15 | { 16 | "event_type": "agent_speaks_with_agent_event" 17 | }, 18 | { 19 | "event_type": "agent_speaks_with_user_event" 20 | } 21 | ] 22 | }, 23 | 24 | { 25 | "name": "All events", 26 | "has_input": false, 27 | "screen_type": "event_history", 28 | "tracked_events": [ 29 | { 30 | "event_type": "world_sends_available_action_schemas_event" 31 | }, 32 | { 33 | "event_type": "world_sends_available_entities_event" 34 | }, 35 | { 36 | "event_type": "user_speaks_with_agent_event" 37 | }, 38 | { 39 | "event_type": "user_requests_screens_to_world" 40 | }, 41 | { 42 | "event_type": "agent_wants_updated_state" 43 | }, 44 | { 45 | "event_type": "agent_goes_to_sleep" 46 | }, 47 | { 48 | "event_type": "world_sends_screens_to_user" 49 | } 50 | ] 51 | } 52 | ], 53 | "settings": {} 54 | } -------------------------------------------------------------------------------- /vue-gui/.pnp.loader.mjs: -------------------------------------------------------------------------------- 1 | import { URL as URL$1, fileURLToPath, pathToFileURL } from 'url'; 2 | import fs from 'fs'; 3 | import path from 'path'; 4 | import moduleExports, { Module } from 'module'; 5 | import { EOL } from 'os'; 6 | import assert from 'assert'; 7 | 8 | const SAFE_TIME = 456789e3; 9 | 10 | const PortablePath = { 11 | root: `/`, 12 | dot: `.`, 13 | parent: `..` 14 | }; 15 | const npath = Object.create(path); 16 | const ppath = Object.create(path.posix); 17 | npath.cwd = () => process.cwd(); 18 | ppath.cwd = () => toPortablePath(process.cwd()); 19 | ppath.resolve = (...segments) => { 20 | if (segments.length > 0 && ppath.isAbsolute(segments[0])) { 21 | return path.posix.resolve(...segments); 22 | } else { 23 | return path.posix.resolve(ppath.cwd(), ...segments); 24 | } 25 | }; 26 | const contains = function(pathUtils, from, to) { 27 | from = pathUtils.normalize(from); 28 | to = pathUtils.normalize(to); 29 | if (from === to) 30 | return `.`; 31 | if (!from.endsWith(pathUtils.sep)) 32 | from = from + pathUtils.sep; 33 | if (to.startsWith(from)) { 34 | return to.slice(from.length); 35 | } else { 36 | return null; 37 | } 38 | }; 39 | npath.fromPortablePath = fromPortablePath; 40 | npath.toPortablePath = toPortablePath; 41 | npath.contains = (from, to) => contains(npath, from, to); 42 | ppath.contains = (from, to) => contains(ppath, from, to); 43 | const WINDOWS_PATH_REGEXP = /^([a-zA-Z]:.*)$/; 44 | const UNC_WINDOWS_PATH_REGEXP = /^\/\/(\.\/)?(.*)$/; 45 | const PORTABLE_PATH_REGEXP = /^\/([a-zA-Z]:.*)$/; 46 | const UNC_PORTABLE_PATH_REGEXP = /^\/unc\/(\.dot\/)?(.*)$/; 47 | function fromPortablePath(p) { 48 | if (process.platform !== `win32`) 49 | return p; 50 | let portablePathMatch, uncPortablePathMatch; 51 | if (portablePathMatch = p.match(PORTABLE_PATH_REGEXP)) 52 | p = portablePathMatch[1]; 53 | else if (uncPortablePathMatch = p.match(UNC_PORTABLE_PATH_REGEXP)) 54 | p = `\\\\${uncPortablePathMatch[1] ? `.\\` : ``}${uncPortablePathMatch[2]}`; 55 | else 56 | return p; 57 | return p.replace(/\//g, `\\`); 58 | } 59 | function toPortablePath(p) { 60 | if (process.platform !== `win32`) 61 | return p; 62 | p = p.replace(/\\/g, `/`); 63 | let windowsPathMatch, uncWindowsPathMatch; 64 | if (windowsPathMatch = p.match(WINDOWS_PATH_REGEXP)) 65 | p = `/${windowsPathMatch[1]}`; 66 | else if (uncWindowsPathMatch = p.match(UNC_WINDOWS_PATH_REGEXP)) 67 | p = `/unc/${uncWindowsPathMatch[1] ? `.dot/` : ``}${uncWindowsPathMatch[2]}`; 68 | return p; 69 | } 70 | function convertPath(targetPathUtils, sourcePath) { 71 | return targetPathUtils === npath ? fromPortablePath(sourcePath) : toPortablePath(sourcePath); 72 | } 73 | 74 | const defaultTime = new Date(SAFE_TIME * 1e3); 75 | async function copyPromise(destinationFs, destination, sourceFs, source, opts) { 76 | const normalizedDestination = destinationFs.pathUtils.normalize(destination); 77 | const normalizedSource = sourceFs.pathUtils.normalize(source); 78 | const prelayout = []; 79 | const postlayout = []; 80 | const { atime, mtime } = opts.stableTime ? { atime: defaultTime, mtime: defaultTime } : await sourceFs.lstatPromise(normalizedSource); 81 | await destinationFs.mkdirpPromise(destinationFs.pathUtils.dirname(destination), { utimes: [atime, mtime] }); 82 | const updateTime = typeof destinationFs.lutimesPromise === `function` ? destinationFs.lutimesPromise.bind(destinationFs) : destinationFs.utimesPromise.bind(destinationFs); 83 | await copyImpl(prelayout, postlayout, updateTime, destinationFs, normalizedDestination, sourceFs, normalizedSource, { ...opts, didParentExist: true }); 84 | for (const operation of prelayout) 85 | await operation(); 86 | await Promise.all(postlayout.map((operation) => { 87 | return operation(); 88 | })); 89 | } 90 | async function copyImpl(prelayout, postlayout, updateTime, destinationFs, destination, sourceFs, source, opts) { 91 | var _a, _b; 92 | const destinationStat = opts.didParentExist ? await maybeLStat(destinationFs, destination) : null; 93 | const sourceStat = await sourceFs.lstatPromise(source); 94 | const { atime, mtime } = opts.stableTime ? { atime: defaultTime, mtime: defaultTime } : sourceStat; 95 | let updated; 96 | switch (true) { 97 | case sourceStat.isDirectory(): 98 | { 99 | updated = await copyFolder(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts); 100 | } 101 | break; 102 | case sourceStat.isFile(): 103 | { 104 | updated = await copyFile(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts); 105 | } 106 | break; 107 | case sourceStat.isSymbolicLink(): 108 | { 109 | updated = await copySymlink(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts); 110 | } 111 | break; 112 | default: 113 | { 114 | throw new Error(`Unsupported file type (${sourceStat.mode})`); 115 | } 116 | } 117 | if (updated || ((_a = destinationStat == null ? void 0 : destinationStat.mtime) == null ? void 0 : _a.getTime()) !== mtime.getTime() || ((_b = destinationStat == null ? void 0 : destinationStat.atime) == null ? void 0 : _b.getTime()) !== atime.getTime()) { 118 | postlayout.push(() => updateTime(destination, atime, mtime)); 119 | updated = true; 120 | } 121 | if (destinationStat === null || (destinationStat.mode & 511) !== (sourceStat.mode & 511)) { 122 | postlayout.push(() => destinationFs.chmodPromise(destination, sourceStat.mode & 511)); 123 | updated = true; 124 | } 125 | return updated; 126 | } 127 | async function maybeLStat(baseFs, p) { 128 | try { 129 | return await baseFs.lstatPromise(p); 130 | } catch (e) { 131 | return null; 132 | } 133 | } 134 | async function copyFolder(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts) { 135 | if (destinationStat !== null && !destinationStat.isDirectory()) { 136 | if (opts.overwrite) { 137 | prelayout.push(async () => destinationFs.removePromise(destination)); 138 | destinationStat = null; 139 | } else { 140 | return false; 141 | } 142 | } 143 | let updated = false; 144 | if (destinationStat === null) { 145 | prelayout.push(async () => { 146 | try { 147 | await destinationFs.mkdirPromise(destination, { mode: sourceStat.mode }); 148 | } catch (err) { 149 | if (err.code !== `EEXIST`) { 150 | throw err; 151 | } 152 | } 153 | }); 154 | updated = true; 155 | } 156 | const entries = await sourceFs.readdirPromise(source); 157 | const nextOpts = opts.didParentExist && !destinationStat ? { ...opts, didParentExist: false } : opts; 158 | if (opts.stableSort) { 159 | for (const entry of entries.sort()) { 160 | if (await copyImpl(prelayout, postlayout, updateTime, destinationFs, destinationFs.pathUtils.join(destination, entry), sourceFs, sourceFs.pathUtils.join(source, entry), nextOpts)) { 161 | updated = true; 162 | } 163 | } 164 | } else { 165 | const entriesUpdateStatus = await Promise.all(entries.map(async (entry) => { 166 | await copyImpl(prelayout, postlayout, updateTime, destinationFs, destinationFs.pathUtils.join(destination, entry), sourceFs, sourceFs.pathUtils.join(source, entry), nextOpts); 167 | })); 168 | if (entriesUpdateStatus.some((status) => status)) { 169 | updated = true; 170 | } 171 | } 172 | return updated; 173 | } 174 | const isCloneSupportedCache = /* @__PURE__ */ new WeakMap(); 175 | function makeLinkOperation(opFs, destination, source, sourceStat, linkStrategy) { 176 | return async () => { 177 | await opFs.linkPromise(source, destination); 178 | if (linkStrategy === "readOnly" /* ReadOnly */) { 179 | sourceStat.mode &= ~146; 180 | await opFs.chmodPromise(destination, sourceStat.mode); 181 | } 182 | }; 183 | } 184 | function makeCloneLinkOperation(opFs, destination, source, sourceStat, linkStrategy) { 185 | const isCloneSupported = isCloneSupportedCache.get(opFs); 186 | if (typeof isCloneSupported === `undefined`) { 187 | return async () => { 188 | try { 189 | await opFs.copyFilePromise(source, destination, fs.constants.COPYFILE_FICLONE_FORCE); 190 | isCloneSupportedCache.set(opFs, true); 191 | } catch (err) { 192 | if (err.code === `ENOSYS` || err.code === `ENOTSUP`) { 193 | isCloneSupportedCache.set(opFs, false); 194 | await makeLinkOperation(opFs, destination, source, sourceStat, linkStrategy)(); 195 | } else { 196 | throw err; 197 | } 198 | } 199 | }; 200 | } else { 201 | if (isCloneSupported) { 202 | return async () => opFs.copyFilePromise(source, destination, fs.constants.COPYFILE_FICLONE_FORCE); 203 | } else { 204 | return makeLinkOperation(opFs, destination, source, sourceStat, linkStrategy); 205 | } 206 | } 207 | } 208 | async function copyFile(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts) { 209 | var _a; 210 | if (destinationStat !== null) { 211 | if (opts.overwrite) { 212 | prelayout.push(async () => destinationFs.removePromise(destination)); 213 | destinationStat = null; 214 | } else { 215 | return false; 216 | } 217 | } 218 | const linkStrategy = (_a = opts.linkStrategy) != null ? _a : null; 219 | const op = destinationFs === sourceFs ? linkStrategy !== null ? makeCloneLinkOperation(destinationFs, destination, source, sourceStat, linkStrategy) : async () => destinationFs.copyFilePromise(source, destination, fs.constants.COPYFILE_FICLONE) : linkStrategy !== null ? makeLinkOperation(destinationFs, destination, source, sourceStat, linkStrategy) : async () => destinationFs.writeFilePromise(destination, await sourceFs.readFilePromise(source)); 220 | prelayout.push(async () => op()); 221 | return true; 222 | } 223 | async function copySymlink(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts) { 224 | if (destinationStat !== null) { 225 | if (opts.overwrite) { 226 | prelayout.push(async () => destinationFs.removePromise(destination)); 227 | destinationStat = null; 228 | } else { 229 | return false; 230 | } 231 | } 232 | prelayout.push(async () => { 233 | await destinationFs.symlinkPromise(convertPath(destinationFs.pathUtils, await sourceFs.readlinkPromise(source)), destination); 234 | }); 235 | return true; 236 | } 237 | 238 | function makeError(code, message) { 239 | return Object.assign(new Error(`${code}: ${message}`), { code }); 240 | } 241 | function ENOSYS(message, reason) { 242 | return makeError(`ENOSYS`, `${message}, ${reason}`); 243 | } 244 | 245 | class FakeFS { 246 | constructor(pathUtils) { 247 | this.pathUtils = pathUtils; 248 | } 249 | async *genTraversePromise(init, { stableSort = false } = {}) { 250 | const stack = [init]; 251 | while (stack.length > 0) { 252 | const p = stack.shift(); 253 | const entry = await this.lstatPromise(p); 254 | if (entry.isDirectory()) { 255 | const entries = await this.readdirPromise(p); 256 | if (stableSort) { 257 | for (const entry2 of entries.sort()) { 258 | stack.push(this.pathUtils.join(p, entry2)); 259 | } 260 | } else { 261 | throw new Error(`Not supported`); 262 | } 263 | } else { 264 | yield p; 265 | } 266 | } 267 | } 268 | async removePromise(p, { recursive = true, maxRetries = 5 } = {}) { 269 | let stat; 270 | try { 271 | stat = await this.lstatPromise(p); 272 | } catch (error) { 273 | if (error.code === `ENOENT`) { 274 | return; 275 | } else { 276 | throw error; 277 | } 278 | } 279 | if (stat.isDirectory()) { 280 | if (recursive) { 281 | const entries = await this.readdirPromise(p); 282 | await Promise.all(entries.map((entry) => { 283 | return this.removePromise(this.pathUtils.resolve(p, entry)); 284 | })); 285 | } 286 | for (let t = 0; t <= maxRetries; t++) { 287 | try { 288 | await this.rmdirPromise(p); 289 | break; 290 | } catch (error) { 291 | if (error.code !== `EBUSY` && error.code !== `ENOTEMPTY`) { 292 | throw error; 293 | } else if (t < maxRetries) { 294 | await new Promise((resolve) => setTimeout(resolve, t * 100)); 295 | } 296 | } 297 | } 298 | } else { 299 | await this.unlinkPromise(p); 300 | } 301 | } 302 | removeSync(p, { recursive = true } = {}) { 303 | let stat; 304 | try { 305 | stat = this.lstatSync(p); 306 | } catch (error) { 307 | if (error.code === `ENOENT`) { 308 | return; 309 | } else { 310 | throw error; 311 | } 312 | } 313 | if (stat.isDirectory()) { 314 | if (recursive) 315 | for (const entry of this.readdirSync(p)) 316 | this.removeSync(this.pathUtils.resolve(p, entry)); 317 | this.rmdirSync(p); 318 | } else { 319 | this.unlinkSync(p); 320 | } 321 | } 322 | async mkdirpPromise(p, { chmod, utimes } = {}) { 323 | p = this.resolve(p); 324 | if (p === this.pathUtils.dirname(p)) 325 | return void 0; 326 | const parts = p.split(this.pathUtils.sep); 327 | let createdDirectory; 328 | for (let u = 2; u <= parts.length; ++u) { 329 | const subPath = parts.slice(0, u).join(this.pathUtils.sep); 330 | if (!this.existsSync(subPath)) { 331 | try { 332 | await this.mkdirPromise(subPath); 333 | } catch (error) { 334 | if (error.code === `EEXIST`) { 335 | continue; 336 | } else { 337 | throw error; 338 | } 339 | } 340 | createdDirectory != null ? createdDirectory : createdDirectory = subPath; 341 | if (chmod != null) 342 | await this.chmodPromise(subPath, chmod); 343 | if (utimes != null) { 344 | await this.utimesPromise(subPath, utimes[0], utimes[1]); 345 | } else { 346 | const parentStat = await this.statPromise(this.pathUtils.dirname(subPath)); 347 | await this.utimesPromise(subPath, parentStat.atime, parentStat.mtime); 348 | } 349 | } 350 | } 351 | return createdDirectory; 352 | } 353 | mkdirpSync(p, { chmod, utimes } = {}) { 354 | p = this.resolve(p); 355 | if (p === this.pathUtils.dirname(p)) 356 | return void 0; 357 | const parts = p.split(this.pathUtils.sep); 358 | let createdDirectory; 359 | for (let u = 2; u <= parts.length; ++u) { 360 | const subPath = parts.slice(0, u).join(this.pathUtils.sep); 361 | if (!this.existsSync(subPath)) { 362 | try { 363 | this.mkdirSync(subPath); 364 | } catch (error) { 365 | if (error.code === `EEXIST`) { 366 | continue; 367 | } else { 368 | throw error; 369 | } 370 | } 371 | createdDirectory != null ? createdDirectory : createdDirectory = subPath; 372 | if (chmod != null) 373 | this.chmodSync(subPath, chmod); 374 | if (utimes != null) { 375 | this.utimesSync(subPath, utimes[0], utimes[1]); 376 | } else { 377 | const parentStat = this.statSync(this.pathUtils.dirname(subPath)); 378 | this.utimesSync(subPath, parentStat.atime, parentStat.mtime); 379 | } 380 | } 381 | } 382 | return createdDirectory; 383 | } 384 | async copyPromise(destination, source, { baseFs = this, overwrite = true, stableSort = false, stableTime = false, linkStrategy = null } = {}) { 385 | return await copyPromise(this, destination, baseFs, source, { overwrite, stableSort, stableTime, linkStrategy }); 386 | } 387 | copySync(destination, source, { baseFs = this, overwrite = true } = {}) { 388 | const stat = baseFs.lstatSync(source); 389 | const exists = this.existsSync(destination); 390 | if (stat.isDirectory()) { 391 | this.mkdirpSync(destination); 392 | const directoryListing = baseFs.readdirSync(source); 393 | for (const entry of directoryListing) { 394 | this.copySync(this.pathUtils.join(destination, entry), baseFs.pathUtils.join(source, entry), { baseFs, overwrite }); 395 | } 396 | } else if (stat.isFile()) { 397 | if (!exists || overwrite) { 398 | if (exists) 399 | this.removeSync(destination); 400 | const content = baseFs.readFileSync(source); 401 | this.writeFileSync(destination, content); 402 | } 403 | } else if (stat.isSymbolicLink()) { 404 | if (!exists || overwrite) { 405 | if (exists) 406 | this.removeSync(destination); 407 | const target = baseFs.readlinkSync(source); 408 | this.symlinkSync(convertPath(this.pathUtils, target), destination); 409 | } 410 | } else { 411 | throw new Error(`Unsupported file type (file: ${source}, mode: 0o${stat.mode.toString(8).padStart(6, `0`)})`); 412 | } 413 | const mode = stat.mode & 511; 414 | this.chmodSync(destination, mode); 415 | } 416 | async changeFilePromise(p, content, opts = {}) { 417 | if (Buffer.isBuffer(content)) { 418 | return this.changeFileBufferPromise(p, content, opts); 419 | } else { 420 | return this.changeFileTextPromise(p, content, opts); 421 | } 422 | } 423 | async changeFileBufferPromise(p, content, { mode } = {}) { 424 | let current = Buffer.alloc(0); 425 | try { 426 | current = await this.readFilePromise(p); 427 | } catch (error) { 428 | } 429 | if (Buffer.compare(current, content) === 0) 430 | return; 431 | await this.writeFilePromise(p, content, { mode }); 432 | } 433 | async changeFileTextPromise(p, content, { automaticNewlines, mode } = {}) { 434 | let current = ``; 435 | try { 436 | current = await this.readFilePromise(p, `utf8`); 437 | } catch (error) { 438 | } 439 | const normalizedContent = automaticNewlines ? normalizeLineEndings(current, content) : content; 440 | if (current === normalizedContent) 441 | return; 442 | await this.writeFilePromise(p, normalizedContent, { mode }); 443 | } 444 | changeFileSync(p, content, opts = {}) { 445 | if (Buffer.isBuffer(content)) { 446 | return this.changeFileBufferSync(p, content, opts); 447 | } else { 448 | return this.changeFileTextSync(p, content, opts); 449 | } 450 | } 451 | changeFileBufferSync(p, content, { mode } = {}) { 452 | let current = Buffer.alloc(0); 453 | try { 454 | current = this.readFileSync(p); 455 | } catch (error) { 456 | } 457 | if (Buffer.compare(current, content) === 0) 458 | return; 459 | this.writeFileSync(p, content, { mode }); 460 | } 461 | changeFileTextSync(p, content, { automaticNewlines = false, mode } = {}) { 462 | let current = ``; 463 | try { 464 | current = this.readFileSync(p, `utf8`); 465 | } catch (error) { 466 | } 467 | const normalizedContent = automaticNewlines ? normalizeLineEndings(current, content) : content; 468 | if (current === normalizedContent) 469 | return; 470 | this.writeFileSync(p, normalizedContent, { mode }); 471 | } 472 | async movePromise(fromP, toP) { 473 | try { 474 | await this.renamePromise(fromP, toP); 475 | } catch (error) { 476 | if (error.code === `EXDEV`) { 477 | await this.copyPromise(toP, fromP); 478 | await this.removePromise(fromP); 479 | } else { 480 | throw error; 481 | } 482 | } 483 | } 484 | moveSync(fromP, toP) { 485 | try { 486 | this.renameSync(fromP, toP); 487 | } catch (error) { 488 | if (error.code === `EXDEV`) { 489 | this.copySync(toP, fromP); 490 | this.removeSync(fromP); 491 | } else { 492 | throw error; 493 | } 494 | } 495 | } 496 | async lockPromise(affectedPath, callback) { 497 | const lockPath = `${affectedPath}.flock`; 498 | const interval = 1e3 / 60; 499 | const startTime = Date.now(); 500 | let fd = null; 501 | const isAlive = async () => { 502 | let pid; 503 | try { 504 | [pid] = await this.readJsonPromise(lockPath); 505 | } catch (error) { 506 | return Date.now() - startTime < 500; 507 | } 508 | try { 509 | process.kill(pid, 0); 510 | return true; 511 | } catch (error) { 512 | return false; 513 | } 514 | }; 515 | while (fd === null) { 516 | try { 517 | fd = await this.openPromise(lockPath, `wx`); 518 | } catch (error) { 519 | if (error.code === `EEXIST`) { 520 | if (!await isAlive()) { 521 | try { 522 | await this.unlinkPromise(lockPath); 523 | continue; 524 | } catch (error2) { 525 | } 526 | } 527 | if (Date.now() - startTime < 60 * 1e3) { 528 | await new Promise((resolve) => setTimeout(resolve, interval)); 529 | } else { 530 | throw new Error(`Couldn't acquire a lock in a reasonable time (via ${lockPath})`); 531 | } 532 | } else { 533 | throw error; 534 | } 535 | } 536 | } 537 | await this.writePromise(fd, JSON.stringify([process.pid])); 538 | try { 539 | return await callback(); 540 | } finally { 541 | try { 542 | await this.closePromise(fd); 543 | await this.unlinkPromise(lockPath); 544 | } catch (error) { 545 | } 546 | } 547 | } 548 | async readJsonPromise(p) { 549 | const content = await this.readFilePromise(p, `utf8`); 550 | try { 551 | return JSON.parse(content); 552 | } catch (error) { 553 | error.message += ` (in ${p})`; 554 | throw error; 555 | } 556 | } 557 | readJsonSync(p) { 558 | const content = this.readFileSync(p, `utf8`); 559 | try { 560 | return JSON.parse(content); 561 | } catch (error) { 562 | error.message += ` (in ${p})`; 563 | throw error; 564 | } 565 | } 566 | async writeJsonPromise(p, data) { 567 | return await this.writeFilePromise(p, `${JSON.stringify(data, null, 2)} 568 | `); 569 | } 570 | writeJsonSync(p, data) { 571 | return this.writeFileSync(p, `${JSON.stringify(data, null, 2)} 572 | `); 573 | } 574 | async preserveTimePromise(p, cb) { 575 | const stat = await this.lstatPromise(p); 576 | const result = await cb(); 577 | if (typeof result !== `undefined`) 578 | p = result; 579 | if (this.lutimesPromise) { 580 | await this.lutimesPromise(p, stat.atime, stat.mtime); 581 | } else if (!stat.isSymbolicLink()) { 582 | await this.utimesPromise(p, stat.atime, stat.mtime); 583 | } 584 | } 585 | async preserveTimeSync(p, cb) { 586 | const stat = this.lstatSync(p); 587 | const result = cb(); 588 | if (typeof result !== `undefined`) 589 | p = result; 590 | if (this.lutimesSync) { 591 | this.lutimesSync(p, stat.atime, stat.mtime); 592 | } else if (!stat.isSymbolicLink()) { 593 | this.utimesSync(p, stat.atime, stat.mtime); 594 | } 595 | } 596 | } 597 | class BasePortableFakeFS extends FakeFS { 598 | constructor() { 599 | super(ppath); 600 | } 601 | } 602 | function getEndOfLine(content) { 603 | const matches = content.match(/\r?\n/g); 604 | if (matches === null) 605 | return EOL; 606 | const crlf = matches.filter((nl) => nl === `\r 607 | `).length; 608 | const lf = matches.length - crlf; 609 | return crlf > lf ? `\r 610 | ` : ` 611 | `; 612 | } 613 | function normalizeLineEndings(originalContent, newContent) { 614 | return newContent.replace(/\r?\n/g, getEndOfLine(originalContent)); 615 | } 616 | 617 | class NodeFS extends BasePortableFakeFS { 618 | constructor(realFs = fs) { 619 | super(); 620 | this.realFs = realFs; 621 | if (typeof this.realFs.lutimes !== `undefined`) { 622 | this.lutimesPromise = this.lutimesPromiseImpl; 623 | this.lutimesSync = this.lutimesSyncImpl; 624 | } 625 | } 626 | getExtractHint() { 627 | return false; 628 | } 629 | getRealPath() { 630 | return PortablePath.root; 631 | } 632 | resolve(p) { 633 | return ppath.resolve(p); 634 | } 635 | async openPromise(p, flags, mode) { 636 | return await new Promise((resolve, reject) => { 637 | this.realFs.open(npath.fromPortablePath(p), flags, mode, this.makeCallback(resolve, reject)); 638 | }); 639 | } 640 | openSync(p, flags, mode) { 641 | return this.realFs.openSync(npath.fromPortablePath(p), flags, mode); 642 | } 643 | async opendirPromise(p, opts) { 644 | return await new Promise((resolve, reject) => { 645 | if (typeof opts !== `undefined`) { 646 | this.realFs.opendir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject)); 647 | } else { 648 | this.realFs.opendir(npath.fromPortablePath(p), this.makeCallback(resolve, reject)); 649 | } 650 | }).then((dir) => { 651 | return Object.defineProperty(dir, `path`, { value: p, configurable: true, writable: true }); 652 | }); 653 | } 654 | opendirSync(p, opts) { 655 | const dir = typeof opts !== `undefined` ? this.realFs.opendirSync(npath.fromPortablePath(p), opts) : this.realFs.opendirSync(npath.fromPortablePath(p)); 656 | return Object.defineProperty(dir, `path`, { value: p, configurable: true, writable: true }); 657 | } 658 | async readPromise(fd, buffer, offset = 0, length = 0, position = -1) { 659 | return await new Promise((resolve, reject) => { 660 | this.realFs.read(fd, buffer, offset, length, position, (error, bytesRead) => { 661 | if (error) { 662 | reject(error); 663 | } else { 664 | resolve(bytesRead); 665 | } 666 | }); 667 | }); 668 | } 669 | readSync(fd, buffer, offset, length, position) { 670 | return this.realFs.readSync(fd, buffer, offset, length, position); 671 | } 672 | async writePromise(fd, buffer, offset, length, position) { 673 | return await new Promise((resolve, reject) => { 674 | if (typeof buffer === `string`) { 675 | return this.realFs.write(fd, buffer, offset, this.makeCallback(resolve, reject)); 676 | } else { 677 | return this.realFs.write(fd, buffer, offset, length, position, this.makeCallback(resolve, reject)); 678 | } 679 | }); 680 | } 681 | writeSync(fd, buffer, offset, length, position) { 682 | if (typeof buffer === `string`) { 683 | return this.realFs.writeSync(fd, buffer, offset); 684 | } else { 685 | return this.realFs.writeSync(fd, buffer, offset, length, position); 686 | } 687 | } 688 | async closePromise(fd) { 689 | await new Promise((resolve, reject) => { 690 | this.realFs.close(fd, this.makeCallback(resolve, reject)); 691 | }); 692 | } 693 | closeSync(fd) { 694 | this.realFs.closeSync(fd); 695 | } 696 | createReadStream(p, opts) { 697 | const realPath = p !== null ? npath.fromPortablePath(p) : p; 698 | return this.realFs.createReadStream(realPath, opts); 699 | } 700 | createWriteStream(p, opts) { 701 | const realPath = p !== null ? npath.fromPortablePath(p) : p; 702 | return this.realFs.createWriteStream(realPath, opts); 703 | } 704 | async realpathPromise(p) { 705 | return await new Promise((resolve, reject) => { 706 | this.realFs.realpath(npath.fromPortablePath(p), {}, this.makeCallback(resolve, reject)); 707 | }).then((path) => { 708 | return npath.toPortablePath(path); 709 | }); 710 | } 711 | realpathSync(p) { 712 | return npath.toPortablePath(this.realFs.realpathSync(npath.fromPortablePath(p), {})); 713 | } 714 | async existsPromise(p) { 715 | return await new Promise((resolve) => { 716 | this.realFs.exists(npath.fromPortablePath(p), resolve); 717 | }); 718 | } 719 | accessSync(p, mode) { 720 | return this.realFs.accessSync(npath.fromPortablePath(p), mode); 721 | } 722 | async accessPromise(p, mode) { 723 | return await new Promise((resolve, reject) => { 724 | this.realFs.access(npath.fromPortablePath(p), mode, this.makeCallback(resolve, reject)); 725 | }); 726 | } 727 | existsSync(p) { 728 | return this.realFs.existsSync(npath.fromPortablePath(p)); 729 | } 730 | async statPromise(p, opts) { 731 | return await new Promise((resolve, reject) => { 732 | if (opts) { 733 | this.realFs.stat(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject)); 734 | } else { 735 | this.realFs.stat(npath.fromPortablePath(p), this.makeCallback(resolve, reject)); 736 | } 737 | }); 738 | } 739 | statSync(p, opts) { 740 | if (opts) { 741 | return this.realFs.statSync(npath.fromPortablePath(p), opts); 742 | } else { 743 | return this.realFs.statSync(npath.fromPortablePath(p)); 744 | } 745 | } 746 | async fstatPromise(fd, opts) { 747 | return await new Promise((resolve, reject) => { 748 | if (opts) { 749 | this.realFs.fstat(fd, opts, this.makeCallback(resolve, reject)); 750 | } else { 751 | this.realFs.fstat(fd, this.makeCallback(resolve, reject)); 752 | } 753 | }); 754 | } 755 | fstatSync(fd, opts) { 756 | if (opts) { 757 | return this.realFs.fstatSync(fd, opts); 758 | } else { 759 | return this.realFs.fstatSync(fd); 760 | } 761 | } 762 | async lstatPromise(p, opts) { 763 | return await new Promise((resolve, reject) => { 764 | if (opts) { 765 | this.realFs.lstat(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject)); 766 | } else { 767 | this.realFs.lstat(npath.fromPortablePath(p), this.makeCallback(resolve, reject)); 768 | } 769 | }); 770 | } 771 | lstatSync(p, opts) { 772 | if (opts) { 773 | return this.realFs.lstatSync(npath.fromPortablePath(p), opts); 774 | } else { 775 | return this.realFs.lstatSync(npath.fromPortablePath(p)); 776 | } 777 | } 778 | async fchmodPromise(fd, mask) { 779 | return await new Promise((resolve, reject) => { 780 | this.realFs.fchmod(fd, mask, this.makeCallback(resolve, reject)); 781 | }); 782 | } 783 | fchmodSync(fd, mask) { 784 | return this.realFs.fchmodSync(fd, mask); 785 | } 786 | async chmodPromise(p, mask) { 787 | return await new Promise((resolve, reject) => { 788 | this.realFs.chmod(npath.fromPortablePath(p), mask, this.makeCallback(resolve, reject)); 789 | }); 790 | } 791 | chmodSync(p, mask) { 792 | return this.realFs.chmodSync(npath.fromPortablePath(p), mask); 793 | } 794 | async fchownPromise(fd, uid, gid) { 795 | return await new Promise((resolve, reject) => { 796 | this.realFs.fchown(fd, uid, gid, this.makeCallback(resolve, reject)); 797 | }); 798 | } 799 | fchownSync(fd, uid, gid) { 800 | return this.realFs.fchownSync(fd, uid, gid); 801 | } 802 | async chownPromise(p, uid, gid) { 803 | return await new Promise((resolve, reject) => { 804 | this.realFs.chown(npath.fromPortablePath(p), uid, gid, this.makeCallback(resolve, reject)); 805 | }); 806 | } 807 | chownSync(p, uid, gid) { 808 | return this.realFs.chownSync(npath.fromPortablePath(p), uid, gid); 809 | } 810 | async renamePromise(oldP, newP) { 811 | return await new Promise((resolve, reject) => { 812 | this.realFs.rename(npath.fromPortablePath(oldP), npath.fromPortablePath(newP), this.makeCallback(resolve, reject)); 813 | }); 814 | } 815 | renameSync(oldP, newP) { 816 | return this.realFs.renameSync(npath.fromPortablePath(oldP), npath.fromPortablePath(newP)); 817 | } 818 | async copyFilePromise(sourceP, destP, flags = 0) { 819 | return await new Promise((resolve, reject) => { 820 | this.realFs.copyFile(npath.fromPortablePath(sourceP), npath.fromPortablePath(destP), flags, this.makeCallback(resolve, reject)); 821 | }); 822 | } 823 | copyFileSync(sourceP, destP, flags = 0) { 824 | return this.realFs.copyFileSync(npath.fromPortablePath(sourceP), npath.fromPortablePath(destP), flags); 825 | } 826 | async appendFilePromise(p, content, opts) { 827 | return await new Promise((resolve, reject) => { 828 | const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p; 829 | if (opts) { 830 | this.realFs.appendFile(fsNativePath, content, opts, this.makeCallback(resolve, reject)); 831 | } else { 832 | this.realFs.appendFile(fsNativePath, content, this.makeCallback(resolve, reject)); 833 | } 834 | }); 835 | } 836 | appendFileSync(p, content, opts) { 837 | const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p; 838 | if (opts) { 839 | this.realFs.appendFileSync(fsNativePath, content, opts); 840 | } else { 841 | this.realFs.appendFileSync(fsNativePath, content); 842 | } 843 | } 844 | async writeFilePromise(p, content, opts) { 845 | return await new Promise((resolve, reject) => { 846 | const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p; 847 | if (opts) { 848 | this.realFs.writeFile(fsNativePath, content, opts, this.makeCallback(resolve, reject)); 849 | } else { 850 | this.realFs.writeFile(fsNativePath, content, this.makeCallback(resolve, reject)); 851 | } 852 | }); 853 | } 854 | writeFileSync(p, content, opts) { 855 | const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p; 856 | if (opts) { 857 | this.realFs.writeFileSync(fsNativePath, content, opts); 858 | } else { 859 | this.realFs.writeFileSync(fsNativePath, content); 860 | } 861 | } 862 | async unlinkPromise(p) { 863 | return await new Promise((resolve, reject) => { 864 | this.realFs.unlink(npath.fromPortablePath(p), this.makeCallback(resolve, reject)); 865 | }); 866 | } 867 | unlinkSync(p) { 868 | return this.realFs.unlinkSync(npath.fromPortablePath(p)); 869 | } 870 | async utimesPromise(p, atime, mtime) { 871 | return await new Promise((resolve, reject) => { 872 | this.realFs.utimes(npath.fromPortablePath(p), atime, mtime, this.makeCallback(resolve, reject)); 873 | }); 874 | } 875 | utimesSync(p, atime, mtime) { 876 | this.realFs.utimesSync(npath.fromPortablePath(p), atime, mtime); 877 | } 878 | async lutimesPromiseImpl(p, atime, mtime) { 879 | const lutimes = this.realFs.lutimes; 880 | if (typeof lutimes === `undefined`) 881 | throw ENOSYS(`unavailable Node binding`, `lutimes '${p}'`); 882 | return await new Promise((resolve, reject) => { 883 | lutimes.call(this.realFs, npath.fromPortablePath(p), atime, mtime, this.makeCallback(resolve, reject)); 884 | }); 885 | } 886 | lutimesSyncImpl(p, atime, mtime) { 887 | const lutimesSync = this.realFs.lutimesSync; 888 | if (typeof lutimesSync === `undefined`) 889 | throw ENOSYS(`unavailable Node binding`, `lutimes '${p}'`); 890 | lutimesSync.call(this.realFs, npath.fromPortablePath(p), atime, mtime); 891 | } 892 | async mkdirPromise(p, opts) { 893 | return await new Promise((resolve, reject) => { 894 | this.realFs.mkdir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject)); 895 | }); 896 | } 897 | mkdirSync(p, opts) { 898 | return this.realFs.mkdirSync(npath.fromPortablePath(p), opts); 899 | } 900 | async rmdirPromise(p, opts) { 901 | return await new Promise((resolve, reject) => { 902 | if (opts) { 903 | this.realFs.rmdir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject)); 904 | } else { 905 | this.realFs.rmdir(npath.fromPortablePath(p), this.makeCallback(resolve, reject)); 906 | } 907 | }); 908 | } 909 | rmdirSync(p, opts) { 910 | return this.realFs.rmdirSync(npath.fromPortablePath(p), opts); 911 | } 912 | async linkPromise(existingP, newP) { 913 | return await new Promise((resolve, reject) => { 914 | this.realFs.link(npath.fromPortablePath(existingP), npath.fromPortablePath(newP), this.makeCallback(resolve, reject)); 915 | }); 916 | } 917 | linkSync(existingP, newP) { 918 | return this.realFs.linkSync(npath.fromPortablePath(existingP), npath.fromPortablePath(newP)); 919 | } 920 | async symlinkPromise(target, p, type) { 921 | return await new Promise((resolve, reject) => { 922 | this.realFs.symlink(npath.fromPortablePath(target.replace(/\/+$/, ``)), npath.fromPortablePath(p), type, this.makeCallback(resolve, reject)); 923 | }); 924 | } 925 | symlinkSync(target, p, type) { 926 | return this.realFs.symlinkSync(npath.fromPortablePath(target.replace(/\/+$/, ``)), npath.fromPortablePath(p), type); 927 | } 928 | async readFilePromise(p, encoding) { 929 | return await new Promise((resolve, reject) => { 930 | const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p; 931 | this.realFs.readFile(fsNativePath, encoding, this.makeCallback(resolve, reject)); 932 | }); 933 | } 934 | readFileSync(p, encoding) { 935 | const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p; 936 | return this.realFs.readFileSync(fsNativePath, encoding); 937 | } 938 | async readdirPromise(p, opts) { 939 | return await new Promise((resolve, reject) => { 940 | if (opts == null ? void 0 : opts.withFileTypes) { 941 | this.realFs.readdir(npath.fromPortablePath(p), { withFileTypes: true }, this.makeCallback(resolve, reject)); 942 | } else { 943 | this.realFs.readdir(npath.fromPortablePath(p), this.makeCallback((value) => resolve(value), reject)); 944 | } 945 | }); 946 | } 947 | readdirSync(p, opts) { 948 | if (opts == null ? void 0 : opts.withFileTypes) { 949 | return this.realFs.readdirSync(npath.fromPortablePath(p), { withFileTypes: true }); 950 | } else { 951 | return this.realFs.readdirSync(npath.fromPortablePath(p)); 952 | } 953 | } 954 | async readlinkPromise(p) { 955 | return await new Promise((resolve, reject) => { 956 | this.realFs.readlink(npath.fromPortablePath(p), this.makeCallback(resolve, reject)); 957 | }).then((path) => { 958 | return npath.toPortablePath(path); 959 | }); 960 | } 961 | readlinkSync(p) { 962 | return npath.toPortablePath(this.realFs.readlinkSync(npath.fromPortablePath(p))); 963 | } 964 | async truncatePromise(p, len) { 965 | return await new Promise((resolve, reject) => { 966 | this.realFs.truncate(npath.fromPortablePath(p), len, this.makeCallback(resolve, reject)); 967 | }); 968 | } 969 | truncateSync(p, len) { 970 | return this.realFs.truncateSync(npath.fromPortablePath(p), len); 971 | } 972 | async ftruncatePromise(fd, len) { 973 | return await new Promise((resolve, reject) => { 974 | this.realFs.ftruncate(fd, len, this.makeCallback(resolve, reject)); 975 | }); 976 | } 977 | ftruncateSync(fd, len) { 978 | return this.realFs.ftruncateSync(fd, len); 979 | } 980 | watch(p, a, b) { 981 | return this.realFs.watch( 982 | npath.fromPortablePath(p), 983 | a, 984 | b 985 | ); 986 | } 987 | watchFile(p, a, b) { 988 | return this.realFs.watchFile( 989 | npath.fromPortablePath(p), 990 | a, 991 | b 992 | ); 993 | } 994 | unwatchFile(p, cb) { 995 | return this.realFs.unwatchFile(npath.fromPortablePath(p), cb); 996 | } 997 | makeCallback(resolve, reject) { 998 | return (err, result) => { 999 | if (err) { 1000 | reject(err); 1001 | } else { 1002 | resolve(result); 1003 | } 1004 | }; 1005 | } 1006 | } 1007 | 1008 | class ProxiedFS extends FakeFS { 1009 | getExtractHint(hints) { 1010 | return this.baseFs.getExtractHint(hints); 1011 | } 1012 | resolve(path) { 1013 | return this.mapFromBase(this.baseFs.resolve(this.mapToBase(path))); 1014 | } 1015 | getRealPath() { 1016 | return this.mapFromBase(this.baseFs.getRealPath()); 1017 | } 1018 | async openPromise(p, flags, mode) { 1019 | return this.baseFs.openPromise(this.mapToBase(p), flags, mode); 1020 | } 1021 | openSync(p, flags, mode) { 1022 | return this.baseFs.openSync(this.mapToBase(p), flags, mode); 1023 | } 1024 | async opendirPromise(p, opts) { 1025 | return Object.assign(await this.baseFs.opendirPromise(this.mapToBase(p), opts), { path: p }); 1026 | } 1027 | opendirSync(p, opts) { 1028 | return Object.assign(this.baseFs.opendirSync(this.mapToBase(p), opts), { path: p }); 1029 | } 1030 | async readPromise(fd, buffer, offset, length, position) { 1031 | return await this.baseFs.readPromise(fd, buffer, offset, length, position); 1032 | } 1033 | readSync(fd, buffer, offset, length, position) { 1034 | return this.baseFs.readSync(fd, buffer, offset, length, position); 1035 | } 1036 | async writePromise(fd, buffer, offset, length, position) { 1037 | if (typeof buffer === `string`) { 1038 | return await this.baseFs.writePromise(fd, buffer, offset); 1039 | } else { 1040 | return await this.baseFs.writePromise(fd, buffer, offset, length, position); 1041 | } 1042 | } 1043 | writeSync(fd, buffer, offset, length, position) { 1044 | if (typeof buffer === `string`) { 1045 | return this.baseFs.writeSync(fd, buffer, offset); 1046 | } else { 1047 | return this.baseFs.writeSync(fd, buffer, offset, length, position); 1048 | } 1049 | } 1050 | async closePromise(fd) { 1051 | return this.baseFs.closePromise(fd); 1052 | } 1053 | closeSync(fd) { 1054 | this.baseFs.closeSync(fd); 1055 | } 1056 | createReadStream(p, opts) { 1057 | return this.baseFs.createReadStream(p !== null ? this.mapToBase(p) : p, opts); 1058 | } 1059 | createWriteStream(p, opts) { 1060 | return this.baseFs.createWriteStream(p !== null ? this.mapToBase(p) : p, opts); 1061 | } 1062 | async realpathPromise(p) { 1063 | return this.mapFromBase(await this.baseFs.realpathPromise(this.mapToBase(p))); 1064 | } 1065 | realpathSync(p) { 1066 | return this.mapFromBase(this.baseFs.realpathSync(this.mapToBase(p))); 1067 | } 1068 | async existsPromise(p) { 1069 | return this.baseFs.existsPromise(this.mapToBase(p)); 1070 | } 1071 | existsSync(p) { 1072 | return this.baseFs.existsSync(this.mapToBase(p)); 1073 | } 1074 | accessSync(p, mode) { 1075 | return this.baseFs.accessSync(this.mapToBase(p), mode); 1076 | } 1077 | async accessPromise(p, mode) { 1078 | return this.baseFs.accessPromise(this.mapToBase(p), mode); 1079 | } 1080 | async statPromise(p, opts) { 1081 | return this.baseFs.statPromise(this.mapToBase(p), opts); 1082 | } 1083 | statSync(p, opts) { 1084 | return this.baseFs.statSync(this.mapToBase(p), opts); 1085 | } 1086 | async fstatPromise(fd, opts) { 1087 | return this.baseFs.fstatPromise(fd, opts); 1088 | } 1089 | fstatSync(fd, opts) { 1090 | return this.baseFs.fstatSync(fd, opts); 1091 | } 1092 | lstatPromise(p, opts) { 1093 | return this.baseFs.lstatPromise(this.mapToBase(p), opts); 1094 | } 1095 | lstatSync(p, opts) { 1096 | return this.baseFs.lstatSync(this.mapToBase(p), opts); 1097 | } 1098 | async fchmodPromise(fd, mask) { 1099 | return this.baseFs.fchmodPromise(fd, mask); 1100 | } 1101 | fchmodSync(fd, mask) { 1102 | return this.baseFs.fchmodSync(fd, mask); 1103 | } 1104 | async chmodPromise(p, mask) { 1105 | return this.baseFs.chmodPromise(this.mapToBase(p), mask); 1106 | } 1107 | chmodSync(p, mask) { 1108 | return this.baseFs.chmodSync(this.mapToBase(p), mask); 1109 | } 1110 | async fchownPromise(fd, uid, gid) { 1111 | return this.baseFs.fchownPromise(fd, uid, gid); 1112 | } 1113 | fchownSync(fd, uid, gid) { 1114 | return this.baseFs.fchownSync(fd, uid, gid); 1115 | } 1116 | async chownPromise(p, uid, gid) { 1117 | return this.baseFs.chownPromise(this.mapToBase(p), uid, gid); 1118 | } 1119 | chownSync(p, uid, gid) { 1120 | return this.baseFs.chownSync(this.mapToBase(p), uid, gid); 1121 | } 1122 | async renamePromise(oldP, newP) { 1123 | return this.baseFs.renamePromise(this.mapToBase(oldP), this.mapToBase(newP)); 1124 | } 1125 | renameSync(oldP, newP) { 1126 | return this.baseFs.renameSync(this.mapToBase(oldP), this.mapToBase(newP)); 1127 | } 1128 | async copyFilePromise(sourceP, destP, flags = 0) { 1129 | return this.baseFs.copyFilePromise(this.mapToBase(sourceP), this.mapToBase(destP), flags); 1130 | } 1131 | copyFileSync(sourceP, destP, flags = 0) { 1132 | return this.baseFs.copyFileSync(this.mapToBase(sourceP), this.mapToBase(destP), flags); 1133 | } 1134 | async appendFilePromise(p, content, opts) { 1135 | return this.baseFs.appendFilePromise(this.fsMapToBase(p), content, opts); 1136 | } 1137 | appendFileSync(p, content, opts) { 1138 | return this.baseFs.appendFileSync(this.fsMapToBase(p), content, opts); 1139 | } 1140 | async writeFilePromise(p, content, opts) { 1141 | return this.baseFs.writeFilePromise(this.fsMapToBase(p), content, opts); 1142 | } 1143 | writeFileSync(p, content, opts) { 1144 | return this.baseFs.writeFileSync(this.fsMapToBase(p), content, opts); 1145 | } 1146 | async unlinkPromise(p) { 1147 | return this.baseFs.unlinkPromise(this.mapToBase(p)); 1148 | } 1149 | unlinkSync(p) { 1150 | return this.baseFs.unlinkSync(this.mapToBase(p)); 1151 | } 1152 | async utimesPromise(p, atime, mtime) { 1153 | return this.baseFs.utimesPromise(this.mapToBase(p), atime, mtime); 1154 | } 1155 | utimesSync(p, atime, mtime) { 1156 | return this.baseFs.utimesSync(this.mapToBase(p), atime, mtime); 1157 | } 1158 | async mkdirPromise(p, opts) { 1159 | return this.baseFs.mkdirPromise(this.mapToBase(p), opts); 1160 | } 1161 | mkdirSync(p, opts) { 1162 | return this.baseFs.mkdirSync(this.mapToBase(p), opts); 1163 | } 1164 | async rmdirPromise(p, opts) { 1165 | return this.baseFs.rmdirPromise(this.mapToBase(p), opts); 1166 | } 1167 | rmdirSync(p, opts) { 1168 | return this.baseFs.rmdirSync(this.mapToBase(p), opts); 1169 | } 1170 | async linkPromise(existingP, newP) { 1171 | return this.baseFs.linkPromise(this.mapToBase(existingP), this.mapToBase(newP)); 1172 | } 1173 | linkSync(existingP, newP) { 1174 | return this.baseFs.linkSync(this.mapToBase(existingP), this.mapToBase(newP)); 1175 | } 1176 | async symlinkPromise(target, p, type) { 1177 | const mappedP = this.mapToBase(p); 1178 | if (this.pathUtils.isAbsolute(target)) 1179 | return this.baseFs.symlinkPromise(this.mapToBase(target), mappedP, type); 1180 | const mappedAbsoluteTarget = this.mapToBase(this.pathUtils.join(this.pathUtils.dirname(p), target)); 1181 | const mappedTarget = this.baseFs.pathUtils.relative(this.baseFs.pathUtils.dirname(mappedP), mappedAbsoluteTarget); 1182 | return this.baseFs.symlinkPromise(mappedTarget, mappedP, type); 1183 | } 1184 | symlinkSync(target, p, type) { 1185 | const mappedP = this.mapToBase(p); 1186 | if (this.pathUtils.isAbsolute(target)) 1187 | return this.baseFs.symlinkSync(this.mapToBase(target), mappedP, type); 1188 | const mappedAbsoluteTarget = this.mapToBase(this.pathUtils.join(this.pathUtils.dirname(p), target)); 1189 | const mappedTarget = this.baseFs.pathUtils.relative(this.baseFs.pathUtils.dirname(mappedP), mappedAbsoluteTarget); 1190 | return this.baseFs.symlinkSync(mappedTarget, mappedP, type); 1191 | } 1192 | async readFilePromise(p, encoding) { 1193 | if (encoding === `utf8`) { 1194 | return this.baseFs.readFilePromise(this.fsMapToBase(p), encoding); 1195 | } else { 1196 | return this.baseFs.readFilePromise(this.fsMapToBase(p), encoding); 1197 | } 1198 | } 1199 | readFileSync(p, encoding) { 1200 | if (encoding === `utf8`) { 1201 | return this.baseFs.readFileSync(this.fsMapToBase(p), encoding); 1202 | } else { 1203 | return this.baseFs.readFileSync(this.fsMapToBase(p), encoding); 1204 | } 1205 | } 1206 | async readdirPromise(p, opts) { 1207 | return this.baseFs.readdirPromise(this.mapToBase(p), opts); 1208 | } 1209 | readdirSync(p, opts) { 1210 | return this.baseFs.readdirSync(this.mapToBase(p), opts); 1211 | } 1212 | async readlinkPromise(p) { 1213 | return this.mapFromBase(await this.baseFs.readlinkPromise(this.mapToBase(p))); 1214 | } 1215 | readlinkSync(p) { 1216 | return this.mapFromBase(this.baseFs.readlinkSync(this.mapToBase(p))); 1217 | } 1218 | async truncatePromise(p, len) { 1219 | return this.baseFs.truncatePromise(this.mapToBase(p), len); 1220 | } 1221 | truncateSync(p, len) { 1222 | return this.baseFs.truncateSync(this.mapToBase(p), len); 1223 | } 1224 | async ftruncatePromise(fd, len) { 1225 | return this.baseFs.ftruncatePromise(fd, len); 1226 | } 1227 | ftruncateSync(fd, len) { 1228 | return this.baseFs.ftruncateSync(fd, len); 1229 | } 1230 | watch(p, a, b) { 1231 | return this.baseFs.watch( 1232 | this.mapToBase(p), 1233 | a, 1234 | b 1235 | ); 1236 | } 1237 | watchFile(p, a, b) { 1238 | return this.baseFs.watchFile( 1239 | this.mapToBase(p), 1240 | a, 1241 | b 1242 | ); 1243 | } 1244 | unwatchFile(p, cb) { 1245 | return this.baseFs.unwatchFile(this.mapToBase(p), cb); 1246 | } 1247 | fsMapToBase(p) { 1248 | if (typeof p === `number`) { 1249 | return p; 1250 | } else { 1251 | return this.mapToBase(p); 1252 | } 1253 | } 1254 | } 1255 | 1256 | const NUMBER_REGEXP = /^[0-9]+$/; 1257 | const VIRTUAL_REGEXP = /^(\/(?:[^/]+\/)*?(?:\$\$virtual|__virtual__))((?:\/((?:[^/]+-)?[a-f0-9]+)(?:\/([^/]+))?)?((?:\/.*)?))$/; 1258 | const VALID_COMPONENT = /^([^/]+-)?[a-f0-9]+$/; 1259 | class VirtualFS extends ProxiedFS { 1260 | constructor({ baseFs = new NodeFS() } = {}) { 1261 | super(ppath); 1262 | this.baseFs = baseFs; 1263 | } 1264 | static makeVirtualPath(base, component, to) { 1265 | if (ppath.basename(base) !== `__virtual__`) 1266 | throw new Error(`Assertion failed: Virtual folders must be named "__virtual__"`); 1267 | if (!ppath.basename(component).match(VALID_COMPONENT)) 1268 | throw new Error(`Assertion failed: Virtual components must be ended by an hexadecimal hash`); 1269 | const target = ppath.relative(ppath.dirname(base), to); 1270 | const segments = target.split(`/`); 1271 | let depth = 0; 1272 | while (depth < segments.length && segments[depth] === `..`) 1273 | depth += 1; 1274 | const finalSegments = segments.slice(depth); 1275 | const fullVirtualPath = ppath.join(base, component, String(depth), ...finalSegments); 1276 | return fullVirtualPath; 1277 | } 1278 | static resolveVirtual(p) { 1279 | const match = p.match(VIRTUAL_REGEXP); 1280 | if (!match || !match[3] && match[5]) 1281 | return p; 1282 | const target = ppath.dirname(match[1]); 1283 | if (!match[3] || !match[4]) 1284 | return target; 1285 | const isnum = NUMBER_REGEXP.test(match[4]); 1286 | if (!isnum) 1287 | return p; 1288 | const depth = Number(match[4]); 1289 | const backstep = `../`.repeat(depth); 1290 | const subpath = match[5] || `.`; 1291 | return VirtualFS.resolveVirtual(ppath.join(target, backstep, subpath)); 1292 | } 1293 | getExtractHint(hints) { 1294 | return this.baseFs.getExtractHint(hints); 1295 | } 1296 | getRealPath() { 1297 | return this.baseFs.getRealPath(); 1298 | } 1299 | realpathSync(p) { 1300 | const match = p.match(VIRTUAL_REGEXP); 1301 | if (!match) 1302 | return this.baseFs.realpathSync(p); 1303 | if (!match[5]) 1304 | return p; 1305 | const realpath = this.baseFs.realpathSync(this.mapToBase(p)); 1306 | return VirtualFS.makeVirtualPath(match[1], match[3], realpath); 1307 | } 1308 | async realpathPromise(p) { 1309 | const match = p.match(VIRTUAL_REGEXP); 1310 | if (!match) 1311 | return await this.baseFs.realpathPromise(p); 1312 | if (!match[5]) 1313 | return p; 1314 | const realpath = await this.baseFs.realpathPromise(this.mapToBase(p)); 1315 | return VirtualFS.makeVirtualPath(match[1], match[3], realpath); 1316 | } 1317 | mapToBase(p) { 1318 | if (p === ``) 1319 | return p; 1320 | if (this.pathUtils.isAbsolute(p)) 1321 | return VirtualFS.resolveVirtual(p); 1322 | const resolvedRoot = VirtualFS.resolveVirtual(this.baseFs.resolve(PortablePath.dot)); 1323 | const resolvedP = VirtualFS.resolveVirtual(this.baseFs.resolve(p)); 1324 | return ppath.relative(resolvedRoot, resolvedP) || PortablePath.dot; 1325 | } 1326 | mapFromBase(p) { 1327 | return p; 1328 | } 1329 | } 1330 | 1331 | const [major, minor] = process.versions.node.split(`.`).map((value) => parseInt(value, 10)); 1332 | const HAS_CONSOLIDATED_HOOKS = major > 16 || major === 16 && minor >= 12; 1333 | const HAS_UNFLAGGED_JSON_MODULES = major > 17 || major === 17 && minor >= 5 || major === 16 && minor >= 15; 1334 | const HAS_JSON_IMPORT_ASSERTION_REQUIREMENT = major > 17 || major === 17 && minor >= 1 || major === 16 && minor > 14; 1335 | const WATCH_MODE_MESSAGE_USES_ARRAYS = major > 19 || major === 19 && minor >= 2 || major === 18 && minor >= 13; 1336 | const HAS_LAZY_LOADED_TRANSLATORS = major > 19 || major === 19 && minor >= 3; 1337 | 1338 | const builtinModules = new Set(Module.builtinModules || Object.keys(process.binding(`natives`))); 1339 | const isBuiltinModule = (request) => request.startsWith(`node:`) || builtinModules.has(request); 1340 | function readPackageScope(checkPath) { 1341 | const rootSeparatorIndex = checkPath.indexOf(npath.sep); 1342 | let separatorIndex; 1343 | do { 1344 | separatorIndex = checkPath.lastIndexOf(npath.sep); 1345 | checkPath = checkPath.slice(0, separatorIndex); 1346 | if (checkPath.endsWith(`${npath.sep}node_modules`)) 1347 | return false; 1348 | const pjson = readPackage(checkPath + npath.sep); 1349 | if (pjson) { 1350 | return { 1351 | data: pjson, 1352 | path: checkPath 1353 | }; 1354 | } 1355 | } while (separatorIndex > rootSeparatorIndex); 1356 | return false; 1357 | } 1358 | function readPackage(requestPath) { 1359 | const jsonPath = npath.resolve(requestPath, `package.json`); 1360 | if (!fs.existsSync(jsonPath)) 1361 | return null; 1362 | return JSON.parse(fs.readFileSync(jsonPath, `utf8`)); 1363 | } 1364 | 1365 | async function tryReadFile$1(path2) { 1366 | try { 1367 | return await fs.promises.readFile(path2, `utf8`); 1368 | } catch (error) { 1369 | if (error.code === `ENOENT`) 1370 | return null; 1371 | throw error; 1372 | } 1373 | } 1374 | function tryParseURL(str, base) { 1375 | try { 1376 | return new URL$1(str, base); 1377 | } catch { 1378 | return null; 1379 | } 1380 | } 1381 | let entrypointPath = null; 1382 | function setEntrypointPath(file) { 1383 | entrypointPath = file; 1384 | } 1385 | function getFileFormat(filepath) { 1386 | var _a, _b; 1387 | const ext = path.extname(filepath); 1388 | switch (ext) { 1389 | case `.mjs`: { 1390 | return `module`; 1391 | } 1392 | case `.cjs`: { 1393 | return `commonjs`; 1394 | } 1395 | case `.wasm`: { 1396 | throw new Error( 1397 | `Unknown file extension ".wasm" for ${filepath}` 1398 | ); 1399 | } 1400 | case `.json`: { 1401 | if (HAS_UNFLAGGED_JSON_MODULES) 1402 | return `json`; 1403 | throw new Error( 1404 | `Unknown file extension ".json" for ${filepath}` 1405 | ); 1406 | } 1407 | case `.js`: { 1408 | const pkg = readPackageScope(filepath); 1409 | if (!pkg) 1410 | return `commonjs`; 1411 | return (_a = pkg.data.type) != null ? _a : `commonjs`; 1412 | } 1413 | default: { 1414 | if (entrypointPath !== filepath) 1415 | return null; 1416 | const pkg = readPackageScope(filepath); 1417 | if (!pkg) 1418 | return `commonjs`; 1419 | if (pkg.data.type === `module`) 1420 | return null; 1421 | return (_b = pkg.data.type) != null ? _b : `commonjs`; 1422 | } 1423 | } 1424 | } 1425 | 1426 | async function getFormat$1(resolved, context, defaultGetFormat) { 1427 | const url = tryParseURL(resolved); 1428 | if ((url == null ? void 0 : url.protocol) !== `file:`) 1429 | return defaultGetFormat(resolved, context, defaultGetFormat); 1430 | const format = getFileFormat(fileURLToPath(url)); 1431 | if (format) { 1432 | return { 1433 | format 1434 | }; 1435 | } 1436 | return defaultGetFormat(resolved, context, defaultGetFormat); 1437 | } 1438 | 1439 | async function getSource$1(urlString, context, defaultGetSource) { 1440 | const url = tryParseURL(urlString); 1441 | if ((url == null ? void 0 : url.protocol) !== `file:`) 1442 | return defaultGetSource(urlString, context, defaultGetSource); 1443 | return { 1444 | source: await fs.promises.readFile(fileURLToPath(url), `utf8`) 1445 | }; 1446 | } 1447 | 1448 | async function load$1(urlString, context, nextLoad) { 1449 | var _a; 1450 | const url = tryParseURL(urlString); 1451 | if ((url == null ? void 0 : url.protocol) !== `file:`) 1452 | return nextLoad(urlString, context, nextLoad); 1453 | const filePath = fileURLToPath(url); 1454 | const format = getFileFormat(filePath); 1455 | if (!format) 1456 | return nextLoad(urlString, context, nextLoad); 1457 | if (HAS_JSON_IMPORT_ASSERTION_REQUIREMENT && format === `json` && ((_a = context.importAssertions) == null ? void 0 : _a.type) !== `json`) { 1458 | const err = new TypeError(`[ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "${urlString}" needs an import assertion of type "json"`); 1459 | err.code = `ERR_IMPORT_ASSERTION_TYPE_MISSING`; 1460 | throw err; 1461 | } 1462 | if (process.env.WATCH_REPORT_DEPENDENCIES && process.send) { 1463 | const pathToSend = pathToFileURL( 1464 | npath.fromPortablePath( 1465 | VirtualFS.resolveVirtual(npath.toPortablePath(filePath)) 1466 | ) 1467 | ).href; 1468 | process.send({ 1469 | "watch:import": WATCH_MODE_MESSAGE_USES_ARRAYS ? [pathToSend] : pathToSend 1470 | }); 1471 | } 1472 | return { 1473 | format, 1474 | source: await fs.promises.readFile(filePath, `utf8`), 1475 | shortCircuit: true 1476 | }; 1477 | } 1478 | 1479 | const ArrayIsArray = Array.isArray; 1480 | const JSONStringify = JSON.stringify; 1481 | const ObjectGetOwnPropertyNames = Object.getOwnPropertyNames; 1482 | const ObjectPrototypeHasOwnProperty = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop); 1483 | const RegExpPrototypeExec = (obj, string) => RegExp.prototype.exec.call(obj, string); 1484 | const RegExpPrototypeSymbolReplace = (obj, ...rest) => RegExp.prototype[Symbol.replace].apply(obj, rest); 1485 | const StringPrototypeEndsWith = (str, ...rest) => String.prototype.endsWith.apply(str, rest); 1486 | const StringPrototypeIncludes = (str, ...rest) => String.prototype.includes.apply(str, rest); 1487 | const StringPrototypeLastIndexOf = (str, ...rest) => String.prototype.lastIndexOf.apply(str, rest); 1488 | const StringPrototypeIndexOf = (str, ...rest) => String.prototype.indexOf.apply(str, rest); 1489 | const StringPrototypeReplace = (str, ...rest) => String.prototype.replace.apply(str, rest); 1490 | const StringPrototypeSlice = (str, ...rest) => String.prototype.slice.apply(str, rest); 1491 | const StringPrototypeStartsWith = (str, ...rest) => String.prototype.startsWith.apply(str, rest); 1492 | const SafeMap = Map; 1493 | const JSONParse = JSON.parse; 1494 | 1495 | function createErrorType(code, messageCreator, errorType) { 1496 | return class extends errorType { 1497 | constructor(...args) { 1498 | super(messageCreator(...args)); 1499 | this.code = code; 1500 | this.name = `${errorType.name} [${code}]`; 1501 | } 1502 | }; 1503 | } 1504 | const ERR_PACKAGE_IMPORT_NOT_DEFINED = createErrorType( 1505 | `ERR_PACKAGE_IMPORT_NOT_DEFINED`, 1506 | (specifier, packagePath, base) => { 1507 | return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ``} imported from ${base}`; 1508 | }, 1509 | TypeError 1510 | ); 1511 | const ERR_INVALID_MODULE_SPECIFIER = createErrorType( 1512 | `ERR_INVALID_MODULE_SPECIFIER`, 1513 | (request, reason, base = void 0) => { 1514 | return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ``}`; 1515 | }, 1516 | TypeError 1517 | ); 1518 | const ERR_INVALID_PACKAGE_TARGET = createErrorType( 1519 | `ERR_INVALID_PACKAGE_TARGET`, 1520 | (pkgPath, key, target, isImport = false, base = void 0) => { 1521 | const relError = typeof target === `string` && !isImport && target.length && !StringPrototypeStartsWith(target, `./`); 1522 | if (key === `.`) { 1523 | assert(isImport === false); 1524 | return `Invalid "exports" main target ${JSONStringify(target)} defined in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ``}${relError ? `; targets must start with "./"` : ``}`; 1525 | } 1526 | return `Invalid "${isImport ? `imports` : `exports`}" target ${JSONStringify( 1527 | target 1528 | )} defined for '${key}' in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ``}${relError ? `; targets must start with "./"` : ``}`; 1529 | }, 1530 | Error 1531 | ); 1532 | const ERR_INVALID_PACKAGE_CONFIG = createErrorType( 1533 | `ERR_INVALID_PACKAGE_CONFIG`, 1534 | (path, base, message) => { 1535 | return `Invalid package config ${path}${base ? ` while importing ${base}` : ``}${message ? `. ${message}` : ``}`; 1536 | }, 1537 | Error 1538 | ); 1539 | 1540 | function filterOwnProperties(source, keys) { 1541 | const filtered = /* @__PURE__ */ Object.create(null); 1542 | for (let i = 0; i < keys.length; i++) { 1543 | const key = keys[i]; 1544 | if (ObjectPrototypeHasOwnProperty(source, key)) { 1545 | filtered[key] = source[key]; 1546 | } 1547 | } 1548 | return filtered; 1549 | } 1550 | 1551 | const packageJSONCache = new SafeMap(); 1552 | function getPackageConfig(path, specifier, base, readFileSyncFn) { 1553 | const existing = packageJSONCache.get(path); 1554 | if (existing !== void 0) { 1555 | return existing; 1556 | } 1557 | const source = readFileSyncFn(path); 1558 | if (source === void 0) { 1559 | const packageConfig2 = { 1560 | pjsonPath: path, 1561 | exists: false, 1562 | main: void 0, 1563 | name: void 0, 1564 | type: "none", 1565 | exports: void 0, 1566 | imports: void 0 1567 | }; 1568 | packageJSONCache.set(path, packageConfig2); 1569 | return packageConfig2; 1570 | } 1571 | let packageJSON; 1572 | try { 1573 | packageJSON = JSONParse(source); 1574 | } catch (error) { 1575 | throw new ERR_INVALID_PACKAGE_CONFIG( 1576 | path, 1577 | (base ? `"${specifier}" from ` : "") + fileURLToPath(base || specifier), 1578 | error.message 1579 | ); 1580 | } 1581 | let { imports, main, name, type } = filterOwnProperties(packageJSON, [ 1582 | "imports", 1583 | "main", 1584 | "name", 1585 | "type" 1586 | ]); 1587 | const exports = ObjectPrototypeHasOwnProperty(packageJSON, "exports") ? packageJSON.exports : void 0; 1588 | if (typeof imports !== "object" || imports === null) { 1589 | imports = void 0; 1590 | } 1591 | if (typeof main !== "string") { 1592 | main = void 0; 1593 | } 1594 | if (typeof name !== "string") { 1595 | name = void 0; 1596 | } 1597 | if (type !== "module" && type !== "commonjs") { 1598 | type = "none"; 1599 | } 1600 | const packageConfig = { 1601 | pjsonPath: path, 1602 | exists: true, 1603 | main, 1604 | name, 1605 | type, 1606 | exports, 1607 | imports 1608 | }; 1609 | packageJSONCache.set(path, packageConfig); 1610 | return packageConfig; 1611 | } 1612 | function getPackageScopeConfig(resolved, readFileSyncFn) { 1613 | let packageJSONUrl = new URL("./package.json", resolved); 1614 | while (true) { 1615 | const packageJSONPath2 = packageJSONUrl.pathname; 1616 | if (StringPrototypeEndsWith(packageJSONPath2, "node_modules/package.json")) { 1617 | break; 1618 | } 1619 | const packageConfig2 = getPackageConfig( 1620 | fileURLToPath(packageJSONUrl), 1621 | resolved, 1622 | void 0, 1623 | readFileSyncFn 1624 | ); 1625 | if (packageConfig2.exists) { 1626 | return packageConfig2; 1627 | } 1628 | const lastPackageJSONUrl = packageJSONUrl; 1629 | packageJSONUrl = new URL("../package.json", packageJSONUrl); 1630 | if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) { 1631 | break; 1632 | } 1633 | } 1634 | const packageJSONPath = fileURLToPath(packageJSONUrl); 1635 | const packageConfig = { 1636 | pjsonPath: packageJSONPath, 1637 | exists: false, 1638 | main: void 0, 1639 | name: void 0, 1640 | type: "none", 1641 | exports: void 0, 1642 | imports: void 0 1643 | }; 1644 | packageJSONCache.set(packageJSONPath, packageConfig); 1645 | return packageConfig; 1646 | } 1647 | 1648 | /** 1649 | @license 1650 | Copyright Node.js contributors. All rights reserved. 1651 | 1652 | Permission is hereby granted, free of charge, to any person obtaining a copy 1653 | of this software and associated documentation files (the "Software"), to 1654 | deal in the Software without restriction, including without limitation the 1655 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1656 | sell copies of the Software, and to permit persons to whom the Software is 1657 | furnished to do so, subject to the following conditions: 1658 | 1659 | The above copyright notice and this permission notice shall be included in 1660 | all copies or substantial portions of the Software. 1661 | 1662 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1663 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1664 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1665 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1666 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 1667 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 1668 | IN THE SOFTWARE. 1669 | */ 1670 | function throwImportNotDefined(specifier, packageJSONUrl, base) { 1671 | throw new ERR_PACKAGE_IMPORT_NOT_DEFINED( 1672 | specifier, 1673 | packageJSONUrl && fileURLToPath(new URL(".", packageJSONUrl)), 1674 | fileURLToPath(base) 1675 | ); 1676 | } 1677 | function throwInvalidSubpath(subpath, packageJSONUrl, internal, base) { 1678 | const reason = `request is not a valid subpath for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath(packageJSONUrl)}`; 1679 | throw new ERR_INVALID_MODULE_SPECIFIER( 1680 | subpath, 1681 | reason, 1682 | base && fileURLToPath(base) 1683 | ); 1684 | } 1685 | function throwInvalidPackageTarget(subpath, target, packageJSONUrl, internal, base) { 1686 | if (typeof target === "object" && target !== null) { 1687 | target = JSONStringify(target, null, ""); 1688 | } else { 1689 | target = `${target}`; 1690 | } 1691 | throw new ERR_INVALID_PACKAGE_TARGET( 1692 | fileURLToPath(new URL(".", packageJSONUrl)), 1693 | subpath, 1694 | target, 1695 | internal, 1696 | base && fileURLToPath(base) 1697 | ); 1698 | } 1699 | const invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i; 1700 | const patternRegEx = /\*/g; 1701 | function resolvePackageTargetString(target, subpath, match, packageJSONUrl, base, pattern, internal, conditions) { 1702 | if (subpath !== "" && !pattern && target[target.length - 1] !== "/") 1703 | throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base); 1704 | if (!StringPrototypeStartsWith(target, "./")) { 1705 | if (internal && !StringPrototypeStartsWith(target, "../") && !StringPrototypeStartsWith(target, "/")) { 1706 | let isURL = false; 1707 | try { 1708 | new URL(target); 1709 | isURL = true; 1710 | } catch { 1711 | } 1712 | if (!isURL) { 1713 | const exportTarget = pattern ? RegExpPrototypeSymbolReplace(patternRegEx, target, () => subpath) : target + subpath; 1714 | return exportTarget; 1715 | } 1716 | } 1717 | throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base); 1718 | } 1719 | if (RegExpPrototypeExec( 1720 | invalidSegmentRegEx, 1721 | StringPrototypeSlice(target, 2) 1722 | ) !== null) 1723 | throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base); 1724 | const resolved = new URL(target, packageJSONUrl); 1725 | const resolvedPath = resolved.pathname; 1726 | const packagePath = new URL(".", packageJSONUrl).pathname; 1727 | if (!StringPrototypeStartsWith(resolvedPath, packagePath)) 1728 | throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base); 1729 | if (subpath === "") 1730 | return resolved; 1731 | if (RegExpPrototypeExec(invalidSegmentRegEx, subpath) !== null) { 1732 | const request = pattern ? StringPrototypeReplace(match, "*", () => subpath) : match + subpath; 1733 | throwInvalidSubpath(request, packageJSONUrl, internal, base); 1734 | } 1735 | if (pattern) { 1736 | return new URL( 1737 | RegExpPrototypeSymbolReplace(patternRegEx, resolved.href, () => subpath) 1738 | ); 1739 | } 1740 | return new URL(subpath, resolved); 1741 | } 1742 | function isArrayIndex(key) { 1743 | const keyNum = +key; 1744 | if (`${keyNum}` !== key) 1745 | return false; 1746 | return keyNum >= 0 && keyNum < 4294967295; 1747 | } 1748 | function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath, base, pattern, internal, conditions) { 1749 | if (typeof target === "string") { 1750 | return resolvePackageTargetString( 1751 | target, 1752 | subpath, 1753 | packageSubpath, 1754 | packageJSONUrl, 1755 | base, 1756 | pattern, 1757 | internal); 1758 | } else if (ArrayIsArray(target)) { 1759 | if (target.length === 0) { 1760 | return null; 1761 | } 1762 | let lastException; 1763 | for (let i = 0; i < target.length; i++) { 1764 | const targetItem = target[i]; 1765 | let resolveResult; 1766 | try { 1767 | resolveResult = resolvePackageTarget( 1768 | packageJSONUrl, 1769 | targetItem, 1770 | subpath, 1771 | packageSubpath, 1772 | base, 1773 | pattern, 1774 | internal, 1775 | conditions 1776 | ); 1777 | } catch (e) { 1778 | lastException = e; 1779 | if (e.code === "ERR_INVALID_PACKAGE_TARGET") { 1780 | continue; 1781 | } 1782 | throw e; 1783 | } 1784 | if (resolveResult === void 0) { 1785 | continue; 1786 | } 1787 | if (resolveResult === null) { 1788 | lastException = null; 1789 | continue; 1790 | } 1791 | return resolveResult; 1792 | } 1793 | if (lastException === void 0 || lastException === null) 1794 | return lastException; 1795 | throw lastException; 1796 | } else if (typeof target === "object" && target !== null) { 1797 | const keys = ObjectGetOwnPropertyNames(target); 1798 | for (let i = 0; i < keys.length; i++) { 1799 | const key = keys[i]; 1800 | if (isArrayIndex(key)) { 1801 | throw new ERR_INVALID_PACKAGE_CONFIG( 1802 | fileURLToPath(packageJSONUrl), 1803 | base, 1804 | '"exports" cannot contain numeric property keys.' 1805 | ); 1806 | } 1807 | } 1808 | for (let i = 0; i < keys.length; i++) { 1809 | const key = keys[i]; 1810 | if (key === "default" || conditions.has(key)) { 1811 | const conditionalTarget = target[key]; 1812 | const resolveResult = resolvePackageTarget( 1813 | packageJSONUrl, 1814 | conditionalTarget, 1815 | subpath, 1816 | packageSubpath, 1817 | base, 1818 | pattern, 1819 | internal, 1820 | conditions 1821 | ); 1822 | if (resolveResult === void 0) 1823 | continue; 1824 | return resolveResult; 1825 | } 1826 | } 1827 | return void 0; 1828 | } else if (target === null) { 1829 | return null; 1830 | } 1831 | throwInvalidPackageTarget( 1832 | packageSubpath, 1833 | target, 1834 | packageJSONUrl, 1835 | internal, 1836 | base 1837 | ); 1838 | } 1839 | function patternKeyCompare(a, b) { 1840 | const aPatternIndex = StringPrototypeIndexOf(a, "*"); 1841 | const bPatternIndex = StringPrototypeIndexOf(b, "*"); 1842 | const baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1; 1843 | const baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1; 1844 | if (baseLenA > baseLenB) 1845 | return -1; 1846 | if (baseLenB > baseLenA) 1847 | return 1; 1848 | if (aPatternIndex === -1) 1849 | return 1; 1850 | if (bPatternIndex === -1) 1851 | return -1; 1852 | if (a.length > b.length) 1853 | return -1; 1854 | if (b.length > a.length) 1855 | return 1; 1856 | return 0; 1857 | } 1858 | function packageImportsResolve({ name, base, conditions, readFileSyncFn }) { 1859 | if (name === "#" || StringPrototypeStartsWith(name, "#/") || StringPrototypeEndsWith(name, "/")) { 1860 | const reason = "is not a valid internal imports specifier name"; 1861 | throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath(base)); 1862 | } 1863 | let packageJSONUrl; 1864 | const packageConfig = getPackageScopeConfig(base, readFileSyncFn); 1865 | if (packageConfig.exists) { 1866 | packageJSONUrl = pathToFileURL(packageConfig.pjsonPath); 1867 | const imports = packageConfig.imports; 1868 | if (imports) { 1869 | if (ObjectPrototypeHasOwnProperty(imports, name) && !StringPrototypeIncludes(name, "*")) { 1870 | const resolveResult = resolvePackageTarget( 1871 | packageJSONUrl, 1872 | imports[name], 1873 | "", 1874 | name, 1875 | base, 1876 | false, 1877 | true, 1878 | conditions 1879 | ); 1880 | if (resolveResult != null) { 1881 | return resolveResult; 1882 | } 1883 | } else { 1884 | let bestMatch = ""; 1885 | let bestMatchSubpath; 1886 | const keys = ObjectGetOwnPropertyNames(imports); 1887 | for (let i = 0; i < keys.length; i++) { 1888 | const key = keys[i]; 1889 | const patternIndex = StringPrototypeIndexOf(key, "*"); 1890 | if (patternIndex !== -1 && StringPrototypeStartsWith( 1891 | name, 1892 | StringPrototypeSlice(key, 0, patternIndex) 1893 | )) { 1894 | const patternTrailer = StringPrototypeSlice(key, patternIndex + 1); 1895 | if (name.length >= key.length && StringPrototypeEndsWith(name, patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && StringPrototypeLastIndexOf(key, "*") === patternIndex) { 1896 | bestMatch = key; 1897 | bestMatchSubpath = StringPrototypeSlice( 1898 | name, 1899 | patternIndex, 1900 | name.length - patternTrailer.length 1901 | ); 1902 | } 1903 | } 1904 | } 1905 | if (bestMatch) { 1906 | const target = imports[bestMatch]; 1907 | const resolveResult = resolvePackageTarget( 1908 | packageJSONUrl, 1909 | target, 1910 | bestMatchSubpath, 1911 | bestMatch, 1912 | base, 1913 | true, 1914 | true, 1915 | conditions 1916 | ); 1917 | if (resolveResult != null) { 1918 | return resolveResult; 1919 | } 1920 | } 1921 | } 1922 | } 1923 | } 1924 | throwImportNotDefined(name, packageJSONUrl, base); 1925 | } 1926 | 1927 | const pathRegExp = /^(?![a-zA-Z]:[\\/]|\\\\|\.{0,2}(?:\/|$))((?:node:)?(?:@[^/]+\/)?[^/]+)\/*(.*|)$/; 1928 | const isRelativeRegexp = /^\.{0,2}\//; 1929 | function tryReadFile(filePath) { 1930 | try { 1931 | return fs.readFileSync(filePath, `utf8`); 1932 | } catch (err) { 1933 | if (err.code === `ENOENT`) 1934 | return void 0; 1935 | throw err; 1936 | } 1937 | } 1938 | async function resolvePrivateRequest(specifier, issuer, context, nextResolve) { 1939 | const resolved = packageImportsResolve({ 1940 | name: specifier, 1941 | base: pathToFileURL(issuer), 1942 | conditions: new Set(context.conditions), 1943 | readFileSyncFn: tryReadFile 1944 | }); 1945 | if (resolved instanceof URL$1) { 1946 | return { url: resolved.href, shortCircuit: true }; 1947 | } else { 1948 | if (resolved.startsWith(`#`)) 1949 | throw new Error(`Mapping from one private import to another isn't allowed`); 1950 | return resolve$1(resolved, context, nextResolve); 1951 | } 1952 | } 1953 | async function resolve$1(originalSpecifier, context, nextResolve) { 1954 | var _a; 1955 | const { findPnpApi } = moduleExports; 1956 | if (!findPnpApi || isBuiltinModule(originalSpecifier)) 1957 | return nextResolve(originalSpecifier, context, nextResolve); 1958 | let specifier = originalSpecifier; 1959 | const url = tryParseURL(specifier, isRelativeRegexp.test(specifier) ? context.parentURL : void 0); 1960 | if (url) { 1961 | if (url.protocol !== `file:`) 1962 | return nextResolve(originalSpecifier, context, nextResolve); 1963 | specifier = fileURLToPath(url); 1964 | } 1965 | const { parentURL, conditions = [] } = context; 1966 | const issuer = parentURL ? fileURLToPath(parentURL) : process.cwd(); 1967 | const pnpapi = (_a = findPnpApi(issuer)) != null ? _a : url ? findPnpApi(specifier) : null; 1968 | if (!pnpapi) 1969 | return nextResolve(originalSpecifier, context, nextResolve); 1970 | if (specifier.startsWith(`#`)) 1971 | return resolvePrivateRequest(specifier, issuer, context, nextResolve); 1972 | const dependencyNameMatch = specifier.match(pathRegExp); 1973 | let allowLegacyResolve = false; 1974 | if (dependencyNameMatch) { 1975 | const [, dependencyName, subPath] = dependencyNameMatch; 1976 | if (subPath === `` && dependencyName !== `pnpapi`) { 1977 | const resolved = pnpapi.resolveToUnqualified(`${dependencyName}/package.json`, issuer); 1978 | if (resolved) { 1979 | const content = await tryReadFile$1(resolved); 1980 | if (content) { 1981 | const pkg = JSON.parse(content); 1982 | allowLegacyResolve = pkg.exports == null; 1983 | } 1984 | } 1985 | } 1986 | } 1987 | let result; 1988 | try { 1989 | result = pnpapi.resolveRequest(specifier, issuer, { 1990 | conditions: new Set(conditions), 1991 | extensions: allowLegacyResolve ? void 0 : [] 1992 | }); 1993 | } catch (err) { 1994 | if (err instanceof Error && `code` in err && err.code === `MODULE_NOT_FOUND`) 1995 | err.code = `ERR_MODULE_NOT_FOUND`; 1996 | throw err; 1997 | } 1998 | if (!result) 1999 | throw new Error(`Resolving '${specifier}' from '${issuer}' failed`); 2000 | const resultURL = pathToFileURL(result); 2001 | if (url) { 2002 | resultURL.search = url.search; 2003 | resultURL.hash = url.hash; 2004 | } 2005 | if (!parentURL) 2006 | setEntrypointPath(fileURLToPath(resultURL)); 2007 | return { 2008 | url: resultURL.href, 2009 | shortCircuit: true 2010 | }; 2011 | } 2012 | 2013 | if (!HAS_LAZY_LOADED_TRANSLATORS) { 2014 | const binding = process.binding(`fs`); 2015 | const originalfstat = binding.fstat; 2016 | const ZIP_MASK = 4278190080; 2017 | const ZIP_MAGIC = 704643072; 2018 | binding.fstat = function(...args) { 2019 | const [fd, useBigint, req] = args; 2020 | if ((fd & ZIP_MASK) === ZIP_MAGIC && useBigint === false && req === void 0) { 2021 | try { 2022 | const stats = fs.fstatSync(fd); 2023 | return new Float64Array([ 2024 | stats.dev, 2025 | stats.mode, 2026 | stats.nlink, 2027 | stats.uid, 2028 | stats.gid, 2029 | stats.rdev, 2030 | stats.blksize, 2031 | stats.ino, 2032 | stats.size, 2033 | stats.blocks 2034 | ]); 2035 | } catch { 2036 | } 2037 | } 2038 | return originalfstat.apply(this, args); 2039 | }; 2040 | } 2041 | 2042 | const resolve = resolve$1; 2043 | const getFormat = HAS_CONSOLIDATED_HOOKS ? void 0 : getFormat$1; 2044 | const getSource = HAS_CONSOLIDATED_HOOKS ? void 0 : getSource$1; 2045 | const load = HAS_CONSOLIDATED_HOOKS ? load$1 : void 0; 2046 | 2047 | export { getFormat, getSource, load, resolve }; 2048 | -------------------------------------------------------------------------------- /vue-gui/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use the official image as a parent image 2 | FROM node:18-alpine 3 | 4 | # Set the working directory 5 | WORKDIR /app 6 | 7 | # Copy package.json and yarn.lock 8 | COPY ./genworlds-community/.env /app/.env 9 | COPY ./genworlds-community/packages/nano-vue/package.json ./ 10 | COPY ./genworlds-community/packages/nano-vue/yarn.lock ./ 11 | 12 | # Install dependencies using yarn 13 | RUN yarn install 14 | 15 | # Copy the current directory contents into the container at /app 16 | COPY ./genworlds-community/packages/nano-vue/ . 17 | 18 | # Expose port 8080 (or whatever port your dev server uses) 19 | EXPOSE 8080 20 | 21 | # Start Vue development server with hot-reloading 22 | CMD ["yarn", "serve"] -------------------------------------------------------------------------------- /vue-gui/README.md: -------------------------------------------------------------------------------- 1 | # nano-vue 2 | 3 | ## Project setup 4 | ``` 5 | yarn install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | yarn serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | yarn build 16 | ``` 17 | 18 | ### Lints and fixes files 19 | ``` 20 | yarn lint 21 | ``` 22 | 23 | ### Customize configuration 24 | See [Configuration Reference](https://cli.vuejs.org/config/). 25 | -------------------------------------------------------------------------------- /vue-gui/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /vue-gui/default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name localhost; 4 | 5 | location / { 6 | root /usr/share/nginx/html; 7 | index index.html index.htm; 8 | try_files $uri $uri/ /index.html; 9 | } 10 | 11 | error_page 500 502 503 504 /50x.html; 12 | 13 | location = /50x.html { 14 | root /usr/share/nginx/html; 15 | } 16 | } -------------------------------------------------------------------------------- /vue-gui/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "esnext", 5 | "baseUrl": "./", 6 | "moduleResolution": "node", 7 | "paths": { 8 | "@/*": [ 9 | "src/*" 10 | ] 11 | }, 12 | "lib": [ 13 | "esnext", 14 | "dom", 15 | "dom.iterable", 16 | "scripthost" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /vue-gui/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nano-vue", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^1.4.0", 12 | "core-js": "^3.8.3", 13 | "daisyui": "^3.1.7", 14 | "dompurify": "^3.0.6", 15 | "markdown-it": "^13.0.2", 16 | "markdown-it-prism": "^2.3.0", 17 | "pinia": "^2.1.4", 18 | "pinia-plugin-persistedstate": "^3.1.0", 19 | "prism-themes": "^1.9.0", 20 | "prismjs": "^1.29.0", 21 | "prismjs-themes": "^2.0.0", 22 | "reconnecting-websocket": "^4.4.0", 23 | "tailwindcss": "^3.3.2", 24 | "vue": "^3.2.13", 25 | "vue-router": "^4.0.13" 26 | }, 27 | "devDependencies": { 28 | "@babel/core": "^7.12.16", 29 | "@babel/eslint-parser": "^7.12.16", 30 | "@tailwindcss/typography": "^0.5.9", 31 | "@vue/cli-plugin-babel": "~5.0.0", 32 | "@vue/cli-plugin-eslint": "~5.0.0", 33 | "@vue/cli-service": "~5.0.0", 34 | "eslint": "^7.32.0", 35 | "eslint-plugin-vue": "^8.0.3" 36 | }, 37 | "eslintConfig": { 38 | "root": true, 39 | "env": { 40 | "node": true 41 | }, 42 | "extends": [ 43 | "plugin:vue/vue3-essential", 44 | "eslint:recommended" 45 | ], 46 | "parserOptions": { 47 | "parser": "@babel/eslint-parser" 48 | }, 49 | "rules": {} 50 | }, 51 | "browserslist": [ 52 | "> 1%", 53 | "last 2 versions", 54 | "not dead", 55 | "not ie 11" 56 | ] 57 | } 58 | -------------------------------------------------------------------------------- /vue-gui/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /vue-gui/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeagerai/genworlds-community/9318fb88ecf132f344e433a978a165329df603f8/vue-gui/public/favicon.ico -------------------------------------------------------------------------------- /vue-gui/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /vue-gui/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const path = require('path'); 3 | const app = express(); 4 | const port = 80; 5 | 6 | app.use(express.static('nano-vue')); 7 | 8 | app.get('*', function(req, res) { 9 | res.sendFile(path.join(__dirname, 'index.html')); 10 | }); 11 | 12 | app.listen(port, '0.0.0.0', () => { 13 | console.log(`Server listening at http://0.0.0.0:${port}`); 14 | }); 15 | -------------------------------------------------------------------------------- /vue-gui/src/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | 16 | -------------------------------------------------------------------------------- /vue-gui/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeagerai/genworlds-community/9318fb88ecf132f344e433a978a165329df603f8/vue-gui/src/assets/logo.png -------------------------------------------------------------------------------- /vue-gui/src/components/ChatRoom.vue: -------------------------------------------------------------------------------- 1 | 52 | 53 | 90 | 91 | -------------------------------------------------------------------------------- /vue-gui/src/components/ChatRoomSelector.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /vue-gui/src/components/MockedWorldAlert.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | -------------------------------------------------------------------------------- /vue-gui/src/components/SendMessageBox.vue: -------------------------------------------------------------------------------- 1 | 133 | 134 | -------------------------------------------------------------------------------- /vue-gui/src/components/WorldChatRooms.vue: -------------------------------------------------------------------------------- 1 | 40 | 41 | 63 | 64 | 69 | -------------------------------------------------------------------------------- /vue-gui/src/components/WorldInfo.vue: -------------------------------------------------------------------------------- 1 | 34 | 35 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /vue-gui/src/components/WorldLayout.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 72 | -------------------------------------------------------------------------------- /vue-gui/src/components/WorldSettings.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /vue-gui/src/main.js: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue'; 2 | import App from './App.vue'; 3 | import router from './router'; 4 | import './tailwind.css'; 5 | import { createPinia } from 'pinia'; 6 | import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' 7 | 8 | const app = createApp(App); 9 | const pinia = createPinia(); 10 | pinia.use(piniaPluginPersistedstate) 11 | 12 | app.use(router).use(pinia).mount('#app'); -------------------------------------------------------------------------------- /vue-gui/src/modules/api/resources/TTS.js: -------------------------------------------------------------------------------- 1 | import { useSettingsStore } from '@/stores/settingsStore'; 2 | 3 | 4 | 5 | export default { 6 | baseUrl() { 7 | return `https://api.elevenlabs.io/v1/text-to-speech` 8 | }, 9 | 10 | headers() { 11 | const headers = { 12 | "Content-Type": "application/json", 13 | accept: 'audio/mpeg', 14 | responseType: "arraybuffer", 15 | }; 16 | 17 | const settingsStore = useSettingsStore(); 18 | if (settingsStore.settings.elevenLabsApiKey) { 19 | headers['xi-api-key'] = settingsStore.settings.elevenLabsApiKey.trim(); 20 | } 21 | 22 | return headers; 23 | }, 24 | 25 | async convert(voiceId, text, optimizeStreamingLatency = 0) { 26 | const body = { 27 | "text": text, 28 | "model_id": "eleven_monolingual_v1", 29 | "voice_settings": { 30 | "stability": 0.33, 31 | "similarity_boost": 0.75, 32 | "style": 0.5, 33 | "use_speaker_boost": false 34 | } 35 | } 36 | 37 | const options = { 38 | headers: this.headers(), 39 | method: 'POST', 40 | body: JSON.stringify(body), 41 | } 42 | 43 | const response = await fetch(`${this.baseUrl()}/${voiceId}/stream?`+new URLSearchParams({ 44 | optimize_streaming_latency: optimizeStreamingLatency, 45 | }), options); 46 | return response.blob(); 47 | }, 48 | } -------------------------------------------------------------------------------- /vue-gui/src/modules/downloadEventHistory.js: -------------------------------------------------------------------------------- 1 | export const downloadEventHistory = (fullEventHistory) => { 2 | // Suppose this is your JSON object 3 | const data = { 4 | events: fullEventHistory.value, 5 | } 6 | 7 | // Convert it to JSON string 8 | const jsonStr = JSON.stringify(data, null, 2); 9 | 10 | // Create a Blob from the JSON string 11 | const blob = new Blob([jsonStr], { type: 'application/json' }); 12 | 13 | // Create an object URL from the Blob 14 | const url = URL.createObjectURL(blob); 15 | 16 | // Create a link element 17 | const link = document.createElement('a'); 18 | 19 | // Set the href and download attributes of the link 20 | link.href = url; 21 | link.download = 'websocket_event_history.json'; 22 | 23 | // Append the link to the body 24 | document.body.appendChild(link); 25 | 26 | // Click the link to start the download 27 | link.click(); 28 | 29 | // Remove the link after the download starts 30 | document.body.removeChild(link); 31 | }; -------------------------------------------------------------------------------- /vue-gui/src/modules/worldSocketHandler.js: -------------------------------------------------------------------------------- 1 | // worldSocketHandler.js 2 | import { ref } from 'vue'; 3 | import ReconnectingWebSocket from 'reconnecting-websocket'; 4 | import { useScreensStore } from '@/stores/screensStore'; 5 | import { useWorldStateStore } from '@/stores/worldStateStore'; 6 | 7 | function createWebSocketHandler() { 8 | const isConnected = ref(false); 9 | const fullEventHistory = ref([]); 10 | let connection = null; 11 | 12 | const screensStore = useScreensStore(); 13 | const worldStateStore = useWorldStateStore(); 14 | 15 | function baseUrl() { 16 | const currentUrl = window.location.hostname; 17 | const protocol = currentUrl === 'localhost' ? 'ws' : 'wss'; 18 | const port = 7456; 19 | const full_url = `${protocol}://${currentUrl}:${port}/ws`; 20 | console.log(full_url); 21 | return full_url; 22 | } 23 | 24 | function connect() { 25 | connection = new ReconnectingWebSocket(baseUrl()); 26 | connection.onopen = () => { 27 | isConnected.value = true; 28 | sendEvent({ 29 | event_type: "user_requests_screens_to_world", 30 | description: "The user requests the screens to the world.", 31 | sender_id: "test_user", 32 | target_id: null, 33 | created_at: new Date().toISOString(), 34 | }); 35 | sendEvent({ 36 | event_type: "agent_wants_updated_state", 37 | description: "Agent wants to update its state.", 38 | sender_id: "test_user", 39 | target_id: null, 40 | created_at: new Date().toISOString(), 41 | }); 42 | }; 43 | connection.onmessage = handleMessage; 44 | connection.onerror = handleError; 45 | connection.onclose = handleClose; 46 | } 47 | 48 | function sendEvent(eventArgs) { 49 | if(isConnected.value) { 50 | const message = JSON.stringify(eventArgs); 51 | connection.send(message); 52 | } else { 53 | console.error("WebSocket is not connected. Unable to send message."); 54 | } 55 | } 56 | 57 | function handleMessage(response) { 58 | const data = JSON.parse(response.data); 59 | fullEventHistory.value.push(data); 60 | screensStore.addEventToApplicableScreensHistory(data); 61 | if (data && data.event_type) { 62 | console.log(data); 63 | 64 | switch(data.event_type) { 65 | case "world_sends_screens_to_user": 66 | screensStore.initializeScreens(data.screens_config); 67 | break; 68 | case "world_sends_available_entities_event": 69 | worldStateStore.setWorldState(data); 70 | break; 71 | default: 72 | "" 73 | } 74 | } else { 75 | console.error('Invalid message format received:', data); 76 | } 77 | } 78 | 79 | function handleError(error) { 80 | console.error("WebSocket Error: ", error); 81 | } 82 | 83 | function handleClose() { 84 | isConnected.value = false; 85 | } 86 | 87 | return { 88 | isConnected, 89 | fullEventHistory, 90 | connect, 91 | sendEvent, 92 | handleMessage, 93 | handleError, 94 | handleClose, 95 | } 96 | } 97 | 98 | let worldSocketHandler = null; 99 | 100 | export function getWorldSocketHandler() { 101 | if (!worldSocketHandler) { 102 | worldSocketHandler = createWebSocketHandler(); 103 | } 104 | console.log(worldSocketHandler) 105 | return worldSocketHandler; 106 | } -------------------------------------------------------------------------------- /vue-gui/src/router.js: -------------------------------------------------------------------------------- 1 | import { createRouter, createWebHistory } from 'vue-router'; 2 | import WorldLayout from './components/WorldLayout.vue'; 3 | 4 | const routes = [ 5 | { 6 | path: '/', 7 | name: 'WorldLayout', 8 | component: WorldLayout, 9 | }, 10 | ]; 11 | 12 | const router = createRouter({ 13 | history: createWebHistory(), 14 | routes, 15 | }); 16 | 17 | export default router; 18 | -------------------------------------------------------------------------------- /vue-gui/src/stores/screensStore.js: -------------------------------------------------------------------------------- 1 | import { defineStore } from 'pinia'; 2 | 3 | export const useScreensStore = defineStore({ 4 | id: 'screens', 5 | state: () => ({ 6 | name: "", 7 | screens: [], 8 | settings: {}, 9 | activeScreenName: '', 10 | screensHaveBeenLoaded: false, 11 | }), 12 | actions: { 13 | initializeScreens(screensConfig) { 14 | this.name = screensConfig.name; 15 | this.screens = screensConfig.screens; 16 | this.settings = screensConfig.settings; 17 | 18 | if (this.screens.length > 0) { 19 | this.activeScreenName = this.screens[0].name; 20 | } 21 | this.screensHaveBeenLoaded = true; 22 | for (const screen of this.screens) { 23 | screen.eventHistory = []; 24 | } 25 | }, 26 | setActiveScreen(screenName) { 27 | if (this.screens.some(screen => screen.name === screenName)) { 28 | this.activeScreenName = screenName; 29 | } else { 30 | console.error(`No screen found with the name: ${screenName}`); 31 | } 32 | }, 33 | addEventToScreenHistory(screenName, event) { 34 | const screen = this.screens.find(s => s.name === screenName); 35 | if (screen) { 36 | if (!screen.eventHistory) { 37 | screen.eventHistory = []; 38 | } 39 | screen.eventHistory.push(event); 40 | } else { 41 | console.error(`No screen found with the name: ${screenName}`); 42 | } 43 | }, 44 | addEventToApplicableScreensHistory(event) { 45 | this.screens.forEach(screen => { 46 | const isEventTracked = screen.tracked_events.some(te => te.event_type === event.event_type); 47 | if (isEventTracked) { 48 | if (!screen.eventHistory) { 49 | screen.eventHistory = []; 50 | } 51 | screen.eventHistory.push(event); 52 | } 53 | }); 54 | }, 55 | // Additional utility functions based on your needs. 56 | } 57 | }); 58 | -------------------------------------------------------------------------------- /vue-gui/src/stores/settingsStore.js: -------------------------------------------------------------------------------- 1 | import { defineStore } from 'pinia' 2 | 3 | export const useSettingsStore = defineStore('settingsStore', { 4 | state: () => ({ 5 | settings: { 6 | openaiApiKey: '', 7 | elevenLabsApiKey: '', 8 | enableTTS: false, 9 | }, 10 | }), 11 | actions: { 12 | updateSettings(partialSettings) { 13 | this.settings = { 14 | ...this.settings, 15 | ...partialSettings, 16 | } 17 | }, 18 | }, 19 | persist: true, 20 | }) -------------------------------------------------------------------------------- /vue-gui/src/stores/worldActionsStore.js: -------------------------------------------------------------------------------- 1 | import { defineStore } from 'pinia'; 2 | 3 | export const useUseCaseActionStore = defineStore({ 4 | id: 'useCaseActionStore', 5 | state: () => ({ 6 | performStopUseCaseAction: false, 7 | performRestartUseCaseAction: false, 8 | performDownloadUseCaseEventHistoryAction: false, 9 | }), 10 | actions: { 11 | setPerformStopUseCaseAction(value) { 12 | this.performStopUseCaseAction = value; 13 | }, 14 | setPerformRestartUseCaseAction(value) { 15 | this.performRestartUseCaseAction = value; 16 | }, 17 | setPerformDownloadUseCaseEventHistoryAction(value) { 18 | this.performDownloadUseCaseEventHistoryAction = value; 19 | }, 20 | } 21 | }); -------------------------------------------------------------------------------- /vue-gui/src/stores/worldStateStore.js: -------------------------------------------------------------------------------- 1 | import { defineStore } from 'pinia'; 2 | 3 | export const useWorldStateStore = defineStore({ 4 | // unique id of the store across your application 5 | id: 'worldState', 6 | 7 | // define state 8 | state: () => ({ 9 | worldName: '', 10 | worldDescription: '', 11 | agents: [], 12 | objects: [], 13 | userEvents: [], 14 | }), 15 | 16 | getters: { 17 | findAgentById: (state) => (id) => { 18 | return state.agents.find(agent => agent.id === id); 19 | }, 20 | 21 | findObjectById: (state) => (id) => { 22 | return state.objects.find(object => object.id === id); 23 | }, 24 | }, 25 | 26 | // define actions and mutations 27 | actions: { 28 | // Set world state action 29 | setWorldState(payload) { 30 | const entitiesArray = Object.values(payload.available_entities || {}); 31 | this.worldName = entitiesArray.filter(e => e.entity_type === "WORLD")[0].name; 32 | this.worldDescription = entitiesArray.filter(e => e.entity_type === "WORLD")[0].description; 33 | this.agents = entitiesArray.filter(e => e.entity_type === "AGENT"); 34 | this.objects = entitiesArray.filter(e => e.entity_type === "OBJECT"); 35 | }, 36 | 37 | setUserEvents(payload) { 38 | this.userEvents = payload.user_events; 39 | }, 40 | 41 | // Update/add agent action 42 | updateAgent(agent) { 43 | const index = this.agents.findIndex(a => a.name === agent.name); 44 | if (index !== -1) { 45 | this.agents[index] = agent; 46 | } else { 47 | this.agents.push(agent); 48 | } 49 | }, 50 | 51 | // Remove agent action 52 | removeAgent(agentName) { 53 | this.agents = this.agents.filter(a => a.name !== agentName); 54 | }, 55 | 56 | updateObject(object) { 57 | const index = this.objects.findIndex(o => o.name === object.name); 58 | if (index !== -1) { 59 | this.objects[index] = object; 60 | } else { 61 | this.objects.push(object); 62 | } 63 | }, 64 | 65 | removeObject(objectName) { 66 | this.objects = this.objects.filter(o => o.name !== objectName); 67 | }, 68 | 69 | // Additional actions or mutations as you need them... 70 | } 71 | }); -------------------------------------------------------------------------------- /vue-gui/src/tailwind.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | /* width */ 6 | ::-webkit-scrollbar { 7 | width: 10px; 8 | } 9 | 10 | /* Track */ 11 | ::-webkit-scrollbar-track { 12 | background: transparent; 13 | } 14 | 15 | /* Handle */ 16 | ::-webkit-scrollbar-thumb { 17 | background: #888; 18 | border-radius: 5px; 19 | } 20 | 21 | /* Handle on hover */ 22 | ::-webkit-scrollbar-thumb:hover { 23 | background: #555; 24 | } -------------------------------------------------------------------------------- /vue-gui/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx,json}', '../../use_cases/**/*.{json}'], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [ 8 | require('@tailwindcss/typography'), 9 | require('daisyui'), 10 | ], 11 | daisyui: { 12 | themes: [ 13 | { 14 | genworldsLightTheme: { 15 | "primary": "#a991f7", 16 | "secondary": "#f6d860", 17 | "accent": "#37cdbe", 18 | "neutral": "#3d4451", 19 | "base-100": "#ffffff", 20 | }, 21 | }, 22 | ], 23 | }, 24 | purge: { 25 | options: { 26 | safelist: [ 27 | /^chat-bubble-/, 28 | /^font-/, 29 | "italic", 30 | ], 31 | }, 32 | }, 33 | } 34 | 35 | -------------------------------------------------------------------------------- /vue-gui/vue.config.js: -------------------------------------------------------------------------------- 1 | const { defineConfig } = require('@vue/cli-service') 2 | module.exports = defineConfig({ 3 | transpileDependencies: true, 4 | pages: { 5 | index: { 6 | entry: 'src/main.js', //entry for the public page 7 | template: 'public/index.html', // source template 8 | filename: 'index.html', // output as dist/* 9 | title: 'GenWorlds Community', // when using template and/or filename options, you may need to specify the title in vue.config.js 10 | } 11 | }, 12 | }) 13 | --------------------------------------------------------------------------------