@standardagents/builder 0.27.5 → 0.27.7

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.
@@ -915,6 +915,42 @@ var init_ProviderRegistry = __esm({
915
915
  this.providerOverrideFn = fn;
916
916
  this.providerOverrideRevision += 1;
917
917
  }
918
+ /**
919
+ * The env a provider resolves against for a given execution, scoped to the
920
+ * THREAD rather than just the instance: thread env overrides win, then the
921
+ * thread OWNER's user env, then instance/Worker env. This is what makes
922
+ * per-user BYOK providers work — a credential a user installs in their own
923
+ * account env (e.g. an OAuth token a companion service rotates) is honored
924
+ * for that user's threads no matter which authorized actor plays the turn.
925
+ *
926
+ * Best-effort by design: a missing user id (super-admin/local threads) or
927
+ * an older AgentBuilder DO without user-env storage simply contributes
928
+ * nothing, leaving instance-env behavior untouched.
929
+ */
930
+ async buildThreadScopedEnv(state) {
931
+ const threadEnv = state.thread.metadata?.env ?? state.thread.metadata?.tenvs ?? null;
932
+ const userId = state.thread.metadata?.user_id ?? null;
933
+ let userEnv = null;
934
+ if (userId) {
935
+ try {
936
+ const agentBuilderId = state.env.AGENT_BUILDER.idFromName("singleton");
937
+ const agentBuilder = state.env.AGENT_BUILDER.get(agentBuilderId);
938
+ if (typeof agentBuilder.getUserEnvEntries === "function") {
939
+ const entries = await agentBuilder.getUserEnvEntries(userId);
940
+ if (Array.isArray(entries) && entries.length > 0) {
941
+ userEnv = {};
942
+ for (const entry of entries) {
943
+ if (entry?.name) userEnv[entry.name] = entry.value;
944
+ }
945
+ }
946
+ }
947
+ } catch (error) {
948
+ console.warn("buildThreadScopedEnv: user env unavailable:", error instanceof Error ? error.message : String(error));
949
+ }
950
+ }
951
+ if (!userEnv && !threadEnv) return state.env;
952
+ return { ...state.env, ...userEnv ?? {}, ...threadEnv ?? {} };
953
+ }
918
954
  /**
919
955
  * Get provider for a model.
920
956
  *
@@ -1826,7 +1862,8 @@ var init_LLMRequest = __esm({
1826
1862
  */
1827
1863
  static async callModel(modelId, context, state, logId) {
1828
1864
  const { ProviderRegistry: ProviderRegistry2 } = await Promise.resolve().then(() => (init_providers(), providers_exports));
1829
- const { provider, modelName, modelDef, viaPlatform, platformProxyOrigin } = await ProviderRegistry2.getProvider(modelId, state.env, state.thread.instance);
1865
+ const providerEnv = await ProviderRegistry2.buildThreadScopedEnv(state);
1866
+ const { provider, modelName, modelDef, viaPlatform, platformProxyOrigin } = await ProviderRegistry2.getProvider(modelId, providerEnv, state.thread.instance);
1830
1867
  const streamAbort = new AbortController();
1831
1868
  const parentSignal = state.abortController?.signal;
1832
1869
  let onParentAbort;
@@ -66192,7 +66229,7 @@ var config_get_default = defineController2(async ({ config, env: env2, req }) =>
66192
66229
  });
66193
66230
 
66194
66231
  // src/version.ts
66195
- var BUILDER_VERSION = "0.27.5".length > 0 ? "0.27.5" : "dev";
66232
+ var BUILDER_VERSION = "0.27.7".length > 0 ? "0.27.7" : "dev";
66196
66233
 
66197
66234
  // src/api/diagnostics.get.ts
66198
66235
  init_LLMRequest();