friend-assistant 0.1.72 → 0.1.74
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/README.md +22 -8
- package/dist/BUILD.json +2 -2
- package/dist/friend.mjs +362 -168
- package/dist/sandbox-child.mjs +318 -0
- package/dist/web/assets/{OrgParts-CKm9GiMe.js → OrgParts-Do6LghTp.js} +1 -1
- package/dist/web/assets/{index-Ds89qbOY.js → index-D-7sGBTA.js} +24 -24
- package/dist/web/assets/{jarvis-ui-P2GxXH_b.js → jarvis-ui-BAYSuxFl.js} +1 -1
- package/dist/web/assets/{jarvisTree-DL1hkJfL.js → jarvisTree-UR7AWNFs.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res, err) => function __init() {
|
|
4
|
+
if (err) throw err[0];
|
|
5
|
+
try {
|
|
6
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
7
|
+
} catch (e) {
|
|
8
|
+
throw err = [e], e;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// ../server/src/sandbox/types.ts
|
|
17
|
+
var MAX_SANDBOX_OUTPUT, SANDBOX_MEMORY_MB;
|
|
18
|
+
var init_types = __esm({
|
|
19
|
+
"../server/src/sandbox/types.ts"() {
|
|
20
|
+
"use strict";
|
|
21
|
+
MAX_SANDBOX_OUTPUT = 4e4;
|
|
22
|
+
SANDBOX_MEMORY_MB = 512;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// ../server/src/sandbox/engines/node.ts
|
|
27
|
+
var node_exports = {};
|
|
28
|
+
__export(node_exports, {
|
|
29
|
+
runNode: () => runNode
|
|
30
|
+
});
|
|
31
|
+
import { getQuickJS } from "quickjs-emscripten";
|
|
32
|
+
async function runNode(input) {
|
|
33
|
+
const QuickJS = await getQuickJS();
|
|
34
|
+
const rt = QuickJS.newRuntime();
|
|
35
|
+
rt.setMemoryLimit(MEMORY_BYTES);
|
|
36
|
+
rt.setMaxStackSize(STACK_BYTES);
|
|
37
|
+
const deadline = Date.now() + input.timeoutMs;
|
|
38
|
+
let out = "";
|
|
39
|
+
let err = "";
|
|
40
|
+
let tooMuch = false;
|
|
41
|
+
let timedOut = false;
|
|
42
|
+
rt.setInterruptHandler(() => {
|
|
43
|
+
if (tooMuch) return true;
|
|
44
|
+
if (Date.now() > deadline) {
|
|
45
|
+
timedOut = true;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
});
|
|
50
|
+
const vm = rt.newContext();
|
|
51
|
+
try {
|
|
52
|
+
const add = (which, text) => {
|
|
53
|
+
if (which === "out") out += text;
|
|
54
|
+
else err += text;
|
|
55
|
+
if (out.length + err.length > MAX_SANDBOX_OUTPUT) tooMuch = true;
|
|
56
|
+
};
|
|
57
|
+
const show = (args) => args.map((a) => typeof a === "string" ? a : safeJson(a)).join(" ") + "\n";
|
|
58
|
+
const console_ = vm.newObject();
|
|
59
|
+
for (const [name, which] of [["log", "out"], ["info", "out"], ["error", "err"], ["warn", "err"]]) {
|
|
60
|
+
const fn = vm.newFunction(name, (...args) => {
|
|
61
|
+
add(which, show(args.map((h) => vm.dump(h))));
|
|
62
|
+
});
|
|
63
|
+
vm.setProp(console_, name, fn);
|
|
64
|
+
fn.dispose();
|
|
65
|
+
}
|
|
66
|
+
vm.setProp(vm.global, "console", console_);
|
|
67
|
+
console_.dispose();
|
|
68
|
+
const readFile = vm.newFunction("readFile", (nameHandle) => {
|
|
69
|
+
const name = String(vm.dump(nameHandle));
|
|
70
|
+
if (!Object.prototype.hasOwnProperty.call(input.files, name)) return { error: vm.newString(`No such file: ${name}`) };
|
|
71
|
+
return vm.newString(input.files[name]);
|
|
72
|
+
});
|
|
73
|
+
vm.setProp(vm.global, "readFile", readFile);
|
|
74
|
+
readFile.dispose();
|
|
75
|
+
const r = vm.evalCode(input.code, "main.js");
|
|
76
|
+
let code = 0;
|
|
77
|
+
if (r.error) {
|
|
78
|
+
const e = vm.dump(r.error);
|
|
79
|
+
r.error.dispose();
|
|
80
|
+
const o = typeof e === "object" && e ? e : null;
|
|
81
|
+
const message = o ? `${o.name ?? "Error"}: ${o.message ?? ""}
|
|
82
|
+
${o.stack ?? ""}` : String(e);
|
|
83
|
+
if (!timedOut && !tooMuch) err += message.endsWith("\n") ? message : message + "\n";
|
|
84
|
+
code = 1;
|
|
85
|
+
} else {
|
|
86
|
+
r.value.dispose();
|
|
87
|
+
while (!timedOut && !tooMuch && rt.hasPendingJob()) {
|
|
88
|
+
const jobs = rt.executePendingJobs();
|
|
89
|
+
if (jobs.error) {
|
|
90
|
+
const e = vm.dump(jobs.error);
|
|
91
|
+
jobs.error.dispose();
|
|
92
|
+
err += `${e?.message ?? String(e)}
|
|
93
|
+
`;
|
|
94
|
+
code = 1;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const outOfMemory = /out of memory/i.test(err);
|
|
100
|
+
if (timedOut) code = 1;
|
|
101
|
+
return { code: timedOut ? null : code, stdout: out.slice(0, MAX_SANDBOX_OUTPUT), stderr: err.slice(0, MAX_SANDBOX_OUTPUT), timedOut, outOfMemory };
|
|
102
|
+
} finally {
|
|
103
|
+
try {
|
|
104
|
+
vm.dispose();
|
|
105
|
+
rt.dispose();
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function safeJson(v) {
|
|
111
|
+
try {
|
|
112
|
+
return typeof v === "undefined" ? "undefined" : JSON.stringify(v);
|
|
113
|
+
} catch {
|
|
114
|
+
return String(v);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
var MEMORY_BYTES, STACK_BYTES;
|
|
118
|
+
var init_node = __esm({
|
|
119
|
+
"../server/src/sandbox/engines/node.ts"() {
|
|
120
|
+
"use strict";
|
|
121
|
+
init_types();
|
|
122
|
+
MEMORY_BYTES = 256 * 1024 * 1024;
|
|
123
|
+
STACK_BYTES = 1024 * 1024;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// ../server/src/sandbox/engines/python.ts
|
|
128
|
+
var python_exports = {};
|
|
129
|
+
__export(python_exports, {
|
|
130
|
+
runPython: () => runPython
|
|
131
|
+
});
|
|
132
|
+
import { constants as fsConstants } from "node:fs";
|
|
133
|
+
import { constants as osConstants } from "node:os";
|
|
134
|
+
async function runPython(input) {
|
|
135
|
+
const limitPages = SANDBOX_MEMORY_MB * 1024 * 1024 / 65536;
|
|
136
|
+
const realGrow = WebAssembly.Memory.prototype.grow;
|
|
137
|
+
WebAssembly.Memory.prototype.grow = function(delta) {
|
|
138
|
+
if (this.buffer.byteLength / 65536 + delta > limitPages) throw new RangeError("The program asked for more memory than the sandbox allows.");
|
|
139
|
+
return realGrow.call(this, delta);
|
|
140
|
+
};
|
|
141
|
+
process.binding = (name) => {
|
|
142
|
+
if (name === "constants") return { fs: fsConstants, os: osConstants, crypto: {}, zlib: {}, trace: {} };
|
|
143
|
+
throw new Error(`process.binding is not available: ${name}`);
|
|
144
|
+
};
|
|
145
|
+
const { loadPyodide } = await import("pyodide");
|
|
146
|
+
let out = "";
|
|
147
|
+
let err = "";
|
|
148
|
+
const add = (which, line) => {
|
|
149
|
+
if (out.length + err.length >= MAX_SANDBOX_OUTPUT) return;
|
|
150
|
+
if (which === "out") out += line + "\n";
|
|
151
|
+
else err += line + "\n";
|
|
152
|
+
};
|
|
153
|
+
const py = await loadPyodide({ stdout: (s) => add("out", s), stderr: (s) => add("err", s) });
|
|
154
|
+
py.runPython(HARNESS);
|
|
155
|
+
for (const [name, body] of Object.entries(input.files)) py.FS.writeFile(`/home/pyodide/${name}`, body);
|
|
156
|
+
py.FS.writeFile("/home/pyodide/main.py", input.code);
|
|
157
|
+
py.globals.set("__friend_src", input.code);
|
|
158
|
+
py.runPython(CLOSE_BRIDGE);
|
|
159
|
+
delete process.getBuiltinModule;
|
|
160
|
+
let code = 1;
|
|
161
|
+
try {
|
|
162
|
+
code = Number(await py.runPythonAsync("__friend_run(__friend_src)"));
|
|
163
|
+
} catch (e) {
|
|
164
|
+
err += `${e instanceof Error ? e.message : String(e)}
|
|
165
|
+
`;
|
|
166
|
+
}
|
|
167
|
+
const outOfMemory = /MemoryError/.test(err);
|
|
168
|
+
return { code, stdout: out.slice(0, MAX_SANDBOX_OUTPUT), stderr: err.slice(0, MAX_SANDBOX_OUTPUT), timedOut: false, outOfMemory };
|
|
169
|
+
}
|
|
170
|
+
var HARNESS, CLOSE_BRIDGE;
|
|
171
|
+
var init_python = __esm({
|
|
172
|
+
"../server/src/sandbox/engines/python.ts"() {
|
|
173
|
+
"use strict";
|
|
174
|
+
init_types();
|
|
175
|
+
HARNESS = `
|
|
176
|
+
import sys, traceback
|
|
177
|
+
|
|
178
|
+
def __friend_run(src):
|
|
179
|
+
g = {"__name__": "__main__", "__file__": "main.py"}
|
|
180
|
+
try:
|
|
181
|
+
exec(compile(src, "main.py", "exec"), g)
|
|
182
|
+
return 0
|
|
183
|
+
except SystemExit as e:
|
|
184
|
+
c = e.code
|
|
185
|
+
if c is None:
|
|
186
|
+
return 0
|
|
187
|
+
if isinstance(c, int):
|
|
188
|
+
return c
|
|
189
|
+
print(c, file=sys.stderr)
|
|
190
|
+
return 1
|
|
191
|
+
except BaseException:
|
|
192
|
+
traceback.print_exc()
|
|
193
|
+
return 1
|
|
194
|
+
`;
|
|
195
|
+
CLOSE_BRIDGE = `
|
|
196
|
+
import sys
|
|
197
|
+
for name in ("js", "pyodide_js", "pyodide.code", "pyodide.ffi", "_pyodide_core", "pyodide.webloop", "pyodide.http", "micropip"):
|
|
198
|
+
sys.modules[name] = None
|
|
199
|
+
`;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// ../server/src/sandbox/engines/shell.ts
|
|
204
|
+
var shell_exports = {};
|
|
205
|
+
__export(shell_exports, {
|
|
206
|
+
runShell: () => runShell
|
|
207
|
+
});
|
|
208
|
+
async function runShell(input) {
|
|
209
|
+
const { Bash } = await import("just-bash");
|
|
210
|
+
const files = {};
|
|
211
|
+
for (const [name, body] of Object.entries(input.files)) files[`${HOME}/${name}`] = body;
|
|
212
|
+
const sh = new Bash({ files, cwd: HOME, env: { HOME, USER: "user", PATH: "/usr/bin:/bin" } });
|
|
213
|
+
const controller = new AbortController();
|
|
214
|
+
let timedOut = false;
|
|
215
|
+
const timer = setTimeout(() => {
|
|
216
|
+
timedOut = true;
|
|
217
|
+
controller.abort();
|
|
218
|
+
}, input.timeoutMs);
|
|
219
|
+
try {
|
|
220
|
+
const r = await sh.exec(input.code, { signal: controller.signal });
|
|
221
|
+
const stderr = r.stderr.replace(/^(?:bash: )?([^\s:]+): command not found$/gm, (_m, cmd) => `This script needs the command ${cmd}, which the built-in sandbox does not have. Install Docker to run it.`);
|
|
222
|
+
return { code: timedOut ? null : r.exitCode, stdout: r.stdout.slice(0, MAX_SANDBOX_OUTPUT), stderr: stderr.slice(0, MAX_SANDBOX_OUTPUT), timedOut, outOfMemory: false };
|
|
223
|
+
} catch (e) {
|
|
224
|
+
return { code: timedOut ? null : 1, stdout: "", stderr: `${e instanceof Error ? e.message : String(e)}
|
|
225
|
+
`, timedOut, outOfMemory: false };
|
|
226
|
+
} finally {
|
|
227
|
+
clearTimeout(timer);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
var HOME;
|
|
231
|
+
var init_shell = __esm({
|
|
232
|
+
"../server/src/sandbox/engines/shell.ts"() {
|
|
233
|
+
"use strict";
|
|
234
|
+
init_types();
|
|
235
|
+
HOME = "/home/user";
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// ../server/src/sandbox/child.ts
|
|
240
|
+
import { readFileSync } from "node:fs";
|
|
241
|
+
|
|
242
|
+
// ../server/src/sandbox/lockdown.ts
|
|
243
|
+
import dgram from "node:dgram";
|
|
244
|
+
import dns from "node:dns";
|
|
245
|
+
import http from "node:http";
|
|
246
|
+
import https from "node:https";
|
|
247
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
248
|
+
import net from "node:net";
|
|
249
|
+
import tls from "node:tls";
|
|
250
|
+
var refuse = () => {
|
|
251
|
+
throw new Error("The built-in sandbox has no network.");
|
|
252
|
+
};
|
|
253
|
+
function lockDownNetwork() {
|
|
254
|
+
const g = globalThis;
|
|
255
|
+
for (const name of ["fetch", "WebSocket", "EventSource", "XMLHttpRequest", "XMLHttpRequestUpload"]) {
|
|
256
|
+
try {
|
|
257
|
+
delete g[name];
|
|
258
|
+
} catch {
|
|
259
|
+
g[name] = void 0;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const set = (target, key) => {
|
|
263
|
+
try {
|
|
264
|
+
Object.defineProperty(target, key, { value: refuse, writable: false, configurable: false });
|
|
265
|
+
} catch {
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
for (const k of ["connect", "createConnection", "createServer"]) set(net, k);
|
|
269
|
+
set(net.Socket.prototype, "connect");
|
|
270
|
+
set(net.Server.prototype, "listen");
|
|
271
|
+
for (const k of ["connect"]) set(tls, k);
|
|
272
|
+
for (const k of ["createSocket"]) set(dgram, k);
|
|
273
|
+
for (const k of ["bind", "connect", "send"]) set(dgram.Socket.prototype, k);
|
|
274
|
+
for (const k of ["resolve", "resolve4", "resolve6", "resolveAny", "resolveCaa", "resolveCname", "resolveMx", "resolveNaptr", "resolveNs", "resolvePtr", "resolveSoa", "resolveSrv", "resolveTxt", "reverse", "setServers"]) {
|
|
275
|
+
set(dns.Resolver.prototype, k);
|
|
276
|
+
set(dns.promises.Resolver.prototype, k);
|
|
277
|
+
}
|
|
278
|
+
set(dns, "setServers");
|
|
279
|
+
for (const k of ["request", "get", "createServer"]) {
|
|
280
|
+
set(http, k);
|
|
281
|
+
set(https, k);
|
|
282
|
+
}
|
|
283
|
+
for (const k of ["lookup", "lookupService", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveTxt", "resolveSrv", "reverse"]) {
|
|
284
|
+
set(dns, k);
|
|
285
|
+
set(dns.promises, k);
|
|
286
|
+
}
|
|
287
|
+
syncBuiltinESMExports();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ../server/src/sandbox/child.ts
|
|
291
|
+
var RESULT_MARK = "\n@@friend-sandbox-result@@";
|
|
292
|
+
async function run(input) {
|
|
293
|
+
switch (input.language) {
|
|
294
|
+
case "node":
|
|
295
|
+
return (await Promise.resolve().then(() => (init_node(), node_exports))).runNode(input);
|
|
296
|
+
case "python":
|
|
297
|
+
return (await Promise.resolve().then(() => (init_python(), python_exports))).runPython(input);
|
|
298
|
+
case "shell":
|
|
299
|
+
return (await Promise.resolve().then(() => (init_shell(), shell_exports))).runShell(input);
|
|
300
|
+
default:
|
|
301
|
+
return { unavailable: `The built-in sandbox cannot run ${input.language} yet.` };
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
async function main() {
|
|
305
|
+
const input = JSON.parse(readFileSync(0, "utf8"));
|
|
306
|
+
lockDownNetwork();
|
|
307
|
+
let result;
|
|
308
|
+
try {
|
|
309
|
+
result = await run(input);
|
|
310
|
+
} catch (e) {
|
|
311
|
+
result = { unavailable: `The built-in sandbox could not start: ${e instanceof Error ? e.message : String(e)}` };
|
|
312
|
+
}
|
|
313
|
+
process.stdout.write(RESULT_MARK + JSON.stringify(result) + "\n", () => process.exit(0));
|
|
314
|
+
}
|
|
315
|
+
void main();
|
|
316
|
+
export {
|
|
317
|
+
RESULT_MARK
|
|
318
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,r as t,s as n,t as r}from"./index-
|
|
1
|
+
import{a as e,r as t,s as n,t as r}from"./index-D-7sGBTA.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-BAYSuxFl.js";var c=n(e(),1),l=350,u=174,d=.25,f=2.5,p=96;function m(e){let t=r(e),n=e=>Math.round(e.y/134),i=e=>({x:n(e)===0?0:260+(n(e)-1)*l,y:Math.round(e.x/216*u)}),a=t.nodes.map(e=>({id:e.id,worker:e.worker,w:e.worker?240:150,...i(e)})),o=new Map(a.map(e=>[e.id,e])),s=t.edges.map(e=>{let t=o.get(e.from),n=o.get(e.to);return{from:e.from,to:e.to,x1:t.x+t.w,y1:t.y+70,x2:n.x,y2:n.y+70}}),c=Math.min(...a.map(e=>e.y));for(let e of a)e.y-=c;for(let e of s)e.y1-=c,e.y2-=c;return{nodes:a,edges:s,width:Math.max(...a.map(e=>e.x+e.w)),height:Math.max(...a.map(e=>e.y))+140}}var h=e=>Math.min(f,Math.max(d,e));function g(e,t){let n=h(Math.min((t.width-56)/e.width,(t.height-56)/e.height,1.25));return{k:n,x:(t.width-e.width*n)/2,y:(t.height-e.height*n)/2}}function _(e,t,n){let r=h(e.k*n),i=r/e.k;return{k:r,x:t.x-(t.x-e.x)*i,y:t.y-(t.y-e.y)*i}}function v(e,t,n){let r=t.width*e.k,i=t.height*e.k,a=Math.min(p,r),o=Math.min(p,i);return{k:e.k,x:Math.min(n.width-a,Math.max(a-r,e.x)),y:Math.min(n.height-o,Math.max(o-i,e.y))}}var y=t(),b={starting:`green`,running:`green`,waiting:`amber`,idle:`cyan`,paused:`ghost`,stopped:`ghost`,failed:`red`},x={starting:`active`,running:`active`,waiting:`warning`,idle:`success`,paused:`warning`,stopped:`warning`,failed:`error`},S={starting:`running`,running:`running`,waiting:`waiting`,idle:`idle`,paused:`idle`,stopped:`idle`,failed:`failed`},C=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e),w=1.25;function T({workers:e,name:t,onWorker:n}){let r=(0,c.useRef)(null),l=(0,c.useMemo)(()=>m(e),[e]),u=(0,c.useMemo)(()=>({width:l.width,height:l.height}),[l.width,l.height]),[d,f]=(0,c.useState)({width:640,height:420}),[p,h]=(0,c.useState)(()=>g(u,d)),T=(0,c.useRef)(!1),E=(0,c.useRef)(!1),D=(0,c.useRef)(null),O=new Map(e.map(e=>[e.id,e.status])),k=(0,c.useCallback)(e=>h(v(e,u,d)),[u,d]),A=(0,c.useCallback)(()=>{T.current=!1,h(g(u,d))},[u,d]);(0,c.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();t.width>40&&t.height>40&&f({width:Math.floor(t.width),height:Math.floor(t.height)})};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]),(0,c.useEffect)(()=>{T.current||h(g(u,d))},[u,d]),(0,c.useEffect)(()=>{let e=r.current;if(!e)return;let t=t=>{t.preventDefault();let n=e.getBoundingClientRect();T.current=!0,h(e=>v(_(e,{x:t.clientX-n.left,y:t.clientY-n.top},Math.exp(-t.deltaY*.0015)),u,d))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[u,d]);let j={x:d.width/2,y:d.height/2},M=e=>{T.current=!0,k(_(p,j,e))};return(0,y.jsxs)(`div`,{className:`ob-canvas-room`,ref:r,children:[(0,y.jsx)(`div`,{className:`ob-canvas-pan`,onPointerDown:e=>{e.button===0&&(E.current=!1,D.current={x:e.clientX,y:e.clientY,vx:p.x,vy:p.y,id:e.pointerId,far:!1})},onPointerMove:e=>{let t=D.current;if(!t)return;let n=e.clientX-t.x,r=e.clientY-t.y;!t.far&&Math.hypot(n,r)<5||(t.far||e.currentTarget.setPointerCapture?.(t.id),t.far=!0,E.current=!0,T.current=!0,k({k:p.k,x:t.vx+n,y:t.vy+r}))},onPointerUp:e=>{D.current=null,e.currentTarget.releasePointerCapture?.(e.pointerId)},onPointerCancel:()=>D.current=null,children:(0,y.jsxs)(`div`,{className:`ob-canvas-world`,style:{width:l.width,height:l.height,transform:`translate(${p.x}px, ${p.y}px) scale(${p.k})`},children:[(0,y.jsxs)(`svg`,{className:`ob-canvas-edges`,width:l.width,height:l.height,"aria-hidden":`true`,children:[(0,y.jsx)(`defs`,{children:(0,y.jsx)(`marker`,{id:`ob-arrow`,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,y.jsx)(`path`,{d:`M0 0L10 5L0 10z`,className:`ob-arrow`})})}),l.edges.map(e=>{let t=O.get(e.to),n=(e.x1+e.x2)/2;return(0,y.jsx)(`path`,{d:`M${e.x1} ${e.y1}C${n} ${e.y1} ${n} ${e.y2} ${e.x2} ${e.y2}`,markerEnd:`url(#ob-arrow)`,"data-flow":t===`running`||t===`starting`?`on`:t===`waiting`?`wait`:`off`},`${e.from}>${e.to}`)})]}),l.nodes.map(e=>{let r=e.worker;if(!r)return(0,y.jsxs)(`div`,{className:`ob-cnode ob-cnode-root`,"data-node":`friend`,style:{left:e.x,top:e.y,width:e.w,height:140},children:[(0,y.jsx)(a,{size:92,color:`cyan`,label:t.toUpperCase(),animated:!0}),(0,y.jsx)(`small`,{children:`the assistant`})]},e.id);let c=r.budget&&r.budget>0?Math.min(100,100*r.tokens/r.budget):void 0;return(0,y.jsx)(`div`,{className:`ob-cnode`,role:`button`,tabIndex:0,"data-node":e.id,"data-status":S[r.status],"aria-label":`${r.name}, ${r.title}, ${r.detail||r.status}`,style:{left:e.x,top:e.y,width:240,height:140},onClick:()=>{E.current?E.current=!1:n(e.id)},onKeyDown:t=>(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e.id)),children:(0,y.jsxs)(s,{cardStyle:`SideRail`,color:b[r.status],padding:`8px 12px`,header:(0,y.jsxs)(`div`,{className:`ob-cnode-head`,children:[(0,y.jsx)(`b`,{children:r.name}),(0,y.jsx)(i,{state:x[r.status],children:r.status.toUpperCase()})]}),children:[(0,y.jsx)(o,{label:`JOB`,value:r.title}),(0,y.jsx)(o,{label:`DOING`,value:r.detail||r.status}),(0,y.jsx)(o,{label:`TOKENS`,value:C(r.tokens),...c===void 0?{}:{barPercent:c}})]})},e.id)})]})}),(0,y.jsxs)(`div`,{className:`ob-canvas-tools`,role:`toolbar`,"aria-label":`View of the team`,children:[(0,y.jsx)(`button`,{type:`button`,"aria-label":`Zoom in`,onClick:()=>M(w),children:`+`}),(0,y.jsx)(`button`,{type:`button`,"aria-label":`Zoom out`,onClick:()=>M(1/w),children:`−`}),(0,y.jsx)(`button`,{type:`button`,"aria-label":`Fit the team`,onClick:A,children:`⤢`}),(0,y.jsxs)(`span`,{"aria-hidden":`true`,children:[Math.round(p.k*100),`%`]})]})]})}export{T as OrgCanvas};
|