traceforge-pcb 1.0.0__py3-none-any.whl
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.
- traceforge/__init__.py +3 -0
- traceforge/__main__.py +3 -0
- traceforge/acp_server.py +570 -0
- traceforge/agent.py +680 -0
- traceforge/altium/__init__.py +6 -0
- traceforge/altium/cfb.py +70 -0
- traceforge/altium/cli.py +60 -0
- traceforge/altium/model.py +163 -0
- traceforge/altium/outputs.py +24 -0
- traceforge/altium/pcb.py +301 -0
- traceforge/altium/project.py +328 -0
- traceforge/altium/schematic.py +400 -0
- traceforge/altium/tools.py +166 -0
- traceforge/approval.py +219 -0
- traceforge/attachments.py +346 -0
- traceforge/background.py +253 -0
- traceforge/bench/__init__.py +5 -0
- traceforge/bench/adapters.py +337 -0
- traceforge/bench/checks.py +410 -0
- traceforge/bench/cli.py +121 -0
- traceforge/bench/design.py +439 -0
- traceforge/bench/kicad.py +99 -0
- traceforge/bench/partscheck.py +159 -0
- traceforge/bench/review.py +100 -0
- traceforge/bench/runner.py +226 -0
- traceforge/bench/score.py +204 -0
- traceforge/bench/tasks.py +102 -0
- traceforge/chat.py +1185 -0
- traceforge/checks.py +328 -0
- traceforge/checks_sides.py +118 -0
- traceforge/cli.py +2224 -0
- traceforge/clipboard.py +107 -0
- traceforge/config.py +299 -0
- traceforge/context.py +276 -0
- traceforge/design/__init__.py +1 -0
- traceforge/design/constraints.py +397 -0
- traceforge/design/generate.py +1789 -0
- traceforge/design/outline.py +905 -0
- traceforge/design/schematic_layout.py +932 -0
- traceforge/design/schematic_lint.py +329 -0
- traceforge/design/schematic_route.py +207 -0
- traceforge/design/sheets.py +854 -0
- traceforge/design/sides.py +328 -0
- traceforge/design/spec.py +462 -0
- traceforge/design/specsheet.py +2351 -0
- traceforge/design/specsheet_render.py +183 -0
- traceforge/desktop/__init__.py +109 -0
- traceforge/desktop/keys.py +90 -0
- traceforge/desktop/project.py +443 -0
- traceforge/desktop/review.py +20 -0
- traceforge/desktop/server.py +1277 -0
- traceforge/desktop/static/app.css +223 -0
- traceforge/desktop/static/app.js +683 -0
- traceforge/desktop/static/highlight.js +77 -0
- traceforge/desktop/static/index.html +89 -0
- traceforge/desktop/static/md.js +90 -0
- traceforge/desktop/static/viewer.js +213 -0
- traceforge/desktop/symbols.py +212 -0
- traceforge/desktop/update.py +65 -0
- traceforge/diagnostics.py +67 -0
- traceforge/errata.py +219 -0
- traceforge/fab.py +108 -0
- traceforge/fab_layers.py +44 -0
- traceforge/features/__init__.py +6 -0
- traceforge/features/candidates.py +117 -0
- traceforge/features/cli.py +200 -0
- traceforge/features/package.py +433 -0
- traceforge/features/revdiff.py +224 -0
- traceforge/features/sarif.py +145 -0
- traceforge/features/viewer.py +265 -0
- traceforge/firmware/__init__.py +3 -0
- traceforge/firmware/cli.py +174 -0
- traceforge/firmware/drivers.py +372 -0
- traceforge/firmware/drivers_data.py +256 -0
- traceforge/firmware/mcus.py +177 -0
- traceforge/firmware/netlist.py +55 -0
- traceforge/firmware/pinmap.py +296 -0
- traceforge/firmware/scaffold.py +466 -0
- traceforge/firmware/toolchain.py +262 -0
- traceforge/hooks.py +237 -0
- traceforge/kicad/__init__.py +0 -0
- traceforge/kicad/cli.py +519 -0
- traceforge/kicad/diffpair.py +174 -0
- traceforge/kicad/edgegeom.py +191 -0
- traceforge/kicad/edit.py +405 -0
- traceforge/kicad/escape.py +1410 -0
- traceforge/kicad/formats.py +1073 -0
- traceforge/kicad/impedance.py +320 -0
- traceforge/kicad/install.py +75 -0
- traceforge/kicad/libraries.py +490 -0
- traceforge/kicad/models3d.py +942 -0
- traceforge/kicad/outputs.py +81 -0
- traceforge/kicad/pcb.py +787 -0
- traceforge/kicad/planes.py +1242 -0
- traceforge/kicad/project.py +136 -0
- traceforge/kicad/route.py +2698 -0
- traceforge/kicad/routegeom.py +164 -0
- traceforge/kicad/schematic.py +268 -0
- traceforge/kicad/sides.py +34 -0
- traceforge/kicad/stackup.py +424 -0
- traceforge/kicad_plugin/__init__.py +12 -0
- traceforge/kicad_plugin/actions.py +92 -0
- traceforge/kicad_plugin/cli.py +66 -0
- traceforge/kicad_plugin/client.py +86 -0
- traceforge/kicad_plugin/context.py +257 -0
- traceforge/kicad_plugin/discovery.py +81 -0
- traceforge/kicad_plugin/install.py +203 -0
- traceforge/kicad_plugin/overlay.py +60 -0
- traceforge/kicad_plugin/payload/action_plugin.py +65 -0
- traceforge/kicad_plugin/payload/ipc_main.py +42 -0
- traceforge/kicad_plugin/payload/plugin.json +90 -0
- traceforge/kicad_plugin/payload/requirements.txt +1 -0
- traceforge/kicad_plugin/views.py +202 -0
- traceforge/langchain.py +57 -0
- traceforge/local.py +580 -0
- traceforge/mcp_server.py +304 -0
- traceforge/models.py +310 -0
- traceforge/next_steps.py +110 -0
- traceforge/parts/__init__.py +52 -0
- traceforge/parts/alternates.py +488 -0
- traceforge/parts/bom.py +423 -0
- traceforge/parts/brief.py +705 -0
- traceforge/parts/catalog.py +297 -0
- traceforge/parts/cli_sourcing.py +156 -0
- traceforge/parts/data/duty_rates.yaml +37 -0
- traceforge/parts/data/hs_codes.yaml +103 -0
- traceforge/parts/datasheet.py +278 -0
- traceforge/parts/fx.py +100 -0
- traceforge/parts/model.py +185 -0
- traceforge/parts/net.py +187 -0
- traceforge/parts/offers.py +46 -0
- traceforge/parts/packages.py +397 -0
- traceforge/parts/pinout.py +714 -0
- traceforge/parts/providers/__init__.py +17 -0
- traceforge/parts/providers/base.py +100 -0
- traceforge/parts/providers/jlc.py +364 -0
- traceforge/parts/providers/keyed.py +661 -0
- traceforge/parts/report.py +508 -0
- traceforge/parts/supply.py +330 -0
- traceforge/parts/verify.py +455 -0
- traceforge/parts/web.py +575 -0
- traceforge/plans.py +70 -0
- traceforge/preferences.py +127 -0
- traceforge/prices.py +130 -0
- traceforge/prices.yaml +28 -0
- traceforge/prompts/__init__.py +54 -0
- traceforge/prompts/system.md +103 -0
- traceforge/providers.py +764 -0
- traceforge/remote/__init__.py +33 -0
- traceforge/remote/client.py +422 -0
- traceforge/remote/oidc.py +240 -0
- traceforge/remote/orgs.py +510 -0
- traceforge/remote/server.py +690 -0
- traceforge/remote/store.py +100 -0
- traceforge/review_changes.py +187 -0
- traceforge/routing.py +99 -0
- traceforge/runtime.py +435 -0
- traceforge/sessions.py +324 -0
- traceforge/sexpr.py +279 -0
- traceforge/sim/__init__.py +17 -0
- traceforge/sim/acmath.py +234 -0
- traceforge/sim/circuit.py +499 -0
- traceforge/sim/cli.py +162 -0
- traceforge/sim/engine.py +172 -0
- traceforge/sim/ltspice.py +175 -0
- traceforge/sim/measure.py +123 -0
- traceforge/sim/models.py +76 -0
- traceforge/sim/project.py +218 -0
- traceforge/sim/rawfile.py +123 -0
- traceforge/sim/results.py +298 -0
- traceforge/sim/tune.py +172 -0
- traceforge/skill_commands.py +165 -0
- traceforge/skill_library/circuit-simulation/SKILL.md +30 -0
- traceforge/skill_library/compliance-review/SKILL.md +51 -0
- traceforge/skill_library/design-review/SKILL.md +47 -0
- traceforge/skill_library/errata-hunt/SKILL.md +30 -0
- traceforge/skill_library/firmware/SKILL.md +26 -0
- traceforge/skill_library/power-budget/SKILL.md +27 -0
- traceforge/skill_library/release-package/SKILL.md +29 -0
- traceforge/skill_library/sourcing-brief/SKILL.md +24 -0
- traceforge/skill_library/thermal-review/SKILL.md +15 -0
- traceforge/skills.py +131 -0
- traceforge/thermal.py +557 -0
- traceforge/tools/__init__.py +48 -0
- traceforge/tools/agent_tools.py +213 -0
- traceforge/tools/base.py +303 -0
- traceforge/tools/batch.py +155 -0
- traceforge/tools/connections.py +245 -0
- traceforge/tools/files.py +777 -0
- traceforge/tools/firmware_tools.py +218 -0
- traceforge/tools/kicad_tools.py +1072 -0
- traceforge/tools/models3d_tools.py +141 -0
- traceforge/tools/parts_tools.py +473 -0
- traceforge/tools/processes.py +246 -0
- traceforge/tools/review_tools.py +178 -0
- traceforge/tools/sim_tools.py +230 -0
- traceforge/tui.py +620 -0
- traceforge/updates.py +124 -0
- traceforge/validate/__init__.py +77 -0
- traceforge/validate/builtins.py +1091 -0
- traceforge/validate/circuits.py +1240 -0
- traceforge/validate/config.py +410 -0
- traceforge/validate/default.yaml +113 -0
- traceforge/validate/design.py +191 -0
- traceforge/validate/explain.py +112 -0
- traceforge/validate/grounding.py +169 -0
- traceforge/validate/ipc2221.py +350 -0
- traceforge/validate/multilayer.py +805 -0
- traceforge/validate/netmodel.py +261 -0
- traceforge/validate/partcheck.py +472 -0
- traceforge/validate/report.py +280 -0
- traceforge/validate/review.py +322 -0
- traceforge/validate/runner.py +662 -0
- traceforge/workspace.py +171 -0
- traceforge_pcb-1.0.0.dist-info/METADATA +463 -0
- traceforge_pcb-1.0.0.dist-info/RECORD +219 -0
- traceforge_pcb-1.0.0.dist-info/WHEEL +4 -0
- traceforge_pcb-1.0.0.dist-info/entry_points.txt +2 -0
- traceforge_pcb-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Traceforge plugin for KiCad 9 and 10 (IPC API). Run by KiCad as ``main.py <action>``.
|
|
2
|
+
|
|
3
|
+
KiCad starts this in the plugin's own virtual environment (``requirements.txt`` installs
|
|
4
|
+
``kicad-python``) with ``KICAD_API_SOCKET`` and ``KICAD_API_TOKEN`` set. It reads the selection
|
|
5
|
+
through the API, asks the running Traceforge app and shows the answer.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
14
|
+
if HERE not in sys.path:
|
|
15
|
+
sys.path.insert(0, HERE)
|
|
16
|
+
|
|
17
|
+
from traceforge_kicad import actions, context, views # noqa: E402
|
|
18
|
+
from traceforge_kicad.overlay import Overlay # noqa: E402
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def run(argv: list[str], kicad: object = None, view: object = None) -> str:
|
|
22
|
+
action_id = argv[0] if argv else "chat"
|
|
23
|
+
actions.get(action_id)
|
|
24
|
+
if kicad is None:
|
|
25
|
+
from kipy import KiCad
|
|
26
|
+
|
|
27
|
+
kicad = KiCad()
|
|
28
|
+
try:
|
|
29
|
+
parts = context.read_kipy_selection(kicad)
|
|
30
|
+
except context.SelectionError as exc:
|
|
31
|
+
print(f"Traceforge: {exc}", file=sys.stderr)
|
|
32
|
+
return str(exc)
|
|
33
|
+
return (view or views.choose_view("tk")).show(Overlay(parts), action_id)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def main() -> int:
|
|
37
|
+
run(sys.argv[1:])
|
|
38
|
+
return 0
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://go.kicad.org/api/schemas/v1",
|
|
3
|
+
"identifier": "org.traceforge.kicad",
|
|
4
|
+
"name": "Traceforge",
|
|
5
|
+
"description": "Ask Traceforge about the selected part: wiring diagram, datasheet summary, pin functions, errata, alternatives and chat. Needs the Traceforge app running (traceforge app).",
|
|
6
|
+
"runtime": {
|
|
7
|
+
"type": "python",
|
|
8
|
+
"min_version": "3.9"
|
|
9
|
+
},
|
|
10
|
+
"actions": [
|
|
11
|
+
{
|
|
12
|
+
"identifier": "org.traceforge.kicad.wiring",
|
|
13
|
+
"name": "Traceforge: Wiring diagram",
|
|
14
|
+
"description": "Draw a wiring diagram of the selected part",
|
|
15
|
+
"show-button": false,
|
|
16
|
+
"scopes": [
|
|
17
|
+
"pcb"
|
|
18
|
+
],
|
|
19
|
+
"entrypoint": "main.py",
|
|
20
|
+
"args": [
|
|
21
|
+
"wiring"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"identifier": "org.traceforge.kicad.datasheet",
|
|
26
|
+
"name": "Traceforge: Datasheet summary",
|
|
27
|
+
"description": "Summarise the datasheet of the selected part",
|
|
28
|
+
"show-button": false,
|
|
29
|
+
"scopes": [
|
|
30
|
+
"pcb"
|
|
31
|
+
],
|
|
32
|
+
"entrypoint": "main.py",
|
|
33
|
+
"args": [
|
|
34
|
+
"datasheet"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"identifier": "org.traceforge.kicad.pins",
|
|
39
|
+
"name": "Traceforge: Pin functions",
|
|
40
|
+
"description": "List the pin functions of the selected part",
|
|
41
|
+
"show-button": false,
|
|
42
|
+
"scopes": [
|
|
43
|
+
"pcb"
|
|
44
|
+
],
|
|
45
|
+
"entrypoint": "main.py",
|
|
46
|
+
"args": [
|
|
47
|
+
"pins"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"identifier": "org.traceforge.kicad.errata",
|
|
52
|
+
"name": "Traceforge: Errata",
|
|
53
|
+
"description": "Find errata that may affect the selected part",
|
|
54
|
+
"show-button": false,
|
|
55
|
+
"scopes": [
|
|
56
|
+
"pcb"
|
|
57
|
+
],
|
|
58
|
+
"entrypoint": "main.py",
|
|
59
|
+
"args": [
|
|
60
|
+
"errata"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"identifier": "org.traceforge.kicad.alternatives",
|
|
65
|
+
"name": "Traceforge: Alternatives",
|
|
66
|
+
"description": "Suggest alternatives for the selected part",
|
|
67
|
+
"show-button": false,
|
|
68
|
+
"scopes": [
|
|
69
|
+
"pcb"
|
|
70
|
+
],
|
|
71
|
+
"entrypoint": "main.py",
|
|
72
|
+
"args": [
|
|
73
|
+
"alternatives"
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"identifier": "org.traceforge.kicad.chat",
|
|
78
|
+
"name": "Traceforge: Ask about this part",
|
|
79
|
+
"description": "Open the Traceforge chat for the selected part",
|
|
80
|
+
"show-button": true,
|
|
81
|
+
"scopes": [
|
|
82
|
+
"pcb"
|
|
83
|
+
],
|
|
84
|
+
"entrypoint": "main.py",
|
|
85
|
+
"args": [
|
|
86
|
+
"chat"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kicad-python>=0.4
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""Dialogs for the chat overlay: wxPython (KiCad's own toolkit), tkinter, or plain text.
|
|
2
|
+
|
|
3
|
+
The toolkits are imported only when a dialog opens. The dialogs are thin: the logic is in
|
|
4
|
+
``overlay.Overlay`` (selected parts, the conversation, the call to the app).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import queue
|
|
10
|
+
import threading
|
|
11
|
+
import webbrowser
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from . import actions, discovery
|
|
15
|
+
from .client import PluginError
|
|
16
|
+
from .overlay import Overlay
|
|
17
|
+
|
|
18
|
+
TITLE = "Traceforge"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def labels() -> list[tuple[str, str]]:
|
|
22
|
+
return [(a.id, a.label) for a in actions.ACTIONS]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TextView:
|
|
26
|
+
"""No GUI toolkit: run one action, store the answer, open the app."""
|
|
27
|
+
|
|
28
|
+
def show(self, overlay: Overlay, first_action: str) -> str:
|
|
29
|
+
overlay.run(first_action if first_action != "chat" else "datasheet")
|
|
30
|
+
text = overlay.transcript()
|
|
31
|
+
try:
|
|
32
|
+
path = discovery.config_dir() / "last-answer.md"
|
|
33
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
34
|
+
path.write_text(text + "\n", encoding="utf-8")
|
|
35
|
+
except OSError:
|
|
36
|
+
pass
|
|
37
|
+
try:
|
|
38
|
+
webbrowser.open(overlay.client.app_url())
|
|
39
|
+
except (PluginError, OSError):
|
|
40
|
+
pass
|
|
41
|
+
return text
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class TkView:
|
|
45
|
+
def __init__(self, tk: Any = None, ttk: Any = None) -> None:
|
|
46
|
+
if tk is None:
|
|
47
|
+
import tkinter as tk # noqa: PLC0415
|
|
48
|
+
from tkinter import ttk # noqa: PLC0415
|
|
49
|
+
self.tk, self.ttk = tk, ttk
|
|
50
|
+
|
|
51
|
+
def show(self, overlay: Overlay, first_action: str) -> str:
|
|
52
|
+
tk, ttk = self.tk, self.ttk
|
|
53
|
+
root = tk.Tk()
|
|
54
|
+
root.title(f"{TITLE}: {overlay.titles()[0] if overlay.parts else 'no part'}")
|
|
55
|
+
root.geometry("760x560")
|
|
56
|
+
done: queue.Queue = queue.Queue()
|
|
57
|
+
names = [label for _, label in labels()]
|
|
58
|
+
top = ttk.Frame(root)
|
|
59
|
+
top.pack(fill="x", padx=8, pady=6)
|
|
60
|
+
part_box = ttk.Combobox(top, values=overlay.titles(), state="readonly", width=28)
|
|
61
|
+
part_box.current(0)
|
|
62
|
+
part_box.pack(side="left")
|
|
63
|
+
action_box = ttk.Combobox(top, values=names, state="readonly", width=22)
|
|
64
|
+
action_box.current([i for i, _ in labels()].index(first_action))
|
|
65
|
+
action_box.pack(side="left", padx=6)
|
|
66
|
+
output = tk.Text(root, wrap="word", state="disabled")
|
|
67
|
+
output.pack(fill="both", expand=True, padx=8)
|
|
68
|
+
entry = ttk.Entry(root)
|
|
69
|
+
entry.pack(fill="x", padx=8, pady=6)
|
|
70
|
+
busy = {"on": False}
|
|
71
|
+
|
|
72
|
+
def render() -> None:
|
|
73
|
+
output.configure(state="normal")
|
|
74
|
+
output.delete("1.0", "end")
|
|
75
|
+
output.insert("end", overlay.transcript())
|
|
76
|
+
output.configure(state="disabled")
|
|
77
|
+
output.see("end")
|
|
78
|
+
|
|
79
|
+
def go(action_id: str, question: str = "") -> None:
|
|
80
|
+
if busy["on"]:
|
|
81
|
+
return
|
|
82
|
+
busy["on"] = True
|
|
83
|
+
overlay.index = max(part_box.current(), 0)
|
|
84
|
+
|
|
85
|
+
def work() -> None:
|
|
86
|
+
overlay.run(action_id, question)
|
|
87
|
+
done.put(True)
|
|
88
|
+
|
|
89
|
+
threading.Thread(target=work, daemon=True).start()
|
|
90
|
+
poll()
|
|
91
|
+
|
|
92
|
+
def poll() -> None:
|
|
93
|
+
try:
|
|
94
|
+
done.get_nowait()
|
|
95
|
+
except queue.Empty:
|
|
96
|
+
root.after(150, poll)
|
|
97
|
+
return
|
|
98
|
+
busy["on"] = False
|
|
99
|
+
render()
|
|
100
|
+
|
|
101
|
+
def ask() -> None:
|
|
102
|
+
action_id = labels()[max(action_box.current(), 0)][0]
|
|
103
|
+
question, _ = entry.get(), entry.delete(0, "end")
|
|
104
|
+
go(action_id, question)
|
|
105
|
+
|
|
106
|
+
def open_app() -> None:
|
|
107
|
+
try:
|
|
108
|
+
webbrowser.open(overlay.client.app_url())
|
|
109
|
+
except PluginError:
|
|
110
|
+
pass
|
|
111
|
+
|
|
112
|
+
ttk.Button(top, text="Ask", command=ask).pack(side="left")
|
|
113
|
+
ttk.Button(top, text="Open in app", command=open_app).pack(side="right")
|
|
114
|
+
entry.bind("<Return>", lambda _e: ask())
|
|
115
|
+
render()
|
|
116
|
+
if first_action != "chat":
|
|
117
|
+
go(first_action)
|
|
118
|
+
root.mainloop()
|
|
119
|
+
return overlay.transcript()
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class WxView:
|
|
123
|
+
def __init__(self, wx: Any = None) -> None:
|
|
124
|
+
if wx is None:
|
|
125
|
+
import wx # noqa: PLC0415
|
|
126
|
+
self.wx = wx
|
|
127
|
+
|
|
128
|
+
def show(self, overlay: Overlay, first_action: str) -> str:
|
|
129
|
+
wx = self.wx
|
|
130
|
+
dialog = wx.Dialog(
|
|
131
|
+
None,
|
|
132
|
+
title=f"{TITLE}: {overlay.titles()[0] if overlay.parts else 'no part'}",
|
|
133
|
+
size=(760, 560),
|
|
134
|
+
style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
|
|
135
|
+
)
|
|
136
|
+
sizer = wx.BoxSizer(wx.VERTICAL)
|
|
137
|
+
row = wx.BoxSizer(wx.HORIZONTAL)
|
|
138
|
+
part_box = wx.Choice(dialog, choices=overlay.titles())
|
|
139
|
+
part_box.SetSelection(0)
|
|
140
|
+
action_box = wx.Choice(dialog, choices=[label for _, label in labels()])
|
|
141
|
+
action_box.SetSelection([i for i, _ in labels()].index(first_action))
|
|
142
|
+
ask_button = wx.Button(dialog, label="Ask")
|
|
143
|
+
app_button = wx.Button(dialog, label="Open in app")
|
|
144
|
+
for widget in (part_box, action_box, ask_button, app_button):
|
|
145
|
+
row.Add(widget, 0, wx.ALL, 4)
|
|
146
|
+
output = wx.TextCtrl(dialog, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_WORDWRAP)
|
|
147
|
+
entry = wx.TextCtrl(dialog, style=wx.TE_PROCESS_ENTER)
|
|
148
|
+
sizer.Add(row, 0, wx.EXPAND)
|
|
149
|
+
sizer.Add(output, 1, wx.EXPAND | wx.ALL, 4)
|
|
150
|
+
sizer.Add(entry, 0, wx.EXPAND | wx.ALL, 4)
|
|
151
|
+
dialog.SetSizer(sizer)
|
|
152
|
+
busy = {"on": False}
|
|
153
|
+
|
|
154
|
+
def finished() -> None:
|
|
155
|
+
busy["on"] = False
|
|
156
|
+
output.SetValue(overlay.transcript())
|
|
157
|
+
output.ShowPosition(output.GetLastPosition())
|
|
158
|
+
ask_button.Enable(True)
|
|
159
|
+
|
|
160
|
+
def go(action_id: str, question: str = "") -> None:
|
|
161
|
+
if busy["on"]:
|
|
162
|
+
return
|
|
163
|
+
busy["on"] = True
|
|
164
|
+
ask_button.Enable(False)
|
|
165
|
+
overlay.index = max(part_box.GetSelection(), 0)
|
|
166
|
+
|
|
167
|
+
def work() -> None:
|
|
168
|
+
overlay.run(action_id, question)
|
|
169
|
+
wx.CallAfter(finished)
|
|
170
|
+
|
|
171
|
+
threading.Thread(target=work, daemon=True).start()
|
|
172
|
+
|
|
173
|
+
def on_ask(_event: Any = None) -> None:
|
|
174
|
+
question = entry.GetValue()
|
|
175
|
+
entry.SetValue("")
|
|
176
|
+
go(labels()[max(action_box.GetSelection(), 0)][0], question)
|
|
177
|
+
|
|
178
|
+
def on_app(_event: Any) -> None:
|
|
179
|
+
try:
|
|
180
|
+
webbrowser.open(overlay.client.app_url())
|
|
181
|
+
except PluginError:
|
|
182
|
+
pass
|
|
183
|
+
|
|
184
|
+
ask_button.Bind(wx.EVT_BUTTON, on_ask)
|
|
185
|
+
entry.Bind(wx.EVT_TEXT_ENTER, on_ask)
|
|
186
|
+
app_button.Bind(wx.EVT_BUTTON, on_app)
|
|
187
|
+
if first_action != "chat":
|
|
188
|
+
go(first_action)
|
|
189
|
+
dialog.ShowModal()
|
|
190
|
+
dialog.Destroy()
|
|
191
|
+
return overlay.transcript()
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def choose_view(prefer: str = "") -> Any:
|
|
195
|
+
"""The best dialog available: ``prefer`` ("wx" or "tk") first, then the other, then text."""
|
|
196
|
+
order = [prefer, "wx", "tk"] if prefer else ["wx", "tk"]
|
|
197
|
+
for kind in dict.fromkeys(order):
|
|
198
|
+
try:
|
|
199
|
+
return WxView() if kind == "wx" else TkView()
|
|
200
|
+
except ImportError:
|
|
201
|
+
continue
|
|
202
|
+
return TextView()
|
traceforge/langchain.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""LangChain integration: traceforge as a Runnable.
|
|
2
|
+
|
|
3
|
+
from traceforge.langchain import TraceforgeRunnable
|
|
4
|
+
board_agent = TraceforgeRunnable(workspace="hardware/")
|
|
5
|
+
result = await board_agent.ainvoke("Add reverse-polarity protection to the 12 V input")
|
|
6
|
+
|
|
7
|
+
Input: a string, or {"input": str, "thread_id": str | None, "mode": "agent"|"plan"|"ask"}.
|
|
8
|
+
Output: {"output": str, "thread_id": str, "usage": {...}}.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import asyncio
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
from langchain_core.runnables import RunnableConfig, RunnableSerializable
|
|
19
|
+
except ImportError as exc: # pragma: no cover - optional dependency
|
|
20
|
+
raise ImportError(
|
|
21
|
+
"install the 'langchain' extra: pip install 'traceforge-pcb[langchain]'"
|
|
22
|
+
) from exc
|
|
23
|
+
|
|
24
|
+
from traceforge.config import Settings
|
|
25
|
+
from traceforge.runtime import Runtime
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class TraceforgeRunnable(RunnableSerializable[Any, dict]):
|
|
29
|
+
workspace: str = "."
|
|
30
|
+
mode: str = "agent"
|
|
31
|
+
approval: str = "auto"
|
|
32
|
+
effort: str | None = None
|
|
33
|
+
|
|
34
|
+
def _runtime(self, mode: str) -> Runtime:
|
|
35
|
+
workspace = Path(self.workspace).resolve()
|
|
36
|
+
settings = Settings.load(workspace, {"approval": self.approval, "effort": self.effort})
|
|
37
|
+
return Runtime(workspace, settings, mode=mode)
|
|
38
|
+
|
|
39
|
+
async def ainvoke(
|
|
40
|
+
self, input: Any, config: RunnableConfig | None = None, **kwargs: Any
|
|
41
|
+
) -> dict:
|
|
42
|
+
if isinstance(input, str):
|
|
43
|
+
prompt, thread_id, mode = input, None, self.mode
|
|
44
|
+
else:
|
|
45
|
+
prompt, thread_id, mode = (
|
|
46
|
+
input["input"],
|
|
47
|
+
input.get("thread_id"),
|
|
48
|
+
input.get("mode", self.mode),
|
|
49
|
+
)
|
|
50
|
+
runtime = self._runtime(mode)
|
|
51
|
+
thread = runtime.load_thread(thread_id) if thread_id else None
|
|
52
|
+
thread = thread or runtime.new_thread(prompt[:80])
|
|
53
|
+
result = await runtime.turn(thread, prompt)
|
|
54
|
+
return {"output": result.text, "thread_id": thread.id, "usage": result.usage.to_dict()}
|
|
55
|
+
|
|
56
|
+
def invoke(self, input: Any, config: RunnableConfig | None = None, **kwargs: Any) -> dict:
|
|
57
|
+
return asyncio.run(self.ainvoke(input, config, **kwargs))
|