@standardagents/builder 0.27.10 → 0.27.11

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) {