@standardagents/builder 0.9.13 → 0.9.15

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/plugin.js CHANGED
@@ -2051,12 +2051,12 @@ function agentbuilder(options = {}) {
2051
2051
  }
2052
2052
  return {
2053
2053
  name: "vite-plugin-agent",
2054
+ enforce: "pre",
2054
2055
  config() {
2055
2056
  const depsToExclude = [
2056
2057
  "@standardagents/builder",
2057
2058
  "@standardagents/builder/runtime",
2058
- "@standardagents/builder/built-in-routes",
2059
- "@standardagents/builder/mcp"
2059
+ "@standardagents/builder/built-in-routes"
2060
2060
  ];
2061
2061
  return {
2062
2062
  optimizeDeps: {
@@ -2065,8 +2065,6 @@ function agentbuilder(options = {}) {
2065
2065
  exclude: depsToExclude
2066
2066
  },
2067
2067
  ssr: {
2068
- // Only MCP should be external (not used in worker)
2069
- external: ["@standardagents/builder/mcp"],
2070
2068
  // noExternal ensures Vite transforms these instead of leaving as external
2071
2069
  // The Cloudflare plugin handles the actual bundling and knows about cloudflare:workers
2072
2070
  noExternal: [
@@ -2074,11 +2072,6 @@ function agentbuilder(options = {}) {
2074
2072
  "@standardagents/builder/runtime",
2075
2073
  "@standardagents/builder/built-in-routes"
2076
2074
  ]
2077
- },
2078
- build: {
2079
- rollupOptions: {
2080
- external: ["@standardagents/builder/mcp"]
2081
- }
2082
2075
  }
2083
2076
  };
2084
2077
  },
@@ -2087,8 +2080,7 @@ function agentbuilder(options = {}) {
2087
2080
  const depsToExclude = [
2088
2081
  "@standardagents/builder",
2089
2082
  "@standardagents/builder/runtime",
2090
- "@standardagents/builder/built-in-routes",
2091
- "@standardagents/builder/mcp"
2083
+ "@standardagents/builder/built-in-routes"
2092
2084
  ];
2093
2085
  config.optimizeDeps = config.optimizeDeps || {};
2094
2086
  config.optimizeDeps.exclude = [
@@ -2833,6 +2825,101 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
2833
2825
  return;
2834
2826
  }
2835
2827
  }
2828
+ if (pathWithoutMount === "/api/prompts" && method === "GET") {
2829
+ try {
2830
+ const fs4 = await import('fs');
2831
+ const files = fs4.existsSync(promptsDir) ? fs4.readdirSync(promptsDir).filter((f) => f.endsWith(".ts")) : [];
2832
+ const modelFiles = fs4.existsSync(modelsDir) ? fs4.readdirSync(modelsDir).filter((f) => f.endsWith(".ts")) : [];
2833
+ const modelMap = {};
2834
+ for (const file of modelFiles) {
2835
+ try {
2836
+ const filePath = path3.join(modelsDir, file);
2837
+ const content = fs4.readFileSync(filePath, "utf-8");
2838
+ const name = content.match(/name:\s*['"]([^'"]+)['"]/)?.[1];
2839
+ const provider = content.match(/provider:\s*['"]([^'"]+)['"]/)?.[1];
2840
+ if (name) {
2841
+ modelMap[name] = { name, provider: provider || "unknown" };
2842
+ }
2843
+ } catch (error) {
2844
+ }
2845
+ }
2846
+ const promptList = files.map((file) => {
2847
+ try {
2848
+ const filePath = path3.join(promptsDir, file);
2849
+ const content = fs4.readFileSync(filePath, "utf-8");
2850
+ const getName = (c) => c.match(/name:\s*['"]([^'"]+)['"]/)?.[1];
2851
+ const getToolDescription = (c) => c.match(/toolDescription:\s*['"]([^'"]+)['"]/)?.[1];
2852
+ const getModel = (c) => c.match(/model:\s*['"]([^'"]+)['"]/)?.[1];
2853
+ const getIncludeChat = (c) => c.match(/includeChat:\s*(true|false)/)?.[1] === "true";
2854
+ const getIncludePastTools = (c) => c.match(/includePastTools:\s*(true|false)/)?.[1] === "true";
2855
+ const getParallelToolCalls = (c) => c.match(/parallelToolCalls:\s*(true|false)/)?.[1] === "true";
2856
+ const getToolChoice = (c) => c.match(/toolChoice:\s*['"]([^'"]+)['"]/)?.[1];
2857
+ const getBeforeTool = (c) => c.match(/beforeTool:\s*['"]([^'"]+)['"]/)?.[1];
2858
+ const getAfterTool = (c) => c.match(/afterTool:\s*['"]([^'"]+)['"]/)?.[1];
2859
+ const getTools = (c) => {
2860
+ const match = c.match(/tools:\s*\[([^\]]*)\]/);
2861
+ if (!match) return [];
2862
+ const items = match[1].match(/['"]([^'"]+)['"]/g);
2863
+ return items ? items.map((s) => s.replace(/['"]/g, "")) : [];
2864
+ };
2865
+ const getHandoffAgents = (c) => {
2866
+ const match = c.match(/handoffAgents:\s*\[([^\]]*)\]/);
2867
+ if (!match) return [];
2868
+ const items = match[1].match(/['"]([^'"]+)['"]/g);
2869
+ return items ? items.map((s) => s.replace(/['"]/g, "")) : [];
2870
+ };
2871
+ const getPrompt = (c) => {
2872
+ const backtickMatch = c.match(/prompt:\s*`([\s\S]*?)`/);
2873
+ if (backtickMatch) return backtickMatch[1];
2874
+ const quotedMatch = c.match(/prompt:\s*['"]([^'"]*)['"]/);
2875
+ if (quotedMatch) return quotedMatch[1];
2876
+ const arrayMatch = c.match(/prompt:\s*(\[[\s\S]*?\])/);
2877
+ if (arrayMatch) return arrayMatch[1];
2878
+ return "";
2879
+ };
2880
+ const name = getName(content);
2881
+ if (!name) return null;
2882
+ const modelId = getModel(content);
2883
+ const modelDef = modelId ? modelMap[modelId] : null;
2884
+ return {
2885
+ id: name,
2886
+ name,
2887
+ tool_description: getToolDescription(content) || "",
2888
+ prompt: getPrompt(content),
2889
+ required_schema: null,
2890
+ // Complex to parse, skip for now
2891
+ model_id: modelId || "",
2892
+ model_name: modelDef?.name || modelId || "",
2893
+ model_provider: modelDef?.provider || "unknown",
2894
+ include_chat: getIncludeChat(content),
2895
+ include_past_tools: getIncludePastTools(content),
2896
+ parallel_tool_calls: getParallelToolCalls(content),
2897
+ tool_choice: getToolChoice(content) || "auto",
2898
+ before_tool: getBeforeTool(content) || null,
2899
+ after_tool: getAfterTool(content) || null,
2900
+ tools: getTools(content),
2901
+ prompts: getHandoffAgents(content),
2902
+ reasoning: null,
2903
+ // Complex to parse
2904
+ created_at: Math.floor(Date.now() / 1e3)
2905
+ };
2906
+ } catch (error) {
2907
+ console.error(`Error loading prompt ${file}:`, error);
2908
+ return null;
2909
+ }
2910
+ });
2911
+ const validPrompts = promptList.filter(Boolean);
2912
+ res.statusCode = 200;
2913
+ res.setHeader("Content-Type", "application/json");
2914
+ res.end(JSON.stringify({ prompts: validPrompts }));
2915
+ return;
2916
+ } catch (error) {
2917
+ res.statusCode = 500;
2918
+ res.setHeader("Content-Type", "application/json");
2919
+ res.end(JSON.stringify({ error: error.message || "Failed to list prompts" }));
2920
+ return;
2921
+ }
2922
+ }
2836
2923
  if (pathWithoutMount === "/api/prompts" && method === "POST") {
2837
2924
  try {
2838
2925
  const rawBody = await parseRequestBody(req);
@@ -2958,6 +3045,54 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
2958
3045
  return;
2959
3046
  }
2960
3047
  }
3048
+ if (pathWithoutMount === "/api/agents" && method === "GET") {
3049
+ try {
3050
+ const fs4 = await import('fs');
3051
+ const files = fs4.existsSync(agentsDir) ? fs4.readdirSync(agentsDir).filter((f) => f.endsWith(".ts")) : [];
3052
+ const agentList = files.map((file) => {
3053
+ try {
3054
+ const filePath = path3.join(agentsDir, file);
3055
+ const content = fs4.readFileSync(filePath, "utf-8");
3056
+ const getName = (c) => c.match(/name:\s*['"]([^'"]+)['"]/)?.[1];
3057
+ const getTitle = (c) => c.match(/title:\s*['"]([^'"]+)['"]/)?.[1];
3058
+ const getType = (c) => c.match(/type:\s*['"]([^'"]+)['"]/)?.[1];
3059
+ const getDefaultPrompt = (c) => c.match(/defaultPrompt:\s*['"]([^'"]+)['"]/)?.[1];
3060
+ const getDefaultModel = (c) => c.match(/defaultModel:\s*['"]([^'"]+)['"]/)?.[1];
3061
+ const getTools = (c) => {
3062
+ const match = c.match(/tools:\s*\[([^\]]*)\]/);
3063
+ if (!match) return [];
3064
+ const items = match[1].match(/['"]([^'"]+)['"]/g);
3065
+ return items ? items.map((s) => s.replace(/['"]/g, "")) : [];
3066
+ };
3067
+ const name = getName(content);
3068
+ if (!name) return null;
3069
+ return {
3070
+ id: name,
3071
+ name,
3072
+ title: getTitle(content) || name,
3073
+ type: getType(content) || "ai_human",
3074
+ default_prompt: getDefaultPrompt(content) || "",
3075
+ default_model: getDefaultModel(content) || "",
3076
+ tools: getTools(content),
3077
+ created_at: Math.floor(Date.now() / 1e3)
3078
+ };
3079
+ } catch (error) {
3080
+ console.error(`Error loading agent ${file}:`, error);
3081
+ return null;
3082
+ }
3083
+ });
3084
+ const validAgents = agentList.filter(Boolean);
3085
+ res.statusCode = 200;
3086
+ res.setHeader("Content-Type", "application/json");
3087
+ res.end(JSON.stringify({ agents: validAgents }));
3088
+ return;
3089
+ } catch (error) {
3090
+ res.statusCode = 500;
3091
+ res.setHeader("Content-Type", "application/json");
3092
+ res.end(JSON.stringify({ error: error.message || "Failed to list agents" }));
3093
+ return;
3094
+ }
3095
+ }
2961
3096
  if (pathWithoutMount === "/api/agents" && method === "POST") {
2962
3097
  try {
2963
3098
  const rawBody = await parseRequestBody(req);