@llmnative/agentico 0.25.0 → 0.26.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/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -70
- package/dist/index.mjs.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +298 -250
- package/dist/server.mjs.map +1 -1
- package/dist/types/backend/agenticoBackend.d.ts +5 -1
- package/dist/types/server/runners.d.ts +30 -7
- package/dist/types/server/server.d.ts +20 -8
- package/package.json +2 -2
package/dist/server.mjs
CHANGED
|
@@ -391,111 +391,136 @@ function M(e, t) {
|
|
|
391
391
|
if (!A.test(t)) throw new j(`invalid tenant "${t}"`);
|
|
392
392
|
return `${e}-${t}`;
|
|
393
393
|
}
|
|
394
|
-
var N = (e, t) => t === e || t.startsWith(`${e}-`), P = (e, t) => t === e ? void 0 : t.slice(e.length + 1), F = "agentico_runners", I = "agentico_runner_pairings", L = "agentico_namespaces", R = "agentico_runner_chats", z = "agentico_runner_installs", B = class extends Error {
|
|
394
|
+
var N = (e, t) => t === e || t.startsWith(`${e}-`), P = (e, t) => t === e ? void 0 : t.slice(e.length + 1), F = "agentico_runners", I = "agentico_runner_pairings", L = "agentico_namespaces", R = "agentico_runner_chats", z = "agentico_runner_installs", B = (e, t) => e.platform || !!t.owners?.includes(e.namespace), V = (e, t) => !t.owners?.length || t.owners.includes(e), H = class extends Error {
|
|
395
395
|
code;
|
|
396
396
|
constructor(e, t) {
|
|
397
397
|
super(t), this.name = "FleetError", this.code = e;
|
|
398
398
|
}
|
|
399
|
-
},
|
|
399
|
+
}, U = [
|
|
400
400
|
"complete",
|
|
401
401
|
"chat",
|
|
402
402
|
"chat:tools",
|
|
403
403
|
"accounts",
|
|
404
404
|
"act-as-user"
|
|
405
|
-
],
|
|
406
|
-
function
|
|
405
|
+
], W = [...U, "accounts:tenant"], G = (e) => `runner/${e}/platform`, K = (e) => `runner-pairing/${e}`, q = (e, t) => `namespace/${e}/runner/${t}`;
|
|
406
|
+
function J(e) {
|
|
407
407
|
let t;
|
|
408
408
|
try {
|
|
409
409
|
t = new URL(e.trim().replace(/\/+$/, ""));
|
|
410
410
|
} catch {
|
|
411
|
-
throw new
|
|
411
|
+
throw new H("invalid", "INVALID_URL");
|
|
412
412
|
}
|
|
413
|
-
if (t.protocol !== "https:" || t.pathname !== "/" || t.search || t.hash) throw new
|
|
413
|
+
if (t.protocol !== "https:" || t.pathname !== "/" || t.search || t.hash) throw new H("invalid", "INVALID_URL");
|
|
414
414
|
return t.origin;
|
|
415
415
|
}
|
|
416
|
-
var
|
|
416
|
+
var Y = (e) => ({
|
|
417
417
|
id: e.id,
|
|
418
418
|
name: e.name,
|
|
419
419
|
url: e.url,
|
|
420
420
|
isDefault: e.isDefault,
|
|
421
|
-
draining: e.draining
|
|
421
|
+
draining: e.draining,
|
|
422
|
+
...e.owners?.length ? { owners: [...e.owners] } : {}
|
|
422
423
|
});
|
|
423
|
-
function
|
|
424
|
+
function X(t) {
|
|
424
425
|
let { project: n, records: r, secrets: i } = t, a = t.connect ?? ((t, n) => new e({
|
|
425
426
|
url: t,
|
|
426
427
|
...n ? { key: n } : {}
|
|
427
|
-
})), o = t.install ?? c, s = t.newId ?? (() => crypto.randomUUID().replace(/-/g, "").slice(0, 12)), l = t.now ?? Date.now, u = async (e) => {
|
|
428
|
-
let
|
|
429
|
-
if (!t) throw new
|
|
430
|
-
return
|
|
428
|
+
})), o = t.install ?? c, s = t.newId ?? (() => crypto.randomUUID().replace(/-/g, "").slice(0, 12)), l = t.now ?? Date.now, u = async (e, t) => {
|
|
429
|
+
let n = await r.get(F, e);
|
|
430
|
+
if (!n || t && !B(t, n)) throw new H("not-found", "RUNNER_NOT_FOUND");
|
|
431
|
+
return n;
|
|
431
432
|
}, d = async (e) => {
|
|
432
433
|
let t = await i.get(e);
|
|
433
|
-
if (!t) throw new
|
|
434
|
+
if (!t) throw new H("not-found", "KEY_NOT_FOUND");
|
|
434
435
|
return t;
|
|
435
|
-
}, f = async (e) => a(e.url, await d(
|
|
436
|
-
let t =
|
|
437
|
-
if ((await r.list("agentico_runners")).some((e) => e.url === t)) throw new
|
|
436
|
+
}, f = async (e) => a(e.url, await d(G(e.id))), p = async (e) => {
|
|
437
|
+
let t = J(e);
|
|
438
|
+
if ((await r.list("agentico_runners")).some((e) => e.url === t)) throw new H("conflict", "RUNNER_ALREADY_CONNECTED");
|
|
438
439
|
return t;
|
|
439
440
|
}, m = (e, t) => String(t ?? "").trim() || new URL(e).hostname, h = async (e) => {
|
|
440
441
|
let t = s(), n = l();
|
|
441
|
-
await i.set(
|
|
442
|
+
await i.set(G(t), e.key);
|
|
442
443
|
let a = {
|
|
443
444
|
id: t,
|
|
444
445
|
name: e.name,
|
|
445
446
|
url: e.url,
|
|
446
|
-
isDefault: (await r.list(
|
|
447
|
+
isDefault: !e.owner && !(await r.list("agentico_runners")).some((e) => !e.owners?.length),
|
|
447
448
|
draining: !1,
|
|
449
|
+
...e.owner ? { owners: [e.owner] } : {},
|
|
448
450
|
...e.keyId ? { keyId: e.keyId } : {},
|
|
449
451
|
...e.hostFingerprint ? { hostFingerprint: e.hostFingerprint } : {},
|
|
450
452
|
createdAt: n,
|
|
451
453
|
updatedAt: n
|
|
452
454
|
};
|
|
453
|
-
return await r.put(F, a),
|
|
455
|
+
return await r.put(F, a), Y(a);
|
|
454
456
|
}, g = async (e) => await r.get("agentico_namespaces", e) ?? { id: e }, _ = {
|
|
455
|
-
async list() {
|
|
456
|
-
return (await r.list(F)).map(
|
|
457
|
+
async list(e) {
|
|
458
|
+
return (await r.list(F)).filter((t) => !e || B(e, t)).map(Y).sort((e, t) => e.name.localeCompare(t.name));
|
|
459
|
+
},
|
|
460
|
+
async hasRunnerFor(e) {
|
|
461
|
+
let t = await g(e), n = await r.list(F);
|
|
462
|
+
return n.some((e) => e.id === t.runnerId) || n.some((t) => !t.draining && V(e, t));
|
|
463
|
+
},
|
|
464
|
+
async share(e, t) {
|
|
465
|
+
let n = await u(e);
|
|
466
|
+
n.owners?.includes(t) || await r.put(F, {
|
|
467
|
+
...n,
|
|
468
|
+
owners: [...n.owners ?? [], t],
|
|
469
|
+
updatedAt: l()
|
|
470
|
+
});
|
|
471
|
+
},
|
|
472
|
+
async unshare(e, t) {
|
|
473
|
+
let n = await u(e);
|
|
474
|
+
n.owners?.includes(t) && await r.put(F, {
|
|
475
|
+
...n,
|
|
476
|
+
owners: n.owners.filter((e) => e !== t),
|
|
477
|
+
updatedAt: l()
|
|
478
|
+
});
|
|
457
479
|
},
|
|
458
|
-
async add(e, r = {}) {
|
|
459
|
-
let
|
|
480
|
+
async add(e, r = {}, i) {
|
|
481
|
+
let o = await p(String(e.url ?? "")), s = m(o, e.name);
|
|
460
482
|
if (e.code) {
|
|
461
|
-
let
|
|
483
|
+
let c = await a(o).pair(String(e.code).trim(), t.platformName, n);
|
|
462
484
|
return h({
|
|
463
|
-
name:
|
|
464
|
-
url:
|
|
465
|
-
key:
|
|
466
|
-
keyId:
|
|
467
|
-
...r
|
|
485
|
+
name: s,
|
|
486
|
+
url: o,
|
|
487
|
+
key: c.key,
|
|
488
|
+
keyId: c.record.id,
|
|
489
|
+
...r,
|
|
490
|
+
...i ? { owner: i } : {}
|
|
468
491
|
});
|
|
469
492
|
}
|
|
470
493
|
if (e.key) {
|
|
471
494
|
let t = String(e.key).trim();
|
|
472
|
-
return await a(
|
|
473
|
-
name:
|
|
474
|
-
url:
|
|
495
|
+
return await a(o, t).platform.status(), h({
|
|
496
|
+
name: s,
|
|
497
|
+
url: o,
|
|
475
498
|
key: t,
|
|
476
|
-
...r
|
|
499
|
+
...r,
|
|
500
|
+
...i ? { owner: i } : {}
|
|
477
501
|
});
|
|
478
502
|
}
|
|
479
|
-
throw new
|
|
503
|
+
throw new H("invalid", "CODE_OR_KEY_REQUIRED");
|
|
480
504
|
},
|
|
481
|
-
async startPairing(e, o) {
|
|
482
|
-
let
|
|
483
|
-
return await i.set(
|
|
484
|
-
id:
|
|
485
|
-
name: m(
|
|
486
|
-
url:
|
|
505
|
+
async startPairing(e, o, c) {
|
|
506
|
+
let l = await p(String(e.url ?? "")), u = await a(l).requestPairing(t.platformName, n), d = s();
|
|
507
|
+
return await i.set(K(d), u.request), await r.put(I, {
|
|
508
|
+
id: d,
|
|
509
|
+
name: m(l, e.name),
|
|
510
|
+
url: l,
|
|
487
511
|
startedBy: o,
|
|
488
|
-
expiresAt:
|
|
512
|
+
expiresAt: u.expiresAt,
|
|
513
|
+
...c ? { owner: c } : {}
|
|
489
514
|
}), {
|
|
490
|
-
id:
|
|
491
|
-
code:
|
|
492
|
-
approveUrl:
|
|
493
|
-
expiresAt:
|
|
515
|
+
id: d,
|
|
516
|
+
code: u.code,
|
|
517
|
+
approveUrl: u.approveUrl,
|
|
518
|
+
expiresAt: u.expiresAt
|
|
494
519
|
};
|
|
495
520
|
},
|
|
496
521
|
async pairingStatus(e, t) {
|
|
497
|
-
let n = await r.get(I, e), o = await i.get(
|
|
498
|
-
await r.delete(I, e), await i.delete(
|
|
522
|
+
let n = await r.get(I, e), o = await i.get(K(e)), s = async () => {
|
|
523
|
+
await r.delete(I, e), await i.delete(K(e));
|
|
499
524
|
};
|
|
500
525
|
if (!n || n.startedBy !== t || !o) return { status: "expired" };
|
|
501
526
|
if (Date.parse(n.expiresAt) <= l()) return await s(), { status: "expired" };
|
|
@@ -506,52 +531,61 @@ function J(t) {
|
|
|
506
531
|
name: n.name,
|
|
507
532
|
url: n.url,
|
|
508
533
|
key: c.key,
|
|
509
|
-
keyId: c.record.id
|
|
534
|
+
keyId: c.record.id,
|
|
535
|
+
...n.owner ? { owner: n.owner } : {}
|
|
510
536
|
})
|
|
511
537
|
} : { status: c.status });
|
|
512
538
|
},
|
|
513
|
-
async update(e, t) {
|
|
514
|
-
let
|
|
515
|
-
|
|
539
|
+
async update(e, t, n) {
|
|
540
|
+
let i = await u(e, n);
|
|
541
|
+
if (typeof t.isDefault == "boolean" && (n && !n.platform || i.owners?.length)) throw new H("invalid", "NOT_A_PROJECT_RUNNER");
|
|
542
|
+
let a = {
|
|
543
|
+
...i,
|
|
516
544
|
updatedAt: l()
|
|
517
545
|
};
|
|
518
|
-
if (typeof t.name == "string" && t.name.trim() && (
|
|
546
|
+
if (typeof t.name == "string" && t.name.trim() && (a.name = t.name.trim().slice(0, 100)), typeof t.draining == "boolean" && (a.draining = t.draining), typeof t.isDefault == "boolean" && (a.isDefault = t.isDefault, t.isDefault)) for (let t of await r.list(F)) t.id !== e && t.isDefault && await r.put(F, {
|
|
519
547
|
...t,
|
|
520
548
|
isDefault: !1,
|
|
521
549
|
updatedAt: l()
|
|
522
550
|
});
|
|
523
|
-
await r.put(F,
|
|
551
|
+
await r.put(F, a);
|
|
524
552
|
},
|
|
525
|
-
async remove(e) {
|
|
526
|
-
let
|
|
527
|
-
if (
|
|
528
|
-
|
|
553
|
+
async remove(e, t) {
|
|
554
|
+
let n = await u(e, t);
|
|
555
|
+
if (t && !t.platform && (n.owners?.length ?? 0) > 1) {
|
|
556
|
+
if ((await g(t.namespace)).runnerId === e) throw new H("conflict", "RUNNER_HAS_NAMESPACES");
|
|
557
|
+
await _.unshare(e, t.namespace);
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
if ((await r.list("agentico_namespaces")).some((t) => t.runnerId === e)) throw new H("conflict", "RUNNER_HAS_NAMESPACES");
|
|
561
|
+
n.keyId && await f(n).then((e) => e.platform.revokePlatformKey(n.keyId)).catch(() => !1), await i.delete(G(e)), await r.delete(F, e);
|
|
529
562
|
},
|
|
530
|
-
async status(e) {
|
|
531
|
-
return (await f(await u(e))).platform.status();
|
|
563
|
+
async status(e, t) {
|
|
564
|
+
return (await f(await u(e, t))).platform.status();
|
|
532
565
|
},
|
|
533
566
|
async assign(e, n, a = {}) {
|
|
534
567
|
let o = await g(e), s = await u(n);
|
|
535
|
-
if (
|
|
536
|
-
if (
|
|
568
|
+
if (!V(e, s)) throw new H("not-found", "RUNNER_NOT_FOUND");
|
|
569
|
+
if (o.runnerId === n && await i.get(q(e, n))) return;
|
|
570
|
+
if (s.draining) throw new H("conflict", "RUNNER_DRAINING");
|
|
537
571
|
let c = await f(s), l = (await c.platform.tenants()).some((t) => t.id === e), d, p;
|
|
538
572
|
if (l) {
|
|
539
573
|
let n = await c.platform.createKey(e, {
|
|
540
574
|
name: t.platformName,
|
|
541
|
-
permissions:
|
|
575
|
+
permissions: W
|
|
542
576
|
});
|
|
543
577
|
d = n.key, p = n.record.id;
|
|
544
578
|
} else {
|
|
545
579
|
let t = await c.platform.createTenant(e, {
|
|
546
580
|
...a.name ? { name: a.name } : {},
|
|
547
|
-
keyPermissions:
|
|
581
|
+
keyPermissions: W
|
|
548
582
|
});
|
|
549
583
|
if (!t.key || !t.keyRecord) throw Error("the runner made the tenant without a key");
|
|
550
584
|
d = t.key, p = t.keyRecord.id;
|
|
551
585
|
}
|
|
552
|
-
if (await i.set(
|
|
586
|
+
if (await i.set(q(e, n), d), !a.keepBefore && o.runnerId && o.runnerId !== n && o.runnerKeyId) {
|
|
553
587
|
let t = await r.get(F, o.runnerId);
|
|
554
|
-
t && await f(t).then((t) => t.platform.revokeKey(e, o.runnerKeyId)).catch(() => !1), await i.delete(
|
|
588
|
+
t && await f(t).then((t) => t.platform.revokeKey(e, o.runnerKeyId)).catch(() => !1), await i.delete(q(e, o.runnerId));
|
|
555
589
|
}
|
|
556
590
|
await r.put(L, {
|
|
557
591
|
...o,
|
|
@@ -561,20 +595,20 @@ function J(t) {
|
|
|
561
595
|
},
|
|
562
596
|
async route(e, t = {}) {
|
|
563
597
|
if (t.chat && t.user) {
|
|
564
|
-
let n = await r.get(R, `${e}_${t.user}_${t.chat}`), a = n ? await r.get(F, n.runnerId) : null, o = a ? await i.get(
|
|
598
|
+
let n = await r.get(R, `${e}_${t.user}_${t.chat}`), a = n ? await r.get(F, n.runnerId) : null, o = a ? await i.get(q(e, a.id)) : null;
|
|
565
599
|
if (a && o) return {
|
|
566
600
|
runnerId: a.id,
|
|
567
601
|
url: a.url,
|
|
568
602
|
key: o
|
|
569
603
|
};
|
|
570
604
|
}
|
|
571
|
-
let n = await r.list(F), a = await g(e), o = a.runnerId ? n.find((e) => e.id === a.runnerId) : void 0, s = n.find((e) => e.isDefault && !e.draining && e.id !== o?.id) ?? (o ? void 0 : n.find((e) => !e.draining));
|
|
605
|
+
let n = (await r.list(F)).filter((t) => V(e, t)), a = await g(e), o = a.runnerId ? n.find((e) => e.id === a.runnerId) : void 0, s = n.find((e) => e.isDefault && !e.draining && e.id !== o?.id) ?? n.find((e) => !!e.owners?.length && !e.draining && e.id !== o?.id) ?? (o ? void 0 : n.find((e) => !e.draining));
|
|
572
606
|
if (o) t.newChat && o.draining && s && (await _.assign(e, s.id, { keepBefore: !0 }), a = await g(e));
|
|
573
607
|
else {
|
|
574
608
|
if (!s) return null;
|
|
575
609
|
await _.assign(e, s.id), a = await g(e);
|
|
576
610
|
}
|
|
577
|
-
let c = a.runnerId ? await r.get(F, a.runnerId) : null, l = c ? await i.get(
|
|
611
|
+
let c = a.runnerId ? await r.get(F, a.runnerId) : null, l = c ? await i.get(q(e, c.id)) : null;
|
|
578
612
|
return c && l ? {
|
|
579
613
|
runnerId: c.id,
|
|
580
614
|
url: c.url,
|
|
@@ -590,45 +624,45 @@ function J(t) {
|
|
|
590
624
|
async chatClosed(e, t, n) {
|
|
591
625
|
await r.delete(R, `${e}_${t}_${n}`);
|
|
592
626
|
},
|
|
593
|
-
async install(e, t, n) {
|
|
594
|
-
if (!e.access?.host || !e.access.username || !e.access.privateKey && !e.access.password) throw new
|
|
595
|
-
if (!String(e.domain ?? "").trim()) throw new
|
|
596
|
-
let
|
|
597
|
-
id:
|
|
627
|
+
async install(e, t, n, i) {
|
|
628
|
+
if (!e.access?.host || !e.access.username || !e.access.privateKey && !e.access.password) throw new H("invalid", "SSH_ACCESS_REQUIRED");
|
|
629
|
+
if (!String(e.domain ?? "").trim()) throw new H("invalid", "DOMAIN_REQUIRED");
|
|
630
|
+
let a = s(), c = {
|
|
631
|
+
id: a,
|
|
598
632
|
status: "running",
|
|
599
633
|
lines: [],
|
|
600
634
|
startedBy: t
|
|
601
635
|
};
|
|
602
|
-
await r.put(z,
|
|
603
|
-
let
|
|
604
|
-
n?.(e),
|
|
605
|
-
},
|
|
636
|
+
await r.put(z, c);
|
|
637
|
+
let l = Promise.resolve(), u = (e) => {
|
|
638
|
+
n?.(e), c.lines = [...c.lines, e.line].slice(-2e3), l = l.then(() => r.put(z, c)).catch(() => void 0);
|
|
639
|
+
}, d = (async () => {
|
|
606
640
|
try {
|
|
607
641
|
let t = await o(e.access, {
|
|
608
642
|
domain: e.domain,
|
|
609
643
|
...e.version ? { version: e.version } : {},
|
|
610
|
-
onProgress:
|
|
644
|
+
onProgress: u
|
|
611
645
|
}), n = await _.add({
|
|
612
646
|
name: e.name,
|
|
613
647
|
url: t.url,
|
|
614
648
|
code: t.pairingCode
|
|
615
|
-
}, { hostFingerprint: t.hostFingerprint });
|
|
616
|
-
return await
|
|
617
|
-
...
|
|
649
|
+
}, { hostFingerprint: t.hostFingerprint }, i);
|
|
650
|
+
return await l, await r.put(z, {
|
|
651
|
+
...c,
|
|
618
652
|
status: "done",
|
|
619
653
|
runnerId: n.id
|
|
620
654
|
}), n;
|
|
621
655
|
} catch (e) {
|
|
622
|
-
throw await
|
|
623
|
-
...
|
|
656
|
+
throw await l, await r.put(z, {
|
|
657
|
+
...c,
|
|
624
658
|
status: "error",
|
|
625
659
|
error: e instanceof Error ? e.message : String(e)
|
|
626
660
|
}), e;
|
|
627
661
|
}
|
|
628
662
|
})();
|
|
629
|
-
return
|
|
630
|
-
installId:
|
|
631
|
-
done:
|
|
663
|
+
return d.catch(() => void 0), {
|
|
664
|
+
installId: a,
|
|
665
|
+
done: d
|
|
632
666
|
};
|
|
633
667
|
},
|
|
634
668
|
async installState(e, t, n = 0) {
|
|
@@ -646,16 +680,16 @@ function J(t) {
|
|
|
646
680
|
}
|
|
647
681
|
//#endregion
|
|
648
682
|
//#region src/server/server.ts
|
|
649
|
-
var
|
|
683
|
+
var Z = class extends Error {
|
|
650
684
|
status;
|
|
651
685
|
constructor(e, t) {
|
|
652
686
|
super(t), this.status = e;
|
|
653
687
|
}
|
|
654
|
-
},
|
|
688
|
+
}, Q = {
|
|
655
689
|
member: 0,
|
|
656
690
|
admin: 1,
|
|
657
691
|
platform: 2
|
|
658
|
-
},
|
|
692
|
+
}, $ = (e, t) => new Response(JSON.stringify(t), {
|
|
659
693
|
status: e,
|
|
660
694
|
headers: {
|
|
661
695
|
"content-type": "application/json",
|
|
@@ -682,7 +716,7 @@ function ie(e) {
|
|
|
682
716
|
...e.now ? { now: e.now } : {}
|
|
683
717
|
}), c = /* @__PURE__ */ new Map(), l = (t) => {
|
|
684
718
|
let i = c.get(t);
|
|
685
|
-
return i || (i =
|
|
719
|
+
return i || (i = X({
|
|
686
720
|
project: t,
|
|
687
721
|
platformName: e.platformName,
|
|
688
722
|
records: n,
|
|
@@ -691,28 +725,28 @@ function ie(e) {
|
|
|
691
725
|
...e.install ? { install: e.install } : {},
|
|
692
726
|
...e.now ? { now: e.now } : {}
|
|
693
727
|
}), c.set(t, i)), i;
|
|
694
|
-
}, u = (e, t) => {
|
|
695
|
-
if (
|
|
696
|
-
},
|
|
728
|
+
}, u = (t) => e.tenantOwned?.[t] ? "admin" : "platform", d = (e, t) => {
|
|
729
|
+
if (Q[e.role] < Q[t]) throw new Z(403, "forbidden");
|
|
730
|
+
}, f = async (e) => {
|
|
697
731
|
try {
|
|
698
732
|
let t = await e.json();
|
|
699
733
|
return t && typeof t == "object" ? t : {};
|
|
700
734
|
} catch {
|
|
701
735
|
return {};
|
|
702
736
|
}
|
|
703
|
-
},
|
|
737
|
+
}, p = (e, t) => {
|
|
704
738
|
let n = M(e.project, e.tenant), r = t.searchParams.get("namespace");
|
|
705
739
|
if (!r || r === n) return n;
|
|
706
|
-
if (
|
|
740
|
+
if (d(e, "platform"), !N(e.project, r)) throw new Z(404, "not found");
|
|
707
741
|
return M(e.project, P(e.project, r)), r;
|
|
708
|
-
},
|
|
709
|
-
async function
|
|
742
|
+
}, m = async (e) => (await n.list(L)).filter((t) => N(e, t.id)), h = async (e) => await n.get("agentico_namespaces", e) ?? { id: e };
|
|
743
|
+
async function g(e, t, n, r) {
|
|
710
744
|
if (!te.test(n) || r && !n.startsWith("/v1/accounts") || ![
|
|
711
745
|
"GET",
|
|
712
746
|
"POST",
|
|
713
747
|
"PUT",
|
|
714
748
|
"DELETE"
|
|
715
|
-
].includes(e.method)) return
|
|
749
|
+
].includes(e.method)) return $(404, { error: "not found" });
|
|
716
750
|
let o = M(t.project, t.tenant), s = l(t.project), c = ne.exec(n)?.[1], u = n === "/v1/chats" && e.method === "POST", d = e.method === "GET" || e.method === "DELETE" ? void 0 : await e.arrayBuffer(), f = u && d ? (() => {
|
|
717
751
|
try {
|
|
718
752
|
let e = JSON.parse(new TextDecoder().decode(d));
|
|
@@ -727,7 +761,7 @@ function ie(e) {
|
|
|
727
761
|
user: t.user.id
|
|
728
762
|
} : {}
|
|
729
763
|
}).catch(() => null);
|
|
730
|
-
if (!p) return
|
|
764
|
+
if (!p) return $(409, { error: "no-runner" });
|
|
731
765
|
let m = { authorization: `Bearer ${p.key}` };
|
|
732
766
|
r || (m["x-runner-user"] = t.user.id);
|
|
733
767
|
let h = e.headers.get("content-type");
|
|
@@ -741,7 +775,7 @@ function ie(e) {
|
|
|
741
775
|
signal: e.signal
|
|
742
776
|
});
|
|
743
777
|
} catch {
|
|
744
|
-
return
|
|
778
|
+
return $(502, { error: "unreachable" });
|
|
745
779
|
}
|
|
746
780
|
return f && g.ok && await s.chatStarted(o, t.user.id, f, p.runnerId), c && e.method === "DELETE" && n === `/v1/chats/${c}` && await s.chatClosed(o, t.user.id, c).catch(() => void 0), i("runner request", {
|
|
747
781
|
namespace: o,
|
|
@@ -757,77 +791,81 @@ function ie(e) {
|
|
|
757
791
|
}
|
|
758
792
|
});
|
|
759
793
|
}
|
|
760
|
-
async function
|
|
761
|
-
let
|
|
762
|
-
if (
|
|
763
|
-
let e = M(
|
|
764
|
-
return
|
|
794
|
+
async function _(t, r, c, _) {
|
|
795
|
+
let v = c.split("/").filter(Boolean).map(decodeURIComponent), [y, b, x, S] = v, C = t.method, w = r.project;
|
|
796
|
+
if (y === "me" && C === "GET") {
|
|
797
|
+
let e = M(w, r.tenant), t = await l(w).hasRunnerFor(e), n = (e) => Q[r.role] >= Q[u(e)];
|
|
798
|
+
return $(200, {
|
|
765
799
|
user: r.user,
|
|
766
800
|
role: r.role,
|
|
767
|
-
project:
|
|
801
|
+
project: w,
|
|
768
802
|
...r.tenant ? { tenant: r.tenant } : {},
|
|
769
803
|
namespace: e,
|
|
770
|
-
hasRunner: t
|
|
804
|
+
hasRunner: t,
|
|
805
|
+
administers: {
|
|
806
|
+
runners: n("runners"),
|
|
807
|
+
memories: n("memories")
|
|
808
|
+
}
|
|
771
809
|
});
|
|
772
810
|
}
|
|
773
|
-
if (
|
|
774
|
-
let e =
|
|
775
|
-
if (!
|
|
776
|
-
if (
|
|
777
|
-
|
|
778
|
-
let n = (await
|
|
779
|
-
return await o.setOrder(e, Array.isArray(n) ? n.map(String) : null),
|
|
811
|
+
if (y === "connections") {
|
|
812
|
+
let e = p(r, _);
|
|
813
|
+
if (!b && C === "GET") return $(200, await o.snapshot(e));
|
|
814
|
+
if (b === "order" && !x && C === "PUT") {
|
|
815
|
+
d(r, "admin");
|
|
816
|
+
let n = (await f(t)).order;
|
|
817
|
+
return await o.setOrder(e, Array.isArray(n) ? n.map(String) : null), $(200, { ok: !0 });
|
|
780
818
|
}
|
|
781
|
-
if (
|
|
782
|
-
if (
|
|
783
|
-
|
|
819
|
+
if (b && !x && C === "GET") return $(404, { error: "not found" });
|
|
820
|
+
if (b && x === "models" && C === "GET") return $(200, { models: await o.models(e, b) });
|
|
821
|
+
d(r, "admin");
|
|
784
822
|
let n = async () => {
|
|
785
|
-
let e = (await
|
|
823
|
+
let e = (await f(t)).fields;
|
|
786
824
|
return Object.fromEntries(Object.entries(e && typeof e == "object" ? e : {}).map(([e, t]) => [e, String(t ?? "")]));
|
|
787
825
|
};
|
|
788
|
-
if (
|
|
789
|
-
let t = await o.connect(e,
|
|
826
|
+
if (b && !x && C === "POST") {
|
|
827
|
+
let t = await o.connect(e, b, await n());
|
|
790
828
|
return i("connection", {
|
|
791
829
|
namespace: e,
|
|
792
|
-
provider:
|
|
830
|
+
provider: b,
|
|
793
831
|
ok: t.ok,
|
|
794
832
|
by: r.user.id
|
|
795
|
-
}),
|
|
833
|
+
}), $(t.ok ? 200 : 422, t);
|
|
796
834
|
}
|
|
797
|
-
if (
|
|
798
|
-
if (
|
|
799
|
-
let t = await o.addAccount(e,
|
|
800
|
-
return
|
|
835
|
+
if (b && !x && C === "DELETE") return await o.disconnect(e, b), $(200, { ok: !0 });
|
|
836
|
+
if (b && x === "accounts" && !S && C === "POST") {
|
|
837
|
+
let t = await o.addAccount(e, b, await n());
|
|
838
|
+
return $(t.ok ? 200 : 422, t);
|
|
801
839
|
}
|
|
802
|
-
if (
|
|
803
|
-
let n = (await
|
|
804
|
-
return await o.orderAccounts(e,
|
|
840
|
+
if (b && x === "accounts" && S === "order" && C === "PUT") {
|
|
841
|
+
let n = (await f(t)).ids;
|
|
842
|
+
return await o.orderAccounts(e, b, Array.isArray(n) ? n.map(String) : []), $(200, { ok: !0 });
|
|
805
843
|
}
|
|
806
|
-
if (
|
|
844
|
+
if (b && x === "accounts" && S && C === "DELETE") return await o.removeAccount(e, b, S), $(200, { ok: !0 });
|
|
807
845
|
}
|
|
808
|
-
if (
|
|
809
|
-
let e = await
|
|
810
|
-
throw new
|
|
846
|
+
if (y === "ai" && b === "complete" && C === "POST") {
|
|
847
|
+
let e = await f(t), n = String(e.provider ?? ""), a = await o.complete(M(w, r.tenant), n, e.request).catch((e) => {
|
|
848
|
+
throw new Z(e instanceof Error && e.message === "no-provider" ? 409 : 502, e instanceof Error && e.message === "no-provider" ? "no-provider" : "failed");
|
|
811
849
|
});
|
|
812
850
|
return i("ai complete", {
|
|
813
|
-
namespace: M(
|
|
851
|
+
namespace: M(w, r.tenant),
|
|
814
852
|
provider: n,
|
|
815
853
|
user: r.user.id
|
|
816
|
-
}),
|
|
854
|
+
}), $(200, { result: a });
|
|
817
855
|
}
|
|
818
|
-
if (
|
|
819
|
-
let n =
|
|
856
|
+
if (y === "ai" && b === "proxy") {
|
|
857
|
+
let n = _.searchParams.get("url") ?? "", i = /* @__PURE__ */ new Set([...re, ...(e.sessionHeaders ?? []).map((e) => e.toLowerCase())]), s = {};
|
|
820
858
|
t.headers.forEach((e, t) => {
|
|
821
859
|
i.has(t.toLowerCase()) || (s[t] = e);
|
|
822
860
|
});
|
|
823
|
-
let c = await o.resolve(M(
|
|
861
|
+
let c = await o.resolve(M(w, r.tenant), {
|
|
824
862
|
url: n,
|
|
825
863
|
headers: s
|
|
826
864
|
});
|
|
827
|
-
if (!c.ok) return
|
|
828
|
-
if (new URL(c.url).protocol !== "https:") return
|
|
829
|
-
let l =
|
|
830
|
-
method:
|
|
865
|
+
if (!c.ok) return $(c.status, { error: c.error });
|
|
866
|
+
if (new URL(c.url).protocol !== "https:") return $(403, { error: "forbidden-target" });
|
|
867
|
+
let l = C === "GET" || C === "HEAD" ? void 0 : await t.arrayBuffer(), u = await a(c.url, {
|
|
868
|
+
method: C,
|
|
831
869
|
headers: c.headers,
|
|
832
870
|
...l && l.byteLength ? { body: l } : {},
|
|
833
871
|
signal: t.signal
|
|
@@ -838,120 +876,123 @@ function ie(e) {
|
|
|
838
876
|
"content-type": u.headers.get("content-type") ?? "application/json",
|
|
839
877
|
"cache-control": "no-store"
|
|
840
878
|
}
|
|
841
|
-
}) :
|
|
879
|
+
}) : $(502, { error: "unreachable" });
|
|
842
880
|
}
|
|
843
|
-
if (
|
|
844
|
-
if (
|
|
845
|
-
if (
|
|
846
|
-
|
|
847
|
-
let e = l(
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
881
|
+
if (y === "runner") return g(t, r, `/${v.slice(1).map(encodeURIComponent).join("/")}`, !1);
|
|
882
|
+
if (y === "runner-namespace") return d(r, "admin"), g(t, r, `/${v.slice(1).map(encodeURIComponent).join("/")}`, !0);
|
|
883
|
+
if (y === "runners") {
|
|
884
|
+
d(r, u("runners"));
|
|
885
|
+
let e = l(w), n = r.role === "platform" ? { platform: !0 } : {
|
|
886
|
+
platform: !1,
|
|
887
|
+
namespace: M(w, r.tenant)
|
|
888
|
+
}, a = n.platform ? void 0 : n.namespace;
|
|
889
|
+
if (!b && C === "GET") return $(200, { runners: await e.list(n) });
|
|
890
|
+
if (!b && C === "POST") {
|
|
891
|
+
let n = await f(t), o = await e.add({
|
|
851
892
|
url: String(n.url ?? ""),
|
|
852
893
|
...typeof n.name == "string" ? { name: n.name } : {},
|
|
853
894
|
...typeof n.code == "string" ? { code: n.code } : {},
|
|
854
895
|
...typeof n.key == "string" ? { key: n.key } : {}
|
|
855
|
-
});
|
|
896
|
+
}, {}, a);
|
|
856
897
|
return i("runner connected", {
|
|
857
|
-
project:
|
|
858
|
-
runner:
|
|
898
|
+
project: w,
|
|
899
|
+
runner: o.id,
|
|
859
900
|
by: r.user.id
|
|
860
|
-
}),
|
|
901
|
+
}), $(201, { runner: o });
|
|
861
902
|
}
|
|
862
|
-
if (
|
|
863
|
-
let n = await
|
|
864
|
-
return
|
|
903
|
+
if (b === "pairings" && !x && C === "POST") {
|
|
904
|
+
let n = await f(t);
|
|
905
|
+
return $(201, await e.startPairing({
|
|
865
906
|
url: String(n.url ?? ""),
|
|
866
907
|
...typeof n.name == "string" ? { name: n.name } : {}
|
|
867
|
-
}, r.user.id));
|
|
908
|
+
}, r.user.id, a));
|
|
868
909
|
}
|
|
869
|
-
if (
|
|
870
|
-
if (
|
|
871
|
-
let n = await
|
|
910
|
+
if (b === "pairings" && x && C === "GET") return $(200, await e.pairingStatus(x, r.user.id));
|
|
911
|
+
if (b === "installs" && !x && C === "POST") {
|
|
912
|
+
let n = await f(t), o = await e.install({
|
|
872
913
|
domain: String(n.domain ?? ""),
|
|
873
914
|
access: n.access ?? {},
|
|
874
915
|
...typeof n.name == "string" ? { name: n.name } : {},
|
|
875
916
|
...typeof n.version == "string" ? { version: n.version } : {}
|
|
876
|
-
}, r.user.id);
|
|
917
|
+
}, r.user.id, void 0, a);
|
|
877
918
|
return i("runner install", {
|
|
878
|
-
project:
|
|
879
|
-
install:
|
|
919
|
+
project: w,
|
|
920
|
+
install: o.installId,
|
|
880
921
|
by: r.user.id
|
|
881
|
-
}),
|
|
922
|
+
}), $(202, { installId: o.installId });
|
|
882
923
|
}
|
|
883
|
-
if (
|
|
884
|
-
let t = await e.installState(
|
|
885
|
-
return t ?
|
|
924
|
+
if (b === "installs" && x && C === "GET") {
|
|
925
|
+
let t = await e.installState(x, r.user.id, Number(_.searchParams.get("from")) || 0);
|
|
926
|
+
return t ? $(200, t) : $(404, { error: "not found" });
|
|
886
927
|
}
|
|
887
|
-
if (
|
|
888
|
-
let
|
|
889
|
-
return await e.update(
|
|
890
|
-
...typeof
|
|
891
|
-
...typeof
|
|
892
|
-
...typeof
|
|
893
|
-
}),
|
|
928
|
+
if (b && !x && C === "PATCH") {
|
|
929
|
+
let r = await f(t);
|
|
930
|
+
return await e.update(b, {
|
|
931
|
+
...typeof r.name == "string" ? { name: r.name } : {},
|
|
932
|
+
...typeof r.isDefault == "boolean" ? { isDefault: r.isDefault } : {},
|
|
933
|
+
...typeof r.draining == "boolean" ? { draining: r.draining } : {}
|
|
934
|
+
}, n), $(200, { ok: !0 });
|
|
894
935
|
}
|
|
895
|
-
if (
|
|
896
|
-
if (
|
|
936
|
+
if (b && !x && C === "DELETE") return await e.remove(b, n), $(200, { ok: !0 });
|
|
937
|
+
if (b && x === "status" && C === "GET") return $(200, await e.status(b, n));
|
|
897
938
|
}
|
|
898
|
-
if (
|
|
899
|
-
|
|
939
|
+
if (y === "memories") {
|
|
940
|
+
d(r, u("memories"));
|
|
900
941
|
let e = r.role === "platform" ? { platform: !0 } : {
|
|
901
942
|
platform: !1,
|
|
902
|
-
namespace: M(
|
|
943
|
+
namespace: M(w, r.tenant)
|
|
903
944
|
};
|
|
904
|
-
if (!
|
|
905
|
-
if (
|
|
906
|
-
let e = await
|
|
907
|
-
return
|
|
945
|
+
if (!b && C === "GET") return $(200, { memories: await s.list(e) });
|
|
946
|
+
if (b === "check" && C === "POST") {
|
|
947
|
+
let e = await f(t);
|
|
948
|
+
return $(200, await s.check({
|
|
908
949
|
apiUrl: String(e.apiUrl ?? ""),
|
|
909
950
|
key: String(e.key ?? "")
|
|
910
951
|
}));
|
|
911
952
|
}
|
|
912
|
-
if (!
|
|
913
|
-
let n = await
|
|
953
|
+
if (!b && C === "POST") {
|
|
954
|
+
let n = await f(t), a = await s.add({
|
|
914
955
|
apiUrl: String(n.apiUrl ?? ""),
|
|
915
956
|
key: String(n.key ?? ""),
|
|
916
957
|
...typeof n.name == "string" ? { name: n.name } : {},
|
|
917
958
|
...typeof n.mcpUrl == "string" ? { mcpUrl: n.mcpUrl } : {}
|
|
918
959
|
}, e.platform ? void 0 : e.namespace);
|
|
919
960
|
return i("memory connected", {
|
|
920
|
-
project:
|
|
961
|
+
project: w,
|
|
921
962
|
memory: a.id,
|
|
922
963
|
by: r.user.id
|
|
923
|
-
}),
|
|
964
|
+
}), $(201, { memory: a });
|
|
924
965
|
}
|
|
925
|
-
if (
|
|
926
|
-
let n = await
|
|
927
|
-
return
|
|
966
|
+
if (b && C === "PATCH") {
|
|
967
|
+
let n = await f(t);
|
|
968
|
+
return $(200, { memory: await s.update(b, {
|
|
928
969
|
...typeof n.name == "string" ? { name: n.name } : {},
|
|
929
970
|
...n.mcpUrl === null || typeof n.mcpUrl == "string" ? { mcpUrl: n.mcpUrl } : {},
|
|
930
971
|
...typeof n.key == "string" ? { key: n.key } : {}
|
|
931
972
|
}, e) });
|
|
932
973
|
}
|
|
933
|
-
if (
|
|
934
|
-
let t = await s.of(
|
|
974
|
+
if (b && C === "DELETE") {
|
|
975
|
+
let t = await s.of(b, e), r = (await n.list(L)).filter((e) => e.memoryId === b);
|
|
935
976
|
if (!e.platform && (t.owners?.length ?? 0) > 1) {
|
|
936
|
-
await s.remove(
|
|
977
|
+
await s.remove(b, !1, e);
|
|
937
978
|
for (let t of r.filter((t) => t.id === e.namespace)) {
|
|
938
979
|
let { memoryId: e, ...r } = t;
|
|
939
980
|
await n.put(L, r);
|
|
940
981
|
}
|
|
941
|
-
} else await s.remove(
|
|
942
|
-
return
|
|
982
|
+
} else await s.remove(b, r.length > 0, e);
|
|
983
|
+
return $(200, { ok: !0 });
|
|
943
984
|
}
|
|
944
985
|
}
|
|
945
|
-
if (
|
|
946
|
-
let e = M(
|
|
947
|
-
if (!
|
|
986
|
+
if (y === "memory") {
|
|
987
|
+
let e = M(w, r.tenant), n = (await h(e)).memoryId;
|
|
988
|
+
if (!b && C === "GET") return $(200, n ? {
|
|
948
989
|
configured: !0,
|
|
949
990
|
...await s.coordinates(n, e)
|
|
950
991
|
} : { configured: !1 });
|
|
951
|
-
if (!n) return
|
|
952
|
-
let a = await
|
|
953
|
-
if (
|
|
954
|
-
if (
|
|
992
|
+
if (!n) return $(409, { error: "no-memory" });
|
|
993
|
+
let a = await f(t);
|
|
994
|
+
if (b === "search" && C === "POST") return $(200, { results: await s.search(n, e, String(a.query ?? ""), Number(a.limit) || 10) });
|
|
995
|
+
if (b === "write" && C === "POST") {
|
|
955
996
|
let t = await s.write(n, e, {
|
|
956
997
|
title: String(a.title ?? ""),
|
|
957
998
|
content: String(a.content ?? ""),
|
|
@@ -960,30 +1001,33 @@ function ie(e) {
|
|
|
960
1001
|
return i("memory write", {
|
|
961
1002
|
namespace: e,
|
|
962
1003
|
user: r.user.id
|
|
963
|
-
}),
|
|
1004
|
+
}), $(200, t);
|
|
964
1005
|
}
|
|
965
1006
|
}
|
|
966
|
-
if (
|
|
967
|
-
|
|
1007
|
+
if (y === "projects" && !b && C === "GET") {
|
|
1008
|
+
d(r, "admin");
|
|
968
1009
|
let [t, n, i, a] = await Promise.all([
|
|
969
|
-
|
|
970
|
-
|
|
1010
|
+
Q[r.role] >= Q[u("runners")] ? l(w).list(r.role === "platform" ? { platform: !0 } : {
|
|
1011
|
+
platform: !1,
|
|
1012
|
+
namespace: M(w, r.tenant)
|
|
1013
|
+
}) : Promise.resolve([]),
|
|
1014
|
+
Q[r.role] >= Q[u("memories")] ? s.list(r.role === "platform" ? { platform: !0 } : {
|
|
971
1015
|
platform: !1,
|
|
972
|
-
namespace: M(
|
|
973
|
-
}),
|
|
974
|
-
|
|
1016
|
+
namespace: M(w, r.tenant)
|
|
1017
|
+
}) : Promise.resolve([]),
|
|
1018
|
+
m(w),
|
|
975
1019
|
e.tenants && r.role === "platform" ? e.tenants(r) : Promise.resolve([])
|
|
976
|
-
]), o = M(
|
|
1020
|
+
]), o = M(w, r.tenant), c = /* @__PURE__ */ new Map();
|
|
977
1021
|
if (c.set(o, void 0), r.role === "platform") {
|
|
978
1022
|
for (let e of i) c.set(e.id, void 0);
|
|
979
1023
|
for (let e of a) try {
|
|
980
|
-
c.set(M(
|
|
1024
|
+
c.set(M(w, e.id), e.name);
|
|
981
1025
|
} catch {}
|
|
982
1026
|
}
|
|
983
|
-
return
|
|
984
|
-
project:
|
|
1027
|
+
return $(200, {
|
|
1028
|
+
project: w,
|
|
985
1029
|
namespaces: [...c.entries()].map(([e, r]) => {
|
|
986
|
-
let a = i.find((t) => t.id === e), o = t.find((e) => e.id === a?.runnerId), s = n.find((e) => e.id === a?.memoryId), c = P(
|
|
1030
|
+
let a = i.find((t) => t.id === e), o = t.find((e) => e.id === a?.runnerId), s = n.find((e) => e.id === a?.memoryId), c = P(w, e);
|
|
987
1031
|
return {
|
|
988
1032
|
namespace: e,
|
|
989
1033
|
...c ? { tenant: c } : {},
|
|
@@ -1000,35 +1044,39 @@ function ie(e) {
|
|
|
1000
1044
|
}).sort((e, t) => e.namespace.localeCompare(t.namespace))
|
|
1001
1045
|
});
|
|
1002
1046
|
}
|
|
1003
|
-
if (
|
|
1004
|
-
if (
|
|
1005
|
-
M(
|
|
1047
|
+
if (y === "namespaces" && b && !x && C === "PUT") {
|
|
1048
|
+
if (d(r, "admin"), !N(w, b)) throw new Z(404, "not found");
|
|
1049
|
+
M(w, P(w, b));
|
|
1006
1050
|
let e = r.role === "platform";
|
|
1007
|
-
if (!e &&
|
|
1008
|
-
let a = await
|
|
1051
|
+
if (!e && b !== M(w, r.tenant)) throw new Z(403, "forbidden");
|
|
1052
|
+
let a = await f(t);
|
|
1009
1053
|
if (typeof a.runnerId == "string" && a.runnerId) {
|
|
1010
|
-
if (!e
|
|
1011
|
-
|
|
1054
|
+
if (d(r, u("runners")), !e && !(await l(w).list({
|
|
1055
|
+
platform: !1,
|
|
1056
|
+
namespace: b
|
|
1057
|
+
})).some((e) => e.id === a.runnerId)) throw new Z(404, "runner not found");
|
|
1058
|
+
await l(w).assign(b, a.runnerId);
|
|
1012
1059
|
}
|
|
1013
1060
|
if (a.memoryId !== void 0) {
|
|
1014
|
-
|
|
1061
|
+
d(r, u("memories"));
|
|
1062
|
+
let t = await h(b);
|
|
1015
1063
|
if (a.memoryId === null || a.memoryId === "") delete t.memoryId;
|
|
1016
1064
|
else {
|
|
1017
1065
|
let n = e ? { platform: !0 } : {
|
|
1018
1066
|
platform: !1,
|
|
1019
|
-
namespace:
|
|
1067
|
+
namespace: b
|
|
1020
1068
|
};
|
|
1021
|
-
if (!(await s.list(n)).some((e) => e.id === a.memoryId)) throw new
|
|
1069
|
+
if (!(await s.list(n)).some((e) => e.id === a.memoryId)) throw new Z(404, "memory not found");
|
|
1022
1070
|
t.memoryId = String(a.memoryId);
|
|
1023
1071
|
}
|
|
1024
1072
|
await n.put(L, t);
|
|
1025
1073
|
}
|
|
1026
1074
|
return i("namespace set", {
|
|
1027
|
-
namespace:
|
|
1075
|
+
namespace: b,
|
|
1028
1076
|
by: r.user.id
|
|
1029
|
-
}),
|
|
1077
|
+
}), $(200, { ok: !0 });
|
|
1030
1078
|
}
|
|
1031
|
-
return
|
|
1079
|
+
return $(404, { error: "not found" });
|
|
1032
1080
|
}
|
|
1033
1081
|
return {
|
|
1034
1082
|
connections: o,
|
|
@@ -1036,15 +1084,15 @@ function ie(e) {
|
|
|
1036
1084
|
fleet: l,
|
|
1037
1085
|
async handle(n) {
|
|
1038
1086
|
let r = new URL(n.url), a = (e.basePath ?? "").replace(/\/+$/, "");
|
|
1039
|
-
if (a && r.pathname !== a && !r.pathname.startsWith(`${a}/`)) return
|
|
1087
|
+
if (a && r.pathname !== a && !r.pathname.startsWith(`${a}/`)) return $(404, { error: "not found" });
|
|
1040
1088
|
let o = r.pathname.slice(a.length) || "/";
|
|
1041
1089
|
try {
|
|
1042
1090
|
let t = await e.identity(n);
|
|
1043
|
-
return t ? await
|
|
1091
|
+
return t ? await _(n, t, o, r) : $(401, { error: "unauthenticated" });
|
|
1044
1092
|
} catch (e) {
|
|
1045
|
-
if (e instanceof
|
|
1046
|
-
if (e instanceof j) return
|
|
1047
|
-
if (e instanceof
|
|
1093
|
+
if (e instanceof Z) return $(e.status, { error: e.message });
|
|
1094
|
+
if (e instanceof j) return $(400, { error: "invalid namespace" });
|
|
1095
|
+
if (e instanceof H) return $(e.code === "invalid" ? 400 : e.code === "not-found" ? 404 : 409, { error: e.message });
|
|
1048
1096
|
if (e instanceof T) {
|
|
1049
1097
|
let t = {
|
|
1050
1098
|
invalid: 400,
|
|
@@ -1053,19 +1101,19 @@ function ie(e) {
|
|
|
1053
1101
|
unreachable: 502,
|
|
1054
1102
|
rejected: 422
|
|
1055
1103
|
}[e.code];
|
|
1056
|
-
return
|
|
1104
|
+
return $(t, { error: e.message });
|
|
1057
1105
|
}
|
|
1058
|
-
return e instanceof t ?
|
|
1106
|
+
return e instanceof t ? $(502, { error: e.code }) : (i("agentico server error", {
|
|
1059
1107
|
path: o,
|
|
1060
1108
|
error: e instanceof Error ? e.name : "error"
|
|
1061
|
-
}),
|
|
1109
|
+
}), $(500, { error: "failed" }));
|
|
1062
1110
|
}
|
|
1063
1111
|
}
|
|
1064
1112
|
};
|
|
1065
1113
|
}
|
|
1066
1114
|
//#endregion
|
|
1067
1115
|
//#region src/server/stores.ts
|
|
1068
|
-
function
|
|
1116
|
+
function ae(e, t) {
|
|
1069
1117
|
return {
|
|
1070
1118
|
async get(t, n) {
|
|
1071
1119
|
return e()[t]?.[n] ?? null;
|
|
@@ -1086,7 +1134,7 @@ function Q(e, t) {
|
|
|
1086
1134
|
}
|
|
1087
1135
|
};
|
|
1088
1136
|
}
|
|
1089
|
-
function
|
|
1137
|
+
function oe(e, t) {
|
|
1090
1138
|
return {
|
|
1091
1139
|
async get(t) {
|
|
1092
1140
|
return e()[t] ?? null;
|
|
@@ -1103,40 +1151,40 @@ function $(e, t) {
|
|
|
1103
1151
|
}
|
|
1104
1152
|
};
|
|
1105
1153
|
}
|
|
1106
|
-
function
|
|
1154
|
+
function se() {
|
|
1107
1155
|
let e = {}, t = {};
|
|
1108
1156
|
return {
|
|
1109
|
-
records:
|
|
1157
|
+
records: ae(() => structuredClone(e), (t) => {
|
|
1110
1158
|
e = t;
|
|
1111
1159
|
}),
|
|
1112
|
-
secrets:
|
|
1160
|
+
secrets: oe(() => ({ ...t }), (e) => {
|
|
1113
1161
|
t = e;
|
|
1114
1162
|
})
|
|
1115
1163
|
};
|
|
1116
1164
|
}
|
|
1117
|
-
function
|
|
1165
|
+
function ce(e, t) {
|
|
1118
1166
|
try {
|
|
1119
1167
|
return l(e) ? JSON.parse(d(e, "utf8")) : t;
|
|
1120
1168
|
} catch {
|
|
1121
1169
|
return t;
|
|
1122
1170
|
}
|
|
1123
1171
|
}
|
|
1124
|
-
function
|
|
1172
|
+
function le(e, t) {
|
|
1125
1173
|
let n = `${e}.tmp`;
|
|
1126
1174
|
p(n, JSON.stringify(t, null, 2), { mode: 384 }), f(n, e);
|
|
1127
1175
|
}
|
|
1128
|
-
function
|
|
1176
|
+
function ue(e) {
|
|
1129
1177
|
u(e, {
|
|
1130
1178
|
recursive: !0,
|
|
1131
1179
|
mode: 448
|
|
1132
1180
|
});
|
|
1133
1181
|
let t = m(e, "records.json"), n = m(e, "secrets.json");
|
|
1134
1182
|
return {
|
|
1135
|
-
records:
|
|
1136
|
-
secrets:
|
|
1183
|
+
records: ae(() => ce(t, {}), (e) => le(t, e)),
|
|
1184
|
+
secrets: oe(() => ce(n, {}), (e) => le(n, e))
|
|
1137
1185
|
};
|
|
1138
1186
|
}
|
|
1139
1187
|
//#endregion
|
|
1140
|
-
export { h as CONNECTIONS,
|
|
1188
|
+
export { h as CONNECTIONS, H as FleetError, C as MEMORIES, T as MemoryError, L as NAMESPACES, U as NAMESPACE_KEY_PERMISSIONS, j as NamespaceError, k as PROJECT_ID, F as RUNNERS, A as TENANT_ID, w as administers, ie as createAgenticoServer, S as createConnections, X as createFleet, O as createMemories, v as defaultAdapterFactory, ue as fileStores, N as inProject, se as memoryStores, M as namespaceOf, J as normalizeRunnerUrl, P as tenantOf };
|
|
1141
1189
|
|
|
1142
1190
|
//# sourceMappingURL=server.mjs.map
|