@standardagents/builder 0.17.0-next.a4b7340 → 0.17.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 { e as ThreadEnv, h as ThreadMetadata, M as Message, l as FileRecord, F as FlowState, n as FileStats, G as GrepResult, m as AttachmentRef, r as MessageContent, E as Env, g as ThreadInstance } from './index-EaxysUHv.js';
2
- export { A as Agent, f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, j as FlowResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, T as ToolCall, i as ToolResult, c as createThreadEndpointHandler, d as defineController } from './index-EaxysUHv.js';
1
+ import { e as ThreadEnv, h as ThreadMetadata, M as Message, l as FileRecord, F as FlowState, n as FileStats, G as GrepResult, m as AttachmentRef, r as MessageContent, E as Env, g as ThreadInstance } from './index-BnrKzXpJ.js';
2
+ export { A as Agent, f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, j as FlowResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, T as ToolCall, i as ToolResult, c as createThreadEndpointHandler, d as defineController } from './index-BnrKzXpJ.js';
3
3
  import { CodeExecutionOptions, CodeExecutionResult, SubagentRegistryEntry, InjectMessageInput, QueueMessageInput, 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, 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';
@@ -2930,6 +2930,13 @@ type ProviderFilePart = FilePart;
2930
2930
  * Returns a provider to override the default, or null to fall through.
2931
2931
  */
2932
2932
  type ProviderOverrideFn = (modelName: string, modelDef: ModelDefinition$1<string>, env: Env) => LLMProviderInterface | null;
2933
+ interface ProviderLookupResult {
2934
+ provider: LLMProviderInterface;
2935
+ modelName: string;
2936
+ modelDef: ModelDefinition$1<string>;
2937
+ /** True when requests route through the Standard Agents platform (hosted routing or a registered override). */
2938
+ viaPlatform: boolean;
2939
+ }
2933
2940
  /**
2934
2941
  * Provider registry implementation
2935
2942
  *
@@ -2954,11 +2961,7 @@ declare class ProviderRegistryImpl {
2954
2961
  * @param thread - Thread instance for loading model from virtual modules
2955
2962
  * @returns Provider and model definition
2956
2963
  */
2957
- getProvider(modelName: string, env: Env, thread?: ThreadInstance): Promise<{
2958
- provider: LLMProviderInterface;
2959
- modelName: string;
2960
- modelDef: ModelDefinition$1<string>;
2961
- }>;
2964
+ getProvider(modelName: string, env: Env, thread?: ThreadInstance): Promise<ProviderLookupResult>;
2962
2965
  private buildResult;
2963
2966
  private cacheAndReturn;
2964
2967
  private getProviderFingerprint;
package/dist/runtime.js CHANGED
@@ -195,6 +195,16 @@ function getGoogleFallbackPricing(modelId) {
195
195
  if (prefixMatch) return { ...prefixMatch.pricing, source: "google-static" };
196
196
  return null;
197
197
  }
198
+ function getAnthropicFallbackPricing(modelId) {
199
+ const normalized = normalizeModelId(modelId);
200
+ let best = null;
201
+ for (const entry of ANTHROPIC_MODEL_PRICING_PREFIXES) {
202
+ if (normalized.startsWith(entry.prefix) && (!best || entry.prefix.length > best.prefix.length)) {
203
+ best = entry;
204
+ }
205
+ }
206
+ return best ? { ...best.pricing, source: "anthropic-static" } : null;
207
+ }
198
208
  function getGroqFallbackPricing(modelId) {
199
209
  const pricing = GROQ_MODEL_PRICING[normalizeModelId(modelId)];
200
210
  return pricing ? { ...pricing, source: "groq-static" } : null;
@@ -225,6 +235,9 @@ function resolveModelPricing(modelDef, providerName) {
225
235
  source: "model"
226
236
  };
227
237
  }
238
+ if (providerName === "anthropic") {
239
+ return getAnthropicFallbackPricing(modelDef.model);
240
+ }
228
241
  if (providerName === "cerebras") {
229
242
  return getCerebrasFallbackPricing(modelDef.model);
230
243
  }
@@ -260,10 +273,29 @@ function calculateUsageCost(usage, pricing) {
260
273
  costTotal: roundCost(costInput + costOutput)
261
274
  };
262
275
  }
