@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.
@@ -533,7 +533,13 @@ interface PromptToolConfig {
533
533
  * Subagent tool configuration for dual_ai agent invocation.
534
534
  */
535
535
  interface SubagentToolConfig {
536
+ /** Exposed tool name — the name the model invokes this subagent by. */
536
537
  name: string;
538
+ /**
539
+ * The `dual_ai` agent this tool invokes when exposed under a different
540
+ * name. Defaults to `name`. Mirrors spec `SubagentToolConfig.agent`.
541
+ */
542
+ agent?: string;
537
543
  blocking?: boolean;
538
544
  initUserMessageProperty?: string;
539
545
  initAttachmentsProperty?: string;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ModelDefinition, AgentDefinition } from './runtime.js';
2
2
  export { AgentBuilderEnv, AgentBuilderEvent, BroadcastOptions, CodeExecutionBridge, DurableAgentBuilder, DurableThread, DurableUserHub, FlowStateSdk, FlowStateWithSdk, HubClientInfo, ImageContextConfig, InjectMessageOptions, LLMProviderInterface, NamespaceResolutionError, PromptContent, PromptDefinition, PromptIncludePart, PromptPart, PromptToolConfig, Provider, ProviderContentPart, ProviderFilePart, ProviderImagePart, ProviderRegistry, ProviderTextPart, SessionToolBinding, SessionToolConfig, SideConfig, SubagentToolConfig, SubpromptConfig, ThreadEventPayload, ThreadRegistryEntry, ThreadWatchdog, ThreadWatchdogState, ToolConfig, UpdateThreadParams, User, WatchdogCheckin, WatchdogProbeResult, applyRuntimeCors, buildImageDescription, canAccessThread, cat, createNamespaceContext, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateImageDescription, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, head, injectMessage, isAdminOnlyApiRoute, isHostedInstance, isPublicApiRoute, isQualifiedName, isSameOriginBrowserRequest, isTrustedLocalDevelopmentRequest, linkFile, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, runtimeCorsHeaders, runtimePreflightResponse, stat, tail, unlink, updateThread, writeFile, writeImage } from './runtime.js';
3
3
  export { AgentPluginOptions, agentbuilder, builder } from './plugin.js';
4
- export { w as Agent, J as AttachmentRef, j as AuthContext, A as AuthUser, f as BuilderThreadEndpointHandler, C as CLIENT_STREAM_CHUNK_BYTES, u as ClientDuplex, v as ClientForwarding, q as ClientStreamRequest, t as ClientStreamResponse, o as ClientToolRequest, p as ClientToolResponse, B as Controller, a as ControllerContext, G as Env, H as FileRecord, N as FileStats, D as FlowResult, F as FlowState, K as GrepResult, P as ImageContentPart, I as ImageMetadata, L as LLMResponse, M as Message, U as MessageContent, Q as MultimodalContent, R as RequestContext, S as StorageBackend, E as TelemetryEvent, O as TextContentPart, b as ThreadEndpointContext, e as ThreadEnv, x as ThreadInstance, y as ThreadMetadata, T as ToolCall, z as ToolResult, 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';
4
+ export { w as Agent, J as AttachmentRef, j as AuthContext, A as AuthUser, f as BuilderThreadEndpointHandler, C as CLIENT_STREAM_CHUNK_BYTES, u as ClientDuplex, v as ClientForwarding, q as ClientStreamRequest, t as ClientStreamResponse, o as ClientToolRequest, p as ClientToolResponse, B as Controller, a as ControllerContext, G as Env, H as FileRecord, N as FileStats, D as FlowResult, F as FlowState, K as GrepResult, P as ImageContentPart, I as ImageMetadata, L as LLMResponse, M as Message, U as MessageContent, Q as MultimodalContent, R as RequestContext, S as StorageBackend, E as TelemetryEvent, O as TextContentPart, b as ThreadEndpointContext, e as ThreadEnv, x as ThreadInstance, y as ThreadMetadata, T as ToolCall, z as ToolResult, 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';
5
5
  export { AgentType, DefinitionLoader, GlobalNamespaceContext, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, NamespaceContext, PackageSignature, PackedExports, PackedMeta, PackedMetadata, PackedNamespaceContext, PromptInput, PromptTextPart, ProviderAssistantMessage, ProviderConfigSlot, ProviderConfigSlots, ProviderConfigValueSource, ProviderDefinition, ProviderError, ProviderErrorCode, ProviderFactory, ProviderFactoryConfig, ProviderFinishReason, ProviderGeneratedImage, ProviderMessage, ProviderMessageContent, ProviderMethodOverrides, ModelCapabilities as ProviderModelCapabilities, ProviderOverride, ProviderOverrideContext, ProviderReasoningDetail, ProviderRequest, ProviderResponse, ProviderStreamChunk, ProviderSyncOverride, ProviderSystemMessage, ProviderTool, ProviderToolCallPart, ProviderToolMessage, ProviderToolResultContent, ProviderUsage, ProviderUserMessage, ReasoningConfig, StructuredPrompt, TextContent, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineProvider, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel, providerConst, providerEnv, providerValue } from '@standardagents/spec';
6
6
  export { C as ConstituentItem, D as DiscoveredPackage, N as NamespacedRegistry, P as PackingAnalysis, a as PackingOptions, b as PackingResult, c as UnpackOptions, d as UnpackResult } from './types-Bpe7IANZ.js';
7
7
  export { D as DiscoveryConfig, P as PackageDiscoveryService, d as discoverPackages } from './discovery-DiMJWisl.js';
package/dist/index.js CHANGED
@@ -4283,6 +4283,24 @@ var init_ToolExecutor = __esm({
4283
4283
  }
4284
4284
  } catch {
4285
4285
  }
4286
+ const aliasTarget = this.subagentAliasTarget(state, toolName);
4287
+ if (aliasTarget) {
4288
+ if (packageId) {
4289
+ try {
4290
+ const qualified = aliasTarget.includes("/") ? aliasTarget : `${packageId}/${aliasTarget}`;
4291
+ if (await state.thread.instance.loadAgent(qualified)) {
4292
+ return "agent";
4293
+ }
4294
+ } catch {
4295
+ }
4296
+ }
4297
+ try {
4298
+ if (await state.thread.instance.loadAgent(aliasTarget)) {
4299
+ return "agent";
4300
+ }
4301
+ } catch {
4302
+ }
4303
+ }
4286
4304
  const isInToolsArray = (agentName) => {
4287
4305
  const tools2 = state.prompt._tools || [];
4288
4306
  return tools2.some((t) => typeof t === "string" ? t === agentName : t.name === agentName);
@@ -4798,15 +4816,20 @@ Message one with subagent_message(referenceId, message).`
4798
4816
  const builtinCreateAttachmentValue = createArgs?.attachments;
4799
4817
  const builtinCreateInitialArguments = createArgs?.initialArguments ?? {};
4800
4818
  const registryAgentName = targetAgentForCreate || call.function.name;
4819
+ const aliasConfig = this.resolveSubagentToolConfig(state, registryAgentName);
4820
+ const implementingAgentName = typeof aliasConfig.agent === "string" && aliasConfig.agent.trim().length > 0 ? aliasConfig.agent.trim() : registryAgentName;
4801
4821
  const packageId = getPackageId(state);
4802
4822
  let agentDef = null;
4803
- let agentName = registryAgentName;
4823
+ let agentName = implementingAgentName;
4804
4824
  if (builtinSubagentAction === "create" && targetAgentForCreate) {
4805
4825
  const availableSubagents = await this.getPromptSubagentNames(state);
4806
4826
  if (!availableSubagents.includes(targetAgentForCreate)) {
4827
+ const configuredDirect = (state.prompt._tools || []).some(
4828
+ (t) => typeof t === "string" ? t === targetAgentForCreate : t?.name === targetAgentForCreate
4829
+ );
4807
4830
  return {
4808
4831
  status: "error",
4809
- error: `Subagent "${targetAgentForCreate}" is not available for this prompt. Use one of: ${availableSubagents.join(", ") || "(none)"}.`
4832
+ 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)"}.`
4810
4833
  };
4811
4834
  }
4812
4835
  }
@@ -4847,7 +4870,7 @@ Message one with subagent_message(referenceId, message).`
4847
4870
  if (agentType === "ai_human") {
4848
4871
  const parentToolConfigs = state.prompt._tools || [];
4849
4872
  const toolConfig = parentToolConfigs.find(
4850
- (t) => typeof t === "string" ? t === agentName : t.name === agentName
4873
+ (t) => typeof t === "string" ? t === registryAgentName || t === agentName : t.name === registryAgentName || t.name === agentName
4851
4874
  );
4852
4875
  const subpromptToolConfig = this.getSubpromptToolConfig(toolConfig);
4853
4876
  const targetState = state.rootState || state;
@@ -5425,6 +5448,27 @@ Message one with subagent_message(referenceId, message).`
5425
5448
  }
