jvserve 2.0.11__tar.gz → 2.0.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jvserve
3
- Version: 2.0.11
3
+ Version: 2.0.12
4
4
  Summary: FastAPI webserver for loading and interaction with JIVAS agents.
5
5
  Home-page: https://github.com/TrueSelph/jvserve
6
6
  Author: TrueSelph Inc.
@@ -4,5 +4,5 @@ jvserve package initialization.
4
4
  This package provides the webserver for loading and interacting with JIVAS agents.
5
5
  """
6
6
 
7
- __version__ = "2.0.11"
7
+ __version__ = "2.0.12"
8
8
  __supported__jivas__versions__ = ["2.0.0"]
@@ -176,7 +176,7 @@ class JacCmd:
176
176
  def jvfileserve(
177
177
  directory: str, host: str = "0.0.0.0", port: int = 9000
178
178
  ) -> None:
179
- """Launch the file server."""
179
+ """Launch the file server for local files."""
180
180
  # load FastAPI
181
181
  from fastapi import FastAPI
182
182
  from fastapi.middleware.cors import CORSMiddleware
@@ -194,21 +194,45 @@ class JacCmd:
194
194
  allow_headers=["*"],
195
195
  )
196
196
 
197
- if FILE_INTERFACE == "local":
198
- if directory:
199
- os.environ["JIVAS_FILES_ROOT_PATH"] = directory
197
+ if not os.path.exists(directory):
198
+ os.makedirs(directory)
200
199
 
201
- if not os.path.exists(directory):
202
- os.makedirs(directory)
200
+ # Set the environment variable for the file root path
201
+ os.environ["JIVAS_FILES_ROOT_PATH"] = directory
203
202
 
204
- app.mount(
205
- "/files",
206
- StaticFiles(
207
- directory=os.environ.get("JIVAS_FILES_ROOT_PATH", ".files")
208
- ),
209
- name="files",
210
- )
203
+ # Mount the static files directory
204
+ app.mount(
205
+ "/files",
206
+ StaticFiles(directory=directory),
207
+ name="files",
208
+ )
209
+
210
+ # run the app
211
+ _run(app, host=host, port=port)
212
+
213
+ @cmd_registry.register
214
+ def jvproxyserve(
215
+ directory: str, host: str = "0.0.0.0", port: int = 9000
216
+ ) -> None:
217
+ """Launch the file proxy server for remote files."""
218
+ # load FastAPI
219
+ from bson import ObjectId
220
+ from fastapi import FastAPI, HTTPException
221
+ from fastapi.middleware.cors import CORSMiddleware
222
+
223
+ # Setup custom routes
224
+ app = FastAPI()
225
+
226
+ # Add CORS middleware
227
+ app.add_middleware(
228
+ CORSMiddleware,
229
+ allow_origins=["*"],
230
+ allow_credentials=True,
231
+ allow_methods=["*"],
232
+ allow_headers=["*"],
233
+ )
211
234
 
235
+ # Add proxy routes only if using S3
212
236
  if FILE_INTERFACE == "s3":
213
237
 
214
238
  @app.get("/files/{file_path:path}", response_model=None)
@@ -221,9 +245,6 @@ class JacCmd:
221
245
  async def get_proxied_file(
222
246
  file_id: str,
223
247
  ) -> Response:
224
- from bson import ObjectId
225
- from fastapi import HTTPException
226
-
227
248
  params = file_id.split("/")
228
249
  object_id = params[0]
229
250
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jvserve
3
- Version: 2.0.11
3
+ Version: 2.0.12
4
4
  Summary: FastAPI webserver for loading and interaction with JIVAS agents.
5
5
  Home-page: https://github.com/TrueSelph/jvserve
6
6
  Author: TrueSelph Inc.
@@ -118,6 +118,26 @@ class JVServeCliTest(unittest.TestCase):
118
118
  os.remove(f"{directory}/test.txt")
119
119
  os.rmdir(directory)
120
120
 
121
+ def test_jvproxyserve_runs(self) -> None:
122
+ """Ensure `jac jvproxyserve` runs successfully."""
123
+ try:
124
+ directory = "test_files"
125
+ server_process = subprocess.Popen(
126
+ ["jac", "jvproxyserve", directory, "--port", "9100"],
127
+ stdout=subprocess.PIPE,
128
+ stderr=subprocess.PIPE,
129
+ text=True,
130
+ )
131
+
132
+ # Wait for the proxy server to be ready
133
+ self.wait_for_server("http://127.0.0.1:9100/docs")
134
+
135
+ res = httpx.get("http://127.0.0.1:9100/docs")
136
+ self.assertEqual(res.status_code, 200)
137
+
138
+ finally:
139
+ server_process.kill()
140
+
121
141
  def tearDown(self) -> None:
122
142
  """Cleanup after each test."""
123
143
  self.stop_server()
File without changes
File without changes
File without changes
File without changes