263
- var TOKENS_PER_MILLION, CEREBRAS_MODEL_PRICING, GOOGLE_MODEL_PRICING, GOOGLE_MODEL_PRICING_PREFIXES, GROQ_MODEL_PRICING, XAI_MODEL_PRICING;
276
+ var TOKENS_PER_MILLION, ANTHROPIC_MODEL_PRICING_PREFIXES, CEREBRAS_MODEL_PRICING, GOOGLE_MODEL_PRICING, GOOGLE_MODEL_PRICING_PREFIXES, GROQ_MODEL_PRICING, XAI_MODEL_PRICING;
264
277
  var init_pricing = __esm({
265
278
  "src/agents/pricing.ts"() {
266
279
  TOKENS_PER_MILLION = 1e6;
280
+ ANTHROPIC_MODEL_PRICING_PREFIXES = [
281
+ { prefix: "claude-fable-5", pricing: { inputPrice: 10, outputPrice: 50, cachedPrice: 1 } },
282
+ { prefix: "claude-mythos", pricing: { inputPrice: 10, outputPrice: 50, cachedPrice: 1 } },
283
+ { prefix: "claude-opus-4-8", pricing: { inputPrice: 5, outputPrice: 25, cachedPrice: 0.5 } },
284
+ { prefix: "claude-opus-4-7", pricing: { inputPrice: 5, outputPrice: 25, cachedPrice: 0.5 } },
285
+ { prefix: "claude-opus-4-6", pricing: { inputPrice: 5, outputPrice: 25, cachedPrice: 0.5 } },
286
+ { prefix: "claude-opus-4-5", pricing: { inputPrice: 5, outputPrice: 25, cachedPrice: 0.5 } },
287
+ { prefix: "claude-opus-4-1", pricing: { inputPrice: 15, outputPrice: 75, cachedPrice: 1.5 } },
288
+ { prefix: "claude-opus-4", pricing: { inputPrice: 15, outputPrice: 75, cachedPrice: 1.5 } },
289
+ { prefix: "claude-sonnet-4-6", pricing: { inputPrice: 3, outputPrice: 15, cachedPrice: 0.3 } },
290
+ { prefix: "claude-sonnet-4-5", pricing: { inputPrice: 3, outputPrice: 15, cachedPrice: 0.3 } },
291
+ { prefix: "claude-sonnet-4", pricing: { inputPrice: 3, outputPrice: 15, cachedPrice: 0.3 } },
292
+ { prefix: "claude-haiku-4-5", pricing: { inputPrice: 1, outputPrice: 5, cachedPrice: 0.1 } },
293
+ { prefix: "claude-3-7-sonnet", pricing: { inputPrice: 3, outputPrice: 15, cachedPrice: 0.3 } },
294
+ { prefix: "claude-3-5-sonnet", pricing: { inputPrice: 3, outputPrice: 15, cachedPrice: 0.3 } },
295
+ { prefix: "claude-3-5-haiku", pricing: { inputPrice: 0.8, outputPrice: 4, cachedPrice: 0.08 } },
296
+ { prefix: "claude-3-opus", pricing: { inputPrice: 15, outputPrice: 75, cachedPrice: 1.5 } },
297
+ { prefix: "claude-3-haiku", pricing: { inputPrice: 0.25, outputPrice: 1.25, cachedPrice: 0.03 } }
298
+ ];
267
299
  CEREBRAS_MODEL_PRICING = {
268
300
  "zai-glm-4.7": {
269
301
  inputPrice: 2.25,
@@ -926,9 +958,9 @@ var init_ProviderRegistry = __esm({
926
958
  const fingerprint = this.getProviderFingerprint(providerName, modelDef);
927
959
  const cached = this.providerCache.get(modelName);
928
960
  if (cached?.fingerprint === fingerprint) {
929
- return this.buildResult(cached.provider, modelDef);
961
+ return this.buildResult(cached.provider, modelDef, false);
930
962
  }
931
- return this.cacheAndReturn(modelName, createTestProvider(), modelDef, fingerprint);
963
+ return this.cacheAndReturn(modelName, createTestProvider(), modelDef, fingerprint, false);
932
964
  }
933
965
  const apiKey = this.getApiKeyForProvider(providerName, env);
934
966
  if (apiKey) {
@@ -945,19 +977,19 @@ var init_ProviderRegistry = __esm({
945
977
  const fingerprint = this.getProviderFingerprint(providerName, modelDef, config);
946
978
  const cached = this.providerCache.get(modelName);
947
979
  if (cached?.fingerprint === fingerprint) {
948
- return this.buildResult(cached.provider, modelDef);
980
+ return this.buildResult(cached.provider, modelDef, false);
949
981
  }
950
- return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint);
982
+ return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint, false);
951
983
  }
952
984
  if (this.providerOverrideFn) {
953
985
  const overrideFingerprint = this.getProviderFingerprint(`override:${this.providerOverrideRevision}`, modelDef);
954
986
  const overrideCached = this.providerCache.get(modelName);
955
987
  if (overrideCached?.fingerprint === overrideFingerprint) {
956
- return this.buildResult(overrideCached.provider, modelDef);
988
+ return this.buildResult(overrideCached.provider, modelDef, true);
957
989
  }
958
990
  const overrideProvider = this.providerOverrideFn(modelName, modelDef, env);
959
991
  if (overrideProvider) {
960
- return this.cacheAndReturn(modelName, overrideProvider, modelDef, overrideFingerprint);
992
+ return this.cacheAndReturn(modelName, overrideProvider, modelDef, overrideFingerprint, true);
961
993
  }
962
994
  }
963
995
  const routing = resolvePlatformRouting(providerName, env);
@@ -969,18 +1001,18 @@ var init_ProviderRegistry = __esm({
969
1001
  const fingerprint = this.getProviderFingerprint(`platform:${providerName}`, modelDef, config);
970
1002
  const cached = this.providerCache.get(modelName);
971
1003
  if (cached?.fingerprint === fingerprint) {
972
- return this.buildResult(cached.provider, modelDef);
1004
+ return this.buildResult(cached.provider, modelDef, true);
973
1005
  }
974
- return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint);
1006
+ return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint, true);
975
1007
  }
976
1008
  throw new Error(`No API key found for provider: ${providerName}. Set the provider key or STANDARD_AGENTS_API_KEY.`);
977
1009
  }
978
- buildResult(provider, modelDef) {
979
- return { provider, modelName: modelDef.model, modelDef };
1010
+ buildResult(provider, modelDef, viaPlatform) {
1011
+ return { provider, modelName: modelDef.model, modelDef, viaPlatform };
980
1012
  }
981
- cacheAndReturn(modelName, provider, modelDef, fingerprint) {
982
- this.providerCache.set(modelName, { provider, fingerprint });
983
- return this.buildResult(provider, modelDef);
1013
+ cacheAndReturn(modelName, provider, modelDef, fingerprint, viaPlatform) {
1014
+ this.providerCache.set(modelName, { provider, fingerprint, viaPlatform });
1015
+ return this.buildResult(provider, modelDef, viaPlatform);
984
1016
  }
985
1017
  getProviderFingerprint(providerName, modelDef, config) {
986
1018
  return JSON.stringify({
@@ -1661,7 +1693,7 @@ var init_LLMRequest = __esm({
1661
1693
  */
1662
1694
  static async callModel(modelId, context, state, logId) {
1663
1695
  const { ProviderRegistry: ProviderRegistry2 } = await Promise.resolve().then(() => (init_providers(), providers_exports));
1664
- const { provider, modelName, modelDef } = await ProviderRegistry2.getProvider(
1696
+ const { provider, modelName, modelDef, viaPlatform } = await ProviderRegistry2.getProvider(
1665
1697
  modelId,
1666
1698
  state.env,
1667
1699
  state.thread.instance
@@ -1795,6 +1827,7 @@ var init_LLMRequest = __esm({
1795
1827
  }
1796
1828
  };
1797
1829
  response._provider = provider;
1830
+ response._viaPlatform = viaPlatform;
1798
1831
  response._providerResponseId = providerResponseId;
1799
1832
  response._aggregate_response = {
1800
1833
  id: responseId,
@@ -1872,7 +1905,7 @@ var init_LLMRequest = __esm({
1872
1905
  try {
1873
1906
  const toolsCalled = response.tool_calls ? JSON.stringify(response.tool_calls.map((tc) => tc.function.name)) : null;
1874
1907
  const providerName = response._provider?.name;
1875
- const standardAgentsRouterUsed = providerName === "platform";
1908
+ const standardAgentsRouterUsed = response._viaPlatform === true || providerName === "platform";
1876
1909
  const resolvedPricing = resolveModelPricing(modelDef, providerName);
1877
1910
  const calculatedCost = calculateUsageCost(response.usage, resolvedPricing);
1878
1911
  const providerReportedCost = typeof response.usage.cost === "number" ? response.usage.cost : typeof response.usage.cost === "string" ? parseFloat(response.usage.cost) : null;
@@ -5977,7 +6010,7 @@ var init_FlowEngine = __esm({
5977
6010
  max_session_turns: newAgentDef.maxSessionTurns ?? null,
5978
6011
  side_a_label: newAgentDef.sideA?.label ?? null,
5979
6012
  side_a_agent_prompt: newAgentDef.sideA?.prompt ?? null,
5980
- side_a_stop_on_response: newAgentDef.sideA?.stopOnResponse ?? false,
6013
+ side_a_stop_on_response: newAgentDef.sideA?.stopOnResponse ?? true,
5981
6014
  side_a_stop_tool: newAgentDef.sideA?.stopTool ?? null,
5982
6015
  side_a_stop_tool_response_property: newAgentDef.sideA?.stopToolResponseProperty ?? null,
5983
6016
  side_a_max_steps: newAgentDef.sideA?.maxSteps ?? null,
@@ -5992,7 +6025,7 @@ var init_FlowEngine = __esm({
5992
6025
  side_a_session_status_attachments_property: sideASession.status.attachmentsProperty,
5993
6026
  side_b_label: newAgentDef.sideB?.label ?? null,
5994
6027
  side_b_agent_prompt: newAgentDef.sideB?.prompt ?? null,
5995
- side_b_stop_on_response: newAgentDef.sideB?.stopOnResponse ?? false,
6028
+ side_b_stop_on_response: newAgentDef.sideB?.stopOnResponse ?? true,
5996
6029
  side_b_stop_tool: newAgentDef.sideB?.stopTool ?? null,
5997
6030
  side_b_stop_tool_response_property: newAgentDef.sideB?.stopToolResponseProperty ?? null,
5998
6031
  side_b_max_steps: newAgentDef.sideB?.maxSteps ?? null,
@@ -17473,7 +17506,7 @@ ${resultContent}${attachmentSummary}`;
17473
17506
  max_session_turns: agentDef.maxSessionTurns,
17474
17507
  side_a_label: agentDef.sideA?.label,
17475
17508
  side_a_agent_prompt: qualifyPromptName(agentDef.sideA?.prompt),
17476
- side_a_stop_on_response: agentDef.sideA?.stopOnResponse ?? false,
17509
+ side_a_stop_on_response: agentDef.sideA?.stopOnResponse ?? true,
17477
17510
  side_a_stop_tool: agentDef.sideA?.stopTool,
17478
17511
  side_a_stop_tool_response_property: agentDef.sideA?.stopToolResponseProperty,
17479
17512
  side_a_max_steps: agentDef.sideA?.maxSteps,
@@ -17488,7 +17521,7 @@ ${resultContent}${attachmentSummary}`;
17488
17521
  side_a_session_status_attachments_property: sideASession.status.attachmentsProperty,
17489
17522
  side_b_label: agentDef.sideB?.label,
17490
17523
  side_b_agent_prompt: qualifyPromptName(agentDef.sideB?.prompt),
17491
- side_b_stop_on_response: agentDef.sideB?.stopOnResponse ?? false,
17524
+ side_b_stop_on_response: agentDef.sideB?.stopOnResponse ?? true,
17492
17525
  side_b_stop_tool: agentDef.sideB?.stopTool,
17493
17526
  side_b_stop_tool_response_property: agentDef.sideB?.stopToolResponseProperty,
17494
17527
  side_b_max_steps: agentDef.sideB?.maxSteps,
@@ -17666,7 +17699,7 @@ ${resultContent}${attachmentSummary}`;
17666
17699
  max_session_turns: agentDef.maxSessionTurns,
17667
17700
  side_a_label: agentDef.sideA?.label,
17668
17701
  side_a_agent_prompt: qualifyPromptName(agentDef.sideA?.prompt),
17669
- side_a_stop_on_response: agentDef.sideA?.stopOnResponse ?? false,
17702
+ side_a_stop_on_response: agentDef.sideA?.stopOnResponse ?? true,
17670
17703
  side_a_stop_tool: agentDef.sideA?.stopTool,
17671
17704
  side_a_stop_tool_response_property: agentDef.sideA?.stopToolResponseProperty,
17672
17705
  side_a_max_steps: agentDef.sideA?.maxSteps,
@@ -17681,7 +17714,7 @@ ${resultContent}${attachmentSummary}`;
17681
17714
  side_a_session_status_attachments_property: sideASession.status.attachmentsProperty,
17682
17715
  side_b_label: agentDef.sideB?.label,
17683
17716
  side_b_agent_prompt: qualifyPromptName(agentDef.sideB?.prompt),
17684
- side_b_stop_on_response: agentDef.sideB?.stopOnResponse ?? false,
17717
+ side_b_stop_on_response: agentDef.sideB?.stopOnResponse ?? true,
17685
17718
  side_b_stop_tool: agentDef.sideB?.stopTool,
17686
17719
  side_b_stop_tool_response_property: agentDef.sideB?.stopToolResponseProperty,
17687
17720
  side_b_max_steps: agentDef.sideB?.maxSteps,
@@ -17812,7 +17845,7 @@ ${resultContent}${attachmentSummary}`;
17812
17845
  max_session_turns: agentDef.maxSessionTurns,
17813
17846
  side_a_label: agentDef.sideA?.label,
17814
17847
  side_a_agent_prompt: qualifyPromptName(agentDef.sideA?.prompt),
17815
- side_a_stop_on_response: agentDef.sideA?.stopOnResponse ?? false,
17848
+ side_a_stop_on_response: agentDef.sideA?.stopOnResponse ?? true,
17816
17849
  side_a_stop_tool: agentDef.sideA?.stopTool,
17817
17850
  side_a_stop_tool_response_property: agentDef.sideA?.stopToolResponseProperty,
17818
17851
  side_a_max_steps: agentDef.sideA?.maxSteps,
@@ -17827,7 +17860,7 @@ ${resultContent}${attachmentSummary}`;
17827
17860
  side_a_session_status_attachments_property: sideASession.status.attachmentsProperty,
17828
17861
  side_b_label: agentDef.sideB?.label,
17829
17862
  side_b_agent_prompt: qualifyPromptName(agentDef.sideB?.prompt),
17830
- side_b_stop_on_response: agentDef.sideB?.stopOnResponse ?? false,
17863
+ side_b_stop_on_response: agentDef.sideB?.stopOnResponse ?? true,
17831
17864
  side_b_stop_tool: agentDef.sideB?.stopTool,
17832
17865
  side_b_stop_tool_response_property: agentDef.sideB?.stopToolResponseProperty,
17833
17866
  side_b_max_steps: agentDef.sideB?.maxSteps,