@nylorun/studio 0.2.0-rc.1
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 +192 -0
- package/README.md +22 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +62 -0
- package/dist/host.d.ts +20 -0
- package/dist/host.js +189 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/protocol.d.ts +39 -0
- package/dist/protocol.js +1 -0
- package/dist/web/assets/index-B1IsK-Ev.js +64 -0
- package/dist/web/assets/index-B9jULDuO.css +2 -0
- package/dist/web/brand/nylorun-mark.svg +32 -0
- package/dist/web/index.html +14 -0
- package/dist/web/nylo-studio.config.json +1 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
Copyright 2026 Nylo
|
|
181
|
+
|
|
182
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
183
|
+
you may not use this file except in compliance with the License.
|
|
184
|
+
You may obtain a copy of the License at
|
|
185
|
+
|
|
186
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
187
|
+
|
|
188
|
+
Unless required by applicable law or agreed to in writing, software
|
|
189
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
190
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
191
|
+
See the License for the specific language governing permissions and
|
|
192
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# `@nylorun/studio`
|
|
2
|
+
|
|
3
|
+
Studio is a loopback-only dashboard for developer-owned agent servers. It serves static UI assets;
|
|
4
|
+
it does not load agent code, proxy provider requests, or receive browser credentials.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npx @nylorun/studio@beta studio --agent-server-url http://127.0.0.1:4111
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The agent server must allow Studio's loopback origin with CORS and expose:
|
|
11
|
+
|
|
12
|
+
| Endpoint | Purpose |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| `GET /v1/agents` | Agent IDs and manifest URLs |
|
|
15
|
+
| `GET /agents/:id/manifest.json` | One non-secret agent manifest |
|
|
16
|
+
| `POST /agents/:id/v1/ag-ui` | AG-UI SSE run stream |
|
|
17
|
+
| `GET/POST /agents/:id/v1/sessions/...` | Sessions, events, history, and approvals |
|
|
18
|
+
|
|
19
|
+
The dependency-free discovery and manifest types are exported from this package. Do not put keys,
|
|
20
|
+
cookies, headers, or provider payloads in Studio configuration, manifests, or events.
|
|
21
|
+
|
|
22
|
+
See [Examples](../examples/README.md) for a direct-Harness Hono implementation.
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { startStudio } from "./host.js";
|
|
3
|
+
function usage() {
|
|
4
|
+
return "nylo studio — open the Nylorun Studio dashboard\n\n nylo studio --agent-server-url <http(s)-url> [--port <n>] [--no-open]";
|
|
5
|
+
}
|
|
6
|
+
function port(value, flag) {
|
|
7
|
+
const parsed = Number(value);
|
|
8
|
+
return Number.isInteger(parsed) && parsed >= 1 && parsed <= 65535 ? parsed : `${flag} ${value} is not a port number.`;
|
|
9
|
+
}
|
|
10
|
+
function studioArgs(argv) {
|
|
11
|
+
let agentServerUrl;
|
|
12
|
+
let studioPort;
|
|
13
|
+
let open = true;
|
|
14
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
15
|
+
const arg = argv[index];
|
|
16
|
+
if (arg === "--help" || arg === "-h")
|
|
17
|
+
return usage();
|
|
18
|
+
if (arg === "--no-open") {
|
|
19
|
+
open = false;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (arg === "--agent-server-url" || arg === "--port") {
|
|
23
|
+
const value = argv[++index];
|
|
24
|
+
if (value === undefined || value.startsWith("-"))
|
|
25
|
+
return `${arg} needs a value.\n${usage()}`;
|
|
26
|
+
if (arg === "--agent-server-url")
|
|
27
|
+
agentServerUrl = value;
|
|
28
|
+
else {
|
|
29
|
+
const parsed = port(value, "--port");
|
|
30
|
+
if (typeof parsed === "string")
|
|
31
|
+
return parsed;
|
|
32
|
+
studioPort = parsed;
|
|
33
|
+
}
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
return `Unknown Studio option ${arg}.\n${usage()}`;
|
|
37
|
+
}
|
|
38
|
+
if (agentServerUrl === undefined)
|
|
39
|
+
return `--agent-server-url is required.\n${usage()}`;
|
|
40
|
+
return Object.freeze({ agentServerUrl, ...(studioPort === undefined ? {} : { port: studioPort }), open });
|
|
41
|
+
}
|
|
42
|
+
async function main() {
|
|
43
|
+
const command = process.argv[2];
|
|
44
|
+
if (command !== "studio") {
|
|
45
|
+
process.stdout.write(`${usage()}\n`);
|
|
46
|
+
process.exitCode = 2;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const options = studioArgs(process.argv.slice(3));
|
|
50
|
+
if (typeof options === "string") {
|
|
51
|
+
process.stdout.write(`${options}\n`);
|
|
52
|
+
process.exitCode = options === usage() ? 0 : 2;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const studio = await startStudio(options);
|
|
56
|
+
process.stdout.write(`Studio on ${studio.address}\n`);
|
|
57
|
+
process.stdout.write(`Agent Server ${studio.agentServerUrl}\n`);
|
|
58
|
+
process.stdout.write("Bound to loopback. Press Ctrl-C to stop.\n");
|
|
59
|
+
await new Promise((stop) => process.once("SIGINT", stop));
|
|
60
|
+
await studio.close();
|
|
61
|
+
}
|
|
62
|
+
void main().catch((error) => { process.stderr.write(`error ${error instanceof Error ? error.message : String(error)}\n`); process.exitCode = 2; });
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type StudioOptions = Readonly<{
|
|
2
|
+
agentServerUrl?: string;
|
|
3
|
+
port?: number;
|
|
4
|
+
open?: boolean;
|
|
5
|
+
}>;
|
|
6
|
+
export type StudioHost = Readonly<{
|
|
7
|
+
address: string;
|
|
8
|
+
readonly agentServerUrl: string;
|
|
9
|
+
setAgentServerUrl(url: string | undefined): void;
|
|
10
|
+
open(): void;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}>;
|
|
13
|
+
export type StudioConfig = Readonly<{
|
|
14
|
+
agentServerUrl?: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function parseAgentServerUrl(value: string): string;
|
|
17
|
+
/** Serves the packaged React distribution and a non-secret in-memory runtime configuration. */
|
|
18
|
+
export declare function startStudio(options?: StudioOptions): Promise<StudioHost>;
|
|
19
|
+
/** Alias retained for programmatic callers that used the static host name. */
|
|
20
|
+
export declare const startStaticStudio: typeof startStudio;
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { dirname, extname, join, resolve, sep } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
const CONFIG_PATH = "/nylo-studio.config.json";
|
|
7
|
+
const MIME_TYPES = Object.freeze({
|
|
8
|
+
".css": "text/css; charset=utf-8",
|
|
9
|
+
".html": "text/html; charset=utf-8",
|
|
10
|
+
".ico": "image/x-icon",
|
|
11
|
+
".js": "text/javascript; charset=utf-8",
|
|
12
|
+
".json": "application/json; charset=utf-8",
|
|
13
|
+
".map": "application/json; charset=utf-8",
|
|
14
|
+
".png": "image/png",
|
|
15
|
+
".svg": "image/svg+xml",
|
|
16
|
+
".webp": "image/webp",
|
|
17
|
+
".woff2": "font/woff2"
|
|
18
|
+
});
|
|
19
|
+
export function parseAgentServerUrl(value) {
|
|
20
|
+
let url;
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(value);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw new Error("--agent-server-url must be an absolute http(s) URL.");
|
|
26
|
+
}
|
|
27
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
28
|
+
throw new Error("--agent-server-url must use http or https.");
|
|
29
|
+
if (url.username !== "" || url.password !== "")
|
|
30
|
+
throw new Error("--agent-server-url must not contain credentials.");
|
|
31
|
+
if (url.search !== "" || url.hash !== "")
|
|
32
|
+
throw new Error("--agent-server-url must not contain a query string or fragment.");
|
|
33
|
+
return url.href.replace(/\/$/u, "");
|
|
34
|
+
}
|
|
35
|
+
function json(response, status, value) {
|
|
36
|
+
response.writeHead(status, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store", "x-content-type-options": "nosniff" });
|
|
37
|
+
response.end(`${JSON.stringify(value)}\n`);
|
|
38
|
+
}
|
|
39
|
+
function reject(response, status, message) { json(response, status, { error: { message } }); }
|
|
40
|
+
function browser(address) {
|
|
41
|
+
const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
42
|
+
const args = process.platform === "win32" ? ["/c", "start", "", address] : [address];
|
|
43
|
+
const child = spawn(command, args, { detached: true, stdio: "ignore" });
|
|
44
|
+
child.unref();
|
|
45
|
+
}
|
|
46
|
+
function staticPath(root, pathname) {
|
|
47
|
+
let decoded;
|
|
48
|
+
try {
|
|
49
|
+
decoded = decodeURIComponent(pathname);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
if (decoded.includes("\0"))
|
|
55
|
+
return undefined;
|
|
56
|
+
const candidate = resolve(root, decoded.replace(/^\/+/, "") || "index.html");
|
|
57
|
+
return candidate === root || candidate.startsWith(`${root}${sep}`) ? candidate : undefined;
|
|
58
|
+
}
|
|
59
|
+
function staticHeaders(file) {
|
|
60
|
+
const immutable = file.includes(`${sep}assets${sep}`);
|
|
61
|
+
return {
|
|
62
|
+
"content-type": MIME_TYPES[extname(file)] ?? "application/octet-stream",
|
|
63
|
+
"cache-control": immutable ? "public, max-age=31536000, immutable" : "no-store",
|
|
64
|
+
"x-content-type-options": "nosniff"
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function sendFile(response, method, file) {
|
|
68
|
+
try {
|
|
69
|
+
const content = await readFile(file);
|
|
70
|
+
response.writeHead(200, staticHeaders(file));
|
|
71
|
+
response.end(method === "HEAD" ? undefined : content);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function loopbackHosts(port) {
|
|
79
|
+
return new Set([`localhost:${port}`, `127.0.0.1:${port}`, `[::1]:${port}`]);
|
|
80
|
+
}
|
|
81
|
+
async function listenOn(host, port, handle) {
|
|
82
|
+
const server = createServer(handle);
|
|
83
|
+
await new Promise((ready, reject) => {
|
|
84
|
+
const failed = (error) => reject(error);
|
|
85
|
+
server.once("error", failed);
|
|
86
|
+
server.listen(port, host, () => {
|
|
87
|
+
server.off("error", failed);
|
|
88
|
+
ready();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return server;
|
|
92
|
+
}
|
|
93
|
+
function ipv6Optional(error) {
|
|
94
|
+
return error instanceof Error && "code" in error && ["EADDRNOTAVAIL", "EAFNOSUPPORT", "EPERM"].includes(String(error.code));
|
|
95
|
+
}
|
|
96
|
+
async function bindLoopback(handle, port) {
|
|
97
|
+
const ipv4 = await listenOn("127.0.0.1", port, handle);
|
|
98
|
+
const address = ipv4.address();
|
|
99
|
+
if (address === null || typeof address === "string") {
|
|
100
|
+
ipv4.close();
|
|
101
|
+
throw new Error("Studio did not report a TCP address.");
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
return Object.freeze({ port: address.port, servers: Object.freeze([ipv4, await listenOn("::1", address.port, handle)]) });
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (ipv6Optional(error))
|
|
108
|
+
return Object.freeze({ port: address.port, servers: Object.freeze([ipv4]) });
|
|
109
|
+
ipv4.close();
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function listenForStudio(handle, port) {
|
|
114
|
+
if (port !== undefined)
|
|
115
|
+
return bindLoopback(handle, port);
|
|
116
|
+
let lastError;
|
|
117
|
+
for (let candidate = 4161; candidate <= 4260; candidate += 1) {
|
|
118
|
+
try {
|
|
119
|
+
return await bindLoopback(handle, candidate);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
lastError = error;
|
|
123
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "EADDRINUSE")
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`No Studio port is available in the range 4161-4260.${lastError instanceof Error ? ` ${lastError.message}` : ""}`);
|
|
128
|
+
}
|
|
129
|
+
/** Serves the packaged React distribution and a non-secret in-memory runtime configuration. */
|
|
130
|
+
export async function startStudio(options = {}) {
|
|
131
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..", "dist", "web");
|
|
132
|
+
const requestedAgentServerUrl = options.agentServerUrl === undefined ? undefined : parseAgentServerUrl(options.agentServerUrl);
|
|
133
|
+
let origin = "";
|
|
134
|
+
let agentServerUrl = requestedAgentServerUrl;
|
|
135
|
+
const handle = (request, response) => {
|
|
136
|
+
void (async () => {
|
|
137
|
+
const url = new URL(request.url ?? "/", origin || "http://localhost");
|
|
138
|
+
if (origin === "" || !loopbackHosts(Number(new URL(origin).port)).has(request.headers.host ?? "")) {
|
|
139
|
+
reject(response, 421, "Studio only accepts its own loopback Host header.");
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (url.pathname === "/_studio" || url.pathname.startsWith("/_studio/")) {
|
|
143
|
+
reject(response, 404, "Studio has no API routes.");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (url.pathname === CONFIG_PATH && request.method === "GET") {
|
|
147
|
+
json(response, 200, agentServerUrl === undefined ? {} : { agentServerUrl });
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
151
|
+
reject(response, 405, "Studio only serves static assets.");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const target = staticPath(root, url.pathname);
|
|
155
|
+
if (target === undefined) {
|
|
156
|
+
reject(response, 400, "Invalid Studio asset path.");
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (await sendFile(response, request.method, target))
|
|
160
|
+
return;
|
|
161
|
+
if (extname(target) !== "") {
|
|
162
|
+
reject(response, 404, "Studio asset not found.");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (!(await sendFile(response, request.method, join(root, "index.html"))))
|
|
166
|
+
reject(response, 500, "Studio distribution is missing. Reinstall or rebuild @nylorun/studio.");
|
|
167
|
+
})();
|
|
168
|
+
};
|
|
169
|
+
const bound = await listenForStudio(handle, options.port);
|
|
170
|
+
origin = `http://localhost:${bound.port}`;
|
|
171
|
+
const address = origin;
|
|
172
|
+
const host = Object.freeze({
|
|
173
|
+
address,
|
|
174
|
+
get agentServerUrl() { return agentServerUrl ?? ""; },
|
|
175
|
+
setAgentServerUrl: (url) => { agentServerUrl = url === undefined ? undefined : parseAgentServerUrl(url); },
|
|
176
|
+
open: () => browser(address),
|
|
177
|
+
close: async () => {
|
|
178
|
+
await Promise.all(bound.servers.map((server) => new Promise((done, reject) => {
|
|
179
|
+
server.closeAllConnections();
|
|
180
|
+
server.close((error) => error === undefined ? done() : reject(error));
|
|
181
|
+
})));
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
if (options.open !== false)
|
|
185
|
+
host.open();
|
|
186
|
+
return host;
|
|
187
|
+
}
|
|
188
|
+
/** Alias retained for programmatic callers that used the static host name. */
|
|
189
|
+
export const startStaticStudio = startStudio;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { parseAgentServerUrl, startStaticStudio, startStudio } from "./host.js";
|
|
2
|
+
export type { StudioConfig, StudioHost, StudioOptions } from "./host.js";
|
|
3
|
+
export type { StudioAgentManifest, StudioDiscoveryDocument, StudioDiscoveryEntry, StudioEndpointSet } from "./protocol.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseAgentServerUrl, startStaticStudio, startStudio } from "./host.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** The dependency-free JSON contract a developer-owned agent server exposes to Studio. */
|
|
2
|
+
export type StudioDiscoveryDocument = Readonly<{
|
|
3
|
+
protocolVersion: 1;
|
|
4
|
+
agents: readonly StudioDiscoveryEntry[];
|
|
5
|
+
}>;
|
|
6
|
+
export type StudioDiscoveryEntry = Readonly<{
|
|
7
|
+
id: string;
|
|
8
|
+
manifestUrl: string;
|
|
9
|
+
}>;
|
|
10
|
+
export type StudioEndpointSet = Readonly<{
|
|
11
|
+
agUi: string;
|
|
12
|
+
sessions: string;
|
|
13
|
+
}>;
|
|
14
|
+
/** A generated, JSON-safe description of one direct Harness agent. */
|
|
15
|
+
export type StudioAgentManifest = Readonly<{
|
|
16
|
+
protocolVersion: 1;
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
capabilities: readonly string[];
|
|
21
|
+
requirements?: Readonly<Record<string, boolean>>;
|
|
22
|
+
model: Readonly<{
|
|
23
|
+
provider: string;
|
|
24
|
+
id: string;
|
|
25
|
+
}>;
|
|
26
|
+
harness: Readonly<{
|
|
27
|
+
name: "@nylorun/harness";
|
|
28
|
+
version: string;
|
|
29
|
+
manifest: Readonly<{
|
|
30
|
+
middleware: readonly Readonly<{
|
|
31
|
+
id: string;
|
|
32
|
+
}>[];
|
|
33
|
+
}>;
|
|
34
|
+
}>;
|
|
35
|
+
endpoints: StudioEndpointSet;
|
|
36
|
+
records?: Readonly<{
|
|
37
|
+
path: string;
|
|
38
|
+
}>;
|
|
39
|
+
}>;
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|