@standardagents/builder 0.37.8 → 0.38.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/built-in-routes.js +106 -177
- package/dist/built-in-routes.js.map +1 -1
- package/dist/{index-Lfan8QMN.d.ts → index-BBu-Osn5.d.ts} +10 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +98 -60
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +29 -4
- package/dist/plugin.js.map +1 -1
- package/dist/runtime.d.ts +3 -2
- package/dist/runtime.js +69 -56
- package/dist/runtime.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/package.json +5 -5
package/dist/plugin.js
CHANGED
|
@@ -7462,14 +7462,16 @@ import { prompts, promptNames } from "virtual:@standardagents-prompts";
|
|
|
7462
7462
|
import { agents, agentNames } from "virtual:@standardagents-agents";
|
|
7463
7463
|
import { registry } from "virtual:@standardagents-registry";
|
|
7464
7464
|
import {
|
|
7465
|
+
authenticate,
|
|
7465
7466
|
requireAuth,
|
|
7466
7467
|
createThreadEndpointHandler,
|
|
7467
7468
|
canAccessThread,
|
|
7469
|
+
endpointCallerFromAuth,
|
|
7468
7470
|
isHostedInstance,
|
|
7469
7471
|
isPublicApiRoute,
|
|
7470
7472
|
isAdminOnlyApiRoute,
|
|
7471
7473
|
} from "@standardagents/builder/runtime";
|
|
7472
|
-
import { isThreadEndpoint } from "@standardagents/spec";
|
|
7474
|
+
import { isThreadEndpoint, getEndpointAccess } from "@standardagents/spec";
|
|
7473
7475
|
|
|
7474
7476
|
function platformEndpoint(env) {
|
|
7475
7477
|
const configured =
|
|
@@ -7612,8 +7614,16 @@ ${packedThreadRouteCode}
|
|
|
7612
7614
|
);
|
|
7613
7615
|
|
|
7614
7616
|
if (routeMatch) {
|
|
7617
|
+
let controller = await routeMatch.data();
|
|
7618
|
+
|
|
7619
|
+
// Endpoint-declared access (spec: EndpointAccess). A 'public' declaration
|
|
7620
|
+
// opts that one endpoint out of the router's authentication gate; the
|
|
7621
|
+
// handler still receives the resolved caller identity when the request
|
|
7622
|
+
// presents verifiable credentials.
|
|
7623
|
+
const declaredPublic = getEndpointAccess(controller) === 'public';
|
|
7624
|
+
|
|
7615
7625
|
// Check if authentication is required for this route
|
|
7616
|
-
const publicRoute = isPublicApiRoute(routePath, request, env);
|
|
7626
|
+
const publicRoute = declaredPublic || isPublicApiRoute(routePath, request, env);
|
|
7617
7627
|
const isApiRoute = routePath.startsWith('/api/');
|
|
7618
7628
|
|
|
7619
7629
|
let authContext = null;
|
|
@@ -7656,10 +7666,24 @@ ${packedThreadRouteCode}
|
|
|
7656
7666
|
threadAccess = { threadId, thread };
|
|
7657
7667
|
}
|
|
7658
7668
|
}
|
|
7669
|
+
} else if (isApiRoute && declaredPublic) {
|
|
7670
|
+
// Optional caller resolution for endpoint-declared public routes:
|
|
7671
|
+
// verifiable credentials attribute the request, anything else stays
|
|
7672
|
+
// anonymous instead of being rejected (spec ThreadEndpointAuth).
|
|
7673
|
+
authContext = await authenticate(request, env);
|
|
7674
|
+
if (authContext && routePath.startsWith('/api/threads/')) {
|
|
7675
|
+
const threadId = routeMatch.params?.threadId || routeMatch.params?.id;
|
|
7676
|
+
if (threadId) {
|
|
7677
|
+
const agentBuilderId = env.AGENT_BUILDER.idFromName('singleton');
|
|
7678
|
+
const agentBuilder = env.AGENT_BUILDER.get(agentBuilderId);
|
|
7679
|
+
const thread = await agentBuilder.getThread(threadId);
|
|
7680
|
+
if (thread && canAccessThread(authContext, thread)) {
|
|
7681
|
+
threadAccess = { threadId, thread };
|
|
7682
|
+
}
|
|
7683
|
+
}
|
|
7684
|
+
}
|
|
7659
7685
|
}
|
|
7660
7686
|
|
|
7661
|
-
let controller = await routeMatch.data();
|
|
7662
|
-
|
|
7663
7687
|
// Check if this is a thread endpoint (marked by defineThreadEndpoint)
|
|
7664
7688
|
// If so, wrap it with createThreadEndpointHandler to provide ThreadState
|
|
7665
7689
|
if (isThreadEndpoint(controller)) {
|
|
@@ -7674,6 +7698,7 @@ ${packedThreadRouteCode}
|
|
|
7674
7698
|
config,
|
|
7675
7699
|
tools,
|
|
7676
7700
|
auth: authContext, // Add auth context to controller context
|
|
7701
|
+
caller: endpointCallerFromAuth(authContext), // Spec ControllerContext.caller
|
|
7677
7702
|
threadAccess, // Router's thread authorization, bound to the exact id
|
|
7678
7703
|
};
|
|
7679
7704
|
const result = await controller(context);
|