@capagents/forgeqe 2.6.1 → 2.6.3
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.
- package/HOW_TO_USE.md +311 -15
- package/README.md +5 -25
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/bin/activate-web.d.ts +16 -0
- package/bin/activate-web.js +117 -0
- package/bin/bundle.d.ts +27 -0
- package/bin/bundle.js +173 -0
- package/bin/forgeqe.js +109 -2
- package/bin/license.d.ts +25 -0
- package/bin/license.js +178 -0
- package/dist/docs-site/docs/architecture/index.html +2 -1
- package/dist/docs-site/docs/index.html +291 -11
- package/dist/docs-site/docs/search.js +1 -1
- package/dist/docs-site/docs/web-app/index.html +35 -6
- package/dist/forgeqe.js +1513 -1291
- package/dist/template.html +64 -64
- package/dist/web/assets/Agent-yd1DyMzR.js +4 -0
- package/dist/web/assets/ApiTests-BwOGta9J.js +10 -0
- package/dist/web/assets/Chat-P8GH_6gl.js +3 -0
- package/dist/web/assets/Data-D2iCqk3t.js +3 -0
- package/dist/web/assets/Features-Bu38clxs.js +1 -0
- package/dist/web/assets/Jobs-DymuaGeN.js +5 -0
- package/dist/web/assets/KindPage-zl6TBkEl.js +6 -0
- package/dist/web/assets/Migration-Cg_FUqS_.js +2 -0
- package/dist/web/assets/Quality-D3bSHP_B.js +1 -0
- package/dist/web/assets/Record-DkCLJos6.js +2 -0
- package/dist/web/assets/Regression-B2qMKjAE.js +5 -0
- package/dist/web/assets/Reports-D_G9yfDa.js +2 -0
- package/dist/web/assets/Response-BnPAefP-.js +4 -0
- package/dist/web/assets/Runs-DsDj9-LT.js +2 -0
- package/dist/web/assets/Shell-DlZHZN0d.js +3 -0
- package/dist/web/assets/TestData-qI1R5Q9v.js +2 -0
- package/dist/web/assets/WhatsNew-CoCHqSDm.js +1 -0
- package/dist/web/assets/accessibility-CH8EpEAV.svg +1 -0
- package/dist/web/assets/{arrow-down-BqARSDDZ.js → arrow-down-BWCXlJU0.js} +1 -1
- package/dist/web/assets/arrow-right-CdxkQBV7.js +1 -0
- package/dist/web/assets/{bot-BtKTIZEs.js → bot-D8486kSA.js} +1 -1
- package/dist/web/assets/capgemini-mark-D6aZFnD3.png +0 -0
- package/dist/web/assets/chevron-up-CQz_ZmIK.js +1 -0
- package/dist/web/assets/circle-BqXBUsQS.js +1 -0
- package/dist/web/assets/{circle-dashed-DwIAhHPq.js → circle-dashed-DlOiCbWD.js} +1 -1
- package/dist/web/assets/dataParts-bwNleJYd.js +3 -0
- package/dist/web/assets/forgeqe-logo-D3CwM2Jl.png +0 -0
- package/dist/web/assets/forgeqe-logo-white-CoE-hF2l.png +0 -0
- package/dist/web/assets/forgeqe-mark-ZLd4S3hw.png +0 -0
- package/dist/web/assets/index-Bh4NBbEU.js +37 -0
- package/dist/web/assets/index-DkgUrjyL.css +2 -0
- package/dist/web/assets/keyboard-wpCM6HMa.js +1 -0
- package/dist/web/assets/qualityParts-iy-mouSI.js +1 -0
- package/dist/web/assets/{thread-iCgQPYwX.js → thread-BfW2V-2U.js} +1 -1
- package/dist/web/assets/upload-CwExsxOd.js +1 -0
- package/dist/web/assets/usePageChat-CzWbP_sa.js +1 -0
- package/dist/web/index.html +3 -3
- package/docs/ARCHITECTURE.md +2 -1
- package/docs/CUSTOM_AGENTS_FIRST_RUN.md +107 -0
- package/docs/WEB_APP.md +36 -6
- package/docs/security-data-flow.html +3 -3
- package/docs/user-guide.html +291 -11
- package/docs/walkthrough/hotfix-narration.md +443 -297
- package/forgeqe.example.yaml +13 -2
- package/package.json +6 -3
- package/prompts/README.md +1 -0
- package/prompts/agent-builder.md +69 -0
- package/prompts/api-tests.md +1 -1
- package/prompts/brain.md +22 -2
- package/prompts/browser-persona.md +14 -0
- package/prompts/db-agent.md +73 -0
- package/prompts/heal.md +1 -1
- package/prompts/migrate.md +54 -0
- package/prompts/test-agent.md +1 -0
- package/py/forgeqe_engine/cli.py +9 -1
- package/py/forgeqe_engine/copilot_gateway.py +162 -9
- package/py/forgeqe_engine/persona.py +435 -0
- package/py/forgeqe_engine/proceed.py +67 -0
- package/py/forgeqe_engine/service.py +93 -11
- package/skills/test-data/SKILL.md +4 -0
- package/dist/web/assets/Agent-jYaYLJO8.js +0 -1
- package/dist/web/assets/ApiTests-BYQ0VYx3.js +0 -10
- package/dist/web/assets/Chat-DOcK3ngF.js +0 -3
- package/dist/web/assets/Data-KFQ0-EbI.js +0 -4
- package/dist/web/assets/Features-9rw1s5Vs.js +0 -1
- package/dist/web/assets/Jobs-MRHq6isA.js +0 -5
- package/dist/web/assets/Quality-CGrki-iI.js +0 -1
- package/dist/web/assets/Record-Bamcsz1Y.js +0 -2
- package/dist/web/assets/Regression-D0yEt-3X.js +0 -5
- package/dist/web/assets/Reports-BwvQNDFa.js +0 -2
- package/dist/web/assets/Response-XIaBzLD_.js +0 -4
- package/dist/web/assets/Runs-DtgNqxHd.js +0 -2
- package/dist/web/assets/Shell-E3JKoPtx.js +0 -3
- package/dist/web/assets/accessibility-BSaq_4Me.svg +0 -1
- package/dist/web/assets/capgemini-BO8ajcbd.svg +0 -21
- package/dist/web/assets/capgemini-white-ByjwPW8N.svg +0 -21
- package/dist/web/assets/circle-C_9D6W14.js +0 -1
- package/dist/web/assets/index-CVa5dAjG.js +0 -26
- package/dist/web/assets/index-DF-gVa3Q.css +0 -2
- package/dist/web/assets/markdown-OsvJ-mly.js +0 -10
- package/dist/web/assets/trending-up-fRykocOw.js +0 -1
- package/dist/web/assets/usePageChat-B5pKShGC.js +0 -1
|
@@ -224,6 +224,7 @@ def translate(body: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
224
224
|
prompt += "\n\nReply with a single JSON object and nothing else."
|
|
225
225
|
return {
|
|
226
226
|
"model": model,
|
|
227
|
+
"reasoning_effort": reasoning_effort(body.get("reasoning_effort")),
|
|
227
228
|
"system": "\n\n".join(s for s in system if s),
|
|
228
229
|
"prompt": prompt,
|
|
229
230
|
"attachments": attachments,
|
|
@@ -234,8 +235,25 @@ def translate(body: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
234
235
|
}
|
|
235
236
|
|
|
236
237
|
|
|
237
|
-
|
|
238
|
-
|
|
238
|
+
# OpenAI's reasoning_effort values as Copilot names them; "none" and anything unknown leave the model's default.
|
|
239
|
+
_EFFORTS = {"minimal": "low", "low": "low", "medium": "medium", "high": "high", "xhigh": "xhigh", "max": "max"}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def reasoning_effort(value: Any) -> Optional[str]:
|
|
243
|
+
"""The Copilot reasoning effort for OpenAI's reasoning_effort, or None for the model's default."""
|
|
244
|
+
return _EFFORTS.get(str(value).strip().lower()) if isinstance(value, str) else None
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
_EFFORT_PATH = re.compile(r"^/effort/([a-z]{1,8})(/.*)?$")
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
# Copilot's finish reasons that mean the reply is not the whole answer, as OpenAI names them.
|
|
251
|
+
_FINISH = {"length": "length", "max_tokens": "length", "content_filter": "content_filter"}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def completion(model: str, content: str, usage: Dict[str, Any], tool_calls: Optional[List[Dict[str, Any]]] = None, finish: Optional[str] = None) -> Dict[str, Any]:
|
|
255
|
+
"""An OpenAI chat.completion object; with tool_calls, the calls the model made and finish_reason tool_calls. `finish`
|
|
256
|
+
is Copilot's reason a reply stopped: one cut at the length limit or by the content filter says so."""
|
|
239
257
|
prompt_tokens = int(usage.get("input", 0))
|
|
240
258
|
completion_tokens = int(usage.get("output", 0))
|
|
241
259
|
message: Dict[str, Any] = {"role": "assistant", "content": content}
|
|
@@ -246,11 +264,14 @@ def completion(model: str, content: str, usage: Dict[str, int], tool_calls: Opti
|
|
|
246
264
|
"object": "chat.completion",
|
|
247
265
|
"created": int(time.time()),
|
|
248
266
|
"model": model,
|
|
249
|
-
"choices": [{"index": 0, "message": message, "finish_reason": "tool_calls" if tool_calls else "stop"}],
|
|
267
|
+
"choices": [{"index": 0, "message": message, "finish_reason": "tool_calls" if tool_calls else _FINISH.get(str(finish or "").lower(), "stop")}],
|
|
250
268
|
"usage": {"prompt_tokens": prompt_tokens, "completion_tokens": completion_tokens, "total_tokens": prompt_tokens + completion_tokens},
|
|
251
269
|
}
|
|
252
270
|
if usage.get("cached"):
|
|
253
271
|
out["usage"]["prompt_tokens_details"] = {"cached_tokens": int(usage["cached"])}
|
|
272
|
+
if usage.get("premium"):
|
|
273
|
+
# Copilot's own count of premium requests this call used; not an OpenAI field, so callers that do not know it skip it.
|
|
274
|
+
out["usage"]["copilot_premium_requests"] = round(float(usage["premium"]), 4)
|
|
254
275
|
return out
|
|
255
276
|
|
|
256
277
|
|
|
@@ -307,6 +328,56 @@ def copilot_home() -> str:
|
|
|
307
328
|
return os.path.join(os.environ.get("FORGEQE_HOME") or os.path.join(os.path.expanduser("~"), ".forgeqe"), "copilot")
|
|
308
329
|
|
|
309
330
|
|
|
331
|
+
# The SDK's runtime wrapper says only this when Windows refuses its native library, without Windows' reason.
|
|
332
|
+
_RUNTIME_LOAD = re.compile(r"failed to load runtime cdylib (.+?runtime\.node)\b", re.IGNORECASE)
|
|
333
|
+
# Loads the library in a child, so Windows' error code is seen without loading it into the gateway.
|
|
334
|
+
_LOAD_PROBE = "import ctypes,sys\ntry:\n ctypes.WinDLL(sys.argv[1])\n print(0)\nexcept OSError as e:\n print(getattr(e, 'winerror', None) or -1)\n"
|
|
335
|
+
# DirectX 12, which the runtime imports; missing on Windows Server without the desktop experience and some VDI images.
|
|
336
|
+
_DIRECTX = ("d3d12.dll", "dxgi.dll")
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def probe_runtime_load(path: str) -> Optional[int]:
|
|
340
|
+
"""Windows' error code for loading `path` in a separate Python (0: it loads), or None when it cannot be learned."""
|
|
341
|
+
import subprocess
|
|
342
|
+
|
|
343
|
+
env = {k: v for k, v in os.environ.items() if k not in (TOKEN_ENV, KEY_ENV)}
|
|
344
|
+
try:
|
|
345
|
+
r = subprocess.run([sys.executable, "-I", "-c", _LOAD_PROBE, path], capture_output=True, text=True, timeout=120, env=env)
|
|
346
|
+
return int(r.stdout.strip().splitlines()[-1])
|
|
347
|
+
except Exception:
|
|
348
|
+
return None
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def runtime_load_hint(message: str, probe: Callable[[str], Optional[int]] = probe_runtime_load, system32: Optional[str] = None) -> str:
|
|
352
|
+
"""What to do when Windows refused the Copilot runtime's library, from Windows' own reason; "" for other errors."""
|
|
353
|
+
m = _RUNTIME_LOAD.search(message)
|
|
354
|
+
if not m or sys.platform != "win32" and probe is probe_runtime_load:
|
|
355
|
+
return ""
|
|
356
|
+
path = m.group(1).strip()
|
|
357
|
+
if os.path.basename(path).lower() != "runtime.node" or not os.path.isfile(path):
|
|
358
|
+
return ""
|
|
359
|
+
folder = os.path.dirname(os.path.dirname(os.path.dirname(path)))
|
|
360
|
+
redo = f"delete {folder} and run forgeqe auth login copilot again, which downloads it afresh"
|
|
361
|
+
code = probe(path)
|
|
362
|
+
sys32 = system32 or os.path.join(os.environ.get("SystemRoot", r"C:\Windows"), "System32")
|
|
363
|
+
if code == 126:
|
|
364
|
+
missing = [d for d in _DIRECTX if not os.path.isfile(os.path.join(sys32, d))]
|
|
365
|
+
if missing:
|
|
366
|
+
return f"Windows lacks {', '.join(missing)} (DirectX 12), which Copilot's runtime needs: use Windows 10 or 11, or Windows Server with the Desktop Experience, or sign in with a token on a machine that has it."
|
|
367
|
+
return f"A Windows library Copilot's runtime needs could not be found (Windows error 126). Install the latest Windows updates; if it persists, {redo}."
|
|
368
|
+
if code in (5, 1260, 4551):
|
|
369
|
+
return f"Your organisation's application control (AppLocker or Windows Defender Application Control) blocks Copilot's runtime (Windows error {code}). Ask IT to allow GitHub-signed files in {folder}."
|
|
370
|
+
if code in (225, 226):
|
|
371
|
+
return f"Antivirus blocked Copilot's runtime (Windows error {code}). Ask IT to allow {path}, or {redo}."
|
|
372
|
+
if code in (193, 216, 1392):
|
|
373
|
+
return f"Copilot's runtime is damaged or incomplete (Windows error {code}): {redo}."
|
|
374
|
+
if code == 0:
|
|
375
|
+
return f"It loads when tried again, so something held it the first time (often antivirus scanning it): run forgeqe auth login copilot again. If it fails again, {redo}."
|
|
376
|
+
if code is None:
|
|
377
|
+
return f"If it persists, {redo}."
|
|
378
|
+
return f"Windows error {code}. If it persists, {redo}."
|
|
379
|
+
|
|
380
|
+
|
|
310
381
|
def client_options(token: Optional[str], home: str, workdir: str) -> Dict[str, Any]:
|
|
311
382
|
"""With a token, that token only; without one, the signed-in user, as the Copilot SDK recommends on a user's machine."""
|
|
312
383
|
auth: Dict[str, Any] = {"github_token": token, "use_logged_in_user": False} if token else {"use_logged_in_user": True}
|
|
@@ -337,8 +408,11 @@ class Copilot:
|
|
|
337
408
|
raise GatewayError(401, "GitHub Copilot is not signed in: run forgeqe auth login copilot, which opens GitHub in your browser.")
|
|
338
409
|
raise GatewayError(401, "GitHub Copilot did not accept the token: use a fine-grained token with the Copilot Requests permission, for an account with a Copilot seat.")
|
|
339
410
|
|
|
340
|
-
def refusal(self, message: str) -> "GatewayError":
|
|
341
|
-
"""Copilot's error as the gateway reports it. A refused sign-in says whose, and whether it was a token
|
|
411
|
+
def refusal(self, message: str, status: Optional[int] = None) -> "GatewayError":
|
|
412
|
+
"""Copilot's error as the gateway reports it. A refused sign-in says whose, and whether it was a token; a rate
|
|
413
|
+
limit or a used-up allowance is a 429, so callers wait or stop rather than retry at once."""
|
|
414
|
+
if limited(message, status):
|
|
415
|
+
return GatewayError(429, f"GitHub Copilot: {message} ({LIMITED_HINT})"[:2000])
|
|
342
416
|
if not signin_refused(message):
|
|
343
417
|
return GatewayError(502, f"GitHub Copilot: {message}"[:2000])
|
|
344
418
|
what = "the sign-in" if self.signed_in_user else "the token"
|
|
@@ -351,6 +425,16 @@ class Copilot:
|
|
|
351
425
|
except Exception:
|
|
352
426
|
pass
|
|
353
427
|
|
|
428
|
+
async def reasons(self, model: str) -> bool:
|
|
429
|
+
"""Whether `model` takes a reasoning effort on this seat; asked once. A model that does not is sent none."""
|
|
430
|
+
if getattr(self, "_reasoning", None) is None:
|
|
431
|
+
try:
|
|
432
|
+
found = await self.client.list_models()
|
|
433
|
+
self._reasoning = {m.id for m in found if getattr(getattr(getattr(m, "capabilities", None), "supports", None), "reasoning_effort", False)}
|
|
434
|
+
except Exception:
|
|
435
|
+
self._reasoning = set()
|
|
436
|
+
return model in self._reasoning
|
|
437
|
+
|
|
354
438
|
async def models(self) -> List[Dict[str, Any]]:
|
|
355
439
|
out = []
|
|
356
440
|
for m in await self.client.list_models():
|
|
@@ -364,6 +448,7 @@ class Copilot:
|
|
|
364
448
|
"object": "model",
|
|
365
449
|
"owned_by": "github-copilot",
|
|
366
450
|
"vision": bool(getattr(supports, "vision", False)),
|
|
451
|
+
"reasoning_effort": bool(getattr(supports, "reasoning_effort", False)),
|
|
367
452
|
# enabled, disabled (the seat's policy turns it off) or unconfigured (enable it in GitHub's Copilot settings).
|
|
368
453
|
"policy": str(policy) if policy else "enabled",
|
|
369
454
|
**({"multiplier": float(multiplier)} if isinstance(multiplier, (int, float)) else {}),
|
|
@@ -406,8 +491,10 @@ class Copilot:
|
|
|
406
491
|
# The text callback while this request streams; None once it is asked for again without streaming.
|
|
407
492
|
stream: Dict[str, Any] = {"to": None if req["schema"] is not None or req["json_only"] else on_text, "sent": False}
|
|
408
493
|
|
|
409
|
-
usage = {"input": 0, "output": 0, "cached": 0}
|
|
494
|
+
usage: Dict[str, Any] = {"input": 0, "output": 0, "cached": 0, "premium": 0.0}
|
|
495
|
+
finish: Dict[str, Optional[str]] = {"reason": None}
|
|
410
496
|
errors: List[str] = []
|
|
497
|
+
statuses: List[Optional[int]] = []
|
|
411
498
|
calls: List[Dict[str, Any]] = []
|
|
412
499
|
# The last root reply without tool requests, and the timer that ends the wait when a turn ends without idle.
|
|
413
500
|
turn: Dict[str, Any] = {"final": None, "timer": None, "settled": asyncio.Event()}
|
|
@@ -437,8 +524,12 @@ class Copilot:
|
|
|
437
524
|
usage["input"] += data.input_tokens or 0
|
|
438
525
|
usage["output"] += data.output_tokens or 0
|
|
439
526
|
usage["cached"] += data.cache_read_tokens or 0
|
|
527
|
+
usage["premium"] += float(getattr(data, "cost", None) or 0)
|
|
528
|
+
if not getattr(data, "parent_tool_call_id", None):
|
|
529
|
+
finish["reason"] = "content_filter" if getattr(data, "content_filter_triggered", False) else getattr(data, "finish_reason", None)
|
|
440
530
|
elif isinstance(data, SessionErrorData):
|
|
441
531
|
errors.append(data.message or data.error_type or "error")
|
|
532
|
+
statuses.append(getattr(data, "status_code", None))
|
|
442
533
|
# A sub-agent's text is not the reply.
|
|
443
534
|
elif stream["to"] and isinstance(data, AssistantMessageDeltaData) and data.delta_content and not data.parent_tool_call_id:
|
|
444
535
|
stream["sent"] = True
|
|
@@ -456,8 +547,10 @@ class Copilot:
|
|
|
456
547
|
|
|
457
548
|
tried: set = set()
|
|
458
549
|
reply: Any = None
|
|
550
|
+
effort = req.get("reasoning_effort") if await self.reasons(req["model"]) else None
|
|
459
551
|
for _ in range(MAX_TOOL_RETRIES + 2):
|
|
460
552
|
errors.clear()
|
|
553
|
+
statuses.clear()
|
|
461
554
|
calls.clear()
|
|
462
555
|
on_loop(unsettle)
|
|
463
556
|
turn["final"] = None
|
|
@@ -476,7 +569,10 @@ class Copilot:
|
|
|
476
569
|
enable_config_discovery=False,
|
|
477
570
|
enable_skills=False,
|
|
478
571
|
enable_session_store=False,
|
|
572
|
+
# GitHub's session telemetry is on by default for a signed-in user: off, like every telemetry ForgeQE starts.
|
|
573
|
+
enable_session_telemetry=False,
|
|
479
574
|
on_event=on_event,
|
|
575
|
+
**({"reasoning_effort": effort} if effort else {}),
|
|
480
576
|
**({"streaming": True} if stream["to"] else {}),
|
|
481
577
|
)
|
|
482
578
|
failure: Optional[str] = None
|
|
@@ -521,11 +617,12 @@ class Copilot:
|
|
|
521
617
|
continue
|
|
522
618
|
if failure:
|
|
523
619
|
raise self.refusal(failure)
|
|
620
|
+
# A rate limit or a used-up allowance is not asked again here: the caller waits, or stops.
|
|
524
621
|
break
|
|
525
622
|
else:
|
|
526
623
|
raise GatewayError(502, "GitHub Copilot kept refusing the names of the caller's tools.")
|
|
527
624
|
if errors and not calls:
|
|
528
|
-
raise self.refusal(errors[-1])
|
|
625
|
+
raise self.refusal(errors[-1], statuses[-1] if statuses else None)
|
|
529
626
|
data = getattr(reply, "data", None)
|
|
530
627
|
content = (data.content or "") if isinstance(data, AssistantMessageData) else ""
|
|
531
628
|
if calls:
|
|
@@ -534,7 +631,7 @@ class Copilot:
|
|
|
534
631
|
raise GatewayError(502, "GitHub Copilot sent no reply.")
|
|
535
632
|
if req["schema"] is not None or req["json_only"]:
|
|
536
633
|
content = strip_fences(content)
|
|
537
|
-
return completion(req["model"], content, usage)
|
|
634
|
+
return completion(req["model"], content, usage, finish=finish["reason"])
|
|
538
635
|
|
|
539
636
|
|
|
540
637
|
async def _wait(self, rid: str, session: Any, req: Dict[str, Any], turn: Dict[str, Any], gone: Optional["asyncio.Future[Any]"]) -> Tuple[Any, bool]:
|
|
@@ -576,6 +673,15 @@ _NO_BUILTIN = re.compile(r'tool "([A-Za-z0-9_-]{1,64})"[^"\n]{0,80}(?:does not|d
|
|
|
576
673
|
_SIGNIN_REFUSED = re.compile(r"authori[sz]ation error|credentials may be expired|bad credentials|unauthori[sz]ed|not authenticated|no github oauth token|\b401\b", re.I)
|
|
577
674
|
|
|
578
675
|
|
|
676
|
+
_LIMITED = re.compile(r"rate.?limit|too many requests|quota|premium request|allowance|exceeded your|usage limit|\b429\b", re.I)
|
|
677
|
+
LIMITED_HINT = "the seat's rate limit or premium request allowance; wait, or pick a model with a lower multiplier: forgeqe models --copilot"
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
def limited(message: str, status: Optional[int] = None) -> bool:
|
|
681
|
+
"""Whether Copilot's error is a rate limit or a used-up premium request allowance."""
|
|
682
|
+
return status == 429 or bool(_LIMITED.search(message or ""))
|
|
683
|
+
|
|
684
|
+
|
|
579
685
|
def signin_refused(message: str) -> bool:
|
|
580
686
|
"""Whether Copilot's error says it would not take the sign-in or token (as opposed to the model or the request)."""
|
|
581
687
|
return bool(_SIGNIN_REFUSED.search(message or ""))
|
|
@@ -726,6 +832,11 @@ async def handle(reader: asyncio.StreamReader, writer: asyncio.StreamWriter, cop
|
|
|
726
832
|
writer.write(_error(401, "Unauthorized"))
|
|
727
833
|
return
|
|
728
834
|
path = path.split("?", 1)[0].rstrip("/")
|
|
835
|
+
# /effort/<level>/v1/...: a profile's reasoning effort (llms.json), for callers that send none of their own.
|
|
836
|
+
effort = None
|
|
837
|
+
m = _EFFORT_PATH.match(path)
|
|
838
|
+
if m:
|
|
839
|
+
effort, path = reasoning_effort(m.group(1)), m.group(2) or "/"
|
|
729
840
|
if path.startswith("/v1/"):
|
|
730
841
|
path = path[3:]
|
|
731
842
|
if method == "GET" and path == "/models":
|
|
@@ -748,6 +859,8 @@ async def handle(reader: asyncio.StreamReader, writer: asyncio.StreamWriter, cop
|
|
|
748
859
|
writer.write(_error(400, "The request body is not JSON."))
|
|
749
860
|
return
|
|
750
861
|
req = translate(body)
|
|
862
|
+
if effort and not req["reasoning_effort"]:
|
|
863
|
+
req["reasoning_effort"] = effort
|
|
751
864
|
gone = asyncio.ensure_future(caller_gone(reader))
|
|
752
865
|
try:
|
|
753
866
|
if req["stream"]:
|
|
@@ -799,7 +912,9 @@ async def serve(out: TextIO, copilot: Any = None) -> int:
|
|
|
799
912
|
out.write(json.dumps({"error": f"GitHub's Copilot SDK is not installed in the ForgeQE engine ({e}): run forgeqe setup, which installs it from pypi.org."}) + "\n")
|
|
800
913
|
return 1
|
|
801
914
|
except Exception as e:
|
|
802
|
-
|
|
915
|
+
hint = runtime_load_hint(str(e))
|
|
916
|
+
error = f"GitHub Copilot could not start: {type(e).__name__}: {e}"[:1500]
|
|
917
|
+
out.write(json.dumps({"error": f"{error}\n{hint}" if hint else error}) + "\n")
|
|
803
918
|
return 1
|
|
804
919
|
server = await asyncio.start_server(lambda r, w: handle(r, w, copilot, key), host="127.0.0.1", port=0, limit=64 * 1024)
|
|
805
920
|
port = server.sockets[0].getsockname()[1]
|
|
@@ -814,6 +929,44 @@ async def serve(out: TextIO, copilot: Any = None) -> int:
|
|
|
814
929
|
return 0
|
|
815
930
|
|
|
816
931
|
|
|
932
|
+
async def sign_out(out: TextIO, client: Any = None) -> int:
|
|
933
|
+
"""
|
|
934
|
+
Removes the browser sign-in (forgeqe auth logout copilot): every account Copilot keeps in ForgeQE's Copilot home is
|
|
935
|
+
logged out, from the system's credential store and Copilot's own state. Prints {"removed": n} or {"error": ...}.
|
|
936
|
+
"""
|
|
937
|
+
try:
|
|
938
|
+
if client is None:
|
|
939
|
+
from copilot import CopilotClient
|
|
940
|
+
|
|
941
|
+
home = copilot_home()
|
|
942
|
+
os.makedirs(home, exist_ok=True)
|
|
943
|
+
client = CopilotClient(**client_options(None, home, tempfile.mkdtemp(prefix="forgeqe-copilot-")))
|
|
944
|
+
await client.start()
|
|
945
|
+
from copilot.generated.rpc import AccountLogoutRequest
|
|
946
|
+
|
|
947
|
+
removed = 0
|
|
948
|
+
for user in await client.rpc.account.get_all_users():
|
|
949
|
+
sel = user.get("selectionId") if isinstance(user, dict) else getattr(user, "selection_id", None)
|
|
950
|
+
if isinstance(sel, str) and sel:
|
|
951
|
+
await client.rpc.account.logout(AccountLogoutRequest(selection_id=sel))
|
|
952
|
+
removed += 1
|
|
953
|
+
out.write(json.dumps({"removed": removed}) + "\n")
|
|
954
|
+
return 0
|
|
955
|
+
except Exception as e:
|
|
956
|
+
out.write(json.dumps({"error": f"{type(e).__name__}: {e}"[:500]}) + "\n")
|
|
957
|
+
return 1
|
|
958
|
+
finally:
|
|
959
|
+
try:
|
|
960
|
+
await client.stop()
|
|
961
|
+
except Exception:
|
|
962
|
+
pass
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
def sign_out_main(out: TextIO) -> int:
|
|
966
|
+
use_system_certificates()
|
|
967
|
+
return asyncio.run(sign_out(out))
|
|
968
|
+
|
|
969
|
+
|
|
817
970
|
def main(out: TextIO) -> int:
|
|
818
971
|
use_system_certificates()
|
|
819
972
|
return asyncio.run(serve(out))
|