@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/runtime.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { j as AuthContext, e as ThreadEnv, w as Agent, y as ThreadMetadata, z as ToolResult, M as Message, o as ClientToolRequest, p as ClientToolResponse, q as ClientStreamRequest, t as ClientStreamResponse, H as FileRecord, V as SkillStorageScope, F as FlowState, N as FileStats, K as GrepResult, J as AttachmentRef, U as MessageContent, G as Env, x as ThreadInstance } from './index-CF-lgN47.js';
2
- export { A as AuthUser, f as BuilderThreadEndpointHandler, C as CLIENT_STREAM_CHUNK_BYTES, u as ClientDuplex, v as ClientForwarding, B as Controller, a as ControllerContext, D as FlowResult, P as ImageContentPart, I as ImageMetadata, L as LLMResponse, Q as MultimodalContent, R as RequestContext, S as StorageBackend, E as TelemetryEvent, O as TextContentPart, b as ThreadEndpointContext, T as ToolCall, g as authenticate, k as callClient, l as callClientStream, c as createThreadEndpointHandler, n as decodeStreamChunk, d as defineController, m as encodeStreamChunk, i as endpointCallerFromAuth, h as requireAdmin, r as requireAuth, s as supportsClientForwarding } from './index-CF-lgN47.js';
1
+ import { j as AuthContext, e as ThreadEnv, w as Agent, y as ThreadMetadata, z as ToolResult, M as Message, o as ClientToolRequest, p as ClientToolResponse, q as ClientStreamRequest, t as ClientStreamResponse, H as FileRecord, V as SkillStorageScope, F as FlowState, N as FileStats, K as GrepResult, J as AttachmentRef, U as MessageContent, G as Env, x as ThreadInstance } from './index-yIcqf7DC.js';
2
+ export { A as AuthUser, f as BuilderThreadEndpointHandler, C as CLIENT_STREAM_CHUNK_BYTES, u as ClientDuplex, v as ClientForwarding, B as Controller, a as ControllerContext, D as FlowResult, P as ImageContentPart, I as ImageMetadata, L as LLMResponse, Q as MultimodalContent, R as RequestContext, S as StorageBackend, E as TelemetryEvent, O as TextContentPart, b as ThreadEndpointContext, T as ToolCall, g as authenticate, k as callClient, l as callClientStream, c as createThreadEndpointHandler, n as decodeStreamChunk, d as defineController, m as encodeStreamChunk, i as endpointCallerFromAuth, h as requireAdmin, r as requireAuth, s as supportsClientForwarding } from './index-yIcqf7DC.js';
3
3
  import { CodeExecutionOptions, CodeExecutionResult, SubagentRegistryEntry, InjectMessageInput, QueueMessageInput, CredentialGrant, SkillMetadata, SkillFileInput, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, PromptEnvPart, VariableDefinition, SubpromptConfig as SubpromptConfig$1, PromptToolConfig as PromptToolConfig$1, SubagentToolConfig as SubagentToolConfig$1, ReasoningConfig, SideConfig as SideConfig$1, LLMProviderInterface, ContentPart, TextPart, ImagePart, FilePart, ThreadState, NamespaceContext, DefinitionLoader } from '@standardagents/spec';
4
4
  export { AgentType, DefinitionLoader, GlobalNamespaceContext, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, NamespaceContext, PackageSignature, PackedExports, PackedMeta, PackedMetadata, PackedNamespaceContext, PromptInput, PromptTextPart, ProviderAssistantMessage, ProviderError, ProviderErrorCode, ProviderFactory, ProviderFactoryConfig, ProviderFinishReason, ProviderGeneratedImage, ProviderMessage, ProviderMessageContent, ModelCapabilities as ProviderModelCapabilities, ProviderReasoningDetail, ProviderRequest, ProviderResponse, ProviderStreamChunk, ProviderSystemMessage, ProviderTool, ProviderToolCallPart, ProviderToolMessage, ProviderToolResultContent, ProviderUsage, ProviderUserMessage, ReasoningConfig, StructuredPrompt, TextContent, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel } from '@standardagents/spec';
5
5
  import { DurableObject, WorkerEntrypoint } from 'cloudflare:workers';
package/dist/runtime.js CHANGED
@@ -4274,6 +4274,24 @@ var init_ToolExecutor = __esm({
4274
4274
  }
4275
4275
  } catch {
4276
4276
  }
