@standardagents/builder 0.27.10 → 0.27.12

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/index.js CHANGED
@@ -927,13 +927,25 @@ var init_ProviderRegistry = __esm({
927
927
  */
928
928
  async buildThreadScopedEnv(state) {
929
929
  const threadEnv = state.thread.metadata?.env ?? state.thread.metadata?.tenvs ?? null;
930
- const userId = state.thread.metadata?.user_id ?? null;
930
+ const agentBuilderId = state.env.AGENT_BUILDER.idFromName("singleton");
931
+ const agentBuilder = state.env.AGENT_BUILDER.get(agentBuilderId);
932
+ let userId = state.thread.metadata?.user_id ?? null;
933
+ let parent = state.thread.metadata?.parent ?? null;
934
+ let hops = 0;
935
+ while (!userId && parent && typeof agentBuilder.getThread === "function" && hops < 8) {
936
+ hops++;
937
+ try {
938
+ const parentThread = await agentBuilder.getThread(parent);
939
+ userId = parentThread?.user_id ?? null;
940
+ parent = parentThread?.parent ?? null;
941
+ } catch {
942
+ break;
943
+ }
944
+ }
931
945
  let userEnv = null;
932
- let diagnostic = userId ? "" : "no thread user_id";
946
+ let diagnostic = userId ? hops > 0 ? `owner via ${hops} parent hop(s)` : "" : "no thread user_id";
933
947
  if (userId) {
934
948
  try {
935
- const agentBuilderId = state.env.AGENT_BUILDER.idFromName("singleton");
936
- const agentBuilder = state.env.AGENT_BUILDER.get(agentBuilderId);
937
949
  if (typeof agentBuilder.getUserEnvEntries === "function") {
938
950
  const entries = await agentBuilder.getUserEnvEntries(userId);
939
951
  if (Array.isArray(entries) && entries.length > 0) {
@@ -1755,7 +1767,9 @@ var init_LLMRequest = __esm({
1755
1767
  console.error(`Error calling ${actualModelId} (attempt ${attempts}):`, error2);
1756
1768
  await this.logError(state, error2, "api_error", actualModelId, startTime, logId);
1757
1769
  if (attempts < MAX_RETRIES_PER_MODEL) {
1758
- const backoffMs = BACKOFF_BASE * Math.pow(2, attempts - 1);
1770
+ const base = BACKOFF_BASE * Math.pow(2, attempts - 1);
1771
+ const retryAfterMs = typeof error2?.retryAfter === "number" ? error2.retryAfter * 1e3 : 0;
1772
+ const backoffMs = Math.max(base, retryAfterMs);
1759
1773
  await this.sleep(backoffMs);
1760
1774
  previousLogId = logId;
1761
1775
  logId = void 0;