@standardagents/builder 0.38.1 → 0.39.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 +141 -68
- package/dist/built-in-routes.js.map +1 -1
- package/dist/{index-CF-lgN47.d.ts → index-yIcqf7DC.d.ts} +6 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +57 -7
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +4 -1
- package/dist/plugin.js.map +1 -1
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +53 -6
- package/dist/runtime.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/package.json +5 -5
package/dist/built-in-routes.js
CHANGED
|
@@ -4247,6 +4247,24 @@ var init_ToolExecutor = __esm({
|
|
|
4247
4247
|
}
|
|
4248
4248
|
} catch {
|
|
4249
4249
|
}
|
|
4250
|
+
const aliasTarget = this.subagentAliasTarget(state, toolName);
|
|
4251
|
+
if (aliasTarget) {
|
|
4252
|
+
if (packageId) {
|
|
4253
|
+
try {
|
|
4254
|
+
const qualified = aliasTarget.includes("/") ? aliasTarget : `${packageId}/${aliasTarget}`;
|
|
4255
|
+
if (await state.thread.instance.loadAgent(qualified)) {
|
|
4256
|
+
return "agent";
|
|
4257
|
+
}
|
|
4258
|
+
} catch {
|
|
4259
|
+
}
|
|
4260
|
+
}
|
|
4261
|
+
try {
|
|
4262
|
+
if (await state.thread.instance.loadAgent(aliasTarget)) {
|
|
4263
|
+
return "agent";
|
|
4264
|
+
}
|
|
4265
|
+
} catch {
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4250
4268
|
const isInToolsArray = (agentName) => {
|
|
4251
4269
|
const tools2 = state.prompt._tools || [];
|
|
4252
4270
|
return tools2.some((t) => typeof t === "string" ? t === agentName : t.name === agentName);
|
|
@@ -4762,15 +4780,20 @@ Message one with subagent_message(referenceId, message).`
|
|
|
4762
4780
|
const builtinCreateAttachmentValue = createArgs?.attachments;
|
|
4763
4781
|
const builtinCreateInitialArguments = createArgs?.initialArguments ?? {};
|
|
4764
4782
|
const registryAgentName = targetAgentForCreate || call.function.name;
|
|
4783
|
+
const aliasConfig = this.resolveSubagentToolConfig(state, registryAgentName);
|
|
4784
|
+
const implementingAgentName = typeof aliasConfig.agent === "string" && aliasConfig.agent.trim().length > 0 ? aliasConfig.agent.trim() : registryAgentName;
|
|
4765
4785
|
const packageId = getPackageId(state);
|
|
4766
4786
|
let agentDef = null;
|
|
4767
|
-
let agentName =
|
|
4787
|
+
let agentName = implementingAgentName;
|
|
4768
4788
|
if (builtinSubagentAction === "create" && targetAgentForCreate) {
|
|
4769
4789
|
const availableSubagents = await this.getPromptSubagentNames(state);
|
|
4770
4790
|
if (!availableSubagents.includes(targetAgentForCreate)) {
|
|
4791
|
+
const configuredDirect = (state.prompt._tools || []).some(
|
|
4792
|
+
(t) => typeof t === "string" ? t === targetAgentForCreate : t?.name === targetAgentForCreate
|
|
4793
|
+
);
|
|
4771
4794
|
return {
|
|
4772
4795
|
status: "error",
|
|
4773
|
-
error: `Subagent "${targetAgentForCreate}" is not available for this prompt. Use one of: ${availableSubagents.join(", ") || "(none)"}.`
|
|
4796
|
+
error: configuredDirect ? `"${targetAgentForCreate}" is not a resumable subagent \u2014 call the ${targetAgentForCreate} tool directly; it runs to completion and returns its result in the tool response. subagent_create manages resumable subagents only: ${availableSubagents.join(", ") || "(none)"}.` : `Subagent "${targetAgentForCreate}" is not available for this prompt. Use one of: ${availableSubagents.join(", ") || "(none)"}.`
|
|
4774
4797
|
};
|
|
4775
4798
|
}
|
|
4776
4799
|
}
|
|
@@ -4811,7 +4834,7 @@ Message one with subagent_message(referenceId, message).`
|
|
|
4811
4834
|
if (agentType === "ai_human") {
|
|
4812
4835
|
const parentToolConfigs = state.prompt._tools || [];
|
|
4813
4836
|
const toolConfig = parentToolConfigs.find(
|
|
4814
|
-
(t) => typeof t === "string" ? t === agentName : t.name === agentName
|
|
4837
|
+
(t) => typeof t === "string" ? t === registryAgentName || t === agentName : t.name === registryAgentName || t.name === agentName
|
|
4815
4838
|
);
|
|
4816
4839
|
const subpromptToolConfig = this.getSubpromptToolConfig(toolConfig);
|
|
4817
4840
|
const targetState = state.rootState || state;
|
|
@@ -5389,6 +5412,27 @@ Message one with subagent_message(referenceId, message).`
|
|
|
5389
5412
|
}
|
|
5390
5413
|
return null;
|
|
5391
5414
|
}
|
|
5415
|
+
/**
|
|
5416
|
+
* The implementing agent behind an aliased subagent tool name, or null when
|
|
5417
|
+
* the name carries no alias (`agent` absent, empty, or equal to the name).
|
|
5418
|
+
*/
|
|
5419
|
+
static subagentAliasTarget(state, toolName) {
|
|
5420
|
+
for (const tool3 of state.prompt._tools || []) {
|
|
5421
|
+
if (!tool3 || typeof tool3 !== "object" || tool3.name !== toolName) {
|
|
5422
|
+
continue;
|
|
5423
|
+
}
|
|
5424
|
+
const target = tool3.agent;
|
|
5425
|
+
if (typeof target === "string" && target.trim().length > 0 && target.trim() !== toolName) {
|
|
5426
|
+
return target.trim();
|
|
5427
|
+
}
|
|
5428
|
+
}
|
|
5429
|
+
return null;
|
|
5430
|
+
}
|
|
5431
|
+
/**
|
|
5432
|
+
* Resolve the prompt's subagent tool config for an EXPOSED tool name.
|
|
5433
|
+
* Config entries are keyed by `name` (the model-facing tool name), which
|
|
5434
|
+
* may alias a differently-named implementing agent via `agent`.
|
|
5435
|
+
*/
|
|
5392
5436
|
static resolveSubagentToolConfig(state, agentName) {
|
|
5393
5437
|
const config = (state.prompt._tools || []).find(
|
|
5394
5438
|
(tool3) => typeof tool3 === "string" ? tool3 === agentName : tool3.name === agentName
|
|
@@ -8842,7 +8886,8 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
8842
8886
|
}
|
|
8843
8887
|
if (foundToolNames.has(toolName)) continue;
|
|
8844
8888
|
try {
|
|
8845
|
-
const
|
|
8889
|
+
const implementingAgent = subagentConfig && typeof subagentConfig.agent === "string" && subagentConfig.agent.trim().length > 0 ? subagentConfig.agent.trim() : toolName;
|
|
8890
|
+
const agentDef = await state.thread.instance.loadAgent(implementingAgent);
|
|
8846
8891
|
if (agentDef && (agentDef.type === "ai_human" || agentDef.type === "dual_ai")) {
|
|
8847
8892
|
let parameters;
|
|
8848
8893
|
const sideAPromptName = agentDef.sideA?.prompt;
|
|
@@ -9056,12 +9101,14 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9056
9101
|
if (!toolName || toolName.startsWith("provider:") || seen.has(toolName)) {
|
|
9057
9102
|
continue;
|
|
9058
9103
|
}
|
|
9059
|
-
const
|
|
9104
|
+
const subagentConfigForLoad = this.isSubagentToolConfig(configEntry) ? configEntry : void 0;
|
|
9105
|
+
const implementingAgent = subagentConfigForLoad && typeof subagentConfigForLoad.agent === "string" && subagentConfigForLoad.agent.trim().length > 0 ? subagentConfigForLoad.agent.trim() : toolName;
|
|
9106
|
+
const agentDef = await this.tryLoadPromptToolAgent(state, implementingAgent, packageId);
|
|
9060
9107
|
if (!agentDef || agentDef.type !== "dual_ai") {
|
|
9061
9108
|
continue;
|
|
9062
9109
|
}
|
|
9063
9110
|
seen.add(toolName);
|
|
9064
|
-
const subagentConfig =
|
|
9111
|
+
const subagentConfig = subagentConfigForLoad;
|
|
9065
9112
|
const blocking = subagentConfig?.blocking ?? true;
|
|
9066
9113
|
const resumable = !!subagentConfig?.resumable && typeof subagentConfig.resumable === "object";
|
|
9067
9114
|
const receivesMessages = subagentConfig?.resumable && typeof subagentConfig.resumable === "object" ? subagentConfig.resumable.receives_messages : "side_a";
|
|
@@ -68323,7 +68370,7 @@ var config_get_default = defineController2(async ({ config, env: env2, req }) =>
|
|
|
68323
68370
|
});
|
|
68324
68371
|
|
|
68325
68372
|
// src/version.ts
|
|
68326
|
-
var BUILDER_VERSION = "0.
|
|
68373
|
+
var BUILDER_VERSION = "0.39.0".length > 0 ? "0.39.0" : "dev";
|
|
68327
68374
|
|
|
68328
68375
|
// src/api/diagnostics.get.ts
|
|
68329
68376
|
init_LLMRequest();
|
|
@@ -68442,6 +68489,35 @@ function resolveStreamTimeoutValue(env2, key, fallback) {
|
|
|
68442
68489
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
68443
68490
|
}
|
|
68444
68491
|
|
|
68492
|
+
// src/middleware/request-auth.ts
|
|
68493
|
+
async function resolveRequestAuth(context) {
|
|
68494
|
+
if (context.auth) return context.auth;
|
|
68495
|
+
if (!isAuthenticationEnv(context.env)) {
|
|
68496
|
+
return new Response(JSON.stringify({ error: "Unauthorized" }), {
|
|
68497
|
+
status: 401,
|
|
68498
|
+
headers: { "Content-Type": "application/json" }
|
|
68499
|
+
});
|
|
68500
|
+
}
|
|
68501
|
+
return requireAuth(context.req, context.env);
|
|
68502
|
+
}
|
|
68503
|
+
async function resolveRequestPermission(context, permission) {
|
|
68504
|
+
if (context.auth) {
|
|
68505
|
+
if (!hasPermissionInEnvironment(context.auth.user, permission, context.env)) {
|
|
68506
|
+
return Response.json(
|
|
68507
|
+
{ error: `Forbidden: '${permission}' access required` },
|
|
68508
|
+
{ status: 403 }
|
|
68509
|
+
);
|
|
68510
|
+
}
|
|
68511
|
+
return context.auth;
|
|
68512
|
+
}
|
|
68513
|
+
return requirePermission(context.req, context.env, permission);
|
|
68514
|
+
}
|
|
68515
|
+
function routerAuthorizedThread(context, threadId) {
|
|
68516
|
+
const access = context.threadAccess;
|
|
68517
|
+
if (!access || !threadId) return null;
|
|
68518
|
+
return access.threadId === threadId ? access.thread : null;
|
|
68519
|
+
}
|
|
68520
|
+
|
|
68445
68521
|
// src/events/access.ts
|
|
68446
68522
|
var EVENT_STREAM_USER_ID_HEADER = "X-Standard-Agents-Event-User-Id";
|
|
68447
68523
|
var EVENT_STREAM_SCOPE_HEADER = "X-Standard-Agents-Event-Scope";
|
|
@@ -68473,8 +68549,9 @@ function resolveEventStreamSubscription(request, auth) {
|
|
|
68473
68549
|
}
|
|
68474
68550
|
|
|
68475
68551
|
// src/api/events.get.ts
|
|
68476
|
-
var events_get_default = defineController2(async (
|
|
68477
|
-
const
|
|
68552
|
+
var events_get_default = defineController2(async (context) => {
|
|
68553
|
+
const { req, env: env2 } = context;
|
|
68554
|
+
const authResult = await resolveRequestAuth(context);
|
|
68478
68555
|
if (authResult instanceof Response) {
|
|
68479
68556
|
return authResult;
|
|
68480
68557
|
}
|
|
@@ -68503,9 +68580,10 @@ var events_get_default = defineController2(async ({ req, env: env2 }) => {
|
|
|
68503
68580
|
const stub = env2.AGENT_BUILDER.get(agentBuilderId);
|
|
68504
68581
|
return await stub.fetch(authenticatedUpgrade);
|
|
68505
68582
|
} catch (error) {
|
|
68583
|
+
const message = error instanceof Error ? error.message : "Failed to establish WebSocket connection";
|
|
68506
68584
|
console.error("Error establishing events WebSocket:", error);
|
|
68507
68585
|
return Response.json(
|
|
68508
|
-
{ error:
|
|
68586
|
+
{ error: message },
|
|
68509
68587
|
{ status: 500 }
|
|
68510
68588
|
);
|
|
68511
68589
|
}
|
|
@@ -70840,35 +70918,6 @@ var id_patch_default = defineController2(async ({ req, env: env2, params }) => {
|
|
|
70840
70918
|
}
|
|
70841
70919
|
});
|
|
70842
70920
|
|
|
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
70921
|
// src/api/threads/[id].ts
|
|
70873
70922
|
function resolveIconUrl2(icon, origin) {
|
|
70874
70923
|
if (!icon) return void 0;
|
|
@@ -73832,8 +73881,9 @@ var tools_get_default2 = defineController2(async ({ params, url }) => {
|
|
|
73832
73881
|
});
|
|
73833
73882
|
|
|
73834
73883
|
// src/api/threads/[id]/bridge.ts
|
|
73835
|
-
var bridge_default = defineController2(async (
|
|
73836
|
-
const
|
|
73884
|
+
var bridge_default = defineController2(async (context) => {
|
|
73885
|
+
const { req, params, env: env2 } = context;
|
|
73886
|
+
const authResult = await resolveRequestAuth(context);
|
|
73837
73887
|
if (authResult instanceof Response) {
|
|
73838
73888
|
return authResult;
|
|
73839
73889
|
}
|
|
@@ -73848,22 +73898,31 @@ var bridge_default = defineController2(async ({ req, params, env: env2 }) => {
|
|
|
73848
73898
|
);
|
|
73849
73899
|
}
|
|
73850
73900
|
try {
|
|
73851
|
-
|
|
73852
|
-
|
|
73853
|
-
|
|
73854
|
-
|
|
73855
|
-
|
|
73856
|
-
|
|
73857
|
-
|
|
73858
|
-
|
|
73901
|
+
if (!routerAuthorizedThread(context, threadId)) {
|
|
73902
|
+
const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
|
|
73903
|
+
const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
|
|
73904
|
+
const thread = await agentBuilder.getThread(threadId);
|
|
73905
|
+
if (!thread) {
|
|
73906
|
+
return Response.json(
|
|
73907
|
+
{ error: `Thread not found: ${threadId}` },
|
|
73908
|
+
{ status: 404 }
|
|
73909
|
+
);
|
|
73910
|
+
}
|
|
73911
|
+
if (!canAccessThread(authResult, thread)) {
|
|
73912
|
+
return Response.json(
|
|
73913
|
+
{ error: "Forbidden: You don't have access to this thread" },
|
|
73914
|
+
{ status: 403 }
|
|
73915
|
+
);
|
|
73916
|
+
}
|
|
73859
73917
|
}
|
|
73860
73918
|
const durableId = env2.AGENT_BUILDER_THREAD.idFromName(threadId);
|
|
73861
73919
|
const stub = env2.AGENT_BUILDER_THREAD.get(durableId);
|
|
73862
73920
|
return await stub.fetch(req);
|
|
73863
73921
|
} catch (error) {
|
|
73922
|
+
const message = error instanceof Error ? error.message : "Failed to establish client bridge";
|
|
73864
73923
|
console.error(`Error establishing bridge for thread ${threadId}:`, error);
|
|
73865
73924
|
return Response.json(
|
|
73866
|
-
{ error:
|
|
73925
|
+
{ error: message },
|
|
73867
73926
|
{ status: 500 }
|
|
73868
73927
|
);
|
|
73869
73928
|
}
|
|
@@ -74789,8 +74848,9 @@ var stop_post_default = defineController2(async ({ params, env: env2 }) => {
|
|
|
74789
74848
|
});
|
|
74790
74849
|
|
|
74791
74850
|
// src/api/threads/[id]/stream.ts
|
|
74792
|
-
var stream_default = defineController2(async (
|
|
74793
|
-
const
|
|
74851
|
+
var stream_default = defineController2(async (context) => {
|
|
74852
|
+
const { req, params, env: env2 } = context;
|
|
74853
|
+
const authResult = await resolveRequestAuth(context);
|
|
74794
74854
|
if (authResult instanceof Response) {
|
|
74795
74855
|
return authResult;
|
|
74796
74856
|
}
|
|
@@ -74805,22 +74865,31 @@ var stream_default = defineController2(async ({ req, params, env: env2 }) => {
|
|
|
74805
74865
|
);
|
|
74806
74866
|
}
|
|
74807
74867
|
try {
|
|
74808
|
-
|
|
74809
|
-
|
|
74810
|
-
|
|
74811
|
-
|
|
74812
|
-
|
|
74813
|
-
|
|
74814
|
-
|
|
74815
|
-
|
|
74868
|
+
if (!routerAuthorizedThread(context, threadId)) {
|
|
74869
|
+
const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
|
|
74870
|
+
const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
|
|
74871
|
+
const thread = await agentBuilder.getThread(threadId);
|
|
74872
|
+
if (!thread) {
|
|
74873
|
+
return Response.json(
|
|
74874
|
+
{ error: `Thread not found: ${threadId}` },
|
|
74875
|
+
{ status: 404 }
|
|
74876
|
+
);
|
|
74877
|
+
}
|
|
74878
|
+
if (!canAccessThread(authResult, thread)) {
|
|
74879
|
+
return Response.json(
|
|
74880
|
+
{ error: "Forbidden: You don't have access to this thread" },
|
|
74881
|
+
{ status: 403 }
|
|
74882
|
+
);
|
|
74883
|
+
}
|
|
74816
74884
|
}
|
|
74817
74885
|
const durableId = env2.AGENT_BUILDER_THREAD.idFromName(threadId);
|
|
74818
74886
|
const stub = env2.AGENT_BUILDER_THREAD.get(durableId);
|
|
74819
74887
|
return await stub.fetch(req);
|
|
74820
74888
|
} catch (error) {
|
|
74889
|
+
const message = error instanceof Error ? error.message : "Failed to establish message stream";
|
|
74821
74890
|
console.error(`Error handling message stream for thread ${threadId}:`, error);
|
|
74822
74891
|
return Response.json(
|
|
74823
|
-
{ error:
|
|
74892
|
+
{ error: message },
|
|
74824
74893
|
{ status: 500 }
|
|
74825
74894
|
);
|
|
74826
74895
|
}
|
|
@@ -75056,8 +75125,9 @@ var env_patch_default = defineController2(async ({ req, env: env2, params }) =>
|
|
|
75056
75125
|
});
|
|
75057
75126
|
|
|
75058
75127
|
// src/api/users/[id]/stream.ts
|
|
75059
|
-
var stream_default2 = defineController2(async (
|
|
75060
|
-
const
|
|
75128
|
+
var stream_default2 = defineController2(async (context) => {
|
|
75129
|
+
const { req, env: env2, params } = context;
|
|
75130
|
+
const authResult = await resolveRequestAuth(context);
|
|
75061
75131
|
if (authResult instanceof Response) return authResult;
|
|
75062
75132
|
const isAdmin = authResult.authType === "super_admin" || authResult.user?.role === "admin";
|
|
75063
75133
|
if (!isAdmin) {
|
|
@@ -75485,8 +75555,9 @@ var env_patch_default2 = defineController2(async ({ req, env: env2 }) => {
|
|
|
75485
75555
|
});
|
|
75486
75556
|
|
|
75487
75557
|
// src/api/users/me/hub.ts
|
|
75488
|
-
var hub_default = defineController2(async (
|
|
75489
|
-
const
|
|
75558
|
+
var hub_default = defineController2(async (context) => {
|
|
75559
|
+
const { req, env: env2 } = context;
|
|
75560
|
+
const authResult = await resolveRequestAuth(context);
|
|
75490
75561
|
if (authResult instanceof Response) {
|
|
75491
75562
|
return authResult;
|
|
75492
75563
|
}
|
|
@@ -75514,9 +75585,10 @@ var hub_default = defineController2(async ({ req, env: env2 }) => {
|
|
|
75514
75585
|
const stub = namespace.get(hubId);
|
|
75515
75586
|
return await stub.fetch(req);
|
|
75516
75587
|
} catch (error) {
|
|
75588
|
+
const message = error instanceof Error ? error.message : "Failed to establish hub connection";
|
|
75517
75589
|
console.error("Error establishing user hub socket:", error);
|
|
75518
75590
|
return Response.json(
|
|
75519
|
-
{ error:
|
|
75591
|
+
{ error: message },
|
|
75520
75592
|
{ status: 500 }
|
|
75521
75593
|
);
|
|
75522
75594
|
}
|
|
@@ -75658,8 +75730,9 @@ var index_post_default7 = defineController2(async ({ req, env: env2 }) => {
|
|
|
75658
75730
|
});
|
|
75659
75731
|
|
|
75660
75732
|
// src/api/users/me/stream.ts
|
|
75661
|
-
var stream_default3 = defineController2(async (
|
|
75662
|
-
const
|
|
75733
|
+
var stream_default3 = defineController2(async (context) => {
|
|
75734
|
+
const { req, env: env2 } = context;
|
|
75735
|
+
const authResult = await resolveRequestAuth(context);
|
|
75663
75736
|
if (authResult instanceof Response) return authResult;
|
|
75664
75737
|
if (authResult.authType === "super_admin") {
|
|
75665
75738
|
return Response.json(
|