@standardagents/builder 0.38.1 → 0.38.2
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 +88 -62
- package/dist/built-in-routes.js.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +4 -1
- package/dist/plugin.js.map +1 -1
- package/package.json +5 -5
package/dist/built-in-routes.js
CHANGED
|
@@ -68323,7 +68323,7 @@ var config_get_default = defineController2(async ({ config, env: env2, req }) =>
|
|
|
68323
68323
|
});
|
|
68324
68324
|
|
|
68325
68325
|
// src/version.ts
|
|
68326
|
-
var BUILDER_VERSION = "0.38.
|
|
68326
|
+
var BUILDER_VERSION = "0.38.2".length > 0 ? "0.38.2" : "dev";
|
|
68327
68327
|
|
|
68328
68328
|
// src/api/diagnostics.get.ts
|
|
68329
68329
|
init_LLMRequest();
|
|
@@ -68442,6 +68442,35 @@ function resolveStreamTimeoutValue(env2, key, fallback) {
|
|
|
68442
68442
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
68443
68443
|
}
|
|
68444
68444
|
|
|
68445
|
+
// src/middleware/request-auth.ts
|
|
68446
|
+
async function resolveRequestAuth(context) {
|
|
68447
|
+
if (context.auth) return context.auth;
|
|
68448
|
+
if (!isAuthenticationEnv(context.env)) {
|
|
68449
|
+
return new Response(JSON.stringify({ error: "Unauthorized" }), {
|
|
68450
|
+
status: 401,
|
|
68451
|
+
headers: { "Content-Type": "application/json" }
|
|
68452
|
+
});
|
|
68453
|
+
}
|
|
68454
|
+
return requireAuth(context.req, context.env);
|
|
68455
|
+
}
|
|
68456
|
+
async function resolveRequestPermission(context, permission) {
|
|
68457
|
+
if (context.auth) {
|
|
68458
|
+
if (!hasPermissionInEnvironment(context.auth.user, permission, context.env)) {
|
|
68459
|
+
return Response.json(
|
|
68460
|
+
{ error: `Forbidden: '${permission}' access required` },
|
|
68461
|
+
{ status: 403 }
|
|
68462
|
+
);
|
|
68463
|
+
}
|
|
68464
|
+
return context.auth;
|
|
68465
|
+
}
|
|
68466
|
+
return requirePermission(context.req, context.env, permission);
|
|
68467
|
+
}
|
|
68468
|
+
function routerAuthorizedThread(context, threadId) {
|
|
68469
|
+
const access = context.threadAccess;
|
|
68470
|
+
if (!access || !threadId) return null;
|
|
68471
|
+
return access.threadId === threadId ? access.thread : null;
|
|
68472
|
+
}
|
|
68473
|
+
|
|
68445
68474
|
// src/events/access.ts
|
|
68446
68475
|
var EVENT_STREAM_USER_ID_HEADER = "X-Standard-Agents-Event-User-Id";
|
|
68447
68476
|
var EVENT_STREAM_SCOPE_HEADER = "X-Standard-Agents-Event-Scope";
|
|
@@ -68473,8 +68502,9 @@ function resolveEventStreamSubscription(request, auth) {
|
|
|
68473
68502
|
}
|
|
68474
68503
|
|
|
68475
68504
|
// src/api/events.get.ts
|
|
68476
|
-
var events_get_default = defineController2(async (
|
|
68477
|
-
const
|
|
68505
|
+
var events_get_default = defineController2(async (context) => {
|
|
68506
|
+
const { req, env: env2 } = context;
|
|
68507
|
+
const authResult = await resolveRequestAuth(context);
|
|
68478
68508
|
if (authResult instanceof Response) {
|
|
68479
68509
|
return authResult;
|
|
68480
68510
|
}
|
|
@@ -68503,9 +68533,10 @@ var events_get_default = defineController2(async ({ req, env: env2 }) => {
|
|
|
68503
68533
|
const stub = env2.AGENT_BUILDER.get(agentBuilderId);
|
|
68504
68534
|
return await stub.fetch(authenticatedUpgrade);
|
|
68505
68535
|
} catch (error) {
|
|
68536
|
+
const message = error instanceof Error ? error.message : "Failed to establish WebSocket connection";
|
|
68506
68537
|
console.error("Error establishing events WebSocket:", error);
|
|
68507
68538
|
return Response.json(
|
|
68508
|
-
{ error:
|
|
68539
|
+
{ error: message },
|
|
68509
68540
|
{ status: 500 }
|
|
68510
68541
|
);
|
|
68511
68542
|
}
|
|
@@ -70840,35 +70871,6 @@ var id_patch_default = defineController2(async ({ req, env: env2, params }) => {
|
|
|
70840
70871
|
}
|
|
70841
70872
|
});
|
|
70842
70873
|
|
|
70843
|
-
// src/middleware/request-auth.ts
|
|
70844
|
-
async function resolveRequestAuth(context) {
|
|
70845
|
-
if (context.auth) return context.auth;
|
|
70846
|
-
if (!isAuthenticationEnv(context.env)) {
|
|
70847
|
-
return new Response(JSON.stringify({ error: "Unauthorized" }), {
|
|
70848
|
-
status: 401,
|
|
70849
|
-
headers: { "Content-Type": "application/json" }
|
|
70850
|
-
});
|
|
70851
|
-
}
|
|
70852
|
-
return requireAuth(context.req, context.env);
|
|
70853
|
-
}
|
|
70854
|
-
async function resolveRequestPermission(context, permission) {
|
|
70855
|
-
if (context.auth) {
|
|
70856
|
-
if (!hasPermissionInEnvironment(context.auth.user, permission, context.env)) {
|
|
70857
|
-
return Response.json(
|
|
70858
|
-
{ error: `Forbidden: '${permission}' access required` },
|
|
70859
|
-
{ status: 403 }
|
|
70860
|
-
);
|
|
70861
|
-
}
|
|
70862
|
-
return context.auth;
|
|
70863
|
-
}
|
|
70864
|
-
return requirePermission(context.req, context.env, permission);
|
|
70865
|
-
}
|
|
70866
|
-
function routerAuthorizedThread(context, threadId) {
|
|
70867
|
-
const access = context.threadAccess;
|
|
70868
|
-
if (!access || !threadId) return null;
|
|
70869
|
-
return access.threadId === threadId ? access.thread : null;
|
|
70870
|
-
}
|
|
70871
|
-
|
|
70872
70874
|
// src/api/threads/[id].ts
|
|
70873
70875
|
function resolveIconUrl2(icon, origin) {
|
|
70874
70876
|
if (!icon) return void 0;
|
|
@@ -73832,8 +73834,9 @@ var tools_get_default2 = defineController2(async ({ params, url }) => {
|
|
|
73832
73834
|
});
|
|
73833
73835
|
|
|
73834
73836
|
// src/api/threads/[id]/bridge.ts
|
|
73835
|
-
var bridge_default = defineController2(async (
|
|
73836
|
-
const
|
|
73837
|
+
var bridge_default = defineController2(async (context) => {
|
|
73838
|
+
const { req, params, env: env2 } = context;
|
|
73839
|
+
const authResult = await resolveRequestAuth(context);
|
|
73837
73840
|
if (authResult instanceof Response) {
|
|
73838
73841
|
return authResult;
|
|
73839
73842
|
}
|
|
@@ -73848,22 +73851,31 @@ var bridge_default = defineController2(async ({ req, params, env: env2 }) => {
|
|
|
73848
73851
|
);
|
|
73849
73852
|
}
|
|
73850
73853
|
try {
|
|
73851
|
-
|
|
73852
|
-
|
|
73853
|
-
|
|
73854
|
-
|
|
73855
|
-
|
|
73856
|
-
|
|
73857
|
-
|
|
73858
|
-
|
|
73854
|
+
if (!routerAuthorizedThread(context, threadId)) {
|
|
73855
|
+
const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
|
|
73856
|
+
const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
|
|
73857
|
+
const thread = await agentBuilder.getThread(threadId);
|
|
73858
|
+
if (!thread) {
|
|
73859
|
+
return Response.json(
|
|
73860
|
+
{ error: `Thread not found: ${threadId}` },
|
|
73861
|
+
{ status: 404 }
|
|
73862
|
+
);
|
|
73863
|
+
}
|
|
73864
|
+
if (!canAccessThread(authResult, thread)) {
|
|
73865
|
+
return Response.json(
|
|
73866
|
+
{ error: "Forbidden: You don't have access to this thread" },
|
|
73867
|
+
{ status: 403 }
|
|
73868
|
+
);
|
|
73869
|
+
}
|
|
73859
73870
|
}
|
|
73860
73871
|
const durableId = env2.AGENT_BUILDER_THREAD.idFromName(threadId);
|
|
73861
73872
|
const stub = env2.AGENT_BUILDER_THREAD.get(durableId);
|
|
73862
73873
|
return await stub.fetch(req);
|
|
73863
73874
|
} catch (error) {
|
|
73875
|
+
const message = error instanceof Error ? error.message : "Failed to establish client bridge";
|
|
73864
73876
|
console.error(`Error establishing bridge for thread ${threadId}:`, error);
|
|
73865
73877
|
return Response.json(
|
|
73866
|
-
{ error:
|
|
73878
|
+
{ error: message },
|
|
73867
73879
|
{ status: 500 }
|
|
73868
73880
|
);
|
|
73869
73881
|
}
|
|
@@ -74789,8 +74801,9 @@ var stop_post_default = defineController2(async ({ params, env: env2 }) => {
|
|
|
74789
74801
|
});
|
|
74790
74802
|
|
|
74791
74803
|
// src/api/threads/[id]/stream.ts
|
|
74792
|
-
var stream_default = defineController2(async (
|
|
74793
|
-
const
|
|
74804
|
+
var stream_default = defineController2(async (context) => {
|
|
74805
|
+
const { req, params, env: env2 } = context;
|
|
74806
|
+
const authResult = await resolveRequestAuth(context);
|
|
74794
74807
|
if (authResult instanceof Response) {
|
|
74795
74808
|
return authResult;
|
|
74796
74809
|
}
|
|
@@ -74805,22 +74818,31 @@ var stream_default = defineController2(async ({ req, params, env: env2 }) => {
|
|
|
74805
74818
|
);
|
|
74806
74819
|
}
|
|
74807
74820
|
try {
|
|
74808
|
-
|
|
74809
|
-
|
|
74810
|
-
|
|
74811
|
-
|
|
74812
|
-
|
|
74813
|
-
|
|
74814
|
-
|
|
74815
|
-
|
|
74821
|
+
if (!routerAuthorizedThread(context, threadId)) {
|
|
74822
|
+
const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
|
|
74823
|
+
const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
|
|
74824
|
+
const thread = await agentBuilder.getThread(threadId);
|
|
74825
|
+
if (!thread) {
|
|
74826
|
+
return Response.json(
|
|
74827
|
+
{ error: `Thread not found: ${threadId}` },
|
|
74828
|
+
{ status: 404 }
|
|
74829
|
+
);
|
|
74830
|
+
}
|
|
74831
|
+
if (!canAccessThread(authResult, thread)) {
|
|
74832
|
+
return Response.json(
|
|
74833
|
+
{ error: "Forbidden: You don't have access to this thread" },
|
|
74834
|
+
{ status: 403 }
|
|
74835
|
+
);
|
|
74836
|
+
}
|
|
74816
74837
|
}
|
|
74817
74838
|
const durableId = env2.AGENT_BUILDER_THREAD.idFromName(threadId);
|
|
74818
74839
|
const stub = env2.AGENT_BUILDER_THREAD.get(durableId);
|
|
74819
74840
|
return await stub.fetch(req);
|
|
74820
74841
|
} catch (error) {
|
|
74842
|
+
const message = error instanceof Error ? error.message : "Failed to establish message stream";
|
|
74821
74843
|
console.error(`Error handling message stream for thread ${threadId}:`, error);
|
|
74822
74844
|
return Response.json(
|
|
74823
|
-
{ error:
|
|
74845
|
+
{ error: message },
|
|
74824
74846
|
{ status: 500 }
|
|
74825
74847
|
);
|
|
74826
74848
|
}
|
|
@@ -75056,8 +75078,9 @@ var env_patch_default = defineController2(async ({ req, env: env2, params }) =>
|
|
|
75056
75078
|
});
|
|
75057
75079
|
|
|
75058
75080
|
// src/api/users/[id]/stream.ts
|
|
75059
|
-
var stream_default2 = defineController2(async (
|
|
75060
|
-
const
|
|
75081
|
+
var stream_default2 = defineController2(async (context) => {
|
|
75082
|
+
const { req, env: env2, params } = context;
|
|
75083
|
+
const authResult = await resolveRequestAuth(context);
|
|
75061
75084
|
if (authResult instanceof Response) return authResult;
|
|
75062
75085
|
const isAdmin = authResult.authType === "super_admin" || authResult.user?.role === "admin";
|
|
75063
75086
|
if (!isAdmin) {
|
|
@@ -75485,8 +75508,9 @@ var env_patch_default2 = defineController2(async ({ req, env: env2 }) => {
|
|
|
75485
75508
|
});
|
|
75486
75509
|
|
|
75487
75510
|
// src/api/users/me/hub.ts
|
|
75488
|
-
var hub_default = defineController2(async (
|
|
75489
|
-
const
|
|
75511
|
+
var hub_default = defineController2(async (context) => {
|
|
75512
|
+
const { req, env: env2 } = context;
|
|
75513
|
+
const authResult = await resolveRequestAuth(context);
|
|
75490
75514
|
if (authResult instanceof Response) {
|
|
75491
75515
|
return authResult;
|
|
75492
75516
|
}
|
|
@@ -75514,9 +75538,10 @@ var hub_default = defineController2(async ({ req, env: env2 }) => {
|
|
|
75514
75538
|
const stub = namespace.get(hubId);
|
|
75515
75539
|
return await stub.fetch(req);
|
|
75516
75540
|
} catch (error) {
|
|
75541
|
+
const message = error instanceof Error ? error.message : "Failed to establish hub connection";
|
|
75517
75542
|
console.error("Error establishing user hub socket:", error);
|
|
75518
75543
|
return Response.json(
|
|
75519
|
-
{ error:
|
|
75544
|
+
{ error: message },
|
|
75520
75545
|
{ status: 500 }
|
|
75521
75546
|
);
|
|
75522
75547
|
}
|
|
@@ -75658,8 +75683,9 @@ var index_post_default7 = defineController2(async ({ req, env: env2 }) => {
|
|
|
75658
75683
|
});
|
|
75659
75684
|
|
|
75660
75685
|
// src/api/users/me/stream.ts
|
|
75661
|
-
var stream_default3 = defineController2(async (
|
|
75662
|
-
const
|
|
75686
|
+
var stream_default3 = defineController2(async (context) => {
|
|
75687
|
+
const { req, env: env2 } = context;
|
|
75688
|
+
const authResult = await resolveRequestAuth(context);
|
|
75663
75689
|
if (authResult instanceof Response) return authResult;
|
|
75664
75690
|
if (authResult.authType === "super_admin") {
|
|
75665
75691
|
return Response.json(
|