freeai-code 0.2.0__tar.gz → 0.2.1__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.
- {freeai_code-0.2.0/freeai_code.egg-info → freeai_code-0.2.1}/PKG-INFO +1 -1
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/__init__.py +1 -1
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/builtin_manifest.py +4 -4
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/remote_tools.py +30 -7
- {freeai_code-0.2.0 → freeai_code-0.2.1/freeai_code.egg-info}/PKG-INFO +1 -1
- {freeai_code-0.2.0 → freeai_code-0.2.1}/pyproject.toml +1 -1
- {freeai_code-0.2.0 → freeai_code-0.2.1}/tests/test_remote_tools.py +45 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/LICENSE +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/README.md +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/__main__.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/agent.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/auth.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/cli.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/client.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/cloud.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/config.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/context/__init__.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/context/discovery.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/context/repo_map.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/context/window.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/feedback_ui.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/manifest.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/mcp.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/models.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/sessions.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/streaming.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/telemetry.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/tools/__init__.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/tools/file_ops.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/tools/git_ops.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/tools/i18n.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/tools/list_files.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/tools/search.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/tools/shell.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/tools/test_runner.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/tools/web.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/toolset.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/ui/__init__.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/ui/diff_view.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/ui/prompt.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/ui/terminal.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/free_code/updater.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/freeai_code.egg-info/SOURCES.txt +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/freeai_code.egg-info/dependency_links.txt +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/freeai_code.egg-info/entry_points.txt +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/freeai_code.egg-info/requires.txt +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/freeai_code.egg-info/top_level.txt +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/setup.cfg +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/tests/test_agent.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/tests/test_cli.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/tests/test_login.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/tests/test_manifest.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/tests/test_mcp.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/tests/test_telemetry.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/tests/test_tools_misc.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/tests/test_updater.py +0 -0
- {freeai_code-0.2.0 → freeai_code-0.2.1}/tests/tests_helpers.py +0 -0
|
@@ -54,7 +54,7 @@ BUILTIN_MANIFEST: Dict[str, Any] = {
|
|
|
54
54
|
{"method": "POST", "path": "/v1/image/generate/", "timeout": 300,
|
|
55
55
|
"body": {"prompt": "{prompt}", "model": "{model|flux2-klein}",
|
|
56
56
|
"aspect_ratio": "{aspect_ratio|1:1}", "negative_prompt": "{negative_prompt}"}},
|
|
57
|
-
{"file_url": ["image_url", "url"], "save_arg": "output_path"},
|
|
57
|
+
{"file_url": ["image_url", "url", "output_url"], "save_arg": "output_path"},
|
|
58
58
|
"write",
|
|
59
59
|
),
|
|
60
60
|
_tool(
|
|
@@ -72,7 +72,7 @@ BUILTIN_MANIFEST: Dict[str, Any] = {
|
|
|
72
72
|
{"method": "POST", "path": "/v1/tts/", "timeout": 180,
|
|
73
73
|
"body": {"text": "{text}", "model": "{model|kokoro}", "voice": "{voice|af_heart}",
|
|
74
74
|
"language": "{language|en}"}},
|
|
75
|
-
{"file_url": ["audio_url", "url"], "save_arg": "output_path"},
|
|
75
|
+
{"file_url": ["audio_url", "url", "output_url"], "save_arg": "output_path"},
|
|
76
76
|
"write",
|
|
77
77
|
),
|
|
78
78
|
_tool(
|
|
@@ -87,7 +87,7 @@ BUILTIN_MANIFEST: Dict[str, Any] = {
|
|
|
87
87
|
["prompt", "output_path"],
|
|
88
88
|
{"method": "POST", "path": "/v1/music/generate/", "timeout": 300,
|
|
89
89
|
"body": {"prompt": "{prompt}", "duration": "{duration|10}", "model": "{model}"}},
|
|
90
|
-
{"file_url": ["audio_url", "url"], "save_arg": "output_path"},
|
|
90
|
+
{"file_url": ["audio_url", "url", "output_url"], "save_arg": "output_path"},
|
|
91
91
|
"write",
|
|
92
92
|
),
|
|
93
93
|
_tool(
|
|
@@ -102,7 +102,7 @@ BUILTIN_MANIFEST: Dict[str, Any] = {
|
|
|
102
102
|
["prompt", "output_path"],
|
|
103
103
|
{"method": "POST", "path": "/v1/video/generate/", "timeout": 600,
|
|
104
104
|
"body": {"prompt": "{prompt}", "model": "{model|cogvideox}"}},
|
|
105
|
-
{"file_url": ["video_url", "url"], "save_arg": "output_path"},
|
|
105
|
+
{"file_url": ["video_url", "url", "output_url"], "save_arg": "output_path"},
|
|
106
106
|
"write",
|
|
107
107
|
),
|
|
108
108
|
_tool(
|
|
@@ -288,7 +288,7 @@ def execute_spec(
|
|
|
288
288
|
|
|
289
289
|
job_id = data.get("job_id") if isinstance(data, dict) else None
|
|
290
290
|
if job_id and not _pick(data, result_cfg.get("file_url", []) + result_cfg.get("text", [])):
|
|
291
|
-
polled = _poll_job(client, api_base, str(job_id), token, timeout)
|
|
291
|
+
polled = _poll_job(client, api_base, str(job_id), token, timeout, data.get("poll_url"))
|
|
292
292
|
if isinstance(polled, str):
|
|
293
293
|
return polled
|
|
294
294
|
data = polled
|
|
@@ -315,23 +315,46 @@ def _resolve_read(project_root: Optional[str], rel: str) -> "Path | str":
|
|
|
315
315
|
return p
|
|
316
316
|
|
|
317
317
|
|
|
318
|
-
|
|
318
|
+
WEB_BASE = "https://free.ai"
|
|
319
|
+
JOB_URL_RE = re.compile(r"^/api/v1/jobs/[0-9a-f\-]{36}/$")
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def _poll_job(client: httpx.Client, api_base: str, job_id: str, token: Optional[str], timeout: float,
|
|
323
|
+
poll_url: Optional[str] = None) -> "Dict[str, Any] | str":
|
|
324
|
+
"""Wait for a queued GPU job. Free.ai answers a busy GPU with {queued, job_id, poll_url}
|
|
325
|
+
(poll the web tier's /api/v1/jobs/<id>/) and other endpoints with a bare job_id
|
|
326
|
+
(poll the API's /v1/status/<id>/)."""
|
|
319
327
|
if not re.fullmatch(r"[A-Za-z0-9_\-]{4,80}", job_id):
|
|
320
328
|
return "Error: unexpected job id from API"
|
|
329
|
+
if isinstance(poll_url, str) and JOB_URL_RE.match(poll_url):
|
|
330
|
+
url = WEB_BASE + poll_url
|
|
331
|
+
queue_job = True
|
|
332
|
+
else:
|
|
333
|
+
url = f"{api_base.rstrip('/')}/v1/status/{job_id}/"
|
|
334
|
+
queue_job = False
|
|
321
335
|
deadline = time.time() + POLL_MAX_SECONDS
|
|
336
|
+
last = ""
|
|
322
337
|
while time.time() < deadline:
|
|
323
338
|
time.sleep(POLL_SECONDS)
|
|
324
339
|
try:
|
|
325
|
-
r = client.get(
|
|
340
|
+
r = client.get(url, headers=_headers(token), timeout=30)
|
|
326
341
|
data = r.json()
|
|
327
342
|
except (httpx.HTTPError, ValueError):
|
|
328
343
|
continue
|
|
344
|
+
if queue_job:
|
|
345
|
+
data = data.get("job") if isinstance(data, dict) and isinstance(data.get("job"), dict) else data
|
|
329
346
|
status = str(data.get("status", "")).lower()
|
|
347
|
+
last = status
|
|
330
348
|
if status in ("completed", "complete", "done", "success", "succeeded"):
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
349
|
+
out = dict(data)
|
|
350
|
+
link = out.get("output_url")
|
|
351
|
+
if isinstance(link, str) and link.startswith("/"):
|
|
352
|
+
out["output_url"] = WEB_BASE + link
|
|
353
|
+
return out
|
|
354
|
+
if status in ("failed", "error", "cancelled", "rejected"):
|
|
355
|
+
return f"Error: job {job_id} {status}: {str(data.get('error_message') or data.get('error', ''))[:200]}"
|
|
356
|
+
return (f"Error: job {job_id} did not finish within {POLL_MAX_SECONDS}s (last status {last or 'unknown'}). "
|
|
357
|
+
"It keeps running on Free.ai; the result will appear under your jobs at https://free.ai/account/")
|
|
335
358
|
|
|
336
359
|
|
|
337
360
|
def _finish(client: httpx.Client, spec: Dict[str, Any], data: Any, out_path: Optional[Path], project_root: Optional[str], token: Optional[str]) -> str:
|
|
@@ -138,3 +138,48 @@ def test_job_polling(monkeypatch):
|
|
|
138
138
|
return httpx.Response(200, json={"status": "completed" if calls["n"] > 1 else "running", "text": "done"})
|
|
139
139
|
|
|
140
140
|
assert rt.execute_spec(rt.validate_spec(spec()), {"text": "x"}, client=client_for(handler)) == "done"
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def test_queued_gpu_job_polls_the_web_tier_job_url(monkeypatch, tmp_path):
|
|
144
|
+
monkeypatch.setattr(rt.time, "sleep", lambda s: None)
|
|
145
|
+
jid = "07eb0cd5-b19c-4d9f-b5cb-a7a8c92f0e6f"
|
|
146
|
+
seen = {"polls": 0, "hosts": set()}
|
|
147
|
+
|
|
148
|
+
def handler(req):
|
|
149
|
+
seen["hosts"].add(req.url.host)
|
|
150
|
+
if req.url.path == "/v1/music/generate/":
|
|
151
|
+
return httpx.Response(200, json={"queued": True, "job_id": jid, "poll_url": f"/api/v1/jobs/{jid}/"})
|
|
152
|
+
if req.url.path == f"/api/v1/jobs/{jid}/":
|
|
153
|
+
seen["polls"] += 1
|
|
154
|
+
if seen["polls"] < 3:
|
|
155
|
+
return httpx.Response(200, json={"job": {"status": "queued"}})
|
|
156
|
+
return httpx.Response(200, json={"job": {"status": "completed", "output_url": "https://cdn.example/m.mp3"}})
|
|
157
|
+
return httpx.Response(200, content=b"MP3")
|
|
158
|
+
|
|
159
|
+
s = rt.validate_spec(next(t for t in BUILTIN_MANIFEST["tools"] if t["name"] == "generate_music"))
|
|
160
|
+
out = rt.execute_spec(s, {"prompt": "calm", "output_path": "m.mp3"}, project_root=str(tmp_path), client=client_for(handler))
|
|
161
|
+
assert out == "Saved to m.mp3" and (tmp_path / "m.mp3").read_bytes() == b"MP3"
|
|
162
|
+
assert seen["polls"] == 3 and "free.ai" in seen["hosts"]
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def test_queued_job_failure_and_hostile_poll_url(monkeypatch):
|
|
166
|
+
monkeypatch.setattr(rt.time, "sleep", lambda s: None)
|
|
167
|
+
jid = "07eb0cd5-b19c-4d9f-b5cb-a7a8c92f0e6f"
|
|
168
|
+
|
|
169
|
+
def failing(req):
|
|
170
|
+
if req.url.path == "/v1/demo/":
|
|
171
|
+
return httpx.Response(200, json={"queued": True, "job_id": jid, "poll_url": f"/api/v1/jobs/{jid}/"})
|
|
172
|
+
return httpx.Response(200, json={"job": {"status": "failed", "error_message": "gpu oom"}})
|
|
173
|
+
|
|
174
|
+
assert "gpu oom" in rt.execute_spec(rt.validate_spec(spec()), {"text": "x"}, client=client_for(failing))
|
|
175
|
+
|
|
176
|
+
hosts = []
|
|
177
|
+
|
|
178
|
+
def hostile(req):
|
|
179
|
+
hosts.append(str(req.url))
|
|
180
|
+
if req.url.path == "/v1/demo/":
|
|
181
|
+
return httpx.Response(200, json={"job_id": "job12345", "poll_url": "https://evil.example/steal"})
|
|
182
|
+
return httpx.Response(200, json={"status": "completed", "text": "ok"})
|
|
183
|
+
|
|
184
|
+
assert rt.execute_spec(rt.validate_spec(spec()), {"text": "x"}, client=client_for(hostile)) == "ok"
|
|
185
|
+
assert not any("evil.example" in h for h in hosts)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|