@omochi-ui/utils 0.0.0-stage → 0.1.0
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/LICENSE +202 -0
- package/README.md +201 -2
- package/bin/omochi-utils.js +2 -0
- package/dist/button.d.ts +20 -0
- package/dist/button.js +51 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +239 -0
- package/dist/command.d.ts +28 -0
- package/dist/command.js +110 -0
- package/dist/events.d.ts +23 -0
- package/dist/events.js +54 -0
- package/dist/http-body.d.ts +16 -0
- package/dist/http-body.js +59 -0
- package/dist/http.d.ts +32 -0
- package/dist/http.js +156 -0
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.js +59 -0
- package/dist/output.d.ts +10 -0
- package/dist/output.js +35 -0
- package/dist/process.d.ts +32 -0
- package/dist/process.js +115 -0
- package/dist/publisher.d.ts +31 -0
- package/dist/publisher.js +101 -0
- package/dist/stream.d.ts +18 -0
- package/dist/stream.js +46 -0
- package/dist/surface.d.ts +18 -0
- package/dist/surface.js +51 -0
- package/dist/tail.d.ts +25 -0
- package/dist/tail.js +130 -0
- package/dist/watch.d.ts +37 -0
- package/dist/watch.js +130 -0
- package/package.json +35 -4
package/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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,202 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @omochi-ui/utils
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Publish command controls, development observations, and agent-created A2UI
|
|
4
|
+
surfaces through the existing Omochi gateway. Requires a Unix-like environment,
|
|
5
|
+
like the discovery transport. Build with `bun install && bun run build` from the
|
|
6
|
+
repository root.
|
|
7
|
+
|
|
8
|
+
## Turn a command into a button
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
bun run omochi-utils button --service-id build --name "Build" -- bun run build
|
|
12
|
+
# In another terminal:
|
|
13
|
+
bun run omochi-ui hub
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Open the hub's printed URL, then use **Add view** to add `Build · main` to a
|
|
17
|
+
dashboard. The command runs only when clicked. The surface shows live combined
|
|
18
|
+
stdout/stderr, running status and the exit code. Only one execution can run at
|
|
19
|
+
a time, including when multiple browsers are connected. After completion or a
|
|
20
|
+
startup failure the button can be used again.
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
bun run omochi-utils button --name "Tests" --cwd /path/to/project -- bun run test
|
|
24
|
+
bun run omochi-utils button --name "Pipeline" -- sh -c 'printf hello | wc -c'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Arguments after `--` are passed literally without a shell. Commands inherit the
|
|
28
|
+
environment and current directory unless `--cwd` is supplied; stdin is closed.
|
|
29
|
+
Output keeps the latest 64 KiB, marks truncation, and resets on each run. It is
|
|
30
|
+
displayed as literal code, not interpreted as Markdown. Ctrl+C or SIGTERM stops
|
|
31
|
+
child process groups (TERM, then KILL within one second) and retracts the service.
|
|
32
|
+
|
|
33
|
+
## Watch a command
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
bun run omochi-utils watch --interval 2s -- git status --short
|
|
37
|
+
bun run omochi-utils watch --diff --on-change --history 10 -- bun run test
|
|
38
|
+
bun run omochi-utils watch --timeout 30s --cwd /path/to/project -- command args
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`watch` runs immediately, waits for the command to finish, then waits for the
|
|
42
|
+
interval before running again. Runs never overlap. The surface can pause future
|
|
43
|
+
runs, resume immediately, or run once now. `--timeout` stops a hung process group.
|
|
44
|
+
`--diff` shows the current output and a line diff from the previous run;
|
|
45
|
+
`--on-change` suppresses completed updates whose output and exit result are
|
|
46
|
+
unchanged. `--history N` retains 1–100 short execution records without retaining
|
|
47
|
+
old full output.
|
|
48
|
+
|
|
49
|
+
## Control a long-running process
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
bun run omochi-utils process --name "Dev server" -- bun run dev
|
|
53
|
+
bun run omochi-utils process --restart on-failure --restart-delay 2s -- worker
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Processes start only when **Start** is clicked. The surface provides **Stop** and
|
|
57
|
+
**Restart**, retains the latest 64 KiB of logs across restarts, and records exit
|
|
58
|
+
reasons. `--restart` accepts `never` (the default), `on-failure`, or `always`.
|
|
59
|
+
Manual stops and CLI shutdown never trigger automatic restart.
|
|
60
|
+
|
|
61
|
+
## Follow a log file or stdin
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
bun run omochi-utils tail --lines 200 ./logs/api.log
|
|
65
|
+
journalctl -f | bun run omochi-utils stream --name "System log"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`tail` waits if the path does not exist and follows the name across truncation
|
|
69
|
+
and log rotation, like `tail -F`. It treats the file as UTF-8 and never writes to
|
|
70
|
+
it. `stream` displays stdin as UTF-8. When stdin reaches EOF, it leaves the final
|
|
71
|
+
surface visible until SIGINT or SIGTERM instead of exiting immediately.
|
|
72
|
+
|
|
73
|
+
## Monitor HTTP
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
bun run omochi-utils http http://127.0.0.1:3000/health
|
|
77
|
+
bun run omochi-utils http --interval 30s --timeout 5s \
|
|
78
|
+
--expect-status 200 --expect-body '"ready":true' https://example.test/health
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`http` sends non-overlapping GET requests and provides the same pause, resume,
|
|
82
|
+
and run-now controls as `watch`. It shows status, latency, final URL, content
|
|
83
|
+
type, size, consecutive failures, and health transitions. The default expected
|
|
84
|
+
status is 200–299. Text responses are shown up to 64 KiB; JSON media types are
|
|
85
|
+
parsed and pretty-printed. Binary response bodies are not displayed. For custom
|
|
86
|
+
methods, headers, authentication, or request bodies, use `watch -- curl ...`.
|
|
87
|
+
|
|
88
|
+
## Let an agent publish surfaces over MCP
|
|
89
|
+
|
|
90
|
+
Configure a stdio MCP server in your agent. For a source checkout, point Node to
|
|
91
|
+
the absolute path of the built CLI:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"mcpServers": {
|
|
96
|
+
"omochi": {
|
|
97
|
+
"command": "bun",
|
|
98
|
+
"args": ["/absolute/path/to/omochi-ui/packages/utils/bin/omochi-utils.js", "mcp", "--name", "Agent"]
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The process publishes through `UnixSocketServerTransport`; an existing gateway
|
|
105
|
+
discovers it automatically. Start `omochi-ui hub` separately to view surfaces.
|
|
106
|
+
The agent, gateway and hub must share the same user and `XDG_RUNTIME_DIR` for
|
|
107
|
+
local discovery. Existing SSH/paired-gateway routing works without changes.
|
|
108
|
+
|
|
109
|
+
| Tool | Arguments | Result |
|
|
110
|
+
| --- | --- | --- |
|
|
111
|
+
| `publish_messages` | `messages`: nonempty A2UI v0.9 message array | `accepted`, `serviceId`, `surfaceIds` |
|
|
112
|
+
| `list_surfaces` | none | `serviceId`, `surfaceIds` |
|
|
113
|
+
| `read_events` | `after` (default 0), `timeoutMs` (default 0, max 30000) | `events`, `nextCursor`, `dropped`, `closed` |
|
|
114
|
+
|
|
115
|
+
`publish_messages` accepts standard `createSurface`, `updateComponents`,
|
|
116
|
+
`updateDataModel`, and `deleteSurface` messages. It validates the entire batch
|
|
117
|
+
against the current state before sending anything. Errors report the failing
|
|
118
|
+
array index, leaving the published state intact. Concurrent calls are serialized.
|
|
119
|
+
Use surface-local IDs; gateway/hub prefixes are applied by the existing routers.
|
|
120
|
+
Validation checks wire shape and surface lifecycle; catalog-specific component
|
|
121
|
+
validation is still performed by the renderer.
|
|
122
|
+
|
|
123
|
+
For example, pass this to `publish_messages` to publish an interactive form:
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"messages": [
|
|
128
|
+
{
|
|
129
|
+
"version": "v0.9",
|
|
130
|
+
"createSurface": {
|
|
131
|
+
"surfaceId": "main",
|
|
132
|
+
"catalogId": "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json",
|
|
133
|
+
"sendDataModel": true
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"version": "v0.9",
|
|
138
|
+
"updateComponents": {
|
|
139
|
+
"surfaceId": "main",
|
|
140
|
+
"components": [
|
|
141
|
+
{ "id": "root", "component": "Column", "children": ["title", "request", "submit"] },
|
|
142
|
+
{ "id": "title", "component": "Text", "text": "What should we build?" },
|
|
143
|
+
{ "id": "request", "component": "TextField", "label": "Request", "value": { "path": "/request" } },
|
|
144
|
+
{ "id": "submit", "component": "Button", "child": "label", "action": { "event": { "name": "submit", "context": { "request": { "path": "/request" } } } } },
|
|
145
|
+
{ "id": "label", "component": "Text", "text": "Send" }
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
{ "version": "v0.9", "updateDataModel": { "surfaceId": "main", "path": "/", "value": { "request": "" } } }
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Call `read_events` with `{ "after": 0, "timeoutMs": 30000 }`. Each returned event
|
|
155
|
+
contains `sequence`, `receivedAt` (ISO timestamp), and the original A2UI client
|
|
156
|
+
`message`, including `action.context` and any client data model metadata. The
|
|
157
|
+
example's submitted text is in `message.action.context.request`. Respond by
|
|
158
|
+
publishing another message batch:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"messages": [{
|
|
163
|
+
"version": "v0.9",
|
|
164
|
+
"updateComponents": {
|
|
165
|
+
"surfaceId": "main",
|
|
166
|
+
"components": [{ "id": "title", "component": "Text", "text": "Working…" }]
|
|
167
|
+
}
|
|
168
|
+
}]
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Use the returned `nextCursor` as `after` for the next read. Reads do not consume
|
|
173
|
+
events, so retrying a cursor is safe. The latest 1,000 events are retained;
|
|
174
|
+
`dropped` reports how many events since the requested cursor have expired. A
|
|
175
|
+
timeout returns an empty array. Pending reads support MCP cancellation and are
|
|
176
|
+
woken on shutdown. Button clicks do not automatically wake an idle agent: it
|
|
177
|
+
must call `read_events`. These tools do not execute shell commands or callbacks.
|
|
178
|
+
|
|
179
|
+
To remove a surface, publish
|
|
180
|
+
`{"version":"v0.9","deleteSurface":{"surfaceId":"main"}}`.
|
|
181
|
+
There is no persistence: stdin EOF, SIGINT or SIGTERM closes the MCP server and
|
|
182
|
+
retracts its service. A gateway connecting later receives current surface state.
|
|
183
|
+
|
|
184
|
+
## Shared options and lifetime
|
|
185
|
+
|
|
186
|
+
All subcommands accept `--service-id ID` and `--name NAME`. IDs default to a
|
|
187
|
+
unique `utils-<uuid>`; use an explicit stable ID if saving a dashboard layout.
|
|
188
|
+
Starting a second process with a live ID fails without replacing the first.
|
|
189
|
+
Durations accept `ms`, `s`, and `m` suffixes. Each process has its own surfaces
|
|
190
|
+
and event buffer. Service registration does not start the gateway or
|
|
191
|
+
automatically place panels on a dashboard.
|
|
192
|
+
|
|
193
|
+
Use `bun run omochi-utils --help` for usage. No new TCP listener, dashboard API,
|
|
194
|
+
or transport protocol is introduced. Runtime directory permissions and existing
|
|
195
|
+
gateway access controls apply to these services as to other Omochi apps.
|
|
196
|
+
|
|
197
|
+
## Tests
|
|
198
|
+
|
|
199
|
+
`bun run build` then `bun run --filter @omochi-ui/utils test`
|
|
200
|
+
runs command execution, watch/diff, process restart, tail/stream, HTTP, shutdown,
|
|
201
|
+
event cursor, stdio MCP, and gateway integration tests. Temporary runtime
|
|
202
|
+
directories keep tests separate from real services.
|
package/dist/button.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type UI } from "@omochi-ui/sdk";
|
|
2
|
+
import { Publisher } from "./publisher.js";
|
|
3
|
+
import { UtilitySurface } from "./surface.js";
|
|
4
|
+
export interface ButtonOptions {
|
|
5
|
+
command: string[];
|
|
6
|
+
cwd?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class CommandButton extends UtilitySurface {
|
|
10
|
+
private readonly output;
|
|
11
|
+
private readonly runner;
|
|
12
|
+
private running;
|
|
13
|
+
private status;
|
|
14
|
+
private closePromise?;
|
|
15
|
+
constructor(publisher: Publisher, options: ButtonOptions);
|
|
16
|
+
protected build(ui: UI): void;
|
|
17
|
+
protected onAction(name: string): void;
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
private run;
|
|
20
|
+
}
|
package/dist/button.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Action } from "@omochi-ui/sdk";
|
|
2
|
+
import { ManagedCommand, describeResult } from "./command.js";
|
|
3
|
+
import { OutputBuffer, fenced } from "./output.js";
|
|
4
|
+
import { UtilitySurface } from "./surface.js";
|
|
5
|
+
export class CommandButton extends UtilitySurface {
|
|
6
|
+
output = new OutputBuffer();
|
|
7
|
+
runner;
|
|
8
|
+
running = false;
|
|
9
|
+
status = "Ready";
|
|
10
|
+
closePromise;
|
|
11
|
+
constructor(publisher, options) {
|
|
12
|
+
super(publisher, options.name);
|
|
13
|
+
this.runner = new ManagedCommand({
|
|
14
|
+
command: options.command,
|
|
15
|
+
cwd: options.cwd,
|
|
16
|
+
onData: (chunk) => {
|
|
17
|
+
this.output.append(chunk);
|
|
18
|
+
this.scheduleRender();
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
build(ui) {
|
|
23
|
+
ui.text(this.name, { key: "title", variant: "h3" });
|
|
24
|
+
if (!this.running)
|
|
25
|
+
ui.button("Run", new Action("run").call(null), { key: "run", variant: "primary" });
|
|
26
|
+
ui.text(this.status, { key: "status" });
|
|
27
|
+
ui.text(fenced(this.output.text, this.output.truncated), { key: "output" });
|
|
28
|
+
}
|
|
29
|
+
onAction(name) {
|
|
30
|
+
if (name !== "run" || this.running || this.closing)
|
|
31
|
+
return;
|
|
32
|
+
void this.run();
|
|
33
|
+
}
|
|
34
|
+
close() {
|
|
35
|
+
if (this.closePromise)
|
|
36
|
+
return this.closePromise;
|
|
37
|
+
this.closeSurface();
|
|
38
|
+
this.closePromise = this.runner.close();
|
|
39
|
+
return this.closePromise;
|
|
40
|
+
}
|
|
41
|
+
async run() {
|
|
42
|
+
this.running = true;
|
|
43
|
+
this.output.reset();
|
|
44
|
+
this.status = "Running…";
|
|
45
|
+
this.scheduleRender();
|
|
46
|
+
const result = await this.runner.start();
|
|
47
|
+
this.running = false;
|
|
48
|
+
this.status = describeResult(result);
|
|
49
|
+
this.scheduleRender();
|
|
50
|
+
}
|
|
51
|
+
}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|