@standardagents/builder 0.41.7 → 0.41.8

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.
@@ -79652,7 +79652,7 @@ var config_get_default = defineController2(async ({ config, env: env2, req }) =>
79652
79652
  });
79653
79653
 
79654
79654
  // src/version.ts
79655
- var BUILDER_VERSION = "0.41.7".length > 0 ? "0.41.7" : "dev";
79655
+ var BUILDER_VERSION = "0.41.8".length > 0 ? "0.41.8" : "dev";
79656
79656
 
79657
79657
  // src/api/diagnostics.get.ts
79658
79658
  init_LLMRequest();
@@ -85716,6 +85716,16 @@ var analyze_get_default2 = defineController2(async ({ req, env: env2 }) => {
85716
85716
  });
85717
85717
 
85718
85718
  // src/users/dispatch.ts
85719
+ function userValueStore(env2, userId) {
85720
+ const hub = env2.AGENT_BUILDER_USER_HUB;
85721
+ if (hub) return hub.get(hub.idFromName(userId));
85722
+ const singleton = env2.AGENT_BUILDER;
85723
+ if (!singleton) return null;
85724
+ return singleton.get(singleton.idFromName("singleton"));
85725
+ }
85726
+ function validUserValueKey(key) {
85727
+ return typeof key === "string" && key.length > 0 && key.length <= 512;
85728
+ }
85719
85729
  function userHubStub(env2, userId) {
85720
85730
  const namespace = env2.AGENT_BUILDER_USER_HUB;
85721
85731
  if (!namespace) return null;
@@ -85740,8 +85750,9 @@ async function forwardToUserScope(req, env2, userId, scopePath, channel = "user"
85740
85750
  }
85741
85751
 
85742
85752
  // src/api/users/[id]/[...rest].ts
85743
- var rest_default = defineController2(async ({ req, env: env2, params }) => {
85744
- const authResult = await requireAuth(req, env2);
85753
+ var rest_default = defineController2(async (context) => {
85754
+ const { req, env: env2, params } = context;
85755
+ const authResult = await resolveRequestAuth(context);
85745
85756
  if (authResult instanceof Response) return authResult;
85746
85757
  const isAdmin = authResult.authType === "super_admin" || authResult.user?.role === "admin";
85747
85758
  if (!isAdmin) {
@@ -86192,8 +86203,9 @@ var start_get_default = defineController2(async ({ req, env: env2 }) => {
86192
86203
  });
86193
86204
 
86194
86205
  // src/api/users/me/[...rest].ts
86195
- var rest_default2 = defineController2(async ({ req, env: env2, params }) => {
86196
- const authResult = await requireAuth(req, env2);
86206
+ var rest_default2 = defineController2(async (context) => {
86207
+ const { req, env: env2, params } = context;
86208
+ const authResult = await resolveRequestAuth(context);
86197
86209
  if (authResult instanceof Response) return authResult;
86198
86210
  if (authResult.authType === "super_admin") {
86199
86211
  return Response.json(
@@ -86293,7 +86305,7 @@ var hub_default = defineController2(async (context) => {
86293
86305
  if (req.headers.get("upgrade")?.toLowerCase() !== "websocket") {
86294
86306
  return Response.json(
86295
86307
  { error: "This endpoint only supports WebSocket connections" },
86296
- { status: 400 }
86308
+ { status: 426 }
86297
86309
  );
86298
86310
  }
86299
86311
  const namespace = env2.AGENT_BUILDER_USER_HUB;
@@ -86318,9 +86330,10 @@ var hub_default = defineController2(async (context) => {
86318
86330
  });
86319
86331
 
86320
86332
  // src/api/users/me/kv/index.delete.ts
86321
- var index_delete_default = defineController2(async ({ req, env: env2 }) => {
86333
+ var index_delete_default = defineController2(async (context) => {
86334
+ const { req, env: env2 } = context;
86322
86335
  try {
86323
- const authResult = await requireAuth(req, env2);
86336
+ const authResult = await resolveRequestAuth(context);
86324
86337
  if (authResult instanceof Response) {
86325
86338
  return authResult;
86326
86339
  }
@@ -86332,19 +86345,18 @@ var index_delete_default = defineController2(async ({ req, env: env2 }) => {
86332
86345
  }
86333
86346
  const url = new URL(req.url);
86334
86347
  const key = url.searchParams.get("key");
86335
- if (!key) {
86336
- return Response.json({ error: "key query parameter required" }, { status: 400 });
86348
+ if (!validUserValueKey(key)) {
86349
+ return Response.json({ error: "key query parameter required (1 to 512 characters)" }, { status: 400 });
86337
86350
  }
86338
86351
  if (!isUserKvKeyClientWritable(key)) return reservedKvKeyResponse();
86339
- const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
86340
- const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
86341
- if (typeof agentBuilder.setUserValue !== "function") {
86352
+ const store = userValueStore(env2, authResult.user.id);
86353
+ if (!store) {
86342
86354
  return Response.json(
86343
86355
  { error: "User value storage is not supported by this runtime" },
86344
86356
  { status: 500 }
86345
86357
  );
86346
86358
  }
86347
- await agentBuilder.setUserValue(authResult.user.id, key, null);
86359
+ await store.setUserValue(authResult.user.id, key, null);
86348
86360
  return Response.json({ status: "ok", key });
86349
86361
  } catch (error) {
86350
86362
  console.error("Delete user kv error:", error);
@@ -86356,9 +86368,10 @@ var index_delete_default = defineController2(async ({ req, env: env2 }) => {
86356
86368
  });
86357
86369
 
86358
86370
  // src/api/users/me/kv/index.get.ts
86359
- var index_get_default5 = defineController2(async ({ req, env: env2 }) => {
86371
+ var index_get_default5 = defineController2(async (context) => {
86372
+ const { req, env: env2 } = context;
86360
86373
  try {
86361
- const authResult = await requireAuth(req, env2);
86374
+ const authResult = await resolveRequestAuth(context);
86362
86375
  if (authResult instanceof Response) {
86363
86376
  return authResult;
86364
86377
  }
@@ -86369,28 +86382,24 @@ var index_get_default5 = defineController2(async ({ req, env: env2 }) => {
86369
86382
  );
86370
86383
  }
86371
86384
  const url = new URL(req.url);
86372
- const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
86373
- const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
86374
- const key = url.searchParams.get("key");
86375
- if (key) {
86376
- if (typeof agentBuilder.getUserValue !== "function") {
86377
- return Response.json(
86378
- { error: "User value storage is not supported by this runtime" },
86379
- { status: 500 }
86380
- );
86381
- }
86382
- const value = await agentBuilder.getUserValue(authResult.user.id, key);
86383
- return Response.json({ key, value });
86384
- }
86385
- if (typeof agentBuilder.listUserValues !== "function") {
86385
+ const store = userValueStore(env2, authResult.user.id);
86386
+ if (!store) {
86386
86387
  return Response.json(
86387
86388
  { error: "User value storage is not supported by this runtime" },
86388
86389
  { status: 500 }
86389
86390
  );
86390
86391
  }
86392
+ const key = url.searchParams.get("key");
86393
+ if (key !== null) {
86394
+ if (!validUserValueKey(key)) {
86395
+ return Response.json({ error: "key must be 1 to 512 characters" }, { status: 400 });
86396
+ }
86397
+ const value = await store.getUserValue(authResult.user.id, key);
86398
+ return Response.json({ key, value });
86399
+ }
86391
86400
  const limitParam = Number.parseInt(url.searchParams.get("limit") ?? "", 10);
86392
86401
  const offsetParam = Number.parseInt(url.searchParams.get("offset") ?? "", 10);
86393
- const result = await agentBuilder.listUserValues(authResult.user.id, {
86402
+ const result = await store.listUserValues(authResult.user.id, {
86394
86403
  prefix: url.searchParams.get("prefix"),
86395
86404
  limit: Number.isFinite(limitParam) ? limitParam : void 0,
86396
86405
  offset: Number.isFinite(offsetParam) ? offsetParam : void 0
@@ -86406,9 +86415,10 @@ var index_get_default5 = defineController2(async ({ req, env: env2 }) => {
86406
86415
  });
86407
86416
 
86408
86417
  // src/api/users/me/kv/index.post.ts
86409
- var index_post_default7 = defineController2(async ({ req, env: env2 }) => {
86418
+ var index_post_default7 = defineController2(async (context) => {
86419
+ const { req, env: env2 } = context;
86410
86420
  try {
86411
- const authResult = await requireAuth(req, env2);
86421
+ const authResult = await resolveRequestAuth(context);
86412
86422
  if (authResult instanceof Response) {
86413
86423
  return authResult;
86414
86424
  }
@@ -86429,19 +86439,18 @@ var index_post_default7 = defineController2(async ({ req, env: env2 }) => {
86429
86439
  return Response.json({ error: "Invalid JSON body" }, { status: 400 });
86430
86440
  }
86431
86441
  const key = body.key;
86432
- if (typeof key !== "string" || key.length === 0) {
86433
- return Response.json({ error: "key required" }, { status: 400 });
86442
+ if (!validUserValueKey(key)) {
86443
+ return Response.json({ error: "key required (1 to 512 characters)" }, { status: 400 });
86434
86444
  }
86435
86445
  if (!isUserKvKeyClientWritable(key)) return reservedKvKeyResponse();
86436
- const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
86437
- const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
86438
- if (typeof agentBuilder.setUserValue !== "function") {
86446
+ const store = userValueStore(env2, authResult.user.id);
86447
+ if (!store) {
86439
86448
  return Response.json(
86440
86449
  { error: "User value storage is not supported by this runtime" },
86441
86450
  { status: 500 }
86442
86451
  );
86443
86452
  }
86444
- await agentBuilder.setUserValue(authResult.user.id, key, body.value ?? null);
86453
+ await store.setUserValue(authResult.user.id, key, body.value ?? null);
86445
86454
  return Response.json({ status: "ok", key });
86446
86455
  } catch (error) {
86447
86456
  console.error("Set user kv error:", error);