@llmnative/agentico 0.24.1 → 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 +76 -72
- package/dist/index.mjs.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +433 -315
- package/dist/server.mjs.map +1 -1
- package/dist/types/backend/agenticoBackend.d.ts +6 -1
- package/dist/types/server/index.d.ts +2 -2
- package/dist/types/server/memories.d.ts +39 -5
- package/dist/types/server/runners.d.ts +30 -7
- package/dist/types/server/server.d.ts +32 -13
- package/package.json +2 -2
package/dist/server.mjs
CHANGED
|
@@ -164,31 +164,31 @@ function S(e) {
|
|
|
164
164
|
}
|
|
165
165
|
//#endregion
|
|
166
166
|
//#region src/server/memories.ts
|
|
167
|
-
var C = "agentico_memories", w = class extends Error {
|
|
167
|
+
var C = "agentico_memories", w = (e, t) => e.platform || !!t.owners?.includes(e.namespace), T = class extends Error {
|
|
168
168
|
code;
|
|
169
169
|
constructor(e, t) {
|
|
170
170
|
super(t), this.name = "MemoryError", this.code = e;
|
|
171
171
|
}
|
|
172
|
-
},
|
|
173
|
-
function
|
|
172
|
+
}, E = (e) => `memory/${e}/key`, ee = /^[A-Za-z0-9_.:-]{1,120}$/;
|
|
173
|
+
function D(e, t) {
|
|
174
174
|
let n = String(e ?? "").trim().replace(/\/+$/, "");
|
|
175
175
|
if (!n) {
|
|
176
|
-
if (t) throw new
|
|
176
|
+
if (t) throw new T("invalid", "URL_REQUIRED");
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
179
|
let r;
|
|
180
180
|
try {
|
|
181
181
|
r = new URL(n);
|
|
182
182
|
} catch {
|
|
183
|
-
throw new
|
|
183
|
+
throw new T("invalid", "INVALID_URL");
|
|
184
184
|
}
|
|
185
|
-
if (r.protocol !== "https:" && !(r.protocol === "http:" && ["localhost", "127.0.0.1"].includes(r.hostname))) throw new
|
|
185
|
+
if (r.protocol !== "https:" && !(r.protocol === "http:" && ["localhost", "127.0.0.1"].includes(r.hostname))) throw new T("invalid", "INVALID_URL");
|
|
186
186
|
return n;
|
|
187
187
|
}
|
|
188
|
-
function
|
|
188
|
+
function O(e) {
|
|
189
189
|
let { records: t, secrets: n } = e, r = e.fetch ?? fetch, i = e.newId ?? (() => crypto.randomUUID().replace(/-/g, "").slice(0, 12)), a = e.now ?? Date.now, o = async (e) => {
|
|
190
190
|
let n = await t.get(C, e);
|
|
191
|
-
if (!n) throw new
|
|
191
|
+
if (!n) throw new T("not-found", "MEMORY_NOT_FOUND");
|
|
192
192
|
return n;
|
|
193
193
|
}, s = async (e, t, n, i, a) => {
|
|
194
194
|
try {
|
|
@@ -203,23 +203,28 @@ function D(e) {
|
|
|
203
203
|
signal: AbortSignal.timeout(2e4)
|
|
204
204
|
});
|
|
205
205
|
} catch {
|
|
206
|
-
throw new
|
|
206
|
+
throw new T("unreachable", "MEMORY_UNREACHABLE");
|
|
207
207
|
}
|
|
208
208
|
}, c = (e) => `/ns/${encodeURIComponent(e)}`, l = async (e) => {
|
|
209
|
-
let t = await o(e), r = await n.get(
|
|
210
|
-
if (!r) throw new
|
|
209
|
+
let t = await o(e), r = await n.get(E(e));
|
|
210
|
+
if (!r) throw new T("not-found", "KEY_NOT_FOUND");
|
|
211
211
|
return {
|
|
212
212
|
record: t,
|
|
213
213
|
key: r
|
|
214
214
|
};
|
|
215
215
|
}, u = {
|
|
216
|
-
async list() {
|
|
217
|
-
return (await t.list(C)).map(({ createdAt: e, ...t }) => t).sort((e, t) => e.name.localeCompare(t.name));
|
|
216
|
+
async list(e) {
|
|
217
|
+
return (await t.list(C)).filter((t) => !e || w(e, t)).map(({ createdAt: e, ...t }) => t).sort((e, t) => e.name.localeCompare(t.name));
|
|
218
|
+
},
|
|
219
|
+
async of(e, t) {
|
|
220
|
+
let n = await o(e);
|
|
221
|
+
if (t && !w(t, n)) throw new T("not-found", "MEMORY_NOT_FOUND");
|
|
222
|
+
return n;
|
|
218
223
|
},
|
|
219
224
|
async check(e) {
|
|
220
225
|
let t;
|
|
221
226
|
try {
|
|
222
|
-
t =
|
|
227
|
+
t = D(e.apiUrl, !0);
|
|
223
228
|
} catch {
|
|
224
229
|
return {
|
|
225
230
|
ok: !1,
|
|
@@ -247,53 +252,86 @@ function D(e) {
|
|
|
247
252
|
};
|
|
248
253
|
}
|
|
249
254
|
},
|
|
250
|
-
async add(e) {
|
|
251
|
-
let
|
|
252
|
-
if ((await t.list("agentico_memories")).some((e) => e.apiUrl ===
|
|
253
|
-
let
|
|
254
|
-
apiUrl:
|
|
255
|
+
async add(e, r) {
|
|
256
|
+
let o = D(e.apiUrl, !0), s = D(e.mcpUrl, !1), c = (e) => r ? !!e.owners?.includes(r) : !e.owners?.length;
|
|
257
|
+
if ((await t.list("agentico_memories")).some((e) => e.apiUrl === o && c(e))) throw new T("conflict", "MEMORY_ALREADY_CONNECTED");
|
|
258
|
+
let l = await u.check({
|
|
259
|
+
apiUrl: o,
|
|
255
260
|
key: e.key
|
|
256
261
|
});
|
|
257
|
-
if (!
|
|
258
|
-
let
|
|
259
|
-
await n.set(
|
|
260
|
-
let
|
|
261
|
-
id:
|
|
262
|
-
name: String(e.name ?? "").trim().slice(0, 100) || new URL(
|
|
263
|
-
apiUrl:
|
|
264
|
-
...
|
|
262
|
+
if (!l.ok) throw new T(l.error === "invalid" ? "invalid" : l.error, l.error.toUpperCase());
|
|
263
|
+
let d = i();
|
|
264
|
+
await n.set(E(d), e.key.trim());
|
|
265
|
+
let f = {
|
|
266
|
+
id: d,
|
|
267
|
+
name: String(e.name ?? "").trim().slice(0, 100) || new URL(o).hostname,
|
|
268
|
+
apiUrl: o,
|
|
269
|
+
...s ? { mcpUrl: s } : {},
|
|
270
|
+
...r ? { owners: [r] } : {},
|
|
265
271
|
createdAt: a()
|
|
266
272
|
};
|
|
267
|
-
await t.put(C,
|
|
268
|
-
let { createdAt:
|
|
269
|
-
return
|
|
273
|
+
await t.put(C, f);
|
|
274
|
+
let { createdAt: p, ...m } = f;
|
|
275
|
+
return m;
|
|
270
276
|
},
|
|
271
|
-
async update(e, r) {
|
|
272
|
-
let
|
|
277
|
+
async update(e, r, i) {
|
|
278
|
+
let a = await u.of(e, i);
|
|
273
279
|
if (r.key?.trim()) {
|
|
274
280
|
let t = await u.check({
|
|
275
|
-
apiUrl:
|
|
281
|
+
apiUrl: a.apiUrl,
|
|
276
282
|
key: r.key
|
|
277
283
|
});
|
|
278
|
-
if (!t.ok) throw new
|
|
279
|
-
await n.set(
|
|
284
|
+
if (!t.ok) throw new T(t.error === "invalid" ? "invalid" : t.error, t.error.toUpperCase());
|
|
285
|
+
await n.set(E(e), r.key.trim());
|
|
280
286
|
}
|
|
281
|
-
let
|
|
282
|
-
typeof r.name == "string" && r.name.trim() && (
|
|
283
|
-
let { createdAt: s, ...c } =
|
|
287
|
+
let o = { ...a };
|
|
288
|
+
typeof r.name == "string" && r.name.trim() && (o.name = r.name.trim().slice(0, 100)), r.mcpUrl === null || r.mcpUrl === "" ? delete o.mcpUrl : typeof r.mcpUrl == "string" && (o.mcpUrl = D(r.mcpUrl, !1)), await t.put(C, o);
|
|
289
|
+
let { createdAt: s, ...c } = o;
|
|
284
290
|
return c;
|
|
285
291
|
},
|
|
286
|
-
async remove(e, r) {
|
|
287
|
-
|
|
288
|
-
|
|
292
|
+
async remove(e, r, i) {
|
|
293
|
+
let a = await u.of(e, i);
|
|
294
|
+
if (i && !i.platform && (a.owners?.length ?? 0) > 1) {
|
|
295
|
+
await t.put(C, {
|
|
296
|
+
...a,
|
|
297
|
+
owners: a.owners.filter((e) => e !== i.namespace)
|
|
298
|
+
});
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (r) throw new T("conflict", "MEMORY_IN_USE");
|
|
302
|
+
await n.delete(E(e)), await t.delete(C, e);
|
|
303
|
+
},
|
|
304
|
+
async share(e, n) {
|
|
305
|
+
let r = await o(e);
|
|
306
|
+
r.owners?.includes(n) || await t.put(C, {
|
|
307
|
+
...r,
|
|
308
|
+
owners: [...r.owners ?? [], n]
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
async unshare(e, n) {
|
|
312
|
+
let r = await o(e);
|
|
313
|
+
r.owners?.includes(n) && await t.put(C, {
|
|
314
|
+
...r,
|
|
315
|
+
owners: r.owners.filter((e) => e !== n)
|
|
316
|
+
});
|
|
317
|
+
},
|
|
318
|
+
async put(e, r) {
|
|
319
|
+
r && await n.set(E(e.id), r.trim()), await t.put(C, {
|
|
320
|
+
...e,
|
|
321
|
+
apiUrl: D(e.apiUrl, !0),
|
|
322
|
+
createdAt: e.createdAt ?? a()
|
|
323
|
+
});
|
|
324
|
+
},
|
|
325
|
+
async keyOf(e) {
|
|
326
|
+
return n.get(E(e));
|
|
289
327
|
},
|
|
290
328
|
async search(e, t, n, r = 10) {
|
|
291
|
-
if (!String(n ?? "").trim()) throw new
|
|
329
|
+
if (!String(n ?? "").trim()) throw new T("invalid", "QUERY_REQUIRED");
|
|
292
330
|
let { record: i, key: a } = await l(e), o = await s(i.apiUrl, a, "POST", `${c(t)}/search`, {
|
|
293
331
|
query: n.trim().slice(0, 2e3),
|
|
294
332
|
limit: Math.min(Math.max(Math.trunc(r) || 10, 1), 50)
|
|
295
333
|
});
|
|
296
|
-
if (!o.ok) throw new
|
|
334
|
+
if (!o.ok) throw new T(o.status === 401 || o.status === 403 ? "rejected" : "unreachable", `MEMORY_${o.status}`);
|
|
297
335
|
return ((await o.json().catch(() => ({}))).results ?? []).map((e) => {
|
|
298
336
|
let t = e.metadata && typeof e.metadata == "object" ? e.metadata : void 0;
|
|
299
337
|
return {
|
|
@@ -307,8 +345,8 @@ function D(e) {
|
|
|
307
345
|
},
|
|
308
346
|
async write(e, t, n) {
|
|
309
347
|
let r = String(n.title ?? "").trim().slice(0, 200), i = String(n.content ?? "").trim();
|
|
310
|
-
if (!r || !i || i.length > 2e5) throw new
|
|
311
|
-
if (n.documentId !== void 0 && !ee.test(n.documentId)) throw new
|
|
348
|
+
if (!r || !i || i.length > 2e5) throw new T("invalid", "DOCUMENT_INVALID");
|
|
349
|
+
if (n.documentId !== void 0 && !ee.test(n.documentId)) throw new T("invalid", "DOCUMENT_ID_INVALID");
|
|
312
350
|
let { record: a, key: o } = await l(e), u = {
|
|
313
351
|
content: `# ${r}\n\n${i}`,
|
|
314
352
|
metadata: {
|
|
@@ -319,13 +357,13 @@ function D(e) {
|
|
|
319
357
|
if (n.documentId) {
|
|
320
358
|
let e = await s(a.apiUrl, o, "PATCH", `${c(t)}/document/${encodeURIComponent(n.documentId)}`, u);
|
|
321
359
|
if (e.ok) return { id: n.documentId };
|
|
322
|
-
if (e.status !== 404) throw new
|
|
360
|
+
if (e.status !== 404) throw new T(e.status === 401 || e.status === 403 ? "rejected" : "unreachable", `MEMORY_${e.status}`);
|
|
323
361
|
}
|
|
324
362
|
let d = await s(a.apiUrl, o, "POST", `${c(t)}/document`, {
|
|
325
363
|
...u,
|
|
326
364
|
...n.documentId ? { id: n.documentId } : {}
|
|
327
365
|
});
|
|
328
|
-
if (!d.ok) throw new
|
|
366
|
+
if (!d.ok) throw new T(d.status === 401 || d.status === 403 ? "rejected" : "unreachable", `MEMORY_${d.status}`);
|
|
329
367
|
let f = await d.json().catch(() => ({}));
|
|
330
368
|
return typeof f.id == "string" ? { id: f.id } : {};
|
|
331
369
|
},
|
|
@@ -342,122 +380,147 @@ function D(e) {
|
|
|
342
380
|
}
|
|
343
381
|
//#endregion
|
|
344
382
|
//#region src/server/namespace.ts
|
|
345
|
-
var
|
|
383
|
+
var k = /^[a-z0-9]{1,32}$/, A = /^[a-z0-9][a-z0-9-]{0,29}$/, j = class extends Error {
|
|
346
384
|
constructor(e) {
|
|
347
385
|
super(e), this.name = "NamespaceError";
|
|
348
386
|
}
|
|
349
387
|
};
|
|
350
|
-
function
|
|
351
|
-
if (!
|
|
388
|
+
function M(e, t) {
|
|
389
|
+
if (!k.test(e)) throw new j(`invalid project "${e}"`);
|
|
352
390
|
if (t === void 0 || t === "") return e;
|
|
353
|
-
if (!
|
|
391
|
+
if (!A.test(t)) throw new j(`invalid tenant "${t}"`);
|
|
354
392
|
return `${e}-${t}`;
|
|
355
393
|
}
|
|
356
|
-
var
|
|
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 {
|
|
357
395
|
code;
|
|
358
396
|
constructor(e, t) {
|
|
359
397
|
super(t), this.name = "FleetError", this.code = e;
|
|
360
398
|
}
|
|
361
|
-
},
|
|
399
|
+
}, U = [
|
|
362
400
|
"complete",
|
|
363
401
|
"chat",
|
|
364
402
|
"chat:tools",
|
|
365
403
|
"accounts",
|
|
366
404
|
"act-as-user"
|
|
367
|
-
],
|
|
368
|
-
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) {
|
|
369
407
|
let t;
|
|
370
408
|
try {
|
|
371
409
|
t = new URL(e.trim().replace(/\/+$/, ""));
|
|
372
410
|
} catch {
|
|
373
|
-
throw new
|
|
411
|
+
throw new H("invalid", "INVALID_URL");
|
|
374
412
|
}
|
|
375
|
-
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");
|
|
376
414
|
return t.origin;
|
|
377
415
|
}
|
|
378
|
-
var
|
|
416
|
+
var Y = (e) => ({
|
|
379
417
|
id: e.id,
|
|
380
418
|
name: e.name,
|
|
381
419
|
url: e.url,
|
|
382
420
|
isDefault: e.isDefault,
|
|
383
|
-
draining: e.draining
|
|
421
|
+
draining: e.draining,
|
|
422
|
+
...e.owners?.length ? { owners: [...e.owners] } : {}
|
|
384
423
|
});
|
|
385
|
-
function
|
|
424
|
+
function X(t) {
|
|
386
425
|
let { project: n, records: r, secrets: i } = t, a = t.connect ?? ((t, n) => new e({
|
|
387
426
|
url: t,
|
|
388
427
|
...n ? { key: n } : {}
|
|
389
|
-
})), o = t.install ?? c, s = t.newId ?? (() => crypto.randomUUID().replace(/-/g, "").slice(0, 12)), l = t.now ?? Date.now, u = async (e) => {
|
|
390
|
-
let
|
|
391
|
-
if (!t) throw new
|
|
392
|
-
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;
|
|
393
432
|
}, d = async (e) => {
|
|
394
433
|
let t = await i.get(e);
|
|
395
|
-
if (!t) throw new
|
|
434
|
+
if (!t) throw new H("not-found", "KEY_NOT_FOUND");
|
|
396
435
|
return t;
|
|
397
|
-
}, f = async (e) => a(e.url, await d(
|
|
398
|
-
let t =
|
|
399
|
-
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");
|
|
400
439
|
return t;
|
|
401
440
|
}, m = (e, t) => String(t ?? "").trim() || new URL(e).hostname, h = async (e) => {
|
|
402
441
|
let t = s(), n = l();
|
|
403
|
-
await i.set(
|
|
442
|
+
await i.set(G(t), e.key);
|
|
404
443
|
let a = {
|
|
405
444
|
id: t,
|
|
406
445
|
name: e.name,
|
|
407
446
|
url: e.url,
|
|
408
|
-
isDefault: (await r.list(
|
|
447
|
+
isDefault: !e.owner && !(await r.list("agentico_runners")).some((e) => !e.owners?.length),
|
|
409
448
|
draining: !1,
|
|
449
|
+
...e.owner ? { owners: [e.owner] } : {},
|
|
410
450
|
...e.keyId ? { keyId: e.keyId } : {},
|
|
411
451
|
...e.hostFingerprint ? { hostFingerprint: e.hostFingerprint } : {},
|
|
412
452
|
createdAt: n,
|
|
413
453
|
updatedAt: n
|
|
414
454
|
};
|
|
415
|
-
return await r.put(
|
|
455
|
+
return await r.put(F, a), Y(a);
|
|
416
456
|
}, g = async (e) => await r.get("agentico_namespaces", e) ?? { id: e }, _ = {
|
|
417
|
-
async list() {
|
|
418
|
-
return (await r.list(
|
|
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));
|
|
419
459
|
},
|
|
420
|
-
async
|
|
421
|
-
let
|
|
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
|
+
});
|
|
479
|
+
},
|
|
480
|
+
async add(e, r = {}, i) {
|
|
481
|
+
let o = await p(String(e.url ?? "")), s = m(o, e.name);
|
|
422
482
|
if (e.code) {
|
|
423
|
-
let
|
|
483
|
+
let c = await a(o).pair(String(e.code).trim(), t.platformName, n);
|
|
424
484
|
return h({
|
|
425
|
-
name:
|
|
426
|
-
url:
|
|
427
|
-
key:
|
|
428
|
-
keyId:
|
|
429
|
-
...r
|
|
485
|
+
name: s,
|
|
486
|
+
url: o,
|
|
487
|
+
key: c.key,
|
|
488
|
+
keyId: c.record.id,
|
|
489
|
+
...r,
|
|
490
|
+
...i ? { owner: i } : {}
|
|
430
491
|
});
|
|
431
492
|
}
|
|
432
493
|
if (e.key) {
|
|
433
494
|
let t = String(e.key).trim();
|
|
434
|
-
return await a(
|
|
435
|
-
name:
|
|
436
|
-
url:
|
|
495
|
+
return await a(o, t).platform.status(), h({
|
|
496
|
+
name: s,
|
|
497
|
+
url: o,
|
|
437
498
|
key: t,
|
|
438
|
-
...r
|
|
499
|
+
...r,
|
|
500
|
+
...i ? { owner: i } : {}
|
|
439
501
|
});
|
|
440
502
|
}
|
|
441
|
-
throw new
|
|
503
|
+
throw new H("invalid", "CODE_OR_KEY_REQUIRED");
|
|
442
504
|
},
|
|
443
|
-
async startPairing(e, o) {
|
|
444
|
-
let
|
|
445
|
-
return await i.set(
|
|
446
|
-
id:
|
|
447
|
-
name: m(
|
|
448
|
-
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,
|
|
449
511
|
startedBy: o,
|
|
450
|
-
expiresAt:
|
|
512
|
+
expiresAt: u.expiresAt,
|
|
513
|
+
...c ? { owner: c } : {}
|
|
451
514
|
}), {
|
|
452
|
-
id:
|
|
453
|
-
code:
|
|
454
|
-
approveUrl:
|
|
455
|
-
expiresAt:
|
|
515
|
+
id: d,
|
|
516
|
+
code: u.code,
|
|
517
|
+
approveUrl: u.approveUrl,
|
|
518
|
+
expiresAt: u.expiresAt
|
|
456
519
|
};
|
|
457
520
|
},
|
|
458
521
|
async pairingStatus(e, t) {
|
|
459
|
-
let n = await r.get(
|
|
460
|
-
await r.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));
|
|
461
524
|
};
|
|
462
525
|
if (!n || n.startedBy !== t || !o) return { status: "expired" };
|
|
463
526
|
if (Date.parse(n.expiresAt) <= l()) return await s(), { status: "expired" };
|
|
@@ -468,54 +531,63 @@ function q(t) {
|
|
|
468
531
|
name: n.name,
|
|
469
532
|
url: n.url,
|
|
470
533
|
key: c.key,
|
|
471
|
-
keyId: c.record.id
|
|
534
|
+
keyId: c.record.id,
|
|
535
|
+
...n.owner ? { owner: n.owner } : {}
|
|
472
536
|
})
|
|
473
537
|
} : { status: c.status });
|
|
474
538
|
},
|
|
475
|
-
async update(e, t) {
|
|
476
|
-
let
|
|
477
|
-
|
|
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,
|
|
478
544
|
updatedAt: l()
|
|
479
545
|
};
|
|
480
|
-
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, {
|
|
481
547
|
...t,
|
|
482
548
|
isDefault: !1,
|
|
483
549
|
updatedAt: l()
|
|
484
550
|
});
|
|
485
|
-
await r.put(
|
|
551
|
+
await r.put(F, a);
|
|
486
552
|
},
|
|
487
|
-
async remove(e) {
|
|
488
|
-
let
|
|
489
|
-
if (
|
|
490
|
-
|
|
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);
|
|
491
562
|
},
|
|
492
|
-
async status(e) {
|
|
493
|
-
return (await f(await u(e))).platform.status();
|
|
563
|
+
async status(e, t) {
|
|
564
|
+
return (await f(await u(e, t))).platform.status();
|
|
494
565
|
},
|
|
495
566
|
async assign(e, n, a = {}) {
|
|
496
567
|
let o = await g(e), s = await u(n);
|
|
497
|
-
if (
|
|
498
|
-
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");
|
|
499
571
|
let c = await f(s), l = (await c.platform.tenants()).some((t) => t.id === e), d, p;
|
|
500
572
|
if (l) {
|
|
501
573
|
let n = await c.platform.createKey(e, {
|
|
502
574
|
name: t.platformName,
|
|
503
|
-
permissions:
|
|
575
|
+
permissions: W
|
|
504
576
|
});
|
|
505
577
|
d = n.key, p = n.record.id;
|
|
506
578
|
} else {
|
|
507
579
|
let t = await c.platform.createTenant(e, {
|
|
508
580
|
...a.name ? { name: a.name } : {},
|
|
509
|
-
keyPermissions:
|
|
581
|
+
keyPermissions: W
|
|
510
582
|
});
|
|
511
583
|
if (!t.key || !t.keyRecord) throw Error("the runner made the tenant without a key");
|
|
512
584
|
d = t.key, p = t.keyRecord.id;
|
|
513
585
|
}
|
|
514
|
-
if (await i.set(
|
|
515
|
-
let t = await r.get(
|
|
516
|
-
t && await f(t).then((t) => t.platform.revokeKey(e, o.runnerKeyId)).catch(() => !1), await i.delete(
|
|
586
|
+
if (await i.set(q(e, n), d), !a.keepBefore && o.runnerId && o.runnerId !== n && o.runnerKeyId) {
|
|
587
|
+
let t = await r.get(F, o.runnerId);
|
|
588
|
+
t && await f(t).then((t) => t.platform.revokeKey(e, o.runnerKeyId)).catch(() => !1), await i.delete(q(e, o.runnerId));
|
|
517
589
|
}
|
|
518
|
-
await r.put(
|
|
590
|
+
await r.put(L, {
|
|
519
591
|
...o,
|
|
520
592
|
runnerId: n,
|
|
521
593
|
runnerKeyId: p
|
|
@@ -523,20 +595,20 @@ function q(t) {
|
|
|
523
595
|
},
|
|
524
596
|
async route(e, t = {}) {
|
|
525
597
|
if (t.chat && t.user) {
|
|
526
|
-
let n = await r.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;
|
|
527
599
|
if (a && o) return {
|
|
528
600
|
runnerId: a.id,
|
|
529
601
|
url: a.url,
|
|
530
602
|
key: o
|
|
531
603
|
};
|
|
532
604
|
}
|
|
533
|
-
let n = await r.list(
|
|
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));
|
|
534
606
|
if (o) t.newChat && o.draining && s && (await _.assign(e, s.id, { keepBefore: !0 }), a = await g(e));
|
|
535
607
|
else {
|
|
536
608
|
if (!s) return null;
|
|
537
609
|
await _.assign(e, s.id), a = await g(e);
|
|
538
610
|
}
|
|
539
|
-
let c = a.runnerId ? await r.get(
|
|
611
|
+
let c = a.runnerId ? await r.get(F, a.runnerId) : null, l = c ? await i.get(q(e, c.id)) : null;
|
|
540
612
|
return c && l ? {
|
|
541
613
|
runnerId: c.id,
|
|
542
614
|
url: c.url,
|
|
@@ -544,57 +616,57 @@ function q(t) {
|
|
|
544
616
|
} : null;
|
|
545
617
|
},
|
|
546
618
|
async chatStarted(e, t, n, i) {
|
|
547
|
-
await r.put(
|
|
619
|
+
await r.put(R, {
|
|
548
620
|
id: `${e}_${t}_${n}`,
|
|
549
621
|
runnerId: i
|
|
550
622
|
});
|
|
551
623
|
},
|
|
552
624
|
async chatClosed(e, t, n) {
|
|
553
|
-
await r.delete(
|
|
625
|
+
await r.delete(R, `${e}_${t}_${n}`);
|
|
554
626
|
},
|
|
555
|
-
async install(e, t, n) {
|
|
556
|
-
if (!e.access?.host || !e.access.username || !e.access.privateKey && !e.access.password) throw new
|
|
557
|
-
if (!String(e.domain ?? "").trim()) throw new
|
|
558
|
-
let
|
|
559
|
-
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,
|
|
560
632
|
status: "running",
|
|
561
633
|
lines: [],
|
|
562
634
|
startedBy: t
|
|
563
635
|
};
|
|
564
|
-
await r.put(
|
|
565
|
-
let
|
|
566
|
-
n?.(e),
|
|
567
|
-
},
|
|
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 () => {
|
|
568
640
|
try {
|
|
569
641
|
let t = await o(e.access, {
|
|
570
642
|
domain: e.domain,
|
|
571
643
|
...e.version ? { version: e.version } : {},
|
|
572
|
-
onProgress:
|
|
644
|
+
onProgress: u
|
|
573
645
|
}), n = await _.add({
|
|
574
646
|
name: e.name,
|
|
575
647
|
url: t.url,
|
|
576
648
|
code: t.pairingCode
|
|
577
|
-
}, { hostFingerprint: t.hostFingerprint });
|
|
578
|
-
return await
|
|
579
|
-
...
|
|
649
|
+
}, { hostFingerprint: t.hostFingerprint }, i);
|
|
650
|
+
return await l, await r.put(z, {
|
|
651
|
+
...c,
|
|
580
652
|
status: "done",
|
|
581
653
|
runnerId: n.id
|
|
582
654
|
}), n;
|
|
583
655
|
} catch (e) {
|
|
584
|
-
throw await
|
|
585
|
-
...
|
|
656
|
+
throw await l, await r.put(z, {
|
|
657
|
+
...c,
|
|
586
658
|
status: "error",
|
|
587
659
|
error: e instanceof Error ? e.message : String(e)
|
|
588
660
|
}), e;
|
|
589
661
|
}
|
|
590
662
|
})();
|
|
591
|
-
return
|
|
592
|
-
installId:
|
|
593
|
-
done:
|
|
663
|
+
return d.catch(() => void 0), {
|
|
664
|
+
installId: a,
|
|
665
|
+
done: d
|
|
594
666
|
};
|
|
595
667
|
},
|
|
596
668
|
async installState(e, t, n = 0) {
|
|
597
|
-
let i = await r.get(
|
|
669
|
+
let i = await r.get(z, e);
|
|
598
670
|
return !i || i.startedBy !== t ? null : {
|
|
599
671
|
status: i.status,
|
|
600
672
|
lines: i.lines.slice(n),
|
|
@@ -608,16 +680,16 @@ function q(t) {
|
|
|
608
680
|
}
|
|
609
681
|
//#endregion
|
|
610
682
|
//#region src/server/server.ts
|
|
611
|
-
var
|
|
683
|
+
var Z = class extends Error {
|
|
612
684
|
status;
|
|
613
685
|
constructor(e, t) {
|
|
614
686
|
super(t), this.status = e;
|
|
615
687
|
}
|
|
616
|
-
},
|
|
688
|
+
}, Q = {
|
|
617
689
|
member: 0,
|
|
618
690
|
admin: 1,
|
|
619
691
|
platform: 2
|
|
620
|
-
},
|
|
692
|
+
}, $ = (e, t) => new Response(JSON.stringify(t), {
|
|
621
693
|
status: e,
|
|
622
694
|
headers: {
|
|
623
695
|
"content-type": "application/json",
|
|
@@ -637,14 +709,14 @@ function ie(e) {
|
|
|
637
709
|
records: n,
|
|
638
710
|
secrets: r,
|
|
639
711
|
...e.adapter ? { adapter: e.adapter } : {}
|
|
640
|
-
}), s =
|
|
712
|
+
}), s = O({
|
|
641
713
|
records: n,
|
|
642
714
|
secrets: r,
|
|
643
715
|
fetch: a,
|
|
644
716
|
...e.now ? { now: e.now } : {}
|
|
645
717
|
}), c = /* @__PURE__ */ new Map(), l = (t) => {
|
|
646
718
|
let i = c.get(t);
|
|
647
|
-
return i || (i =
|
|
719
|
+
return i || (i = X({
|
|
648
720
|
project: t,
|
|
649
721
|
platformName: e.platformName,
|
|
650
722
|
records: n,
|
|
@@ -653,29 +725,29 @@ function ie(e) {
|
|
|
653
725
|
...e.install ? { install: e.install } : {},
|
|
654
726
|
...e.now ? { now: e.now } : {}
|
|
655
727
|
}), c.set(t, i)), i;
|
|
656
|
-
}, u = (e, t) => {
|
|
657
|
-
if (
|
|
658
|
-
},
|
|
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) => {
|
|
659
731
|
try {
|
|
660
732
|
let t = await e.json();
|
|
661
733
|
return t && typeof t == "object" ? t : {};
|
|
662
734
|
} catch {
|
|
663
735
|
return {};
|
|
664
736
|
}
|
|
665
|
-
},
|
|
666
|
-
let n =
|
|
737
|
+
}, p = (e, t) => {
|
|
738
|
+
let n = M(e.project, e.tenant), r = t.searchParams.get("namespace");
|
|
667
739
|
if (!r || r === n) return n;
|
|
668
|
-
if (
|
|
669
|
-
return
|
|
670
|
-
},
|
|
671
|
-
async function
|
|
740
|
+
if (d(e, "platform"), !N(e.project, r)) throw new Z(404, "not found");
|
|
741
|
+
return M(e.project, P(e.project, r)), r;
|
|
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) {
|
|
672
744
|
if (!te.test(n) || r && !n.startsWith("/v1/accounts") || ![
|
|
673
745
|
"GET",
|
|
674
746
|
"POST",
|
|
675
747
|
"PUT",
|
|
676
748
|
"DELETE"
|
|
677
|
-
].includes(e.method)) return
|
|
678
|
-
let o =
|
|
749
|
+
].includes(e.method)) return $(404, { error: "not found" });
|
|
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 ? (() => {
|
|
679
751
|
try {
|
|
680
752
|
let e = JSON.parse(new TextDecoder().decode(d));
|
|
681
753
|
return typeof e.id == "string" ? e.id : void 0;
|
|
@@ -689,7 +761,7 @@ function ie(e) {
|
|
|
689
761
|
user: t.user.id
|
|
690
762
|
} : {}
|
|
691
763
|
}).catch(() => null);
|
|
692
|
-
if (!p) return
|
|
764
|
+
if (!p) return $(409, { error: "no-runner" });
|
|
693
765
|
let m = { authorization: `Bearer ${p.key}` };
|
|
694
766
|
r || (m["x-runner-user"] = t.user.id);
|
|
695
767
|
let h = e.headers.get("content-type");
|
|
@@ -703,7 +775,7 @@ function ie(e) {
|
|
|
703
775
|
signal: e.signal
|
|
704
776
|
});
|
|
705
777
|
} catch {
|
|
706
|
-
return
|
|
778
|
+
return $(502, { error: "unreachable" });
|
|
707
779
|
}
|
|
708
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", {
|
|
709
781
|
namespace: o,
|
|
@@ -719,73 +791,81 @@ function ie(e) {
|
|
|
719
791
|
}
|
|
720
792
|
});
|
|
721
793
|
}
|
|
722
|
-
async function
|
|
723
|
-
let
|
|
724
|
-
if (
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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, {
|
|
799
|
+
user: r.user,
|
|
800
|
+
role: r.role,
|
|
801
|
+
project: w,
|
|
802
|
+
...r.tenant ? { tenant: r.tenant } : {},
|
|
803
|
+
namespace: e,
|
|
804
|
+
hasRunner: t,
|
|
805
|
+
administers: {
|
|
806
|
+
runners: n("runners"),
|
|
807
|
+
memories: n("memories")
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
}
|
|
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 });
|
|
738
818
|
}
|
|
739
|
-
if (
|
|
740
|
-
if (
|
|
741
|
-
|
|
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");
|
|
742
822
|
let n = async () => {
|
|
743
|
-
let e = (await
|
|
823
|
+
let e = (await f(t)).fields;
|
|
744
824
|
return Object.fromEntries(Object.entries(e && typeof e == "object" ? e : {}).map(([e, t]) => [e, String(t ?? "")]));
|
|
745
825
|
};
|
|
746
|
-
if (
|
|
747
|
-
let t = await o.connect(e,
|
|
826
|
+
if (b && !x && C === "POST") {
|
|
827
|
+
let t = await o.connect(e, b, await n());
|
|
748
828
|
return i("connection", {
|
|
749
829
|
namespace: e,
|
|
750
|
-
provider:
|
|
830
|
+
provider: b,
|
|
751
831
|
ok: t.ok,
|
|
752
832
|
by: r.user.id
|
|
753
|
-
}),
|
|
833
|
+
}), $(t.ok ? 200 : 422, t);
|
|
754
834
|
}
|
|
755
|
-
if (
|
|
756
|
-
if (
|
|
757
|
-
let t = await o.addAccount(e,
|
|
758
|
-
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);
|
|
759
839
|
}
|
|
760
|
-
if (
|
|
761
|
-
let n = (await
|
|
762
|
-
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 });
|
|
763
843
|
}
|
|
764
|
-
if (
|
|
844
|
+
if (b && x === "accounts" && S && C === "DELETE") return await o.removeAccount(e, b, S), $(200, { ok: !0 });
|
|
765
845
|
}
|
|
766
|
-
if (
|
|
767
|
-
let e = await
|
|
768
|
-
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");
|
|
769
849
|
});
|
|
770
850
|
return i("ai complete", {
|
|
771
|
-
namespace:
|
|
851
|
+
namespace: M(w, r.tenant),
|
|
772
852
|
provider: n,
|
|
773
853
|
user: r.user.id
|
|
774
|
-
}),
|
|
854
|
+
}), $(200, { result: a });
|
|
775
855
|
}
|
|
776
|
-
if (
|
|
777
|
-
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 = {};
|
|
778
858
|
t.headers.forEach((e, t) => {
|
|
779
859
|
i.has(t.toLowerCase()) || (s[t] = e);
|
|
780
860
|
});
|
|
781
|
-
let c = await o.resolve(
|
|
861
|
+
let c = await o.resolve(M(w, r.tenant), {
|
|
782
862
|
url: n,
|
|
783
863
|
headers: s
|
|
784
864
|
});
|
|
785
|
-
if (!c.ok) return
|
|
786
|
-
if (new URL(c.url).protocol !== "https:") return
|
|
787
|
-
let l =
|
|
788
|
-
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,
|
|
789
869
|
headers: c.headers,
|
|
790
870
|
...l && l.byteLength ? { body: l } : {},
|
|
791
871
|
signal: t.signal
|
|
@@ -796,105 +876,123 @@ function ie(e) {
|
|
|
796
876
|
"content-type": u.headers.get("content-type") ?? "application/json",
|
|
797
877
|
"cache-control": "no-store"
|
|
798
878
|
}
|
|
799
|
-
}) :
|
|
879
|
+
}) : $(502, { error: "unreachable" });
|
|
800
880
|
}
|
|
801
|
-
if (
|
|
802
|
-
if (
|
|
803
|
-
if (
|
|
804
|
-
|
|
805
|
-
let e = l(
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
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({
|
|
809
892
|
url: String(n.url ?? ""),
|
|
810
893
|
...typeof n.name == "string" ? { name: n.name } : {},
|
|
811
894
|
...typeof n.code == "string" ? { code: n.code } : {},
|
|
812
895
|
...typeof n.key == "string" ? { key: n.key } : {}
|
|
813
|
-
});
|
|
896
|
+
}, {}, a);
|
|
814
897
|
return i("runner connected", {
|
|
815
|
-
project:
|
|
816
|
-
runner:
|
|
898
|
+
project: w,
|
|
899
|
+
runner: o.id,
|
|
817
900
|
by: r.user.id
|
|
818
|
-
}),
|
|
901
|
+
}), $(201, { runner: o });
|
|
819
902
|
}
|
|
820
|
-
if (
|
|
821
|
-
let n = await
|
|
822
|
-
return
|
|
903
|
+
if (b === "pairings" && !x && C === "POST") {
|
|
904
|
+
let n = await f(t);
|
|
905
|
+
return $(201, await e.startPairing({
|
|
823
906
|
url: String(n.url ?? ""),
|
|
824
907
|
...typeof n.name == "string" ? { name: n.name } : {}
|
|
825
|
-
}, r.user.id));
|
|
908
|
+
}, r.user.id, a));
|
|
826
909
|
}
|
|
827
|
-
if (
|
|
828
|
-
if (
|
|
829
|
-
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({
|
|
830
913
|
domain: String(n.domain ?? ""),
|
|
831
914
|
access: n.access ?? {},
|
|
832
915
|
...typeof n.name == "string" ? { name: n.name } : {},
|
|
833
916
|
...typeof n.version == "string" ? { version: n.version } : {}
|
|
834
|
-
}, r.user.id);
|
|
917
|
+
}, r.user.id, void 0, a);
|
|
835
918
|
return i("runner install", {
|
|
836
|
-
project:
|
|
837
|
-
install:
|
|
919
|
+
project: w,
|
|
920
|
+
install: o.installId,
|
|
838
921
|
by: r.user.id
|
|
839
|
-
}),
|
|
922
|
+
}), $(202, { installId: o.installId });
|
|
840
923
|
}
|
|
841
|
-
if (
|
|
842
|
-
let t = await e.installState(
|
|
843
|
-
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" });
|
|
844
927
|
}
|
|
845
|
-
if (
|
|
846
|
-
let
|
|
847
|
-
return await e.update(
|
|
848
|
-
...typeof
|
|
849
|
-
...typeof
|
|
850
|
-
...typeof
|
|
851
|
-
}),
|
|
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 });
|
|
852
935
|
}
|
|
853
|
-
if (
|
|
854
|
-
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));
|
|
855
938
|
}
|
|
856
|
-
if (
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
939
|
+
if (y === "memories") {
|
|
940
|
+
d(r, u("memories"));
|
|
941
|
+
let e = r.role === "platform" ? { platform: !0 } : {
|
|
942
|
+
platform: !1,
|
|
943
|
+
namespace: M(w, r.tenant)
|
|
944
|
+
};
|
|
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({
|
|
861
949
|
apiUrl: String(e.apiUrl ?? ""),
|
|
862
950
|
key: String(e.key ?? "")
|
|
863
951
|
}));
|
|
864
952
|
}
|
|
865
|
-
if (!
|
|
866
|
-
let
|
|
867
|
-
apiUrl: String(
|
|
868
|
-
key: String(
|
|
869
|
-
...typeof
|
|
870
|
-
...typeof
|
|
871
|
-
});
|
|
953
|
+
if (!b && C === "POST") {
|
|
954
|
+
let n = await f(t), a = await s.add({
|
|
955
|
+
apiUrl: String(n.apiUrl ?? ""),
|
|
956
|
+
key: String(n.key ?? ""),
|
|
957
|
+
...typeof n.name == "string" ? { name: n.name } : {},
|
|
958
|
+
...typeof n.mcpUrl == "string" ? { mcpUrl: n.mcpUrl } : {}
|
|
959
|
+
}, e.platform ? void 0 : e.namespace);
|
|
872
960
|
return i("memory connected", {
|
|
873
|
-
project:
|
|
874
|
-
memory:
|
|
961
|
+
project: w,
|
|
962
|
+
memory: a.id,
|
|
875
963
|
by: r.user.id
|
|
876
|
-
}),
|
|
964
|
+
}), $(201, { memory: a });
|
|
877
965
|
}
|
|
878
|
-
if (
|
|
879
|
-
let
|
|
880
|
-
return
|
|
881
|
-
...typeof
|
|
882
|
-
...
|
|
883
|
-
...typeof
|
|
884
|
-
}) });
|
|
966
|
+
if (b && C === "PATCH") {
|
|
967
|
+
let n = await f(t);
|
|
968
|
+
return $(200, { memory: await s.update(b, {
|
|
969
|
+
...typeof n.name == "string" ? { name: n.name } : {},
|
|
970
|
+
...n.mcpUrl === null || typeof n.mcpUrl == "string" ? { mcpUrl: n.mcpUrl } : {},
|
|
971
|
+
...typeof n.key == "string" ? { key: n.key } : {}
|
|
972
|
+
}, e) });
|
|
973
|
+
}
|
|
974
|
+
if (b && C === "DELETE") {
|
|
975
|
+
let t = await s.of(b, e), r = (await n.list(L)).filter((e) => e.memoryId === b);
|
|
976
|
+
if (!e.platform && (t.owners?.length ?? 0) > 1) {
|
|
977
|
+
await s.remove(b, !1, e);
|
|
978
|
+
for (let t of r.filter((t) => t.id === e.namespace)) {
|
|
979
|
+
let { memoryId: e, ...r } = t;
|
|
980
|
+
await n.put(L, r);
|
|
981
|
+
}
|
|
982
|
+
} else await s.remove(b, r.length > 0, e);
|
|
983
|
+
return $(200, { ok: !0 });
|
|
885
984
|
}
|
|
886
|
-
if (y && S === "DELETE") return await s.remove(y, (await n.list(I)).some((e) => e.memoryId === y)), X(200, { ok: !0 });
|
|
887
985
|
}
|
|
888
|
-
if (
|
|
889
|
-
let e =
|
|
890
|
-
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 ? {
|
|
891
989
|
configured: !0,
|
|
892
990
|
...await s.coordinates(n, e)
|
|
893
991
|
} : { configured: !1 });
|
|
894
|
-
if (!n) return
|
|
895
|
-
let a = await
|
|
896
|
-
if (
|
|
897
|
-
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") {
|
|
898
996
|
let t = await s.write(n, e, {
|
|
899
997
|
title: String(a.title ?? ""),
|
|
900
998
|
content: String(a.content ?? ""),
|
|
@@ -903,27 +1001,33 @@ function ie(e) {
|
|
|
903
1001
|
return i("memory write", {
|
|
904
1002
|
namespace: e,
|
|
905
1003
|
user: r.user.id
|
|
906
|
-
}),
|
|
1004
|
+
}), $(200, t);
|
|
907
1005
|
}
|
|
908
1006
|
}
|
|
909
|
-
if (
|
|
910
|
-
|
|
1007
|
+
if (y === "projects" && !b && C === "GET") {
|
|
1008
|
+
d(r, "admin");
|
|
911
1009
|
let [t, n, i, a] = await Promise.all([
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
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 } : {
|
|
1015
|
+
platform: !1,
|
|
1016
|
+
namespace: M(w, r.tenant)
|
|
1017
|
+
}) : Promise.resolve([]),
|
|
1018
|
+
m(w),
|
|
915
1019
|
e.tenants && r.role === "platform" ? e.tenants(r) : Promise.resolve([])
|
|
916
|
-
]), o =
|
|
1020
|
+
]), o = M(w, r.tenant), c = /* @__PURE__ */ new Map();
|
|
917
1021
|
if (c.set(o, void 0), r.role === "platform") {
|
|
918
1022
|
for (let e of i) c.set(e.id, void 0);
|
|
919
1023
|
for (let e of a) try {
|
|
920
|
-
c.set(
|
|
1024
|
+
c.set(M(w, e.id), e.name);
|
|
921
1025
|
} catch {}
|
|
922
1026
|
}
|
|
923
|
-
return
|
|
924
|
-
project:
|
|
1027
|
+
return $(200, {
|
|
1028
|
+
project: w,
|
|
925
1029
|
namespaces: [...c.entries()].map(([e, r]) => {
|
|
926
|
-
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 =
|
|
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);
|
|
927
1031
|
return {
|
|
928
1032
|
namespace: e,
|
|
929
1033
|
...c ? { tenant: c } : {},
|
|
@@ -940,25 +1044,39 @@ function ie(e) {
|
|
|
940
1044
|
}).sort((e, t) => e.namespace.localeCompare(t.namespace))
|
|
941
1045
|
});
|
|
942
1046
|
}
|
|
943
|
-
if (
|
|
944
|
-
if (
|
|
945
|
-
|
|
946
|
-
let e =
|
|
947
|
-
if (
|
|
948
|
-
|
|
949
|
-
|
|
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));
|
|
1050
|
+
let e = r.role === "platform";
|
|
1051
|
+
if (!e && b !== M(w, r.tenant)) throw new Z(403, "forbidden");
|
|
1052
|
+
let a = await f(t);
|
|
1053
|
+
if (typeof a.runnerId == "string" && a.runnerId) {
|
|
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);
|
|
1059
|
+
}
|
|
1060
|
+
if (a.memoryId !== void 0) {
|
|
1061
|
+
d(r, u("memories"));
|
|
1062
|
+
let t = await h(b);
|
|
1063
|
+
if (a.memoryId === null || a.memoryId === "") delete t.memoryId;
|
|
950
1064
|
else {
|
|
951
|
-
|
|
952
|
-
|
|
1065
|
+
let n = e ? { platform: !0 } : {
|
|
1066
|
+
platform: !1,
|
|
1067
|
+
namespace: b
|
|
1068
|
+
};
|
|
1069
|
+
if (!(await s.list(n)).some((e) => e.id === a.memoryId)) throw new Z(404, "memory not found");
|
|
1070
|
+
t.memoryId = String(a.memoryId);
|
|
953
1071
|
}
|
|
954
|
-
await n.put(
|
|
1072
|
+
await n.put(L, t);
|
|
955
1073
|
}
|
|
956
1074
|
return i("namespace set", {
|
|
957
|
-
namespace:
|
|
1075
|
+
namespace: b,
|
|
958
1076
|
by: r.user.id
|
|
959
|
-
}),
|
|
1077
|
+
}), $(200, { ok: !0 });
|
|
960
1078
|
}
|
|
961
|
-
return
|
|
1079
|
+
return $(404, { error: "not found" });
|
|
962
1080
|
}
|
|
963
1081
|
return {
|
|
964
1082
|
connections: o,
|
|
@@ -966,16 +1084,16 @@ function ie(e) {
|
|
|
966
1084
|
fleet: l,
|
|
967
1085
|
async handle(n) {
|
|
968
1086
|
let r = new URL(n.url), a = (e.basePath ?? "").replace(/\/+$/, "");
|
|
969
|
-
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" });
|
|
970
1088
|
let o = r.pathname.slice(a.length) || "/";
|
|
971
1089
|
try {
|
|
972
1090
|
let t = await e.identity(n);
|
|
973
|
-
return t ? await
|
|
1091
|
+
return t ? await _(n, t, o, r) : $(401, { error: "unauthenticated" });
|
|
974
1092
|
} catch (e) {
|
|
975
|
-
if (e instanceof
|
|
976
|
-
if (e instanceof
|
|
977
|
-
if (e instanceof
|
|
978
|
-
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 });
|
|
1096
|
+
if (e instanceof T) {
|
|
979
1097
|
let t = {
|
|
980
1098
|
invalid: 400,
|
|
981
1099
|
"not-found": 404,
|
|
@@ -983,19 +1101,19 @@ function ie(e) {
|
|
|
983
1101
|
unreachable: 502,
|
|
984
1102
|
rejected: 422
|
|
985
1103
|
}[e.code];
|
|
986
|
-
return
|
|
1104
|
+
return $(t, { error: e.message });
|
|
987
1105
|
}
|
|
988
|
-
return e instanceof t ?
|
|
1106
|
+
return e instanceof t ? $(502, { error: e.code }) : (i("agentico server error", {
|
|
989
1107
|
path: o,
|
|
990
1108
|
error: e instanceof Error ? e.name : "error"
|
|
991
|
-
}),
|
|
1109
|
+
}), $(500, { error: "failed" }));
|
|
992
1110
|
}
|
|
993
1111
|
}
|
|
994
1112
|
};
|
|
995
1113
|
}
|
|
996
1114
|
//#endregion
|
|
997
1115
|
//#region src/server/stores.ts
|
|
998
|
-
function
|
|
1116
|
+
function ae(e, t) {
|
|
999
1117
|
return {
|
|
1000
1118
|
async get(t, n) {
|
|
1001
1119
|
return e()[t]?.[n] ?? null;
|
|
@@ -1016,7 +1134,7 @@ function Z(e, t) {
|
|
|
1016
1134
|
}
|
|
1017
1135
|
};
|
|
1018
1136
|
}
|
|
1019
|
-
function
|
|
1137
|
+
function oe(e, t) {
|
|
1020
1138
|
return {
|
|
1021
1139
|
async get(t) {
|
|
1022
1140
|
return e()[t] ?? null;
|
|
@@ -1033,40 +1151,40 @@ function Q(e, t) {
|
|
|
1033
1151
|
}
|
|
1034
1152
|
};
|
|
1035
1153
|
}
|
|
1036
|
-
function
|
|
1154
|
+
function se() {
|
|
1037
1155
|
let e = {}, t = {};
|
|
1038
1156
|
return {
|
|
1039
|
-
records:
|
|
1157
|
+
records: ae(() => structuredClone(e), (t) => {
|
|
1040
1158
|
e = t;
|
|
1041
1159
|
}),
|
|
1042
|
-
secrets:
|
|
1160
|
+
secrets: oe(() => ({ ...t }), (e) => {
|
|
1043
1161
|
t = e;
|
|
1044
1162
|
})
|
|
1045
1163
|
};
|
|
1046
1164
|
}
|
|
1047
|
-
function
|
|
1165
|
+
function ce(e, t) {
|
|
1048
1166
|
try {
|
|
1049
1167
|
return l(e) ? JSON.parse(d(e, "utf8")) : t;
|
|
1050
1168
|
} catch {
|
|
1051
1169
|
return t;
|
|
1052
1170
|
}
|
|
1053
1171
|
}
|
|
1054
|
-
function
|
|
1172
|
+
function le(e, t) {
|
|
1055
1173
|
let n = `${e}.tmp`;
|
|
1056
1174
|
p(n, JSON.stringify(t, null, 2), { mode: 384 }), f(n, e);
|
|
1057
1175
|
}
|
|
1058
|
-
function
|
|
1176
|
+
function ue(e) {
|
|
1059
1177
|
u(e, {
|
|
1060
1178
|
recursive: !0,
|
|
1061
1179
|
mode: 448
|
|
1062
1180
|
});
|
|
1063
1181
|
let t = m(e, "records.json"), n = m(e, "secrets.json");
|
|
1064
1182
|
return {
|
|
1065
|
-
records:
|
|
1066
|
-
secrets:
|
|
1183
|
+
records: ae(() => ce(t, {}), (e) => le(t, e)),
|
|
1184
|
+
secrets: oe(() => ce(n, {}), (e) => le(n, e))
|
|
1067
1185
|
};
|
|
1068
1186
|
}
|
|
1069
1187
|
//#endregion
|
|
1070
|
-
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 };
|
|
1071
1189
|
|
|
1072
1190
|
//# sourceMappingURL=server.mjs.map
|