agk 0.1.0__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.
- agk-0.1.0/LICENSE +202 -0
- agk-0.1.0/PKG-INFO +74 -0
- agk-0.1.0/README.md +56 -0
- agk-0.1.0/agk/__init__.py +23 -0
- agk-0.1.0/agk/cli.py +189 -0
- agk-0.1.0/agk/core.py +490 -0
- agk-0.1.0/agk/events.py +85 -0
- agk-0.1.0/agk/gates.py +66 -0
- agk-0.1.0/agk/templates/julia/Project.toml.tmpl +6 -0
- agk-0.1.0/agk/templates/julia/README.md.tmpl +28 -0
- agk-0.1.0/agk/templates/julia/app.jl.tmpl +30 -0
- agk-0.1.0/agk/templates/julia/index.html.tmpl +13 -0
- agk-0.1.0/agk/templates/python/README.md.tmpl +32 -0
- agk-0.1.0/agk/templates/python/app.py.tmpl +67 -0
- agk-0.1.0/agk/templates/python/index.html.tmpl +13 -0
- agk-0.1.0/agk/templates/python/pyproject.toml.tmpl +9 -0
- agk-0.1.0/agk.egg-info/PKG-INFO +74 -0
- agk-0.1.0/agk.egg-info/SOURCES.txt +27 -0
- agk-0.1.0/agk.egg-info/dependency_links.txt +1 -0
- agk-0.1.0/agk.egg-info/entry_points.txt +2 -0
- agk-0.1.0/agk.egg-info/requires.txt +1 -0
- agk-0.1.0/agk.egg-info/top_level.txt +1 -0
- agk-0.1.0/pyproject.toml +42 -0
- agk-0.1.0/setup.cfg +4 -0
- agk-0.1.0/tests/test_cli.py +98 -0
- agk-0.1.0/tests/test_endpoints.py +103 -0
- agk-0.1.0/tests/test_import.py +5 -0
- agk-0.1.0/tests/test_jobs.py +59 -0
- agk-0.1.0/tests/test_stream.py +147 -0
agk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
agk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: app-gui-kit Python server SDK — Flask server + framework-less Web Components shell for simulation/agent app GUIs (SSE streaming, HITL gates, pluggable viewers)
|
|
5
|
+
Author: ToPo-ToPo-ToPo
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/ToPo-ToPo-ToPo/app-gui-kit
|
|
8
|
+
Keywords: gui,sse,agent,simulation,flask,web-components
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Framework :: Flask
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: User Interfaces
|
|
13
|
+
Requires-Python: >=3.11
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: flask>=3.1
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# agk — app-gui-kit Python server SDK
|
|
20
|
+
|
|
21
|
+
A small framework for building local, single-user GUIs for simulation / agent
|
|
22
|
+
applications. One `AgkApp` gives you a Flask server implementing the
|
|
23
|
+
app-gui-kit protocol, and the bundled frontend kit (framework-less Web
|
|
24
|
+
Components) gives you a ready-made shell — composer, streaming task log, and
|
|
25
|
+
pluggable result viewers (glTF / STL / FEM mesh / 2D fields / WebGPU / media /
|
|
26
|
+
cards / markdown / deck).
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from agk import AgkApp
|
|
30
|
+
|
|
31
|
+
def runner(req, ctx):
|
|
32
|
+
ctx.emit.task("t1", "running", title="Analyze")
|
|
33
|
+
ctx.emit.text("working…")
|
|
34
|
+
if req.get("options", {}).get("step"):
|
|
35
|
+
ctx.gate("Proceed?") # human-in-the-loop gate
|
|
36
|
+
ctx.emit.artifact("gltf", url="/artifact/result.glb")
|
|
37
|
+
ctx.emit.task("t1", "done")
|
|
38
|
+
ctx.emit.done(summary="finished")
|
|
39
|
+
|
|
40
|
+
AgkApp("My Agent App", runner, capabilities=("step",)).run()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<!-- index.html — zero build step -->
|
|
45
|
+
<link rel="stylesheet" href="/agk/agk.css">
|
|
46
|
+
<script type="module" src="/agk/agk.js"></script>
|
|
47
|
+
<script type="module" src="/agk/agk-viewer-gltf.js"></script>
|
|
48
|
+
<agk-shell app="My Agent App"></agk-shell>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## What `AgkApp` provides
|
|
52
|
+
|
|
53
|
+
- `POST /stream` — SSE event streaming (single-flight), plus a polling
|
|
54
|
+
transport for clients that cannot use SSE
|
|
55
|
+
- `POST /cancel` / `POST /reset` / `POST /intervene` (HITL gates)
|
|
56
|
+
- `GET /artifact/<path>` (traversal-safe) and `POST /upload`
|
|
57
|
+
- `GET /agk/<path>` — serves the bundled frontend kit
|
|
58
|
+
- `/alive` + `/bye` window-lifecycle watchdog (auto-exit when the tab closes)
|
|
59
|
+
- `/agent/*` remote-job queue for headless (LLM) driving
|
|
60
|
+
- `/voice_status` + `/transcribe` with a pluggable transcriber
|
|
61
|
+
|
|
62
|
+
## Scaffolding
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
agk new my-sim-app --viewer field2d # Python app
|
|
66
|
+
agk new my-jl-app --lang julia --viewer gltf # Julia app (AppGuiKit.jl)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Notes
|
|
70
|
+
|
|
71
|
+
- The protocol, endpoints, design tokens and viewer interface are specified in
|
|
72
|
+
the app-gui-kit repository (`spec/`).
|
|
73
|
+
- The bundled frontend (`agk/static/`) includes [three.js](https://threejs.org)
|
|
74
|
+
(MIT, © Three.js Authors); its license banner is retained in the bundle.
|
agk-0.1.0/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# agk — app-gui-kit Python server SDK
|
|
2
|
+
|
|
3
|
+
A small framework for building local, single-user GUIs for simulation / agent
|
|
4
|
+
applications. One `AgkApp` gives you a Flask server implementing the
|
|
5
|
+
app-gui-kit protocol, and the bundled frontend kit (framework-less Web
|
|
6
|
+
Components) gives you a ready-made shell — composer, streaming task log, and
|
|
7
|
+
pluggable result viewers (glTF / STL / FEM mesh / 2D fields / WebGPU / media /
|
|
8
|
+
cards / markdown / deck).
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
from agk import AgkApp
|
|
12
|
+
|
|
13
|
+
def runner(req, ctx):
|
|
14
|
+
ctx.emit.task("t1", "running", title="Analyze")
|
|
15
|
+
ctx.emit.text("working…")
|
|
16
|
+
if req.get("options", {}).get("step"):
|
|
17
|
+
ctx.gate("Proceed?") # human-in-the-loop gate
|
|
18
|
+
ctx.emit.artifact("gltf", url="/artifact/result.glb")
|
|
19
|
+
ctx.emit.task("t1", "done")
|
|
20
|
+
ctx.emit.done(summary="finished")
|
|
21
|
+
|
|
22
|
+
AgkApp("My Agent App", runner, capabilities=("step",)).run()
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<!-- index.html — zero build step -->
|
|
27
|
+
<link rel="stylesheet" href="/agk/agk.css">
|
|
28
|
+
<script type="module" src="/agk/agk.js"></script>
|
|
29
|
+
<script type="module" src="/agk/agk-viewer-gltf.js"></script>
|
|
30
|
+
<agk-shell app="My Agent App"></agk-shell>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## What `AgkApp` provides
|
|
34
|
+
|
|
35
|
+
- `POST /stream` — SSE event streaming (single-flight), plus a polling
|
|
36
|
+
transport for clients that cannot use SSE
|
|
37
|
+
- `POST /cancel` / `POST /reset` / `POST /intervene` (HITL gates)
|
|
38
|
+
- `GET /artifact/<path>` (traversal-safe) and `POST /upload`
|
|
39
|
+
- `GET /agk/<path>` — serves the bundled frontend kit
|
|
40
|
+
- `/alive` + `/bye` window-lifecycle watchdog (auto-exit when the tab closes)
|
|
41
|
+
- `/agent/*` remote-job queue for headless (LLM) driving
|
|
42
|
+
- `/voice_status` + `/transcribe` with a pluggable transcriber
|
|
43
|
+
|
|
44
|
+
## Scaffolding
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
agk new my-sim-app --viewer field2d # Python app
|
|
48
|
+
agk new my-jl-app --lang julia --viewer gltf # Julia app (AppGuiKit.jl)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Notes
|
|
52
|
+
|
|
53
|
+
- The protocol, endpoints, design tokens and viewer interface are specified in
|
|
54
|
+
the app-gui-kit repository (`spec/`).
|
|
55
|
+
- The bundled frontend (`agk/static/`) includes [three.js](https://threejs.org)
|
|
56
|
+
(MIT, © Three.js Authors); its license banner is retained in the bundle.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""app-gui-kit Python サーバ SDK。
|
|
2
|
+
|
|
3
|
+
シミュレーションエージェント系アプリの Flask 定型(SSE ストリーミング、
|
|
4
|
+
単一フライト、ライフサイクル watchdog、成果物配信、remote-job キュー、
|
|
5
|
+
アップロード、HITL ゲート、起動処理)を提供する。
|
|
6
|
+
|
|
7
|
+
使い方::
|
|
8
|
+
|
|
9
|
+
from agk import AgkApp
|
|
10
|
+
|
|
11
|
+
def runner(req, ctx):
|
|
12
|
+
ctx.emit.text("hello")
|
|
13
|
+
ctx.emit.done(summary="finished")
|
|
14
|
+
|
|
15
|
+
AgkApp("my-app", runner).run()
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from .core import AgkApp, AgkContext
|
|
19
|
+
from .events import EventSink
|
|
20
|
+
from .gates import GateHub
|
|
21
|
+
|
|
22
|
+
__all__ = ["AgkApp", "AgkContext", "EventSink", "GateHub", "__version__"]
|
|
23
|
+
__version__ = "0.1.0"
|
agk-0.1.0/agk/cli.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""agk CLI — アプリのスキャフォールド生成。
|
|
2
|
+
|
|
3
|
+
使い方::
|
|
4
|
+
|
|
5
|
+
agk new <name> [--lang python|julia]
|
|
6
|
+
[--viewer media|cards|field2d|gltf|mesh|webgpu|none]
|
|
7
|
+
[--dir .]
|
|
8
|
+
|
|
9
|
+
`agk/templates/<lang>/` の ``*.tmpl`` を ``str.format`` 置換
|
|
10
|
+
({name} / {viewer_script} / {viewer_example} / {viewer_note})で展開する。
|
|
11
|
+
テンプレート内の literal な波括弧は ``{{`` / ``}}`` でエスケープする。
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import argparse
|
|
17
|
+
import re
|
|
18
|
+
import sys
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
__all__ = ["main"]
|
|
22
|
+
|
|
23
|
+
TEMPLATES_DIR = Path(__file__).resolve().parent / "templates"
|
|
24
|
+
LANGS = ("python", "julia")
|
|
25
|
+
VIEWERS = ("media", "cards", "field2d", "gltf", "mesh", "webgpu", "none")
|
|
26
|
+
|
|
27
|
+
NAME_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]*$")
|
|
28
|
+
|
|
29
|
+
# viewer 名 → dist 配布モジュール(/agk/ 配下)。none はインポートなし。
|
|
30
|
+
_VIEWER_MODULES = {v: f"agk-viewer-{v}.js" for v in VIEWERS if v != "none"}
|
|
31
|
+
|
|
32
|
+
# viewer 名 → app.py に埋めるコメント付き成果物例(protocol.md §5)。
|
|
33
|
+
_PY_EXAMPLES = {
|
|
34
|
+
"media": '''\
|
|
35
|
+
# --- 成果物(media ビューア: image / video)---------------------------
|
|
36
|
+
# png = ctx.workspace / "plot.png"
|
|
37
|
+
# png.write_bytes(...) # 画像を生成
|
|
38
|
+
# ctx.emit.artifact("image", url="/artifact/plot.png", mime="image/png")
|
|
39
|
+
''',
|
|
40
|
+
"cards": '''\
|
|
41
|
+
# --- 成果物(cards ビューア)------------------------------------------
|
|
42
|
+
# import json
|
|
43
|
+
# cards = [{"title": "result A", "snippet": "...", "badges": ["ok"]}]
|
|
44
|
+
# path = ctx.workspace / "cards.json"
|
|
45
|
+
# path.write_text(json.dumps(cards, ensure_ascii=False), encoding="utf-8")
|
|
46
|
+
# ctx.emit.artifact("cards", url="/artifact/cards.json",
|
|
47
|
+
# mime="application/json", replace=False)
|
|
48
|
+
''',
|
|
49
|
+
"field2d": '''\
|
|
50
|
+
# --- 成果物(field2d ビューア: 2D スカラー場グリッド)------------------
|
|
51
|
+
# import json
|
|
52
|
+
# nx, ny = 32, 32
|
|
53
|
+
# data = {"nx": nx, "ny": ny,
|
|
54
|
+
# "fields": [{"name": "u", "data": [0.0] * (nx * ny)}]}
|
|
55
|
+
# path = ctx.workspace / "field.json"
|
|
56
|
+
# path.write_text(json.dumps(data), encoding="utf-8")
|
|
57
|
+
# ctx.emit.artifact("field2d", url="/artifact/field.json",
|
|
58
|
+
# mime="application/json")
|
|
59
|
+
''',
|
|
60
|
+
"gltf": '''\
|
|
61
|
+
# --- 成果物(gltf ビューア: GLB / glTF)--------------------------------
|
|
62
|
+
# glb = ctx.workspace / "model.glb"
|
|
63
|
+
# glb.write_bytes(...) # GLB を生成
|
|
64
|
+
# ctx.emit.artifact("gltf", url="/artifact/model.glb",
|
|
65
|
+
# mime="model/gltf-binary", meta={"up": "z"})
|
|
66
|
+
''',
|
|
67
|
+
"mesh": '''\
|
|
68
|
+
# --- 成果物(mesh ビューア: FEM メッシュ+結果)-------------------------
|
|
69
|
+
# path = ctx.workspace / "mesh.json"
|
|
70
|
+
# path.write_text(...) # メッシュ+フィールドを書き出す
|
|
71
|
+
# ctx.emit.artifact("mesh", url="/artifact/mesh.json",
|
|
72
|
+
# meta={"fields": [{"name": "stress", "unit": "MPa"}]})
|
|
73
|
+
''',
|
|
74
|
+
"webgpu": '''\
|
|
75
|
+
# --- 成果物(webgpu ビューア: 大規模粒子/格子の GPU 描画)---------------
|
|
76
|
+
# 標準 kind(field2d 等)かアプリ固有 kind("x-<app>.<name>")を送る。
|
|
77
|
+
# ctx.emit.artifact("field2d", url="/artifact/field.json",
|
|
78
|
+
# mime="application/json")
|
|
79
|
+
''',
|
|
80
|
+
"none": '''\
|
|
81
|
+
# --- 成果物(組み込みビューア: markdown / image / video)---------------
|
|
82
|
+
# md = ctx.workspace / "result.md"
|
|
83
|
+
# md.write_text("## 結果\\n", encoding="utf-8")
|
|
84
|
+
# ctx.emit.artifact("markdown", url="/artifact/result.md",
|
|
85
|
+
# mime="text/markdown")
|
|
86
|
+
''',
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# viewer 名 → app.jl に埋めるコメント例。
|
|
90
|
+
_JL_EXAMPLES = {
|
|
91
|
+
"none": '''\
|
|
92
|
+
# path = joinpath(ctx.workspace, "result.md")
|
|
93
|
+
# write(path, "## 結果\\n")
|
|
94
|
+
# emit(ctx, "artifact"; kind="markdown", url="/artifact/result.md",
|
|
95
|
+
# mime="text/markdown")''',
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _jl_example(viewer: str) -> str:
|
|
100
|
+
if viewer in _JL_EXAMPLES:
|
|
101
|
+
return _JL_EXAMPLES[viewer]
|
|
102
|
+
return (
|
|
103
|
+
f' # emit(ctx, "artifact"; kind="{viewer if viewer != "media" else "image"}",\n'
|
|
104
|
+
f' # url="/artifact/result", mime="application/octet-stream")'
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _viewer_script(viewer: str) -> str:
|
|
109
|
+
"""index.html に挿す viewer モジュールの <script> 行(none は空)。"""
|
|
110
|
+
module = _VIEWER_MODULES.get(viewer)
|
|
111
|
+
if module is None:
|
|
112
|
+
return ""
|
|
113
|
+
return f'<script type="module" src="/agk/{module}"></script>\n'
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _viewer_note(viewer: str) -> str:
|
|
117
|
+
"""README に挿す viewer の補足(none は空)。"""
|
|
118
|
+
module = _VIEWER_MODULES.get(viewer)
|
|
119
|
+
if module is None:
|
|
120
|
+
return ""
|
|
121
|
+
return (
|
|
122
|
+
f"\n## ビューア\n\n"
|
|
123
|
+
f"`{viewer}` ビューア(`/agk/{module}`)を index.html でインポート済み。\n"
|
|
124
|
+
f"対応する artifact イベントの契約は `spec/protocol.md` §5 を参照。\n"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def cmd_new(args: argparse.Namespace) -> int:
|
|
129
|
+
if not NAME_RE.match(args.name):
|
|
130
|
+
print(f"agk new: 不正なアプリ名です: {args.name!r} "
|
|
131
|
+
"(英数字で始まり、英数字と . _ - のみ使用可)", file=sys.stderr)
|
|
132
|
+
return 2
|
|
133
|
+
|
|
134
|
+
src_dir = TEMPLATES_DIR / args.lang
|
|
135
|
+
if not src_dir.is_dir():
|
|
136
|
+
print(f"agk new: テンプレートが見つかりません: {src_dir}", file=sys.stderr)
|
|
137
|
+
return 2
|
|
138
|
+
|
|
139
|
+
target = Path(args.dir).expanduser().resolve() / args.name
|
|
140
|
+
if target.exists() and any(target.iterdir()):
|
|
141
|
+
print(f"agk new: 出力先が空ではありません: {target}", file=sys.stderr)
|
|
142
|
+
return 2
|
|
143
|
+
|
|
144
|
+
subs = {
|
|
145
|
+
"name": args.name,
|
|
146
|
+
"viewer_kind": args.viewer,
|
|
147
|
+
"viewer_script": _viewer_script(args.viewer),
|
|
148
|
+
"viewer_note": _viewer_note(args.viewer),
|
|
149
|
+
"viewer_example": (_PY_EXAMPLES[args.viewer] if args.lang == "python"
|
|
150
|
+
else _jl_example(args.viewer)),
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
154
|
+
created: list[str] = []
|
|
155
|
+
for tmpl in sorted(src_dir.glob("*.tmpl")):
|
|
156
|
+
out = target / tmpl.name.removesuffix(".tmpl")
|
|
157
|
+
out.write_text(tmpl.read_text(encoding="utf-8").format(**subs),
|
|
158
|
+
encoding="utf-8")
|
|
159
|
+
created.append(out.name)
|
|
160
|
+
|
|
161
|
+
print(f"created: {target}")
|
|
162
|
+
for name in created:
|
|
163
|
+
print(f" {name}")
|
|
164
|
+
return 0
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def main(argv: list[str] | None = None) -> int:
|
|
168
|
+
parser = argparse.ArgumentParser(
|
|
169
|
+
prog="agk", description="app-gui-kit CLI(アプリのスキャフォールド生成)")
|
|
170
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
171
|
+
|
|
172
|
+
new = sub.add_parser("new", help="新規アプリの雛形を生成する")
|
|
173
|
+
new.add_argument("name", help="アプリ名(生成するディレクトリ名)")
|
|
174
|
+
new.add_argument("--lang", choices=LANGS, default="python",
|
|
175
|
+
help="サーバ言語(既定: python)")
|
|
176
|
+
new.add_argument("--viewer", choices=VIEWERS, default="none",
|
|
177
|
+
help="使用する標準ビューア(既定: none)")
|
|
178
|
+
new.add_argument("--dir", default=".",
|
|
179
|
+
help="生成先の親ディレクトリ(既定: カレント)")
|
|
180
|
+
|
|
181
|
+
args = parser.parse_args(argv)
|
|
182
|
+
if args.command == "new":
|
|
183
|
+
return cmd_new(args)
|
|
184
|
+
parser.error(f"unknown command: {args.command}")
|
|
185
|
+
return 2 # unreachable
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
if __name__ == "__main__":
|
|
189
|
+
sys.exit(main())
|