4277
+ const aliasTarget = this.subagentAliasTarget(state, toolName);
4278
+ if (aliasTarget) {
4279
+ if (packageId) {
4280
+ try {
4281
+ const qualified = aliasTarget.includes("/") ? aliasTarget : `${packageId}/${aliasTarget}`;
4282
+ if (await state.thread.instance.loadAgent(qualified)) {
4283
+ return "agent";
4284
+ }
4285
+ } catch {
4286
+ }
4287
+ }
4288
+ try {
4289
+ if (await state.thread.instance.loadAgent(aliasTarget)) {
4290
+ return "agent";
4291
+ }
4292
+ } catch {
4293
+ }
4294
+ }
4277
4295
  const isInToolsArray = (agentName) => {
4278
4296
  const tools2 = state.prompt._tools || [];
4279
4297
  return tools2.some((t) => typeof t === "string" ? t === agentName : t.name === agentName);
@@ -4789,15 +4807,20 @@ Message one with subagent_message(referenceId, message).`
4789
4807
  const builtinCreateAttachmentValue = createArgs?.attachments;
4790
4808
  const builtinCreateInitialArguments = createArgs?.initialArguments ?? {};
4791
4809
  const registryAgentName = targetAgentForCreate || call.function.name;
4810
+ const aliasConfig = this.resolveSubagentToolConfig(state, registryAgentName);
4811
+ const implementingAgentName = typeof aliasConfig.agent === "string" && aliasConfig.agent.trim().length > 0 ? aliasConfig.agent.trim() : registryAgentName;
4792
4812
  const packageId = getPackageId(state);
4793
4813
  let agentDef = null;
4794
- let agentName = registryAgentName;
4814
+ let agentName = implementingAgentName;
4795
4815
  if (builtinSubagentAction === "create" && targetAgentForCreate) {
4796
4816
  const availableSubagents = await this.getPromptSubagentNames(state);
4797
4817
  if (!availableSubagents.includes(targetAgentForCreate)) {
4818
+ const configuredDirect = (state.prompt._tools || []).some(
4819
+ (t) => typeof t === "string" ? t === targetAgentForCreate : t?.name === targetAgentForCreate
4820
+ );
4798
4821
  return {
4799
4822
  status: "error",
4800
- error: `Subagent "${targetAgentForCreate}" is not available for this prompt. Use one of: ${availableSubagents.join(", ") || "(none)"}.`
4823
+ 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)"}.`
4801
4824
  };
4802
4825
  }
4803
4826
  }
@@ -4838,7 +4861,7 @@ Message one with subagent_message(referenceId, message).`
4838
4861
  if (agentType === "ai_human") {
4839
4862
  const parentToolConfigs = state.prompt._tools || [];
4840
4863
  const toolConfig = parentToolConfigs.find(
4841
- (t) => typeof t === "string" ? t === agentName : t.name === agentName
4864
+ (t) => typeof t === "string" ? t === registryAgentName || t === agentName : t.name === registryAgentName || t.name === agentName
4842
4865
  );
4843
4866
  const subpromptToolConfig = this.getSubpromptToolConfig(toolConfig);
4844
4867
  const targetState = state.rootState || state;
@@ -5416,6 +5439,27 @@ Message one with subagent_message(referenceId, message).`
5416
5439
  }
5417
5440
  return null;
5418
5441
  }
5442
+ /**
5443
+ * The implementing agent behind an aliased subagent tool name, or null when
5444
+ * the name carries no alias (`agent` absent, empty, or equal to the name).
5445
+ */
5446
+ static subagentAliasTarget(state, toolName) {
5447
+ for (const tool of state.prompt._tools || []) {
5448
+ if (!tool || typeof tool !== "object" || tool.name !== toolName) {
5449
+ continue;
5450
+ }
5451
+ const target = tool.agent;
5452
+ if (typeof target === "string" && target.trim().length > 0 && target.trim() !== toolName) {
5453
+ return target.trim();
5454
+ }
5455
+ }
5456
+ return null;
5457
+ }
5458
+ /**
5459
+ * Resolve the prompt's subagent tool config for an EXPOSED tool name.
5460
+ * Config entries are keyed by `name` (the model-facing tool name), which
5461
+ * may alias a differently-named implementing agent via `agent`.
5462
+ */
5419
5463
  static resolveSubagentToolConfig(state, agentName) {
5420
5464
  const config = (state.prompt._tools || []).find(
5421
5465
  (tool) => typeof tool === "string" ? tool === agentName : tool.name === agentName
@@ -8962,7 +9006,8 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
8962
9006
  }
8963
9007
  if (foundToolNames.has(toolName)) continue;
8964
9008
  try {
8965
- const agentDef = await state.thread.instance.loadAgent(toolName);
9009
+ const implementingAgent = subagentConfig && typeof subagentConfig.agent === "string" && subagentConfig.agent.trim().length > 0 ? subagentConfig.agent.trim() : toolName;
9010
+ const agentDef = await state.thread.instance.loadAgent(implementingAgent);
8966
9011
  if (agentDef && (agentDef.type === "ai_human" || agentDef.type === "dual_ai")) {
8967
9012
  let parameters;
8968
9013
  const sideAPromptName = agentDef.sideA?.prompt;
@@ -9176,12 +9221,14 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
9176
9221
  if (!toolName || toolName.startsWith("provider:") || seen.has(toolName)) {
9177
9222
  continue;
9178
9223
  }
9179
- const agentDef = await this.tryLoadPromptToolAgent(state, toolName, packageId);
9224
+ const subagentConfigForLoad = this.isSubagentToolConfig(configEntry) ? configEntry : void 0;
9225
+ const implementingAgent = subagentConfigForLoad && typeof subagentConfigForLoad.agent === "string" && subagentConfigForLoad.agent.trim().length > 0 ? subagentConfigForLoad.agent.trim() : toolName;
9226
+ const agentDef = await this.tryLoadPromptToolAgent(state, implementingAgent, packageId);
9180
9227
  if (!agentDef || agentDef.type !== "dual_ai") {
9181
9228
  continue;
9182
9229
  }
9183
9230
  seen.add(toolName);
9184
- const subagentConfig = this.isSubagentToolConfig(configEntry) ? configEntry : void 0;
9231
+ const subagentConfig = subagentConfigForLoad;
9185
9232
  const blocking = subagentConfig?.blocking ?? true;
9186
9233
  const resumable = !!subagentConfig?.resumable && typeof subagentConfig.resumable === "object";
9187
9234
  const receivesMessages = subagentConfig?.resumable && typeof subagentConfig.resumable === "object" ? subagentConfig.resumable.receives_messages : "side_a";