@standardagents/builder 0.22.0 → 0.22.1

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.
@@ -5989,9 +5989,10 @@ var init_context = __esm({
5989
5989
  // src/agents/FlowEngine.ts
5990
5990
  var FlowEngine_exports = {};
5991
5991
  __export(FlowEngine_exports, {
5992
- FlowEngine: () => FlowEngine
5992
+ FlowEngine: () => FlowEngine,
5993
+ HookBlockedExecutionError: () => HookBlockedExecutionError
5993
5994
  });
5994
- var IMMEDIATE_BOOTSTRAP_TOOL_NAME, FlowEngine;
5995
+ var IMMEDIATE_BOOTSTRAP_TOOL_NAME, HookBlockedExecutionError, FlowEngine;
5995
5996
  var init_FlowEngine = __esm({
5996
5997
  "src/agents/FlowEngine.ts"() {
5997
5998
  init_types();
@@ -6002,6 +6003,12 @@ var init_FlowEngine = __esm({
6002
6003
  init_sessionTools();
6003
6004
  init_ThreadStateImpl();
6004
6005
  IMMEDIATE_BOOTSTRAP_TOOL_NAME = "bootstrap_immediate_subagent";
6006
+ HookBlockedExecutionError = class extends Error {
6007
+ constructor(message) {
6008
+ super(message);
6009
+ this.name = "HookBlockedExecutionError";
6010
+ }
6011
+ };
6005
6012
  FlowEngine = class _FlowEngine {
6006
6013
  static IMMEDIATE_SCOPED_ENV_CONTEXT_KEY = "__immediate_scoped_env_by_call_id";
6007
6014
  /**
@@ -6549,7 +6556,26 @@ This usually points to something I can't fix from here \u2014 for example the wo
6549
6556
  state.messageHistory = await this.loadMessageHistory(state);
6550
6557
  const context = await this.assembleContext(state);
6551
6558
  state.allowedTools = context.tools;
6552
- context.messages = await this.runPrefilterLLMHistoryHook(state, context.messages);
6559
+ try {
6560
+ context.messages = await this.runPrefilterLLMHistoryHook(state, context.messages);
6561
+ } catch (error) {
6562
+ if (error instanceof HookBlockedExecutionError) {
6563
+ const threadState = ThreadStateImpl.fromFlowState(state);
6564
+ await threadState.injectMessage({ role: "assistant", content: error.message });
6565
+ state.stopped = true;
6566
+ state.stoppedBy = state.currentSide;
6567
+ state.stopReason = error.message;
6568
+ state.stopReasonCode = "hook_blocked";
6569
+ state.emitTelemetry?.({
6570
+ type: "stopped",
6571
+ reason: state.stopReason,
6572
+ side: state.currentSide,
6573
+ timestamp: Date.now()
6574
+ });
6575
+ return;
6576
+ }
6577
+ throw error;
6578
+ }
6553
6579
  const pendingMessageId = await this.createPendingMessage(state);
6554
6580
  state.pendingMessageId = pendingMessageId;
6555
6581
  let responseStatus = "completed";
@@ -8705,6 +8731,9 @@ ${lines.join("\n\n")}`
8705
8731
  try {
8706
8732
  result = await executor(threadState, result);
8707
8733
  } catch (error) {
8734
+ if (error && typeof error === "object" && error.block === true) {
8735
+ throw new HookBlockedExecutionError(error instanceof Error ? error.message : String(error));
8736
+ }
8708
8737
  console.error("[Hooks] \u2717 Error running prefilter_llm_history hook:", error);
8709
8738
  }
8710
8739
  }
@@ -70189,7 +70218,13 @@ var approve_get_default = defineController2(async ({ req, env: env2, params }) =
70189
70218
  const code = params.code;
70190
70219
  if (!code) return page("Missing code", "This device link is malformed.", false);
70191
70220
  const authResult = await requireAuth(req, env2);
70192
- if (authResult instanceof Response) return authResult;
70221
+ if (authResult instanceof Response) {
70222
+ const url = new URL(req.url);
70223
+ const returnTo = encodeURIComponent(url.pathname);
70224
+ const hosted = Boolean(env2.STANDARD_AGENTS_HOSTED && String(env2.STANDARD_AGENTS_HOSTED) !== "0" && String(env2.STANDARD_AGENTS_HOSTED).toLowerCase() !== "false");
70225
+ const target = hosted ? `/api/auth/sa/start?return_to=${returnTo}` : `/login?return_to=${returnTo}`;
70226
+ return new Response(null, { status: 302, headers: { Location: `${url.origin}${target}` } });
70227
+ }
70193
70228
  if (authResult.authType === "api_key") {
70194
70229
  return page("Sign in required", "Device logins must be approved from a signed-in browser session.", false);
70195
70230
  }