@standardagents/builder 0.41.7 → 0.41.9

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