@standardagents/builder 0.24.2 → 0.24.4

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.
@@ -1323,10 +1323,14 @@ function buildRequestBody(context, modelDef) {
1323
1323
  visionFiltering
1324
1324
  };
1325
1325
  }
1326
- function buildProviderRequest(context, modelDef, signal) {
1326
+ function buildProviderRequest(context, modelDef, signal, user) {
1327
1327
  const { requestBody } = buildRequestBody(context, modelDef);
1328
1328
  return {
1329
1329
  ...requestBody,
1330
+ // Stable per-thread identity: providers that support it (OpenRouter's
1331
+ // provider-sticky routing) pin the thread to one upstream, which is what
1332
+ // makes prompt caching hit across consecutive steps.
1333
+ user,
1330
1334
  signal
1331
1335
  };
1332
1336
  }
@@ -1673,7 +1677,7 @@ var init_LLMRequest = __esm({
1673
1677
  parentSignal.addEventListener("abort", onParentAbort, { once: true });
1674
1678
  }
1675
1679
  }
1676
- const request = buildProviderRequest(context, modelDef, streamAbort.signal);
1680
+ const request = buildProviderRequest(context, modelDef, streamAbort.signal, state.threadId);
1677
1681
  let response;
1678
1682
  await state.stream.waitFor(
1679
1683
  async () => {
@@ -5990,8 +5994,22 @@ var init_context = __esm({
5990
5994
  var FlowEngine_exports = {};
5991
5995
  __export(FlowEngine_exports, {
5992
5996
  FlowEngine: () => FlowEngine,
5993
- HookBlockedExecutionError: () => HookBlockedExecutionError
5997
+ HookBlockedExecutionError: () => HookBlockedExecutionError,
5998
+ stepBudgetMessage: () => stepBudgetMessage
5994
5999
  });
6000
+ function stepBudgetMessage(stepsRemaining) {
6001
+ if (stepsRemaining > 20) return null;
6002
+ if (stepsRemaining === 0) {
6003
+ return "[STEP BUDGET] \u26A0\uFE0F CRITICAL: You must complete your task NOW or an error will be thrown. This is your final step.";
6004
+ }
6005
+ if (stepsRemaining === 1) {
6006
+ return "[STEP BUDGET] \u26A0\uFE0F CRITICAL: Only 1 step available after this before an error will be thrown. Reach completion immediately.";
6007
+ }
6008
+ if (stepsRemaining <= 3) {
6009
+ return `[STEP BUDGET] \u26A0\uFE0F WARNING: Only ${stepsRemaining} steps available before an error will be thrown. Reach completion as soon as possible.`;
6010
+ }
6011
+ return `[STEP BUDGET] ${stepsRemaining} steps available before an error will be thrown. Work efficiently toward completion.`;
6012
+ }
5995
6013
  var IMMEDIATE_BOOTSTRAP_TOOL_NAME, HookBlockedExecutionError, FlowEngine;
5996
6014
  var init_FlowEngine = __esm({
5997
6015
  "src/agents/FlowEngine.ts"() {
@@ -7823,20 +7841,13 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
7823
7841
  if (typeof maxSteps === "number" && !isNaN(maxSteps)) {
7824
7842
  const currentSideStepCount = state.currentSide === "a" ? state.sideAStepCount : state.sideBStepCount;
7825
7843
  const stepsRemaining = maxSteps - currentSideStepCount;
7826
- let budgetMessage;
7827
- if (stepsRemaining === 0) {
7828
- budgetMessage = "[STEP BUDGET] \u26A0\uFE0F CRITICAL: You must complete your task NOW or an error will be thrown. This is your final step.";
7829
- } else if (stepsRemaining === 1) {
7830
- budgetMessage = "[STEP BUDGET] \u26A0\uFE0F CRITICAL: Only 1 step available after this before an error will be thrown. Reach completion immediately.";
7831
- } else if (stepsRemaining <= 3) {
7832
- budgetMessage = `[STEP BUDGET] \u26A0\uFE0F WARNING: Only ${stepsRemaining} steps available before an error will be thrown. Reach completion as soon as possible.`;
7833
- } else {
7834
- budgetMessage = `[STEP BUDGET] ${stepsRemaining} steps available before an error will be thrown. Work efficiently toward completion.`;
7844
+ const budgetMessage = stepBudgetMessage(stepsRemaining);
7845
+ if (budgetMessage) {
7846
+ messages.push({
7847
+ role: "system",
7848
+ content: budgetMessage
7849
+ });
7835
7850
  }
7836
- messages.push({
7837
- role: "system",
7838
- content: budgetMessage
7839
- });
7840
7851
  }
7841
7852
  const subagentRegistry = await this.getSubagentRegistry(state);
7842
7853
  if (subagentRegistry.length > 0) {
@@ -54686,7 +54697,7 @@ function transformChatAssistantMessage3(msg) {
54686
54697
  }));
54687
54698
  }
54688
54699
  if (msg.reasoningDetails && msg.reasoningDetails.length > 0) {
54689
- message.reasoning_details = msg.reasoningDetails.map((detail) => {
54700
+ const details = msg.reasoningDetails.filter((detail) => detail.type !== "encrypted" || typeof detail.data === "string" && detail.data.length > 0).map((detail) => {
54690
54701
  if (detail.type === "text") {
54691
54702
  return { type: "reasoning.text", text: detail.text, format: detail.format };
54692
54703
  } else if (detail.type === "summary") {
@@ -54694,6 +54705,9 @@ function transformChatAssistantMessage3(msg) {
54694
54705
  }
54695
54706
  return { type: "reasoning.encrypted", data: detail.data, id: detail.id, format: detail.format };
54696
54707
  });
54708
+ if (details.length > 0) {
54709
+ message.reasoning_details = details;
54710
+ }
54697
54711
  }
54698
54712
  return message;
54699
54713
  }
@@ -55012,12 +55026,14 @@ function processChatStreamChunk2(chunk, state) {
55012
55026
  } else if (detail.type === "reasoning.summary") {
55013
55027
  accumulateReasoningDetail(state, detail);
55014
55028
  } else if (detail.type === "reasoning.encrypted") {
55015
- state.reasoningDetails.push({
55016
- type: "encrypted",
55017
- id: detail.id,
55018
- data: detail.data,
55019
- format: detail.format
55020
- });
55029
+ if (typeof detail.data === "string" && detail.data.length > 0) {
55030
+ state.reasoningDetails.push({
55031
+ type: "encrypted",
55032
+ id: detail.id,
55033
+ data: detail.data,
55034
+ format: detail.format
55035
+ });
55036
+ }
55021
55037
  }
55022
55038
  }
55023
55039
  }
@@ -55212,6 +55228,9 @@ function buildChatParams3(request) {
55212
55228
  }
55213
55229
  }
55214
55230
  }
55231
+ if (request.user) {
55232
+ params.user = request.user;
55233
+ }
55215
55234
  const safeOptions = splitOpenRouterProviderOptions(
55216
55235
  request.providerOptions
55217
55236
  );
@@ -55733,6 +55752,9 @@ function buildCreateParams3(request) {
55733
55752
  }
55734
55753
  }
55735
55754
  }
55755
+ if (request.user) {
55756
+ params.user = request.user;
55757
+ }
55736
55758
  const providerOptions = splitOpenRouterProviderOptions(
55737
55759
  request.providerOptions
55738
55760
  );