5426
5449
  return null;
5427
5450
  }
5451
+ /**
5452
+ * The implementing agent behind an aliased subagent tool name, or null when
5453
+ * the name carries no alias (`agent` absent, empty, or equal to the name).
5454
+ */
5455
+ static subagentAliasTarget(state, toolName) {
5456
+ for (const tool of state.prompt._tools || []) {
5457
+ if (!tool || typeof tool !== "object" || tool.name !== toolName) {
5458
+ continue;
5459
+ }
5460
+ const target = tool.agent;
5461
+ if (typeof target === "string" && target.trim().length > 0 && target.trim() !== toolName) {
5462
+ return target.trim();
5463
+ }
5464
+ }
5465
+ return null;
5466
+ }
5467
+ /**
5468
+ * Resolve the prompt's subagent tool config for an EXPOSED tool name.
5469
+ * Config entries are keyed by `name` (the model-facing tool name), which
5470
+ * may alias a differently-named implementing agent via `agent`.
5471
+ */
5428
5472
  static resolveSubagentToolConfig(state, agentName) {
5429
5473
  const config = (state.prompt._tools || []).find(
5430
5474
  (tool) => typeof tool === "string" ? tool === agentName : tool.name === agentName
@@ -8971,7 +9015,8 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
8971
9015
  }
8972
9016
  if (foundToolNames.has(toolName)) continue;
8973
9017
  try {
8974
- const agentDef = await state.thread.instance.loadAgent(toolName);
9018
+ const implementingAgent = subagentConfig && typeof subagentConfig.agent === "string" && subagentConfig.agent.trim().length > 0 ? subagentConfig.agent.trim() : toolName;
9019
+ const agentDef = await state.thread.instance.loadAgent(implementingAgent);
8975
9020
  if (agentDef && (agentDef.type === "ai_human" || agentDef.type === "dual_ai")) {
8976
9021
  let parameters;
8977
9022
  const sideAPromptName = agentDef.sideA?.prompt;
@@ -9185,12 +9230,14 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
9185
9230
  if (!toolName || toolName.startsWith("provider:") || seen.has(toolName)) {
9186
9231
  continue;
9187
9232
  }
9188
- const agentDef = await this.tryLoadPromptToolAgent(state, toolName, packageId);
9233
+ const subagentConfigForLoad = this.isSubagentToolConfig(configEntry) ? configEntry : void 0;
9234
+ const implementingAgent = subagentConfigForLoad && typeof subagentConfigForLoad.agent === "string" && subagentConfigForLoad.agent.trim().length > 0 ? subagentConfigForLoad.agent.trim() : toolName;
9235
+ const agentDef = await this.tryLoadPromptToolAgent(state, implementingAgent, packageId);
9189
9236
  if (!agentDef || agentDef.type !== "dual_ai") {
9190
9237
  continue;
9191
9238
  }
9192
9239
  seen.add(toolName);
9193
- const subagentConfig = this.isSubagentToolConfig(configEntry) ? configEntry : void 0;
9240
+ const subagentConfig = subagentConfigForLoad;
9194
9241
  const blocking = subagentConfig?.blocking ?? true;
9195
9242
  const resumable = !!subagentConfig?.resumable && typeof subagentConfig.resumable === "object";
9196
9243
  const receivesMessages = subagentConfig?.resumable && typeof subagentConfig.resumable === "object" ? subagentConfig.resumable.receives_messages : "side_a";
@@ -22694,7 +22741,10 @@ ${packedThreadRouteCode}
22694
22741
  // across requests.
22695
22742
  let threadAccess = null;
22696
22743
 
22697
- // Require authentication for all API routes except public ones
22744
+ // Require authentication for all API routes except public ones.
22745
+ // WebSocket tickets are single-use and are consumed here. Controllers
22746
+ // must reuse context.auth (resolveRequestAuth) rather than calling
22747
+ // requireAuth again, or a ticket-only upgrade will 401.
22698
22748
  if (isApiRoute && !publicRoute) {
22699
22749
  const authResult = await requireAuth(request, env);
22700
22750