@standardagents/builder 0.10.1-next.9e1860c → 0.11.0-next.0fa8695

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.
@@ -606,7 +606,6 @@ var init_OpenRouterProvider = __esm({
606
606
  );
607
607
  let content = "";
608
608
  let reasoning_content = "";
609
- let hasReasoningField = false;
610
609
  let reasoning_details = [];
611
610
  const toolCallsMap = /* @__PURE__ */ new Map();
612
611
  let finishReason = "";
@@ -633,16 +632,12 @@ var init_OpenRouterProvider = __esm({
633
632
  }
634
633
  if (choice.delta?.reasoning) {
635
634
  reasoning_content += choice.delta.reasoning;
636
- hasReasoningField = true;
637
635
  }
638
636
  if (choice.delta?.reasoning_details) {
639
637
  const details = choice.delta.reasoning_details;
640
638
  for (const item of details) {
641
639
  if (item.type === "reasoning.text") {
642
- if (!hasReasoningField) {
643
- reasoning_content += item.text || "";
644
- }
645
- reasoning_details.push(item);
640
+ reasoning_content += item.text || "";
646
641
  } else {
647
642
  reasoning_details.push(item);
648
643
  }
@@ -3679,7 +3674,7 @@ var init_FlowEngine = __esm({
3679
3674
  }
3680
3675
  const maxSteps = state.currentSide === "a" ? state.agentConfig.side_a_max_steps : state.agentConfig.side_b_max_steps;
3681
3676
  const currentSideStepCount = state.currentSide === "a" ? state.sideAStepCount : state.sideBStepCount;
3682
- if (typeof maxSteps === "number" && currentSideStepCount >= maxSteps) {
3677
+ if (maxSteps !== null && currentSideStepCount >= maxSteps) {
3683
3678
  state.stopped = true;
3684
3679
  state.stoppedBy = state.currentSide;
3685
3680
  state.emitTelemetry?.({
@@ -3690,7 +3685,7 @@ var init_FlowEngine = __esm({
3690
3685
  });
3691
3686
  return;
3692
3687
  }
3693
- if (state.agentConfig.type === "dual_ai" && typeof state.agentConfig.max_session_turns === "number") {
3688
+ if (state.agentConfig.type === "dual_ai" && state.agentConfig.max_session_turns !== null) {
3694
3689
  const completedExchanges = Math.min(state.sideAStepCount, state.sideBStepCount);
3695
3690
  if (completedExchanges >= state.agentConfig.max_session_turns) {
3696
3691
  state.stopped = true;
@@ -4007,7 +4002,7 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
4007
4002
  }
4008
4003
  }
4009
4004
  const maxSteps = state.currentSide === "a" ? state.agentConfig.side_a_max_steps : state.agentConfig.side_b_max_steps;
4010
- if (typeof maxSteps === "number") {
4005
+ if (maxSteps !== null) {
4011
4006
  const currentSideStepCount = state.currentSide === "a" ? state.sideAStepCount : state.sideBStepCount;
4012
4007
  const stepsRemaining = maxSteps - currentSideStepCount;
4013
4008
  let budgetMessage;
@@ -5008,14 +5003,14 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
5008
5003
  ${columns.join(", ")}
5009
5004
  FROM messages
5010
5005
  WHERE parent_id IS NULL
5011
- ORDER BY created_at ASC, rowid ASC
5006
+ ORDER BY created_at ASC
5012
5007
  `;
5013
5008
  const cursor = await storage.sql.exec(query);
5014
5009
  rows = cursor.toArray();
5015
5010
  }
5016
5011
  if (state.extraMessages && state.extraMessages.length > 0) {
5017
5012
  rows.push(...state.extraMessages);
5018
- rows.sort((a, b) => a.created_at - b.created_at || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
5013
+ rows.sort((a, b) => a.created_at - b.created_at);
5019
5014
  }
5020
5015
  const messages = rows.map((row) => ({
5021
5016
  id: row.id,
@@ -5809,10 +5804,24 @@ var index_post_default = defineController(() => {
5809
5804
  });
5810
5805
 
5811
5806
  // src/api/agents.get.ts
5812
- var agents_get_default = defineController(async ({ agents, agentNames }) => {
5807
+ var agents_get_default = defineController(async ({ agents, agentNames, prompts, promptNames }) => {
5813
5808
  if (!agents || !agentNames) {
5814
5809
  return Response.json({ agents: [] });
5815
5810
  }
5811
+ const promptMap = {};
5812
+ if (prompts && promptNames) {
5813
+ await Promise.all(
5814
+ promptNames.map(async (name) => {
5815
+ try {
5816
+ const loader = prompts[name];
5817
+ if (loader) {
5818
+ promptMap[name] = await loader();
5819
+ }
5820
+ } catch (error) {
5821
+ }
5822
+ })
5823
+ );
5824
+ }
5816
5825
  const agentList = await Promise.all(
5817
5826
  agentNames.map(async (name) => {
5818
5827
  try {
@@ -5821,19 +5830,38 @@ var agents_get_default = defineController(async ({ agents, agentNames }) => {
5821
5830
  return null;
5822
5831
  }
5823
5832
  const definition = await loader();
5833
+ const sideAPrompt = promptMap[definition.sideA?.prompt];
5834
+ const sideBPrompt = definition.sideB ? promptMap[definition.sideB?.prompt] : null;
5824
5835
  return {
5825
5836
  id: definition.name,
5826
5837
  name: definition.name,
5827
- title: definition.title || definition.name,
5838
+ title: definition.title,
5828
5839
  type: definition.type || "ai_human",
5829
- // Use sideA.prompt as the default prompt (new structure)
5830
- default_prompt: definition.sideA?.prompt || "",
5831
- // Model is now specified in the prompt definition, not the agent
5832
- default_model: "",
5833
- // Tools are now specified in the prompt definition, not the agent
5834
- tools: [],
5835
- side_a_agent_prompt: definition.sideA?.prompt || null,
5840
+ // Side A configuration
5841
+ side_a_label: definition.sideA?.label || null,
5842
+ side_a_agent_prompt: definition.sideA?.prompt,
5843
+ side_a_agent_prompt_name: sideAPrompt?.name || definition.sideA?.prompt,
5844
+ side_a_stop_on_response: definition.sideA?.stopOnResponse !== void 0 ? definition.sideA.stopOnResponse : true,
5845
+ side_a_stop_tool: definition.sideA?.stopTool || null,
5846
+ side_a_stop_tool_response_property: definition.sideA?.stopToolResponseProperty || null,
5847
+ side_a_max_steps: definition.sideA?.maxSteps || null,
5848
+ side_a_end_session_tool: definition.sideA?.endSessionTool || null,
5849
+ side_a_manual_stop_condition: definition.sideA?.manualStopCondition || false,
5850
+ // Side B configuration (if dual_ai)
5851
+ side_b_label: definition.sideB?.label || null,
5836
5852
  side_b_agent_prompt: definition.sideB?.prompt || null,
5853
+ side_b_agent_prompt_name: sideBPrompt?.name || definition.sideB?.prompt || null,
5854
+ side_b_stop_on_response: definition.sideB?.stopOnResponse !== void 0 ? definition.sideB.stopOnResponse : true,
5855
+ side_b_stop_tool: definition.sideB?.stopTool || null,
5856
+ side_b_stop_tool_response_property: definition.sideB?.stopToolResponseProperty || null,
5857
+ side_b_max_steps: definition.sideB?.maxSteps || null,
5858
+ side_b_end_session_tool: definition.sideB?.endSessionTool || null,
5859
+ side_b_manual_stop_condition: definition.sideB?.manualStopCondition || false,
5860
+ // Session configuration
5861
+ max_session_turns: definition.maxSessionTurns || null,
5862
+ // Tool exposure
5863
+ expose_as_tool: definition.exposeAsTool || false,
5864
+ tool_description: definition.toolDescription || null,
5837
5865
  created_at: Math.floor(Date.now() / 1e3)
5838
5866
  };
5839
5867
  } catch (error) {
@@ -6030,12 +6058,6 @@ function base64ToBuffer(base64) {
6030
6058
  }
6031
6059
 
6032
6060
  // src/middleware/auth.ts
6033
- var CORS_HEADERS = {
6034
- "Access-Control-Allow-Origin": "*",
6035
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
6036
- "Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With",
6037
- "Access-Control-Max-Age": "86400"
6038
- };
6039
6061
  function extractBearerToken(request) {
6040
6062
  const authHeader = request.headers.get("Authorization");
6041
6063
  if (authHeader && authHeader.startsWith("Bearer ")) {
@@ -6124,7 +6146,7 @@ async function requireAuth(request, env) {
6124
6146
  if (!authContext) {
6125
6147
  return new Response(JSON.stringify({ error: "Unauthorized" }), {
6126
6148
  status: 401,
6127
- headers: { "Content-Type": "application/json", ...CORS_HEADERS }
6149
+ headers: { "Content-Type": "application/json" }
6128
6150
  });
6129
6151
  }
6130
6152
  return authContext;
@@ -6139,7 +6161,7 @@ async function requireAdmin(request, env) {
6139
6161
  JSON.stringify({ error: "Forbidden: Admin access required" }),
6140
6162
  {
6141
6163
  status: 403,
6142
- headers: { "Content-Type": "application/json", ...CORS_HEADERS }
6164
+ headers: { "Content-Type": "application/json" }
6143
6165
  }
6144
6166
  );
6145
6167
  }
@@ -6551,20 +6573,12 @@ var threads_default = defineController(async ({ req, env }) => {
6551
6573
  const limit = parseInt(url.searchParams.get("limit") || "50", 10);
6552
6574
  const offset = parseInt(url.searchParams.get("offset") || "0", 10);
6553
6575
  const agentName = url.searchParams.get("agent_id");
6554
- const search = url.searchParams.get("search");
6555
- const startDateParam = url.searchParams.get("startDate");
6556
- const endDateParam = url.searchParams.get("endDate");
6557
- const startDate = startDateParam ? parseInt(startDateParam, 10) : void 0;
6558
- const endDate = endDateParam ? parseInt(endDateParam, 10) : void 0;
6559
6576
  const userId = auth.user.role === "admin" ? void 0 : auth.user.id;
6560
6577
  const agentBuilderId = env.AGENT_BUILDER.idFromName("singleton");
6561
6578
  const agentBuilder = env.AGENT_BUILDER.get(agentBuilderId);
6562
6579
  const result = await agentBuilder.listThreads({
6563
6580
  agent_name: agentName || void 0,
6564
6581
  user_id: userId || void 0,
6565
- search: search || void 0,
6566
- startDate,
6567
- endDate,
6568
6582
  limit,
6569
6583
  offset
6570
6584
  });
@@ -7681,57 +7695,6 @@ function parseOpenRouterEndpoints(data) {
7681
7695
  }));
7682
7696
  }
7683
7697
 
7684
- // src/api/models/[name]/curl-data.get.ts
7685
- var PROVIDER_ENDPOINTS = {
7686
- openai: "https://api.openai.com/v1/chat/completions",
7687
- openrouter: "https://openrouter.ai/api/v1/chat/completions",
7688
- anthropic: "https://api.anthropic.com/v1/messages",
7689
- google: "https://generativelanguage.googleapis.com/v1beta/models"
7690
- };
7691
- var PROVIDER_ENV_KEYS = {
7692
- openai: "OPENAI_API_KEY",
7693
- openrouter: "OPENROUTER_API_KEY",
7694
- anthropic: "ANTHROPIC_API_KEY",
7695
- google: "GOOGLE_API_KEY"
7696
- };
7697
- var curl_data_get_default = defineController(async ({ params, models, env }) => {
7698
- const { name } = params;
7699
- if (!models || !models[name]) {
7700
- return Response.json({ error: "Model not found" }, { status: 404 });
7701
- }
7702
- try {
7703
- const loader = models[name];
7704
- const definition = await loader();
7705
- const provider = definition.provider.toLowerCase();
7706
- const endpoint = PROVIDER_ENDPOINTS[provider];
7707
- if (!endpoint) {
7708
- return Response.json(
7709
- { error: `Unknown provider: ${provider}` },
7710
- { status: 400 }
7711
- );
7712
- }
7713
- const envKey = PROVIDER_ENV_KEYS[provider];
7714
- const apiKey = envKey ? env[envKey] : null;
7715
- if (!apiKey) {
7716
- return Response.json(
7717
- { error: `API key not configured for provider: ${provider}` },
7718
- { status: 400 }
7719
- );
7720
- }
7721
- return Response.json({
7722
- endpoint,
7723
- api_key: apiKey,
7724
- sdk: provider
7725
- });
7726
- } catch (error) {
7727
- console.error(`Error loading model ${name}:`, error);
7728
- return Response.json(
7729
- { error: `Error loading model: ${error}` },
7730
- { status: 500 }
7731
- );
7732
- }
7733
- });
7734
-
7735
7698
  // src/api/threads/[id]/cost.get.ts
7736
7699
  var cost_get_default = defineController(async ({ req, params, env }) => {
7737
7700
  const threadId = params.id;
@@ -8665,7 +8628,6 @@ var routeHandlers = {
8665
8628
  "GET:/auth/me": me_get_default,
8666
8629
  "POST:/models/available": available_post_default,
8667
8630
  "POST:/models/endpoints": endpoints_post_default,
8668
- "GET:/models/:name/curl-data": curl_data_get_default,
8669
8631
  "GET:/threads/:id/cost": cost_get_default,
8670
8632
  "GET:/threads/:id/fs": fs_default,
8671
8633
  "GET:/threads/:id/logs": logs_get_default,