@standardagents/builder 0.27.9 → 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/runtime.d.ts CHANGED
@@ -3626,6 +3626,7 @@ declare class ProviderRegistryImpl {
3626
3626
  thread: {
3627
3627
  metadata?: {
3628
3628
  user_id?: string | null;
3629
+ parent?: string | null;
3629
3630
  env?: Record<string, unknown> | null;
3630
3631
  tenvs?: Record<string, unknown> | null;
3631
3632
  };
package/dist/runtime.js CHANGED
@@ -918,13 +918,25 @@ var init_ProviderRegistry = __esm({
918
918
  */
919
919
  async buildThreadScopedEnv(state) {
920
920
  const threadEnv = state.thread.metadata?.env ?? state.thread.metadata?.tenvs ?? null;
921
- const userId = state.thread.metadata?.user_id ?? null;
921
+ const agentBuilderId = state.env.AGENT_BUILDER.idFromName("singleton");
922
+ const agentBuilder = state.env.AGENT_BUILDER.get(agentBuilderId);
923
+ let userId = state.thread.metadata?.user_id ?? null;
924
+ let parent = state.thread.metadata?.parent ?? null;
925
+ let hops = 0;
926
+ while (!userId && parent && typeof agentBuilder.getThread === "function" && hops < 8) {
927
+ hops++;
928
+ try {
929
+ const parentThread = await agentBuilder.getThread(parent);
930
+ userId = parentThread?.user_id ?? null;
931
+ parent = parentThread?.parent ?? null;
932
+ } catch {
933
+ break;
934
+ }
935
+ }
922
936
  let userEnv = null;
923
- let diagnostic = userId ? "" : "no thread user_id";
937
+ let diagnostic = userId ? hops > 0 ? `owner via ${hops} parent hop(s)` : "" : "no thread user_id";
924
938
  if (userId) {
925
939
  try {
926
- const agentBuilderId = state.env.AGENT_BUILDER.idFromName("singleton");
927
- const agentBuilder = state.env.AGENT_BUILDER.get(agentBuilderId);
928
940
  if (typeof agentBuilder.getUserEnvEntries === "function") {
929
941
  const entries = await agentBuilder.getUserEnvEntries(userId);
930
942
  if (Array.isArray(entries) && entries.length > 0) {