@standardagents/builder 0.21.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/built-in-routes.js +51 -0
- package/dist/built-in-routes.js.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +1 -0
- package/dist/plugin.js.map +1 -1
- package/dist/runtime.d.ts +9 -0
- package/dist/runtime.js +18 -0
- package/dist/runtime.js.map +1 -1
- package/package.json +4 -4
package/dist/built-in-routes.js
CHANGED
|
@@ -66506,6 +66506,56 @@ async function verifyPlatformSignedPayload(token, publicJwkValue, options) {
|
|
|
66506
66506
|
return verified ? payload : null;
|
|
66507
66507
|
}
|
|
66508
66508
|
|
|
66509
|
+
// src/api/auth/platform-cleanup.post.ts
|
|
66510
|
+
var platform_cleanup_post_default = defineController2(async ({ req, env: env2 }) => {
|
|
66511
|
+
const body = await req.json().catch(() => null);
|
|
66512
|
+
const token = typeof body?.cleanup === "string" ? body.cleanup : req.headers.get("Authorization")?.startsWith("Bearer ") ? req.headers.get("Authorization").slice("Bearer ".length) : null;
|
|
66513
|
+
if (!token) {
|
|
66514
|
+
return Response.json({ error: "Missing cleanup token" }, { status: 400 });
|
|
66515
|
+
}
|
|
66516
|
+
const payload = await verifyPlatformSignedPayload(
|
|
66517
|
+
token,
|
|
66518
|
+
env2.STANDARD_AGENTS_AUTH_PUBLIC_KEY_JWK ?? env2.STANDARD_AGENTS_AUTH_PUBLIC_KEY,
|
|
66519
|
+
{
|
|
66520
|
+
kind: "instance_cleanup",
|
|
66521
|
+
projectId: typeof env2.STANDARD_AGENTS_PROJECT_ID === "string" ? env2.STANDARD_AGENTS_PROJECT_ID : void 0
|
|
66522
|
+
}
|
|
66523
|
+
);
|
|
66524
|
+
if (!payload) {
|
|
66525
|
+
return Response.json({ error: "Invalid cleanup token" }, { status: 401 });
|
|
66526
|
+
}
|
|
66527
|
+
const agentBuilder = env2.AGENT_BUILDER.get(env2.AGENT_BUILDER.idFromName("singleton"));
|
|
66528
|
+
const deletedThreadIds = /* @__PURE__ */ new Set();
|
|
66529
|
+
for (let guard = 0; guard < 1e3; guard += 1) {
|
|
66530
|
+
const batch = await agentBuilder.listThreads({ limit: 100, offset: 0 });
|
|
66531
|
+
const next = batch.threads.filter((thread) => thread.id && !deletedThreadIds.has(thread.id));
|
|
66532
|
+
if (next.length === 0) break;
|
|
66533
|
+
for (const thread of next) {
|
|
66534
|
+
const treeIds = typeof agentBuilder.getThreadTreeIds === "function" ? await agentBuilder.getThreadTreeIds(thread.id) : [thread.id];
|
|
66535
|
+
const ids = Array.from(new Set(treeIds.length > 0 ? treeIds : [thread.id]));
|
|
66536
|
+
if (!ids.includes(thread.id)) ids.push(thread.id);
|
|
66537
|
+
for (const id of ids) {
|
|
66538
|
+
if (deletedThreadIds.has(id)) continue;
|
|
66539
|
+
const durableId = env2.AGENT_BUILDER_THREAD.idFromName(id);
|
|
66540
|
+
const stub = env2.AGENT_BUILDER_THREAD.get(durableId);
|
|
66541
|
+
await stub.deleteThread();
|
|
66542
|
+
}
|
|
66543
|
+
for (const id of ids) {
|
|
66544
|
+
if (deletedThreadIds.has(id)) continue;
|
|
66545
|
+
await agentBuilder.deleteThread(id);
|
|
66546
|
+
deletedThreadIds.add(id);
|
|
66547
|
+
}
|
|
66548
|
+
}
|
|
66549
|
+
}
|
|
66550
|
+
if (typeof agentBuilder.deleteAllStorage === "function") {
|
|
66551
|
+
await agentBuilder.deleteAllStorage();
|
|
66552
|
+
}
|
|
66553
|
+
return Response.json({
|
|
66554
|
+
ok: true,
|
|
66555
|
+
deleted_threads: deletedThreadIds.size
|
|
66556
|
+
});
|
|
66557
|
+
});
|
|
66558
|
+
|
|
66509
66559
|
// src/api/auth/platform-replica.post.ts
|
|
66510
66560
|
var platform_replica_post_default = defineController2(async ({ req, env: env2 }) => {
|
|
66511
66561
|
const body = await req.json().catch(() => null);
|
|
@@ -70640,6 +70690,7 @@ var routeHandlers = {
|
|
|
70640
70690
|
"GET:/auth/logout": logout_get_default,
|
|
70641
70691
|
"POST:/auth/logout": logout_post_default,
|
|
70642
70692
|
"GET:/auth/me": me_get_default,
|
|
70693
|
+
"POST:/auth/platform-cleanup": platform_cleanup_post_default,
|
|
70643
70694
|
"POST:/auth/platform-replica": platform_replica_post_default,
|
|
70644
70695
|
"GET:/envs/instance": instance_get_default,
|
|
70645
70696
|
"PATCH:/envs/instance": instance_patch_default,
|